11#! /bin/bash
22
3+ # # Parameters parsing
4+ for i in " $@ "
5+ do
6+ case $i in
7+ -s|--silent)
8+ NODIALOG=1
9+ shift
10+ ;;
11+ -p=* |--port=* )
12+ PORT=" ${i#* =} "
13+ shift
14+ ;;
15+ -h=* |--hostname=* )
16+ SERVERNAME=" ${i#* =} "
17+ shift
18+ ;;
19+ -e=* |--launch-env=* )
20+ ASPENV=" ${i#* =} "
21+ shift
22+ ;;
23+ -u=* |--username=* )
24+ CURENTUSER=" ${i#* =} "
25+ shift
26+ ;;
27+ --ssl)
28+ SSL=" y"
29+ shift
30+ ;;
31+ * )
32+ # unknown option
33+ ;;
34+ esac
35+ done
36+
37+ # Defaults
38+
39+ if [[ -z " $PORT " ]]; then
40+ PORT=80
41+ fi
42+
43+ if [[ -z " $ASPENV " ]]; then
44+ ASPENV=" Production"
45+ fi
46+
47+ if [[ -z " $SSL " ]]; then
48+ SSL=" n"
49+ fi
50+
51+
352dialog_progress () {
4- echo " $1 " | dialog --guage " $2 " 10 70 0
53+ if [[ -z " $NODIALOG " ]]; then
54+ echo " $1 " | dialog --guage " $2 " 10 70 0
55+ else
56+ echo " [$1 %] Installing: $2 "
57+ fi
558}
659
760install_node () {
@@ -11,18 +64,18 @@ install_node() {
1164}
1265
1366adding_mircosoft_cert () {
14- wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
15- mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
16- wget -q https://packages.microsoft.com/config/ubuntu/18.04/prod.list
17- mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
18- chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
19- chown root:root /etc/apt/sources.list.d/microsoft-prod.list
67+ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
68+ mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
69+ wget -q https://packages.microsoft.com/config/ubuntu/18.04/prod.list
70+ mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
71+ chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
72+ chown root:root /etc/apt/sources.list.d/microsoft-prod.list
2073}
2174
2275install_dotnetcore () {
2376 apt install -y apt-transport-https && \
2477 apt update && \
25- apt install -y aspnetcore -runtime-2.1 dotnet-sdk-2.1
78+ apt install -y dotnet -runtime-2.2 dotnet-sdk-2.2
2679}
2780
2881setup_nginx_conf () {
@@ -68,27 +121,19 @@ preparing_backend() {
68121 su $CURENTUSER -c \
69122 " npm i && npm run build"
70123
71- # dialog_progress 70 "Building Web API"
72-
73124 cd ../eFormAPI/eFormAPI.Web/
74125 su $CURENTUSER -c \
75126 " dotnet publish -o out"
76127 mkdir -p /opt/www/aspnetcore/eform-app
77128 mkdir -p /out/www/aspnetcore/eform-app/wwwroot
78129
79- # dialog_progress 80 "Copy WebAPI to /opt"
80-
81130 rsync -aP out/* /opt/www/aspnetcore/eform-app
82131
83- # dialog_progress 85 "Copy Web Dashboard to /opt"
84-
85132 cd ../../
86133 cd eform-client
87134 rsync -aP dist/* /opt/www/aspnetcore/eform-app/wwwroot
88135 chown -R www-data:www-data /opt/www
89136
90- # dialog_progress 85 "Register eForm service in systemctl"
91-
92137 cat > /etc/systemd/system/eform.service << EndOfUnitFile
93138[Unit]
94139Description=eForm application
@@ -107,47 +152,97 @@ WantedBy=multi-user.target
107152EndOfUnitFile
108153}
109154
155+ setup_ssl () {
156+ add-apt-repository -y ppa:certbot/certbot >> logfile 2>> errlog
157+ apt update >> logfile 2>> errlog && \
158+ apt install -y python-certbot-nginx >> logfile 2>> errlog
159+ certbot --nginx -d $SERVERNAME --redirect --register-unsafely-without-email --agree-tos --non-interactive >> logfile 2>> errlog
160+ if [[ $? != 0 ]]; then
161+ showerror " SSL installing failed"
162+ fi
163+ }
164+
165+ dialog_form () {
166+ # # Install dialog framework
167+ apt update && apt install -y dialog
168+
169+ exec 3>&1
170+ PARAMS=$( dialog --ok-label " Install" \
171+ --backtitle " Microting eForm setup wizard" \
172+ --title " Configuration" \
173+ --form " Define installation parameters for eForm installer" 15 80 0 \
174+ " Username(Required):" 1 1 " $CURENTUSER " 1 20 40 0 \
175+ " hostname(optional):" 2 1 " $SERVERNAME " 2 20 40 0 \
176+ " Launch environment:" 3 1 " $ASPENV " 3 20 40 0 \
177+ " Port:" 4 1 " $PORT " 4 20 40 0 \
178+ " SSL(y/n):" 5 1 " $SSL " 5 20 40 0 \
179+ 2>&1 1>&3 )
180+
181+ if [[ $? != 0 ]];
182+ then
183+ exit 0; # Cancel button pressed
184+ fi
185+
186+ exec 3>& -
187+
188+ ARRAY=($PARAMS )
189+
190+ if [[ ${# ARRAY[@]} < 4 ]]; then
191+ showerror " Not all required fields filed!"
192+ exit 1
193+ fi
194+
195+ if [[ ${# ARRAY[@]} == 4 ]]; then
196+ CURENTUSER=${ARRAY[0,0]}
197+ SERVERNAME=" "
198+ ASPENV=${ARRAY[0,1]}
199+ PORT=${ARRAY[0,2]}
200+ SSL=${ARRAY[0,3]}
201+ else
202+ CURENTUSER=${ARRAY[0,0]}
203+ SERVERNAME=${ARRAY[0,1]}
204+ ASPENV=${ARRAY[0,2]}
205+ PORT=${ARRAY[0,3]}
206+ SSL=${ARRAY[0,4]}
207+ fi
208+ }
209+
210+ showerror () {
211+ if [[ -z " $NODIALOG " ]]; then
212+ dialog --title " Error" --msgbox " '$1 '" 10 50
213+ exit 1
214+ else
215+ echo " Error: $1 "
216+ exit 1
217+ fi
218+ }
219+
110220# # INIT
111221if [[ $EUID -ne 0 ]]; then
112- echo " Run this script via sudo"
222+ echo " Error: Run this script via sudo"
113223 exit 1
114224fi
115225
116- # # Install dialog framework
117- apt update && apt install -y dialog
118-
119- exec 3>&1
120- PARAMS=$( dialog --ok-label " Install" \
121- --backtitle " Microting eForm setup wizard" \
122- --title " Configuration" \
123- --form " Define installation parameters for eForm installer" 15 80 0 \
124- " Username(Required):" 1 1 " " 1 20 40 0 \
125- " hostname(optional):" 2 1 " " 2 20 40 0 \
126- " Launch environment:" 3 1 " Production" 3 20 40 0 \
127- " Port:" 4 1 " 80" 4 20 40 0 \
128- 2>&1 1>&3 )
129- exec 3>& -
130-
131- ARRAY=($PARAMS )
132-
133- if [[ ${# ARRAY[@]} < 3 ]]; then
134- dialog --title " Error" --msgbox ' Not all required fields filed!' 6 20
135- exit 1
136- fi
226+ # Windows CMD.exe dialog fix
227+ export NCURSES_NO_UTF8_ACS=1
137228
138- if [[ ${# ARRAY[@]} == 3 ]]; then
139- CURENTUSER=${ARRAY[0,0]}
140- SERVERNAME=" "
141- ASPENV=${ARRAY[0,1]}
142- PORT=${ARRAY[0,2]}
229+ # # Dialog/cmd params wizard switch
230+ if [[ -z " $NODIALOG " ]]; then
231+ dialog_form
143232else
144- CURENTUSER=${ARRAY[0,0]}
145- SERVERNAME=${ARRAY[0,1]}
146- ASPENV=${ARRAY[0,2]}
147- PORT=${ARRAY[0,3]}
233+ echo " non-interactive installing started!"
234+ fi
235+
236+ # Last validations
237+ if [[ ( -z " $SERVERNAME " ) && ( " $SSL " == " y" ) ]]; then
238+ showerror " SSL require servername specified!"
239+ fi
240+
241+ if [[ -z " $CURENTUSER " ]]; then
242+ showerror " Username not specified!"
148243fi
149244
150- # # Installing
245+ # # Installing scenario
151246
152247dialog_progress 0 " Installing nodejs"
153248install_node >> logfile 2>> errlog
@@ -163,18 +258,23 @@ dialog_progress 25 "Installing NGINX"
163258apt install -y nginx >> logfile 2>> errlog
164259
165260dialog_progress 30 " Setting default host at default config"
166- setup_nginx_conf
261+ setup_nginx_conf >> logfile 2>> errlog
167262
168263dialog_progress 40 " Reloading nginx"
169264nginx -s reload >> logfile 2>> errlog
170265
171266dialog_progress 50 " Cloning project"
172267su $CURENTUSER -c \
173- " git clone https://github.com/microting/eform-angular-frontend.git -b netcore " > logfile 2> errlog
268+ " git clone https://github.com/microting/eform-angular-frontend.git -b master " > logfile 2> errlog
174269
175270dialog_progress 60 " Preparing WEB dashboard"
176271preparing_backend >> logfile 2>> errlog
177272
273+ if [[ " $SSL " == " y" ]]; then
274+ dialog_progress 75 " Installing LetsEncrypt"
275+ setup_ssl
276+ fi
277+
178278dialog_progress 90 " Starting eForm"
179279systemctl daemon-reload >> logfile 2>> errlog
180280systemctl enable eform.service >> logfile 2>> errlog
@@ -184,7 +284,10 @@ dialog_progress 100 "Cleanup"
184284cd ../../
185285rm -rf eform-angular-frontend >> logfile 2>> errlog
186286
187- clear
188- dialog --title " Ready" --msgbox ' eForms installed! Check logfile and errorfile if something wrong' 6 20
287+ if [[ -z " $NODIALOG " ]]; then
288+ dialog --title " Ready" --msgbox ' eForms installed! Check logfile and errorfile if something wrong' 6 20
289+ else
290+ echo " eForms installed! Check logfile and errorfile if something wrong"
291+ fi
189292
190- clear
293+ exit 0
0 commit comments