-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.sh
executable file
·280 lines (238 loc) · 6.22 KB
/
configure.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/bash
pause(){
read -p "$*"
}
# Clear screeen
clear(){
echo -en "\ec"
}
question_header(){
local QUESTION=$1
echo
echo "#######################################################################"
echo "##### $QUESTION"
echo "#######################################################################"
echo
}
check_webserver(){
# Check for Apache
if [[ `ps -acx|grep apache|wc -l` > 0 ]]; then
echo "VM Configured with Apache"
WEB_SERVER="Apache"
return;
fi
# Check for Nginx
if [[ `ps -acx|grep nginx|wc -l` > 0 ]]; then
echo "VM Configured with Nginx"
WEB_SERVER="Nginx"
return;
fi
WEB_SERVER="None"
}
node_config(){
# Q1 : Link to GitHub Repo
while true; do
read -p "Connect to GitHub Repository (y or n) ? " yn
case $yn in
[Yy]* ) GITHUB=true; break;;
[Nn]* ) GITHUB=false; break;;
* ) echo "Please answer (y)es or (n)o";;
esac
done
# Q2 : Install Mongoose DataBase
while true; do
read -p "Add Mongoose DataBase (y or n) ? " yn
case $yn in
[Yy]* ) MONGOOSE=true; break;;
[Nn]* ) MONGOOSE=false; break;;
* ) echo "Please answer (y)es or (n)o";;
esac
done
# Q3 : Choose Port for instance
while true; do
read -e -p "Port Number (4000-9999) - [8080] : " -i 8080 PORT
if [[ $PORT -gt 4000 && $PORT -lt 9999 ]]; then break; fi
done
}
wp_config(){
echo "Config Wordpress"
}
static_config(){
# Q1 : Link to GitHub Repo
while true; do
read -p "Connect to GitHub Repository (y or n) ? " yn
case $yn in
[Yy]* ) GITHUB=true; break;;
[Nn]* ) GITHUB=false; break;;
* ) echo "Please answer (y)es or (n)o";;
esac
done
}
resume_choices(){
local _SITE_NR=$1
# Resume choices
question_header "Resume choices for WebSite n°$_SITE_NR"
echo -e "Domain-name : ${RED}$DOMAIN${NC}"
echo -e "Configure SSL : ${RED}$SSL${NC}"
echo -e "Running Environnement : ${RED}$ENV${NC}"
if [[ "$ENV" == "NodeJS" ]]; then
echo -e "Connect to GitHub : ${RED}$GITHUB${NC}"
echo -e "Port Number : ${RED}$PORT${NC}"
echo -e "Install Mongoose : ${RED}$MONGOOSE${NC}"
fi
if [[ "$ENV" == "Wordpress" ]]; then
echo -e "Modules to install : ${RED}$MODULES${NC}"
echo -e "Teplates to use : ${RED}$TEMPLATES${NC}"
fi
if [[ "$ENV" == "Static" ]]; then
echo ""
fi
echo
}
#### STATIC VALUES #####
RED='\033[0;31m'
NC='\033[0m' # No Color
#### DEFAULT VALUES ####
INSTALL_WS=true
WEB_SERVER="None"
UNSECURE_HTTP=false
NB_SITES=0
clear
## Check if script can launch
## Check if lauched with sudo privileges, else quit
if ! [ $(id -u) = 0 ]; then
echo "The script need to be run as root." >&2
exit 1
fi
## Check linux version, only Debian 9.x for now
if !(lsb_release --description | grep -q 'Debian GNU/Linux 9.'); then
echo "The script works only on Debian 9.x." >&2
exit 1
fi
################# UPDATE MIRRORS #################
question_header "UPDATING MIRRORS"
./web_server.sh --update-mirrors
clear
##################################################
## Check if Apache or Nginx Installed
check_webserver
echo "---> Actual WebServer detected : $WEB_SERVER"
echo
## Select WebServer to install
if [[ $WEB_SERVER == "None" ]];
then
INSTALL_WS=true
#Choose WebServer
PS3='What WebServer do you want to install ? : '
options=("Apache" "Nginx")
select webSrv in "${options[@]}"
do
case $webSrv in
"Apache")
#./web_server.sh --install "Apache" $authorizeHTTP;
WEB_SERVER="Apache"
break;;
"Nginx")
#./web_server.sh --install "Nginx" $authorizeHTTP;
WEB_SERVER="Nginx"
break;;
*)
;;
esac
done
################# INSTALL WEB SERVER #########################
question_header "INSTALLING WEBSERVER"
./web_server.sh --install $WEB_SERVER
##############################################################
fi
# Authorize HTTP connection (Unsecure) ?
while true; do
read -p "Authorize unsecure HTTP access (y or n) ? " yn
case $yn in
[Yy]* ) UNSECURE_HTTP=true; break;;
[Nn]* ) UNSECURE_HTTP=false; break;;
* ) ;;
esac
done
################# UPDATE WEB SERVER FIREWALL #################
question_header "UPDATING FIREWALL"
./web_server.sh --update-firewall $WEB_SERVER $UNSECURE_HTTP
##############################################################
question_header "CONFIGURE SITES INSTANCES"
#How much site instances do you want to create ?
while true; do
read -p "How much site instances (1-10) " NB_SITES
if [[ "$NB_SITES" =~ ^[0-9]+$ ]]; then break; fi
done
## Loops though instances and configure them
for (( i=1; i<=$NB_SITES; i++ ))
do
while true; do
#### DEFAULT VALUES ####
DOMAIN=
SSL=false
ENV=
GITHUB=false
=8080
MONGOOSE=false
MODULES=[]
TEMPLATES=[]
#clear
question_header "Configuring site n°$i"
# Q1 : Get the domain name
read -p "Domain-name : " DOMAIN
# Q2 : Install SSL
while true; do
read -p "Configure SSL (y or N) ? " yn
case $yn in
[Yy]* ) SSL=true; break;;
[Nn]* ) SSL=false; break;;
* ) ;;
esac
done
echo
# Q3 : Get Running Environnement
PS3='Pre-installed Environnement : '
options=("NodeJS" "Wordpress" "Static")
select ENV in "${options[@]}"
do
case $ENV in
"NodeJS")
node_config
break;;
"Wordpress")
wp_config
break;;
"Static")
static_config
break;;
*)
;;
esac
done
resume_choices $i
# Validate choices ?
read -p "Do you confirm that information (y or n) ? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) clear; echo "Starting over";;
* ) echo "Please answer (y)es or (n)o";;
esac
done
# Make installation
question_header "Installing site $DOMAIN ... "
case $ENV in
"NodeJS")
./web_server.sh --add-site $ENV --server $WEB_SERVER --secure $SSL --domain $DOMAIN --github $GITHUB --port $PORT --mongoose $MONGOOSE
break;;
"Wordpress")
./web_server.sh --add-site $ENV --server $WEB_SERVER --secure $SSL --domain $DOMAIN ## TODO --module $MODULES[i] --template $TEMPLATE []
;;
"Static")
./web_server.sh --add-site $ENV --server $WEB_SERVER --secure $SSL --domain $DOMAIN --github $GITHUB
break;;
*)
echo "Nothing to install"
;;
esac
done