-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·111 lines (95 loc) · 2.15 KB
/
install
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
#
# Automating BACKUP's
function make_executable() {
echo "------- Permissions ----------"
echo "- Making the scripts executeable"
chmod +x runner backup_script
}
function create_folders() {
echo "-------- Folders ----------"
mkdir -p ~/automate
echo "- Backup Folder Created: ~/automate"
cp project_backup.json ~/automate/
echo "- Copied sample project_backup.json file in ~/automate"
}
function setup_cron() {
echo "------- CRON ----------"
echo "- Setting UP CRON tab for backups after every $1 days"
crontab -l > cronfile
echo "0 0 */$1 * * $PWD/runner" >> cronfile
crontab cronfile
rm cronfile
}
function display_command() {
echo "===> $1"
}
function install_expect() {
echo "- Trying to install expect"
if [[ ! -z `which apt-get` ]]; then
cmd="sudo apt-get install -y expect"
display_command $cmd
$cmd
elif [[ ! -z `which yum` ]]; then
cmd="sudo yum install -y expect"
display_command $cmd
$cmd
elif [[ ! -z `which brew` ]]; then
cmd="brew install expect"
display_command $cmd
$cmd
fi
}
function check_expect() {
echo "-------- Checking for expect ----------"
if [[ -z `which expect` ]]; then
install_expect
if [[ -z `which expect` ]]; then
echo "- ******** Failed to install EXPECT, will not be able to backup files to Remote SERVER ***********"
fi
fi
}
cronSetup="no"
cronDays="3"
while [[ $# -ge 1 ]]
do
key="$1"
case $key in
-c|--cron)
cronSetup="$2"
shift
;;
-d|--days)
cronDays="$2"
shift
;;
-h|--help)
cat <<- EOF
Usage ./install --cron yes --days 4
Available Options:
--cron -c yes|no Whether Cron should be executed
--days -d int No of days after which the cron should be executed
To Take the Backup Manually do
./runner
EOF
exit
;;
*)
echo "Help DOC ./install --help"
exit
;;
esac
shift # past argument or value
done
check_expect
make_executable
create_folders
# Setup cron if required
cronSetup=$(echo $cronSetup | tr [A-Z] [a-z])
if [[ $cronSetup == "yes" || $cronSetup == "y" ]]; then
setup_cron $cronDays
else
echo "-------- INFO ---------"
echo "- Cron was not installed by the USER"
fi
# Installation complete