This repository has been archived by the owner on Aug 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·66 lines (52 loc) · 1.63 KB
/
setup.sh
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
60
61
62
63
64
65
66
#!/bin/bash
# backup setup script
#TODO: implement safety checks for directory
# sets key $1 with value $2 in config file
storeToConfig() {
sed -i '' "s/\(${1} *= *\).*/\1${2//\//\\/}/" backup.config
}
# store value $1 to target config file
storeToTargets() {
echo "${1}" >>targets.config
}
# store to crontab function
storeToCrontab() {
crontab -l | {
cat echo "${1}"
} | crontab -
}
# check if backup file exists
if [[ -s "backup.config" ]]; then
source "backup.config"
else
echo "fatal: no config file found"
exit 1
fi
# check if targets file exists
if [[ -s "targets.config" ]]; then
echo "fatal: no targets file found"
exit 1
fi
# welcome message
echo "\n Welcome to the backup setup \n"
# get and save directory for backups
echo "Please enter the directory where u want to store your compressed backups"
read -p "prompt: enter backup directory: " backupDirectory
storeToConfig "backupDirectory" ${backupDirectory}
echo "Please enter the directory u want to backup"
while [[ ! ${doneAddingTargets} =~ ^[Nn]$ ]]; do
read -p "prompt: enter directory to backup: " targetDirectory
echo "info: writing to targets..."
storeToTargets ${targetDirectory}
read -p "prompt: do u want to add another one? (Y/n): " doneAddingTargets
done
# Ask for cronjob setup
read -p "prompt: would you like to run your backups automatically daily with a cronjob? (Y/n): " cronjobAnswer
# Check for answer
if [[ $cronjobAnswer =~ ^[Yy]$ ]]; then
echo "info: set scripts directory"
# store directory of scripts
scriptsDirectory=$(pwd)
echo "info: write daily backup to crontab"
To "0 0 * * * cd ${scriptsDirectory} && ./backup.sh"
fi