-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
executable file
·59 lines (49 loc) · 1.76 KB
/
init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
source_directory=$(dirname "${BASH_SOURCE[0]}")
configuration_file_path="$source_directory/database-backup.config"
database_backups_path_default="$HOME/database-backups"
keep_for_days_default=10
function init_configuration_file {
if [ -n "$DATABASE_BACKUPS_PATH" ]; then
database_backups_path=${DATABASE_BACKUPS_PATH}
else
read -r -p "Enter the database backups storage directory path [$database_backups_path_default]: " input_path_backups
database_backups_path=${input_path_backups:-$database_backups_path_default}
fi
if [ -n "$DATABASE_BACKUPS_KEEP_FOR_DAYS" ]; then
keep_for_days=${DATABASE_BACKUPS_KEEP_FOR_DAYS:-$keep_for_days_default}
else
read -r -p "Number of days to keep the backups for [$keep_for_days_default]: " input_keep_for_days
keep_for_days=${input_keep_for_days:-$keep_for_days_default}
fi
{
echo "DATABASE_BACKUPS_PATH=$database_backups_path"
echo "DATABASE_BACKUPS_KEEP_FOR_DAYS=$keep_for_days"
} > "$configuration_file_path"
echo "Configuration saved to $configuration_file_path"
}
function init_my_cnf {
my_cnf_path="$HOME/my.cnf"
touch "$my_cnf_path"
chmod 0600 "$my_cnf_path"
if ! grep -q "[client]" "$my_cnf_path"; then
if [ -n "$DATABASE_BACKUPS_USERNAME" ]; then
username="$DATABASE_BACKUPS_USERNAME"
else
read -r -p "Username: " username
fi
if [ -n "$DATABASE_BACKUPS_PASSWORD" ]; then
password="$DATABASE_BACKUPS_PASSWORD"
else
read -r -s -p "Password: " password
fi
{
echo "[client]"
echo "user=$username"
echo "password=\"$password\""
} >> "$my_cnf_path"
echo ""
echo "Database credentials saved to $my_cnf_path"
fi
}
init_configuration_file && init_my_cnf