1
1
#! /bin/bash
2
2
set -euo pipefail
3
3
IFS=$' \t '
4
- NONINTERACTIVE=" yes"
5
- export DEBIAN_FRONTEND=" noninteractive"
6
4
7
5
# Setting some path
8
6
declare -r DIR=" $( cd " $( dirname " $0 " ) " && pwd ) "
9
7
declare -r DIR_TOOLS=" $( cd " $DIR /tools" && pwd ) "
10
8
declare -r DIR_CONF=" $( cd " $DIR /conf" && pwd ) "
11
- declare -r FILE_LOG=" $( cd " $DIR /log" && pwd ) /install .log"
9
+ declare -r FILE_LOG=" $( cd " $DIR /log" && pwd ) /main .log"
12
10
13
11
# Put all output to logfile
14
12
exec 3>&1 1>> ${FILE_LOG} 2>&1
15
13
16
- [ ! -f " $DIR_CONF /settings.sh" ] && cp " $DIR_CONF /settings.sh.default" " $DIR_CONF /settings.sh"
17
-
18
14
. $DIR_CONF /applicationVersions.sh
19
15
. $DIR_CONF /settings.sh
20
16
. $DIR_TOOLS /precheck.sh
21
17
. $DIR_TOOLS /functions.sh
22
18
19
+ log_headline ` basename " $0 " `
20
+
23
21
while true
24
22
do {
25
23
ping -c1 www.google.com > /dev/null && break
28
26
}
29
27
done
30
28
31
- log " $( date +%T ) script was started"
32
-
33
29
[ ! $( which sudo ) ] && install_package sudo
34
30
35
31
# Setting default values
@@ -73,7 +69,7 @@ infoscreen "Setting" "public ipv6"
73
69
# }
74
70
# }
75
71
76
- [ ! " ${SSHD_PERMITROOTLOGIN:- } " == " yes" ] && {
72
+ [[ ! ${SSHD_PERMITROOTLOGIN:- } == " yes" ] ] && {
77
73
[ ! -z " ${USER_ID:- } " ] && [ ! -z " ${USER_PASSWORD:- } " ] || { echo " User credential not set in config file" ; exit 1; }
78
74
[ ! " ${SSHD_PASSWORDAUTH:- } " == " yes" ] && {
79
75
[ ! " $SSHD_PASSWORDAUTH " == " yes" ] && [ -z " ${USER_SSHKEY:- } " ] && [ ! -f $DIR_CONF /.ssh/keys ] && { echo -e " Global varible USER_SSHKEY not set in config file and there is no sshkey file.\nBut required as no password is acceptet for login" ; exit 1; }
@@ -88,6 +84,16 @@ infoscreen "Setting" "public ipv6"
88
84
} || infoscreenfailed
89
85
}
90
86
87
+ # ##################################################################################
88
+ # Check configuration
89
+ # ##################################################################################
90
+ [[ ( ${NGINX_INSTALL:- } == " on" && ${NGINX_COMPILE:- } == " on" ) ]] && {
91
+ infoscreenfailed " Your settings.sh file have configuration error\nNGINX_INSTALL and NGINX_COMPILE can't both be set to 'on'"
92
+ CHECK_ERROR=1
93
+ }
94
+
95
+ [ ${CHECK_ERROR:- } ] && exit 1
96
+
91
97
# ##################################################################################
92
98
# Servername
93
99
# ##################################################################################
@@ -103,9 +109,9 @@ infoscreen "Setting" "public ipv6"
103
109
# ##################################################################################
104
110
# Creating a priviliged user
105
111
# ##################################################################################
106
- [ ! -z ${USER_ID:- } ] && {
112
+ [ ${USER_ID:- } ] && {
107
113
infoscreen " Adding" " priviliged user ${USER_ID} "
108
- [ ! $( id -u " ${USER_ID} " ) ] && useradd -create-home -s " $USER_SHELL " $( lower " $USER_ID " -p " $USER_PASSWORD " )
114
+ [ ! $( id -u " ${USER_ID} " ) ] && useradd -- create-home -s " $USER_SHELL " $( lower " $USER_ID " -p " $USER_PASSWORD " )
109
115
case $OS in
110
116
" Debian GNU/Linux" )
111
117
adduser " $USER_ID " sudo
@@ -117,7 +123,7 @@ infoscreen "Setting" "public ipv6"
117
123
usermod -aG wheel " $USER_ID "
118
124
;;
119
125
esac
120
- USER_HOME=` system_get_user_home " $USER_ID " `
126
+ USER_HOME=$( system_get_user_home $USER_ID )
121
127
[ ! -d " $USER_HOME /.ssh" ] && sudo -u " $USER_ID " mkdir " $USER_HOME /.ssh"
122
128
[ -f $DIR_CONF /.ssh/keys ] && {
123
129
cp -f $DIR_CONF /.ssh/keys $USER_HOME /.ssh/authorized_keys
@@ -131,7 +137,7 @@ infoscreen "Setting" "public ipv6"
131
137
}
132
138
infoscreendone
133
139
134
- [ ! " $SSHD_PASSWORDAUTH " == " yes" ] && [ ! -f " $USER_HOME /.ssh/authorized_keys" ] && {
140
+ [[ ! $SSHD_PASSWORDAUTH == " yes" ] ] && [ ! -f " $USER_HOME /.ssh/authorized_keys" ] && {
135
141
dialog --title " copy client " \
136
142
--colors \
137
143
--msgbox \
@@ -176,26 +182,27 @@ infoscreendone
176
182
# ##################################################################################
177
183
# Nginx
178
184
# ##################################################################################
179
- [[ ! ( " ${NGINX_INSTALL :- } " == " on " && " ${ NGINX_COMPILE:- }" == " on" ) ]] && {
185
+ [[ ${ NGINX_COMPILE:- } == " on" ]] && {
180
186
181
- [ ! $( id -u www-data) ] && useradd www-data --user-group -s /sbin/nologin
187
+ $DIR_TOOLS /nginx.sh compile --nginx-ver $NGINX_VER
188
+ install_package stunnel4
189
+ [ -f $DIR_CONF /stunnel4/stunnel.conf ] && cp -f $DIR_CONF /stunnel4/stunnel.conf /etc/stunnel/
182
190
183
- [ " ${NGINX_INSTALL:- } " == " on" ] && {
184
- infoscreen " installing" " nginx"
185
- $DIR_TOOLS /nginx.sh install
186
- infoscreendone
187
- }
191
+ [[ ( -f /srv/www/default/html/live.html && ! -z " ${PUBLIC_IPV4:- } " ) ]] && sed -i " s@HOSTNAME_OR_IP@$PUBLIC_IPV4 @g" /srv/www/default/html/live.html
192
+ iptables -A INPUT -p tcp --dport 1935 -m state --state NEW,ESTABLISHED -j ACCEPT # rtmp for live broadcasting
193
+ cat $DIR_CONF /nginx/rtmp.conf >> /etc/nginx/nginx.conf
194
+ }
188
195
189
- [ " ${NGINX_COMPILE :- }" == " on" ] && {
190
- infoscreen " building " " nginx $NGINX_VER "
191
- $DIR_TOOLS /nginx.sh compile --nginx-ver $NGINX_VER
192
- infoscreendone
193
- install_package stunnel4
194
- [ -f $DIR_CONF /stunnel4/stunnel.conf ] && cp -f $DIR_CONF /stunnel4/stunnel.conf /etc/stunnel/
195
- }
196
+ [[ ${NGINX_INSTALL :- } == " on" ] ] && {
197
+ $DIR_TOOLS / nginx.sh install
198
+ [ -f /srv/www/default/html/live.html ] && rm /srv/www/default/html/live.html
199
+ }
200
+
201
+ [[ ${NGINX_COMPILE :- } == " on " || ${NGINX_INSTALL :- } == " on " ]] && {
202
+ [ ! $( id -u www-data ) ] && useradd www-data --user-group -s /sbin/nologin
196
203
197
204
[ -f $DIR_CONF /nginx/nginx.conf ] && cp $DIR_CONF /nginx/nginx.conf /etc/nginx/
198
- [ -d $DIR_CONF /nginx/sites-available ] && cp $DIR_CONF /nginx/sites-available/ * /etc/nginx/sites-available /
205
+ [ -d $DIR_CONF /nginx/sites-available ] && cp -r $DIR_CONF /nginx/sites-available /etc/nginx/
199
206
200
207
find /etc/nginx/sites-available -type f -print0 | while IFS= read -r -d $' \0' file; do ln -s $file /etc/nginx/sites-enabled/ ; done
201
208
@@ -214,33 +221,25 @@ infoscreendone
214
221
ip6tables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
215
222
ip6tables -A INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
216
223
217
- [ " ${NGINX_COMPILE:- } " == " on" ] && {
218
- [[ ( -f /srv/www/default/html/live.html && ! -z " ${PUBLIC_IPV4:- } " ) ]] && sed -i " s@HOSTNAME_OR_IP@$PUBLIC_IPV4 @g" /srv/www/default/html/live.html
219
- iptables -A INPUT -p tcp --dport 1935 -m state --state NEW,ESTABLISHED -j ACCEPT # rtmp for live broadcasting
220
- cat $DIR_CONF /nginx/rtmp.conf >> /etc/nginx/nginx.conf
221
- } || {
222
- [ -f /srv/www/default/html/live.html ] && rm /srv/www/default/html/live.html
223
- }
224
-
225
224
systemctl daemon-reload
226
225
systemctl restart nginx
227
226
systemctl enable nginx
228
227
229
- } || echo " Your settings.sh file have configuration error\nNGINX_INSTALL and NGINX_COMPILE can't both be set to 'on' "
228
+ }
230
229
231
230
# ##################################################################################
232
231
# LetsEncrypt
233
232
# ##################################################################################
234
- [ " ${LETSENCRYPT_INSTALL:- } " == " on" ] && {
233
+ [[ ${LETSENCRYPT_INSTALL:- } == " on" ] ] && {
235
234
regex=" ^[a-z0-9!#\$ %&'*+/=?^_\` {|}~-]+(\.[a-z0-9!#$%&'*+/=?^_\` {|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$ "
236
- [[ ! ${LETSENCRYPT_EMAIL} =~ $regex ]] && {
235
+ [[ ! ${LETSENCRYPT_EMAIL} =~ $regex ]] && {
237
236
log " LETSENCRYPT_EMAIL value is not a valid email adress"
238
237
} || {
239
- [ " ${NGINX_INSTALL:- } " == " on" ] && install_package python-certbot-nginx
240
- [ ! -Z " ${NGINX_SITES_HOSTNAMES:- } " ] && {
238
+ [[ ${NGINX_INSTALL:- } == " on" ] ] && install_package python-certbot-nginx
239
+ [ ! -Z ${NGINX_SITES_HOSTNAMES:- } ] && {
241
240
for HOSTNAME in " ${NGINX_SITES_HOSTNAMES[@]} "
242
241
do
243
- $DIR_TOOLS /nginx.sh add --domain $HOSTNAME --email $LETSENCRYPT_EMAIL
242
+ # $DIR_TOOLS/nginx.sh add --domain $HOSTNAME --email $LETSENCRYPT_EMAIL
244
243
log " ssl certificate for $HOSTNAME "
245
244
done
246
245
}
@@ -250,14 +249,14 @@ infoscreendone
250
249
# ##################################################################################
251
250
# Database
252
251
# ##################################################################################
253
- [ " ${POSTGRESQL_INSTALL:- } " == " yes" ] && {
252
+ [[ ${POSTGRESQL_INSTALL:- } == " yes" ] ] && {
254
253
install_package progresql postgresql-contrib
255
254
}
256
255
257
256
# ##################################################################################
258
257
# Bash stuff
259
258
# ##################################################################################
260
- [ " ${BASH_STUFF:- } " == " on" ] && {
259
+ [[ ${BASH_STUFF:- } == " on" ] ] && {
261
260
infoscreen " Setting" " bash stuff for root - $OS version $OS_VER "
262
261
case $OS in
263
262
' Debian GNU/Linux' |' Ubuntu' )
@@ -269,13 +268,15 @@ infoscreendone
269
268
infoscreendone
270
269
}
271
270
272
- [ ! " ${NONINTERACTIVE:- } " == " yes" ] && {
273
- count_down 9
274
- }
275
-
276
271
# ##################################################################################
277
272
# Extra scripts
278
273
# ##################################################################################
279
- [ -f $DIR_CONF /autorun.sh ] && bash $DIR_CONF /autorun.sh
274
+ [ -f $DIR_CONF /autorun.sh ] && . $DIR_CONF /autorun.sh
275
+
276
+ log_headline ' script finish at'
277
+
278
+ [[ ! ${NONINTERACTIVE:- } == " yes" ]] && {
279
+ count_down 9
280
+ }
280
281
281
282
reboot
0 commit comments