-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
106 lines (92 loc) · 2.72 KB
/
run.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
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
#!/bin/bash
. ./deploy_lib/Log.sh
. ./deploy_lib/Installer.sh
. ./deploy_lib/const.sh
argVerbose=0
argToken=""
argSsh=""
while getopts "v:a:s:" option; do
case "${option}" in
v)
argVerbose=1
;;
a)
argToken=${OPTARG}
;;
s)
argSsh=${OPTARG}
;;
esac
done
seds() {
sed -i '' "s/TOKEN_SED/$argToken/g" deploy_lib/const.sh
sed -i '' "s/TOKEN_SED/$argToken/g" tf/terraform.auto.tfvars
sed -i '' "s/SSH_SED/$argSsh/g" tf/terraform.auto.tfvars
}
prepareLocalEnv() {
infoColor="1;35m"
echo "\n\n\n\n\n\n"
inf "local environment" "Application boot started. Preparing environment..."
createWorkDir 2>/dev/null
isError=$?
if [[ $isError -eq 1 ]]; then
err "local environment" "Can not create work directory. Directory does not exist. Program will exit now as this is vital for its functionality."
exit
fi
installPython 2>&1 | tee $WORKDIR/log/local.log
installLinodeCli 2>&1 | tee $WORKDIR/log/local.log
# special sign removal (some shit colours)
cd $WORKDIR
seds
echo "\n\n"
inf "local application" "App started by $(whoami)"
sh Local.sh
}
createWorkDir() {
if [ -d "$WORKDIR" ]; then
inf "local environment" "Work directory already exists. If terraform files were changed, it requires manual deletion."
else
mkdir $WORKDIR
cd $WORKDIR
mkdir log
mkdir db
cd ..
inf "local environment" "Success - Create work directory"
fi
populateWorkFolder
}
populateWorkFolder() {
if [ -n "$(ls -A $WORKDIR/tf 2>/dev/null)" ]; then
inf "local environment" "Terraform folder already exists, overwrite is not performed automatically."
else
cp -r ./tf $WORKDIR
isError=$?
if [[ $isError -eq 1 ]]; then
err "local environment" "Can not copy terraform folder. Check if working directory exists or root folder is OK"
exit
fi
inf "local environment" "Success - Copy terraform files to work directory"
fi
cp -r ./deploy_lib $WORKDIR
isError=$?
if [[ $isError -eq 1 ]]; then
err "local environment" "Can not copy deploy_lib folder. Check if working directory exists or root folder is OK"
exit
fi
inf "local environment" "Success - Copy deploy_lib files to work directory"
cp -r ./bin $WORKDIR
isError=$?
if [[ $isError -eq 1 ]]; then
err "local environment" "Can not copy bin folder. Check if working directory exists or root folder is OK"
exit
fi
inf "local environment" "Success - Copy bin files to work directory"
cp ./deploy_lib/Local.sh $WORKDIR
isError=$?
if [[ $isError -eq 1 ]]; then
err "local environment" "Can not copy run script. Check if working directory exists or root folder is OK"
exit
fi
inf "local environment" "Success - Copy run script files to work directory"
}
prepareLocalEnv