Bob Mottram il y a 8 ans
Parent
révision
5b7b2d24f2

+ 208
- 208
src/freedombone-addcert Voir le fichier

@@ -58,284 +58,284 @@ FRIENDS_MIRRORS_SSH_PORT=
58 58
 MY_MIRRORS_PASSWORD=
59 59
 
60 60
 function read_repo_servers {
61
-	if [ -f $CONFIGURATION_FILE ]; then
62
-		if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then
63
-			FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
64
-		fi
65
-		if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then
66
-			FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
67
-		fi
68
-		if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
69
-			MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
70
-		fi
71
-		if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
72
-			FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
73
-		fi
61
+    if [ -f $CONFIGURATION_FILE ]; then
62
+	if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then
63
+	    FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
74 64
 	fi
75
-
76
-	if [ ! $FRIENDS_MIRRORS_SERVER ]; then
77
-		return
65
+	if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then
66
+	    FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
78 67
 	fi
79
-	if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then
80
-		return
68
+	if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
69
+	    MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
81 70
 	fi
82
-
83
-	MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME}
84
-	if [ ! -f $MAIN_COMMAND ]; then
85
-		MAIN_COMMAND=/usr/bin/${PROJECT_NAME}
71
+	if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
72
+	    FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
86 73
 	fi
87
-
88
-	REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g'))
89
-
90
-	for line in "${REPOS[@]}"
91
-	do
92
-		repo_name=$(echo "$line" | awk -F '=' '{print $1}')
93
-		mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}')
94
-		friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}"
95
-		${repo_name}="${friends_repo_url}"
96
-	done
74
+    fi
75
+
76
+    if [ ! $FRIENDS_MIRRORS_SERVER ]; then
77
+	return
78
+    fi
79
+    if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then
80
+	return
81
+    fi
82
+
83
+    MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME}
84
+    if [ ! -f $MAIN_COMMAND ]; then
85
+	MAIN_COMMAND=/usr/bin/${PROJECT_NAME}
86
+    fi
87
+
88
+    REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g'))
89
+
90
+    for line in "${REPOS[@]}"
91
+    do
92
+	repo_name=$(echo "$line" | awk -F '=' '{print $1}')
93
+	mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}')
94
+	friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}"
95
+	${repo_name}="${friends_repo_url}"
96
+    done
97 97
 }
98 98
 
99 99
 function show_help {
100
-	echo ''
101
-	echo $"${PROJECT_NAME}-addcert -h [hostname] -c [country code] -a [area] -l [location]"
102
-	echo $'                    -o [organisation] -u [unit] --ca "" --nodh ""'
103
-	echo ''
104
-	echo $'Creates a self-signed certificate for the given hostname'
105
-	echo ''
106
-	echo $'     --help                   Show help'
107
-	echo $'  -h --hostname [name]        Hostname'
108
-	echo $'  -e --letsencrypt [hostname] Hostname to use with Lets Encrypt'
109
-	echo $'  -s --server [url]           Lets Encrypt server URL'
110
-	echo $'  -c --country [code]         Optional country code (eg. US, GB, etc)'
111
-	echo $'  -a --area [description]     Optional area description'
112
-	echo $'  -l --location [locn]        Optional location name'
113
-	echo $'  -o --organisation [name]    Optional organisation name'
114
-	echo $'  -u --unit [name]            Optional unit name'
115
-	echo $'     --email [address]        Email address for letsencrypt'
116
-	echo $'     --dhkey [bits]           DH key length in bits'
117
-	echo $'     --nodh ""                Do not calculate DH params'
118
-	echo $'     --ca ""                  Certificate authority cert'
119
-	echo ''
120
-	exit 0
100
+    echo ''
101
+    echo $"${PROJECT_NAME}-addcert -h [hostname] -c [country code] -a [area] -l [location]"
102
+    echo $'                    -o [organisation] -u [unit] --ca "" --nodh ""'
103
+    echo ''
104
+    echo $'Creates a self-signed certificate for the given hostname'
105
+    echo ''
106
+    echo $'     --help                   Show help'
107
+    echo $'  -h --hostname [name]        Hostname'
108
+    echo $'  -e --letsencrypt [hostname] Hostname to use with Lets Encrypt'
109
+    echo $'  -s --server [url]           Lets Encrypt server URL'
110
+    echo $'  -c --country [code]         Optional country code (eg. US, GB, etc)'
111
+    echo $'  -a --area [description]     Optional area description'
112
+    echo $'  -l --location [locn]        Optional location name'
113
+    echo $'  -o --organisation [name]    Optional organisation name'
114
+    echo $'  -u --unit [name]            Optional unit name'
115
+    echo $'     --email [address]        Email address for letsencrypt'
116
+    echo $'     --dhkey [bits]           DH key length in bits'
117
+    echo $'     --nodh ""                Do not calculate DH params'
118
+    echo $'     --ca ""                  Certificate authority cert'
119
+    echo ''
120
+    exit 0
121 121
 }
122 122
 
123 123
 while [[ $# > 1 ]]
124 124
 do
125
-key="$1"
125
+    key="$1"
126 126
 
127
-case $key in
127
+    case $key in
128 128
 	--help)
129
-	show_help
130
-	;;
129
+	    show_help
130
+	    ;;
131 131
 	-h|--hostname)
132
-	shift
133
-	HOSTNAME="$1"
134
-	;;
132
+	    shift
133
+	    HOSTNAME="$1"
134
+	    ;;
135 135
 	-e|--letsencrypt)
136
-	shift
137
-	LETSENCRYPT_HOSTNAME="$1"
138
-	;;
136
+	    shift
137
+	    LETSENCRYPT_HOSTNAME="$1"
138
+	    ;;
139 139
 	--email)
140
-	shift
141
-	MY_EMAIL_ADDRESS="$1"
142
-	;;
140
+	    shift
141
+	    MY_EMAIL_ADDRESS="$1"
142
+	    ;;
143 143
 	-s|--server)
144
-	shift
145
-	LETSENCRYPT_SERVER="$1"
146
-	;;
144
+	    shift
145
+	    LETSENCRYPT_SERVER="$1"
146
+	    ;;
147 147
 	-c|--country)
148
-	shift
149
-	COUNTRY_CODE="$1"
150
-	;;
148
+	    shift
149
+	    COUNTRY_CODE="$1"
150
+	    ;;
151 151
 	-a|--area)
152
-	shift
153
-	AREA="$1"
154
-	;;
152
+	    shift
153
+	    AREA="$1"
154
+	    ;;
155 155
 	-l|--location)
156
-	shift
157
-	LOCATION="$1"
158
-	;;
156
+	    shift
157
+	    LOCATION="$1"
158
+	    ;;
159 159
 	-o|--organisation)
160
-	shift
161
-	ORGANISATION="$1"
162
-	;;
160
+	    shift
161
+	    ORGANISATION="$1"
162
+	    ;;
163 163
 	-u|--unit)
164
-	shift
165
-	UNIT="$1"
166
-	;;
164
+	    shift
165
+	    UNIT="$1"
166
+	    ;;
167 167
 	--ca)
168
-	shift
169
-	EXTENSIONS="-extensions v3_ca"
170
-	ORGANISATION="Freedombone-CA"
171
-	;;
168
+	    shift
169
+	    EXTENSIONS="-extensions v3_ca"
170
+	    ORGANISATION="Freedombone-CA"
171
+	    ;;
172 172
 	--nodh)
173
-	shift
174
-	NODH="true"
175
-	;;
173
+	    shift
174
+	    NODH="true"
175
+	    ;;
176 176
 	--dhkey)
177
-	shift
178
-	DH_KEYLENGTH=${1}
179
-	;;
177
+	    shift
178
+	    DH_KEYLENGTH=${1}
179
+	    ;;
180 180
 	*)
181
-	# unknown option
182
-	;;
183
-esac
184
-shift
181
+	    # unknown option
182
+	    ;;
183
+    esac
184
+    shift
185 185
 done
186 186
 
187 187
 if [ ! $HOSTNAME ]; then
188
-	if [ ! $LETSENCRYPT_HOSTNAME ]; then
189
-		echo $'No hostname specified'
190
-		exit 5748
191
-	fi
188
+    if [ ! $LETSENCRYPT_HOSTNAME ]; then
189
+	echo $'No hostname specified'
190
+	exit 5748
191
+    fi
192 192
 fi
193 193
 
194 194
 if ! which openssl > /dev/null ;then
195
-	echo $"$0: openssl is not installed, exiting" 1>&2
196
-	exit 5689
195
+    echo $"$0: openssl is not installed, exiting" 1>&2
196
+    exit 5689
197 197
 fi
198 198
 
199 199
 if [ ! -d /etc/ssl/mycerts ]; then
200
-	mkdir /etc/ssl/mycerts
200
+    mkdir /etc/ssl/mycerts
201 201
 fi
202 202
 
203 203
 CERTFILE=$HOSTNAME
204 204
 
205 205
 function add_cert_letsencrypt {
206
-	CERTFILE=$LETSENCRYPT_HOSTNAME
207
-
208
-	# obtain the email address for the admin user
209
-	if [ ! $MY_EMAIL_ADDRESS ]; then
210
-		if [ -f $CONFIGURATION_FILE ]; then
211
-			if grep -q "MY_EMAIL_ADDRESS=" $CONFIGURATION_FILE; then
212
-				MY_EMAIL_ADDRESS=$(cat $CONFIGURATION_FILE | grep "MY_EMAIL_ADDRESS=" | awk -F '=' '{print $2}')
213
-			fi
214
-		fi
206
+    CERTFILE=$LETSENCRYPT_HOSTNAME
207
+
208
+    # obtain the email address for the admin user
209
+    if [ ! $MY_EMAIL_ADDRESS ]; then
210
+	if [ -f $CONFIGURATION_FILE ]; then
211
+	    if grep -q "MY_EMAIL_ADDRESS=" $CONFIGURATION_FILE; then
212
+		MY_EMAIL_ADDRESS=$(cat $CONFIGURATION_FILE | grep "MY_EMAIL_ADDRESS=" | awk -F '=' '{print $2}')
213
+	    fi
215 214
 	fi
216
-	if [ ! $MY_EMAIL_ADDRESS ]; then
217
-		if [ -f $COMPLETION_FILE ]; then
218
-			if grep -q "Admin user:" $COMPLETION_FILE; then
219
-				ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
220
-				MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME
221
-			fi
222
-		fi
215
+    fi
216
+    if [ ! $MY_EMAIL_ADDRESS ]; then
217
+	if [ -f $COMPLETION_FILE ]; then
218
+	    if grep -q "Admin user:" $COMPLETION_FILE; then
219
+		ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
220
+		MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME
221
+	    fi
223 222
 	fi
223
+    fi
224 224
 
225
-	if [ ! -d $INSTALL_DIR ]; then
226
-		mkdir -p $INSTALL_DIR
227
-	fi
228
-	cd $INSTALL_DIR
225
+    if [ ! -d $INSTALL_DIR ]; then
226
+	mkdir -p $INSTALL_DIR
227
+    fi
228
+    cd $INSTALL_DIR
229 229
 
230
-	# obtain the repo
230
+    # obtain the repo
231
+    if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then
232
+	git_clone $LETSENCRYPT_REPO ${INSTALL_DIR}/letsencrypt
231 233
 	if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then
232
-		git_clone $LETSENCRYPT_REPO ${INSTALL_DIR}/letsencrypt
233
-		if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then
234
-			exit 76283
235
-		fi
236
-	else
237
-		cd ${INSTALL_DIR}/letsencrypt
238
-		git_pull $LETSENCRYPT_REPO
234
+	    exit 76283
239 235
 	fi
236
+    else
237
+	cd ${INSTALL_DIR}/letsencrypt
238
+	git_pull $LETSENCRYPT_REPO
239
+    fi
240 240
 
241
-	# stop the web server
242
-	systemctl stop nginx
241
+    # stop the web server
242
+    systemctl stop nginx
243 243
 
244
-	cd ${INSTALL_DIR}/letsencrypt
245
-	./letsencrypt-auto certonly --server $LETSENCRYPT_SERVER --standalone -d $LETSENCRYPT_HOSTNAME --renew-by-default --agree-tos --email $MY_EMAIL_ADDRESS
246
-	if [ ! "$?" = "0" ]; then
247
-		echo $"Failed to install letsencrypt for domain $LETSENCRYPT_HOSTNAME"
248
-		systemctl start nginx
249
-		exit 63216
244
+    cd ${INSTALL_DIR}/letsencrypt
245
+    ./letsencrypt-auto certonly --server $LETSENCRYPT_SERVER --standalone -d $LETSENCRYPT_HOSTNAME --renew-by-default --agree-tos --email $MY_EMAIL_ADDRESS
246
+    if [ ! "$?" = "0" ]; then
247
+	echo $"Failed to install letsencrypt for domain $LETSENCRYPT_HOSTNAME"
248
+	systemctl start nginx
249
+	exit 63216
250
+    fi
251
+
252
+    # replace some legacy filenames
253
+    if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt ]; then
254
+	mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
255
+    fi
256
+    if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt ]; then
257
+	mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
258
+    fi
259
+    sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME
260
+    sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME
261
+
262
+    # link the private key
263
+    if [ -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key ]; then
264
+	if [ ! -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old ]; then
265
+	    mv /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old
266
+	else
267
+	    rm -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
250 268
 	fi
269
+    fi
270
+    ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/privkey.pem /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
251 271
 
252
-	# replace some legacy filenames
253
-	if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt ]; then
254
-		mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
255
-	fi
256
-	if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt ]; then
257
-		mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
258
-	fi
259
-	sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME
260
-	sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME
261
-
262
-	# link the private key
263
-	if [ -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key ]; then
264
-		if [ ! -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old ]; then
265
-			mv /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old
266
-		else
267
-			rm -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
268
-		fi
269
-	fi
270
-	ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/privkey.pem /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
271
-
272
-	# link the public key
273
-	if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem ]; then
274
-		if [ ! -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old ]; then
275
-			mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old
276
-		else
277
-			rm -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
278
-		fi
272
+    # link the public key
273
+    if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem ]; then
274
+	if [ ! -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old ]; then
275
+	    mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old
276
+	else
277
+	    rm -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
279 278
 	fi
280
-	ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
279
+    fi
280
+    ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
281 281
 
282
-	cp /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/mycerts/${LETSENCRYPT_HOSTNAME}.pem
282
+    cp /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/mycerts/${LETSENCRYPT_HOSTNAME}.pem
283 283
 
284
-	systemctl start nginx
284
+    systemctl start nginx
285 285
 
286
-	${PROJECT_NAME}-pin-cert $LETSENCRYPT_HOSTNAME
287
-	if [ ! "$?" = "0" ]; then
288
-		echo $"Certificate for $LETSENCRYPT_HOSTNAME could not be pinned"
289
-		exit 62878
290
-	fi
286
+    ${PROJECT_NAME}-pin-cert $LETSENCRYPT_HOSTNAME
287
+    if [ ! "$?" = "0" ]; then
288
+	echo $"Certificate for $LETSENCRYPT_HOSTNAME could not be pinned"
289
+	exit 62878
290
+    fi
291 291
 }
292 292
 
293 293
 function add_cert_selfsigned {
294
-	if [[ $ORGANISATION == "Freedombone-CA" ]]; then
295
-		CERTFILE="ca-$HOSTNAME"
296
-	fi
297
-
298
-	openssl req -x509 ${EXTENSIONS} -nodes -days 3650 -sha256 \
299
-		-subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
300
-		-newkey rsa:4096 -keyout /etc/ssl/private/${CERTFILE}.key \
301
-		-out /etc/ssl/certs/${CERTFILE}.crt
302
-	chmod 400 /etc/ssl/private/${CERTFILE}.key
303
-	chmod 640 /etc/ssl/certs/${CERTFILE}.crt
304
-	cp /etc/ssl/certs/${CERTFILE}.crt /etc/ssl/mycerts
305
-
306
-	${PROJECT_NAME}-pin-cert $CERTFILE
307
-	if [ ! "$?" = "0" ]; then
308
-		echo $"Certificate for $CERTFILE could not be pinned"
309
-		exit 62879
310
-	fi
294
+    if [[ $ORGANISATION == "Freedombone-CA" ]]; then
295
+	CERTFILE="ca-$HOSTNAME"
296
+    fi
297
+
298
+    openssl req -x509 ${EXTENSIONS} -nodes -days 3650 -sha256 \
299
+	    -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
300
+	    -newkey rsa:4096 -keyout /etc/ssl/private/${CERTFILE}.key \
301
+	    -out /etc/ssl/certs/${CERTFILE}.crt
302
+    chmod 400 /etc/ssl/private/${CERTFILE}.key
303
+    chmod 640 /etc/ssl/certs/${CERTFILE}.crt
304
+    cp /etc/ssl/certs/${CERTFILE}.crt /etc/ssl/mycerts
305
+
306
+    ${PROJECT_NAME}-pin-cert $CERTFILE
307
+    if [ ! "$?" = "0" ]; then
308
+	echo $"Certificate for $CERTFILE could not be pinned"
309
+	exit 62879
310
+    fi
311 311
 }
312 312
 
313 313
 function generate_dh_params {
314
-	if [ ! $NODH ]; then
315
-		if [ ! -f /etc/ssl/certs/${CERTFILE}.dhparam ]; then
316
-			${PROJECT_NAME}-dhparam -h ${CERTFILE} --fast yes
317
-		fi
314
+    if [ ! $NODH ]; then
315
+	if [ ! -f /etc/ssl/certs/${CERTFILE}.dhparam ]; then
316
+	    ${PROJECT_NAME}-dhparam -h ${CERTFILE} --fast yes
318 317
 	fi
318
+    fi
319 319
 }
320 320
 
321 321
 function restart_web_server {
322
-	if [ -f /etc/init.d/nginx ]; then
323
-		/etc/init.d/nginx reload
324
-	fi
322
+    if [ -f /etc/init.d/nginx ]; then
323
+	/etc/init.d/nginx reload
324
+    fi
325 325
 }
326 326
 
327 327
 function make_cert_bundle {
328
-	# Create a bundle of your certificates
329
-	cat /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem > /etc/ssl/${PROJECT_NAME}-bundle.crt
330
-	tar -czvf /etc/ssl/${PROJECT_NAME}-certs.tar.gz /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem
328
+    # Create a bundle of your certificates
329
+    cat /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem > /etc/ssl/${PROJECT_NAME}-bundle.crt
330
+    tar -czvf /etc/ssl/${PROJECT_NAME}-certs.tar.gz /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem
331 331
 }
332 332
 
333 333
 function create_cert {
334
-	if [ $LETSENCRYPT_HOSTNAME ]; then
335
-		add_cert_letsencrypt
336
-	else
337
-		add_cert_selfsigned
338
-	fi
334
+    if [ $LETSENCRYPT_HOSTNAME ]; then
335
+	add_cert_letsencrypt
336
+    else
337
+	add_cert_selfsigned
338
+    fi
339 339
 }
340 340
 
341 341
 read_repo_servers

+ 58
- 58
src/freedombone-addemail Voir le fichier

@@ -49,37 +49,37 @@ function show_help {
49 49
 
50 50
 while [[ $# > 1 ]]
51 51
 do
52
-key="$1"
53
-
54
-case $key in
55
-    -h|--help)
56
-    show_help
57
-    ;;
58
-    -u|--user)
59
-    shift
60
-    MYUSERNAME="$1"
61
-    ;;
62
-    -e|--email)
63
-    shift
64
-    EMAILADDRESS="$1"
65
-    ;;
66
-    -s|--subject)
67
-    shift
68
-    SUBJECT_TEXT="$1"
69
-    ;;
70
-    -g|--group)
52
+    key="$1"
53
+
54
+    case $key in
55
+	-h|--help)
56
+	    show_help
57
+	    ;;
58
+	-u|--user)
59
+	    shift
60
+	    MYUSERNAME="$1"
61
+	    ;;
62
+	-e|--email)
63
+	    shift
64
+	    EMAILADDRESS="$1"
65
+	    ;;
66
+	-s|--subject)
67
+	    shift
68
+	    SUBJECT_TEXT="$1"
69
+	    ;;
70
+	-g|--group)
71
+	    shift
72
+	    GROUP_NAME="$1"
73
+	    ;;
74
+	-p|--public)
75
+	    shift
76
+	    PUBLIC="$1"
77
+	    ;;
78
+	*)
79
+	    # unknown option
80
+	    ;;
81
+    esac
71 82
     shift
72
-    GROUP_NAME="$1"
73
-    ;;
74
-    -p|--public)
75
-    shift
76
-    PUBLIC="$1"
77
-    ;;
78
-    *)
79
-    # unknown option
80
-    ;;
81
-esac
82
-shift
83 83
 done
84 84
 
85 85
 if ! [[ $MYUSERNAME && $GROUP_NAME ]]; then
@@ -88,7 +88,7 @@ fi
88 88
 
89 89
 if [ ${#EMAILADDRESS} -lt 2 ]; then
90 90
     if [ ${#SUBJECT_TEXT} -lt 2 ]; then
91
-        show_help
91
+	show_help
92 92
     fi
93 93
 fi
94 94
 
@@ -112,47 +112,47 @@ fi
112 112
 chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
113 113
 if ! grep -q "$proc_comment" $PM; then
114 114
     if [[ $PUBLIC != "yes" ]]; then
115
-        # private emails go after the encryption stage
116
-        echo '' >> $PM
117
-        echo "$proc_comment" >> $PM
118
-        echo ":0" >> $PM
119
-        echo "$proc_rule" >> $PM
120
-        echo "$LISTDIR/new" >> $PM
121
-        echo "# End of rule" >> $PM
115
+	# private emails go after the encryption stage
116
+	echo '' >> $PM
117
+	echo "$proc_comment" >> $PM
118
+	echo ":0" >> $PM
119
+	echo "$proc_rule" >> $PM
120
+	echo "$LISTDIR/new" >> $PM
121
+	echo "# End of rule" >> $PM
122 122
     else
123
-        # public emails are copied before the encryption stage
124
-        if ! grep -q '# encrypt' $PM; then
125
-            echo '' >> $PM
126
-            echo "$proc_comment" >> $PM
127
-            echo ":0" >> $PM
128
-            echo "$proc_rule" >> $PM
129
-            echo "$LISTDIR/new" >> $PM
130
-            echo "# End of rule" >> $PM
131
-        else
132
-            filter=$(echo "$proc_comment\n:0\n${proc_rule}\n$LISTDIR/new\n# End of rule\n")
133
-            sed -i "/# encrypt/i ${filter}" $PM
134
-        fi
123
+	# public emails are copied before the encryption stage
124
+	if ! grep -q '# encrypt' $PM; then
125
+	    echo '' >> $PM
126
+	    echo "$proc_comment" >> $PM
127
+	    echo ":0" >> $PM
128
+	    echo "$proc_rule" >> $PM
129
+	    echo "$LISTDIR/new" >> $PM
130
+	    echo "# End of rule" >> $PM
131
+	else
132
+	    filter=$(echo "$proc_comment\n:0\n${proc_rule}\n$LISTDIR/new\n# End of rule\n")
133
+	    sed -i "/# encrypt/i ${filter}" $PM
134
+	fi
135 135
     fi
136 136
     chown $MYUSERNAME:$MYUSERNAME $PM
137 137
 fi
138 138
 
139 139
 if [ ! -f "$MUTTRC" ]; then
140
-  cp /etc/Muttrc $MUTTRC
141
-  chown $MYUSERNAME:$MYUSERNAME $MUTTRC
140
+    cp /etc/Muttrc $MUTTRC
141
+    chown $MYUSERNAME:$MYUSERNAME $MUTTRC
142 142
 fi
143 143
 
144 144
 PROCMAILLOG=/home/$MYUSERNAME/log
145 145
 if [ ! -d $PROCMAILLOG ]; then
146
-  mkdir $PROCMAILLOG
147
-  chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
146
+    mkdir $PROCMAILLOG
147
+    chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
148 148
 fi
149 149
 
150 150
 MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
151 151
 if [[ $MUTT_MAILBOXES != *$GROUP_NAME* ]]; then
152
-  if ! grep -q "=$GROUP_NAME" $MUTTRC; then
153
-    sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$GROUP_NAME|g" $MUTTRC
154
-    chown $MYUSERNAME:$MYUSERNAME $MUTTRC
155
-  fi
152
+    if ! grep -q "=$GROUP_NAME" $MUTTRC; then
153
+	sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$GROUP_NAME|g" $MUTTRC
154
+	chown $MYUSERNAME:$MYUSERNAME $MUTTRC
155
+    fi
156 156
 fi
157 157
 
158 158
 exit 0

+ 48
- 48
src/freedombone-addlist Voir le fichier

@@ -49,37 +49,37 @@ function show_help {
49 49
 
50 50
 while [[ $# > 1 ]]
51 51
 do
52
-key="$1"
53
-
54
-case $key in
55
-    -h|--help)
56
-    show_help
57
-    ;;
58
-    -u|--user)
59
-    shift
60
-    MYUSERNAME="$1"
61
-    ;;
62
-    -l|--list)
63
-    shift
64
-    MAILINGLIST="$1"
65
-    ;;
66
-    -s|--subject)
67
-    shift
68
-    SUBJECTTAG="$1"
69
-    ;;
70
-    -e|--email)
71
-    shift
72
-    LIST_ADDRESS="$1"
73
-    ;;
74
-    -p|--public)
52
+    key="$1"
53
+
54
+    case $key in
55
+	-h|--help)
56
+	    show_help
57
+	    ;;
58
+	-u|--user)
59
+	    shift
60
+	    MYUSERNAME="$1"
61
+	    ;;
62
+	-l|--list)
63
+	    shift
64
+	    MAILINGLIST="$1"
65
+	    ;;
66
+	-s|--subject)
67
+	    shift
68
+	    SUBJECTTAG="$1"
69
+	    ;;
70
+	-e|--email)
71
+	    shift
72
+	    LIST_ADDRESS="$1"
73
+	    ;;
74
+	-p|--public)
75
+	    shift
76
+	    PUBLIC="$1"
77
+	    ;;
78
+	*)
79
+	    # unknown option
80
+	    ;;
81
+    esac
75 82
     shift
76
-    PUBLIC="$1"
77
-    ;;
78
-    *)
79
-    # unknown option
80
-    ;;
81
-esac
82
-shift
83 83
 done
84 84
 
85 85
 if [ ! $MYUSERNAME ]; then
@@ -110,33 +110,33 @@ chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
110 110
 if [ ${#SUBJECTTAG} -gt 0 ]; then
111 111
     # use the subject tag
112 112
     if ! grep -q "Subject:.*()\[$SUBJECTTAG\]" $PM; then
113
-        if [[ $PUBLIC != "yes" ]]; then
114
-            # private emails go after the encryption stage
115
-            filter="
113
+	if [[ $PUBLIC != "yes" ]]; then
114
+	    # private emails go after the encryption stage
115
+	    filter="
116 116
 # Email rule for $MAILINGLIST subject [$SUBJECTTAG]
117 117
 :0
118 118
   * ^Subject:.*()\[$SUBJECTTAG\]
119 119
 $LISTDIR/new
120 120
 # End of rule
121 121
 "
122
-            echo "$filter" >> $PM
123
-        else
124
-            # public emails are copied before hte encryption stage
125
-            if ! grep -q '# encrypt' $PM; then
126
-                filter="
122
+	    echo "$filter" >> $PM
123
+	else
124
+	    # public emails are copied before hte encryption stage
125
+	    if ! grep -q '# encrypt' $PM; then
126
+		filter="
127 127
 # Email rule for $MAILINGLIST subject [$SUBJECTTAG]
128 128
 :0
129 129
   * ^Subject:.*()\[$SUBJECTTAG\]
130 130
 $LISTDIR/new
131 131
 # End of rule
132 132
 "
133
-                echo "$filter" >> $PM
134
-            else
135
-                filter=$(echo "# Email rule for $MAILINGLIST subject [$SUBJECTTAG]\n:0\n  * ^Subject:.*()\\\[$SUBJECTTAG\\\]\n$LISTDIR/new\n# End of rule\n")
136
-                sed -i "/# encrypt/i ${filter}" $PM
137
-            fi
138
-        fi
139
-        chown $MYUSERNAME:$MYUSERNAME $PM
133
+		echo "$filter" >> $PM
134
+	    else
135
+		filter=$(echo "# Email rule for $MAILINGLIST subject [$SUBJECTTAG]\n:0\n  * ^Subject:.*()\\\[$SUBJECTTAG\\\]\n$LISTDIR/new\n# End of rule\n")
136
+		sed -i "/# encrypt/i ${filter}" $PM
137
+	    fi
138
+	fi
139
+	chown $MYUSERNAME:$MYUSERNAME $PM
140 140
     fi
141 141
 else
142 142
     exit $(${PROJECT_NAME}-addemail -u $MYUSERNAME -e $LIST_ADDRESS -g $MAILINGLIST --public $PUBLIC)
@@ -156,15 +156,15 @@ fi
156 156
 MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
157 157
 if [[ $MUTT_MAILBOXES != *$MAILINGLIST* ]]; then
158 158
     if ! grep -q "=$MAILINGLIST" $MUTTRC; then
159
-        sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$MAILINGLIST|g" $MUTTRC
160
-        chown $MYUSERNAME:$MYUSERNAME $MUTTRC
159
+	sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$MAILINGLIST|g" $MUTTRC
160
+	chown $MYUSERNAME:$MYUSERNAME $MUTTRC
161 161
     fi
162 162
 fi
163 163
 
164 164
 if [ $LIST_ADDRESS ]; then
165 165
     sed -i "s|unsubscribe $LIST_ADDRESS|subscribe $LIST_ADDRESS|g" $MUTTRC
166 166
     if ! grep -q "subscribe $LIST_ADDRESS" $MUTTRC; then
167
-        echo "subscribe $LIST_ADDRESS" >> $MUTTRC
167
+	echo "subscribe $LIST_ADDRESS" >> $MUTTRC
168 168
     fi
169 169
 fi
170 170
 

+ 49
- 49
src/freedombone-addsipuser Voir le fichier

@@ -50,10 +50,10 @@ function show_help {
50 50
 function sip_user_exists {
51 51
     IFS=''
52 52
     while read line; do
53
-        if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
54
-            USER_EXISTS="yes"
55
-            return
56
-        fi
53
+	if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
54
+	    USER_EXISTS="yes"
55
+	    return
56
+	fi
57 57
     done < $CONFIG_FILE
58 58
 }
59 59
 
@@ -61,28 +61,28 @@ function update_sip_user {
61 61
     USER_FOUND=
62 62
     NEW_CONFIG_FILE="${CONFIG_FILE}.new"
63 63
     if [ -f $NEW_CONFIG_FILE ]; then
64
-        rm -f $NEW_CONFIG_FILE
64
+	rm -f $NEW_CONFIG_FILE
65 65
     fi
66 66
     touch $NEW_CONFIG_FILE
67 67
     IFS=''
68 68
     while read line; do
69
-        if [ ! $USER_FOUND ]; then
70
-            if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
71
-                USER_FOUND="yes"
72
-            fi
73
-        else
74
-            if [[ "$line" == *"<extension>"* ]]; then
75
-                line="      <extension>$EXTENSION</extension>"
76
-            fi
77
-            if [[ "$line" == *"<secret>"* ]]; then
78
-                line="      <secret>$PASSWORD</secret>"
79
-            fi
80
-            if [[ "$line" == *"<display>"* ]]; then
81
-                line="      <display>$MY_USERNAME $EXTENSION</display>"
82
-                USER_FOUND=
83
-            fi
84
-        fi
85
-        echo $line >> $NEW_CONFIG_FILE
69
+	if [ ! $USER_FOUND ]; then
70
+	    if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
71
+		USER_FOUND="yes"
72
+	    fi
73
+	else
74
+	    if [[ "$line" == *"<extension>"* ]]; then
75
+		line="      <extension>$EXTENSION</extension>"
76
+	    fi
77
+	    if [[ "$line" == *"<secret>"* ]]; then
78
+		line="      <secret>$PASSWORD</secret>"
79
+	    fi
80
+	    if [[ "$line" == *"<display>"* ]]; then
81
+		line="      <display>$MY_USERNAME $EXTENSION</display>"
82
+		USER_FOUND=
83
+	    fi
84
+	fi
85
+	echo $line >> $NEW_CONFIG_FILE
86 86
     done < $CONFIG_FILE
87 87
     mv $NEW_CONFIG_FILE $CONFIG_FILE
88 88
 }
@@ -90,19 +90,19 @@ function update_sip_user {
90 90
 function add_sip_user {
91 91
     NEW_CONFIG_FILE="${CONFIG_FILE}.new"
92 92
     if [ -f $NEW_CONFIG_FILE ]; then
93
-        rm -f $NEW_CONFIG_FILE
93
+	rm -f $NEW_CONFIG_FILE
94 94
     fi
95 95
     touch $NEW_CONFIG_FILE
96 96
     IFS=''
97 97
     while read line; do
98
-        if [[ "$line" == *'</provision>' ]]; then
99
-            echo "    <user id=\"$MY_USERNAME\">" >> $NEW_CONFIG_FILE
100
-            echo "      <extension>$EXTENSION</extension>" >> $NEW_CONFIG_FILE
101
-            echo "      <secret>$PASSWORD</secret>" >> $NEW_CONFIG_FILE
102
-            echo "      <display>$MY_USERNAME $EXTENSION</display>" >> $NEW_CONFIG_FILE
103
-            echo '    </user>' >> $NEW_CONFIG_FILE
104
-        fi
105
-        echo $line >> $NEW_CONFIG_FILE
98
+	if [[ "$line" == *'</provision>' ]]; then
99
+	    echo "    <user id=\"$MY_USERNAME\">" >> $NEW_CONFIG_FILE
100
+	    echo "      <extension>$EXTENSION</extension>" >> $NEW_CONFIG_FILE
101
+	    echo "      <secret>$PASSWORD</secret>" >> $NEW_CONFIG_FILE
102
+	    echo "      <display>$MY_USERNAME $EXTENSION</display>" >> $NEW_CONFIG_FILE
103
+	    echo '    </user>' >> $NEW_CONFIG_FILE
104
+	fi
105
+	echo $line >> $NEW_CONFIG_FILE
106 106
     done < $CONFIG_FILE
107 107
     mv $NEW_CONFIG_FILE $CONFIG_FILE
108 108
     usermod -aG sipwitch $MY_USERNAME
@@ -113,24 +113,24 @@ do
113 113
     key="$1"
114 114
 
115 115
     case $key in
116
-        -h|--help)
117
-            show_help
118
-            ;;
119
-        -u|--user)
120
-            shift
121
-            MY_USERNAME="$1"
122
-            ;;
123
-        -e|--extension)
124
-            shift
125
-            EXTENSION="$1"
126
-            ;;
127
-        -p|--password)
128
-            shift
129
-            PASSWORD="$1"
130
-            ;;
131
-        *)
132
-            # unknown option
133
-            ;;
116
+	-h|--help)
117
+	    show_help
118
+	    ;;
119
+	-u|--user)
120
+	    shift
121
+	    MY_USERNAME="$1"
122
+	    ;;
123
+	-e|--extension)
124
+	    shift
125
+	    EXTENSION="$1"
126
+	    ;;
127
+	-p|--password)
128
+	    shift
129
+	    PASSWORD="$1"
130
+	    ;;
131
+	*)
132
+	    # unknown option
133
+	    ;;
134 134
     esac
135 135
     shift
136 136
 done

+ 230
- 230
src/freedombone-adduser Voir le fichier

@@ -46,19 +46,19 @@ FULLBLOG_DOMAIN_NAME=
46 46
 DEFAULT_DOMAIN_NAME=
47 47
 
48 48
 if [ ! $MY_USERNAME ]; then
49
-	echo $'No username was given'
50
-	exit 1
49
+    echo $'No username was given'
50
+    exit 1
51 51
 fi
52 52
 
53 53
 if [ -d /home/$MY_USERNAME ]; then
54
-	echo $"The user $MY_USERNAME already exists"
55
-	exit 2
54
+    echo $"The user $MY_USERNAME already exists"
55
+    exit 2
56 56
 fi
57 57
 
58 58
 if [ ! -f $COMPLETION_FILE ]; then
59
-	echo $"$COMPLETION_FILE not found"
60
-	userdel -r $MY_USERNAME
61
-	exit 3
59
+    echo $"$COMPLETION_FILE not found"
60
+    userdel -r $MY_USERNAME
61
+    exit 3
62 62
 fi
63 63
 
64 64
 # Minimum number of characters in a password
@@ -69,40 +69,40 @@ useradd -m -p "$NEW_USER_PASSWORD" -s /bin/bash $MY_USERNAME
69 69
 adduser $MY_USERNAME sasl
70 70
 
71 71
 if [ ! -d /home/$MY_USERNAME ]; then
72
-	echo $'Home directory was not created'
73
-	exit 4
72
+    echo $'Home directory was not created'
73
+    exit 4
74 74
 fi
75 75
 
76 76
 if [ "$SSH_PUBLIC_KEY" ]; then
77
-	if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
78
-		if [ -f "$SSH_PUBLIC_KEY" ]; then
79
-			mkdir /home/$MY_USERNAME/.ssh
80
-			cp $SSH_PUBLIC_KEY /home/$MY_USERNAME/.ssh/authorized_keys
81
-			chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
82
-			echo $'ssh public key installed'
83
-		else
84
-			if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
85
-				mkdir /home/$MY_USERNAME/.ssh
86
-				echo "$SSH_PUBLIC_KEY" > /home/$MY_USERNAME/.ssh/authorized_keys
87
-				chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
88
-				echo $'ssh public key installed'
89
-			else
90
-				echo $'The second parameter does not look like an ssh key'
91
-				exit 5
92
-			fi
93
-		fi
77
+    if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
78
+	if [ -f "$SSH_PUBLIC_KEY" ]; then
79
+	    mkdir /home/$MY_USERNAME/.ssh
80
+	    cp $SSH_PUBLIC_KEY /home/$MY_USERNAME/.ssh/authorized_keys
81
+	    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
82
+	    echo $'ssh public key installed'
83
+	else
84
+	    if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
85
+		mkdir /home/$MY_USERNAME/.ssh
86
+		echo "$SSH_PUBLIC_KEY" > /home/$MY_USERNAME/.ssh/authorized_keys
87
+		chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
88
+		echo $'ssh public key installed'
89
+	    else
90
+		echo $'The second parameter does not look like an ssh key'
91
+		exit 5
92
+	    fi
94 93
 	fi
94
+    fi
95 95
 fi
96 96
 
97 97
 if [ -d /home/$MY_USERNAME/Maildir ]; then
98
-	if grep -q "set from=" /home/$MY_USERNAME/.muttrc; then
99
-		sed -i "s|set from=.*|set from='$MY_USERNAME <$MY_USERNAME@$HOSTNAME>'|g" /home/$MY_USERNAME/.muttrc
100
-	else
101
-		echo "set from='$MY_USERNAME <$MY_USERNAME@$HOSTNAME>'" >> /home/$MY_USERNAME/.muttrc
102
-	fi
103
-
104
-	USERN='$USER@'
105
-	sed -i "s|$USERN|$MY_USERNAME@|g" /home/$MY_USERNAME/.procmailrc
98
+    if grep -q "set from=" /home/$MY_USERNAME/.muttrc; then
99
+	sed -i "s|set from=.*|set from='$MY_USERNAME <$MY_USERNAME@$HOSTNAME>'|g" /home/$MY_USERNAME/.muttrc
100
+    else
101
+	echo "set from='$MY_USERNAME <$MY_USERNAME@$HOSTNAME>'" >> /home/$MY_USERNAME/.muttrc
102
+    fi
103
+
104
+    USERN='$USER@'
105
+    sed -i "s|$USERN|$MY_USERNAME@|g" /home/$MY_USERNAME/.procmailrc
106 106
 fi
107 107
 
108 108
 # generate a gpg key
@@ -136,9 +136,9 @@ MY_GPG_PUBLIC_KEY=/home/$MY_USERNAME/public_key.gpg
136 136
 su -c "gpg --output $MY_GPG_PUBLIC_KEY --armor --export $MY_GPG_PUBLIC_KEY_ID" - $MY_USERNAME
137 137
 
138 138
 if [ ! -f $MY_GPG_PUBLIC_KEY ]; then
139
-	echo "GPG public key was not generated for $MY_USERNAME@$HOSTNAME $MY_GPG_PUBLIC_KEY_ID"
140
-	userdel -r $MY_USERNAME
141
-	exit 7
139
+    echo "GPG public key was not generated for $MY_USERNAME@$HOSTNAME $MY_GPG_PUBLIC_KEY_ID"
140
+    userdel -r $MY_USERNAME
141
+    exit 7
142 142
 fi
143 143
 
144 144
 # add a monkeysphere subkey
@@ -152,47 +152,47 @@ chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.monkeysphere
152 152
 monkeysphere-authentication update-users
153 153
 
154 154
 if [ -f /home/$MY_USERNAME/.muttrc ]; then
155
-	# encrypt outgoing mail to the "sent" folder
156
-	if ! grep -q "pgp_encrypt_only_command" /home/$MY_USERNAME/.muttrc; then
157
-		echo '' >> /home/$MY_USERNAME/.muttrc
158
-		echo $'# Encrypt items in the Sent folder' >> /home/$MY_USERNAME/.muttrc
159
-		echo "set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 0x$MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"" >> /home/$MY_USERNAME/.muttrc
160
-	else
161
-		sed -i "s|set pgp_encrypt_only_command.*|set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 0x$MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"|g" /home/$MY_USERNAME/.muttrc
162
-	fi
163
-
164
-	if ! grep -q "pgp_encrypt_sign_command" /home/$MY_USERNAME/.muttrc; then
165
-		echo "set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0x$MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"" >> /home/$MY_USERNAME/.muttrc
166
-	else
167
-		sed -i "s|set pgp_encrypt_sign_command.*|set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0x$MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"|g" /home/$MY_USERNAME/.muttrc
168
-	fi
155
+    # encrypt outgoing mail to the "sent" folder
156
+    if ! grep -q "pgp_encrypt_only_command" /home/$MY_USERNAME/.muttrc; then
157
+	echo '' >> /home/$MY_USERNAME/.muttrc
158
+	echo $'# Encrypt items in the Sent folder' >> /home/$MY_USERNAME/.muttrc
159
+	echo "set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 0x$MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"" >> /home/$MY_USERNAME/.muttrc
160
+    else
161
+	sed -i "s|set pgp_encrypt_only_command.*|set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 0x$MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"|g" /home/$MY_USERNAME/.muttrc
162
+    fi
163
+
164
+    if ! grep -q "pgp_encrypt_sign_command" /home/$MY_USERNAME/.muttrc; then
165
+	echo "set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0x$MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"" >> /home/$MY_USERNAME/.muttrc
166
+    else
167
+	sed -i "s|set pgp_encrypt_sign_command.*|set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0x$MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"|g" /home/$MY_USERNAME/.muttrc
168
+    fi
169 169
 fi
170 170
 
171 171
 if ! grep -q "Change your GPG password" /home/$MY_USERNAME/README; then
172
-	echo '' >> /home/$MY_USERNAME/README
173
-	echo '' >> /home/$MY_USERNAME/README
174
-	echo $'Change your GPG password' >> /home/$MY_USERNAME/README
175
-	echo '========================' >> /home/$MY_USERNAME/README
176
-	echo $"It's very important to add a password to your GPG key so that" >> /home/$MY_USERNAME/README
177
-	echo $"if anyone does get access to your email they still won't be able" >> /home/$MY_USERNAME/README
178
-	echo $'to read them without knowning the GPG password.' >> /home/$MY_USERNAME/README
179
-	echo $'You can change the it with:' >> /home/$MY_USERNAME/README
180
-	echo '' >> /home/$MY_USERNAME/README
181
-	echo "  gpg --edit-key $MY_GPG_PUBLIC_KEY_ID" >> /home/$MY_USERNAME/README
182
-	echo '  passwd' >> /home/$MY_USERNAME/README
183
-	echo '  save' >> /home/$MY_USERNAME/README
184
-	echo '  quit' >> /home/$MY_USERNAME/README
172
+    echo '' >> /home/$MY_USERNAME/README
173
+    echo '' >> /home/$MY_USERNAME/README
174
+    echo $'Change your GPG password' >> /home/$MY_USERNAME/README
175
+    echo '========================' >> /home/$MY_USERNAME/README
176
+    echo $"It's very important to add a password to your GPG key so that" >> /home/$MY_USERNAME/README
177
+    echo $"if anyone does get access to your email they still won't be able" >> /home/$MY_USERNAME/README
178
+    echo $'to read them without knowning the GPG password.' >> /home/$MY_USERNAME/README
179
+    echo $'You can change the it with:' >> /home/$MY_USERNAME/README
180
+    echo '' >> /home/$MY_USERNAME/README
181
+    echo "  gpg --edit-key $MY_GPG_PUBLIC_KEY_ID" >> /home/$MY_USERNAME/README
182
+    echo '  passwd' >> /home/$MY_USERNAME/README
183
+    echo '  save' >> /home/$MY_USERNAME/README
184
+    echo '  quit' >> /home/$MY_USERNAME/README
185 185
 fi
186 186
 
187 187
 if ! grep -q "Publish your GPG public key" /home/$MY_USERNAME/README; then
188
-	echo '' >> /home/$MY_USERNAME/README
189
-	echo '' >> /home/$MY_USERNAME/README
190
-	echo $'Publish your GPG public key' >> /home/$MY_USERNAME/README
191
-	echo '===========================' >> /home/$MY_USERNAME/README
192
-	echo $'So that others can send emails to you securely you should' >> /home/$MY_USERNAME/README
193
-	echo $'publish your GPG public key with the command:' >> /home/$MY_USERNAME/README
194
-	echo '' >> /home/$MY_USERNAME/README
195
-	echo "  gpg --send-keys $MY_GPG_PUBLIC_KEY_ID" >> /home/$MY_USERNAME/README
188
+    echo '' >> /home/$MY_USERNAME/README
189
+    echo '' >> /home/$MY_USERNAME/README
190
+    echo $'Publish your GPG public key' >> /home/$MY_USERNAME/README
191
+    echo '===========================' >> /home/$MY_USERNAME/README
192
+    echo $'So that others can send emails to you securely you should' >> /home/$MY_USERNAME/README
193
+    echo $'publish your GPG public key with the command:' >> /home/$MY_USERNAME/README
194
+    echo '' >> /home/$MY_USERNAME/README
195
+    echo "  gpg --send-keys $MY_GPG_PUBLIC_KEY_ID" >> /home/$MY_USERNAME/README
196 196
 fi
197 197
 
198 198
 chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
@@ -200,201 +200,201 @@ chown $MY_USERNAME:$MY_USERNAME $MY_GPG_PUBLIC_KEY
200 200
 chmod 600 /home/$MY_USERNAME/README
201 201
 
202 202
 if grep -q "install_xmpp" $COMPLETION_FILE; then
203
-	echo $"Adding an XMPP account for $MY_USERNAME"
204
-	${PROJECT_NAME}-addxmpp -e "$MY_USERNAME@$HOSTNAME" -p "$NEW_USER_PASSWORD"
205
-	if [ ! "$?" = "0" ]; then
206
-		echo $"XMPP account not created"
207
-		userdel -r $MY_USERNAME
208
-		exit 8
209
-	fi
203
+    echo $"Adding an XMPP account for $MY_USERNAME"
204
+    ${PROJECT_NAME}-addxmpp -e "$MY_USERNAME@$HOSTNAME" -p "$NEW_USER_PASSWORD"
205
+    if [ ! "$?" = "0" ]; then
206
+	echo $"XMPP account not created"
207
+	userdel -r $MY_USERNAME
208
+	exit 8
209
+    fi
210 210
 fi
211 211
 
212 212
 if grep -q "install_xmpp_client" $COMPLETION_FILE; then
213
-	echo $"Adding XMPP client setup"
214
-	XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
215
-	XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
216
-	if [ ! -d $XMPP_CLIENT_DIR ]; then
217
-		mkdir -p $XMPP_CLIENT_DIR
218
-	fi
219
-	if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
220
-		mkdir -p /home/$MY_USERNAME/.config/profanity
221
-	fi
222
-	echo "[${MY_USERNAME}@${HOSTNAME}]" > $XMPP_CLIENT_ACCOUNTS
223
-	echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
224
-	echo "jid=${MY_USERNAME}@${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
225
-	echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
226
-	echo "muc.service=conference.${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
227
-	echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
228
-	echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
229
-	echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
230
-	echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
231
-	echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
232
-	echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
233
-	echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
234
-	echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
235
-
236
-	echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
237
-	echo "account=${MY_USERNAME}@${HOSTNAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
238
-
239
-	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
240
-	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
213
+    echo $"Adding XMPP client setup"
214
+    XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
215
+    XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
216
+    if [ ! -d $XMPP_CLIENT_DIR ]; then
217
+	mkdir -p $XMPP_CLIENT_DIR
218
+    fi
219
+    if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
220
+	mkdir -p /home/$MY_USERNAME/.config/profanity
221
+    fi
222
+    echo "[${MY_USERNAME}@${HOSTNAME}]" > $XMPP_CLIENT_ACCOUNTS
223
+    echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
224
+    echo "jid=${MY_USERNAME}@${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
225
+    echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
226
+    echo "muc.service=conference.${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
227
+    echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
228
+    echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
229
+    echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
230
+    echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
231
+    echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
232
+    echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
233
+    echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
234
+    echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
235
+
236
+    echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
237
+    echo "account=${MY_USERNAME}@${HOSTNAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
238
+
239
+    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
240
+    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
241 241
 fi
242 242
 
243 243
 if grep -q "Blog domain" $COMPLETION_FILE; then
244
-	FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
245
-	if [ ! -d /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users ]; then
246
-		echo $'Blog users directory not found'
247
-		if grep -q "install_xmpp" $COMPLETION_FILE; then
248
-			${PROJECT_NAME}-rmxmpp -e "$MY_USERNAME@$HOSTNAME"
249
-		fi
250
-		userdel -r $MY_USERNAME
251
-		exit 9
244
+    FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
245
+    if [ ! -d /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users ]; then
246
+	echo $'Blog users directory not found'
247
+	if grep -q "install_xmpp" $COMPLETION_FILE; then
248
+	    ${PROJECT_NAME}-rmxmpp -e "$MY_USERNAME@$HOSTNAME"
252 249
 	fi
253
-	NEW_USER_PASSWORD_HASH=$(${PROJECT_NAME}-sec --bloghash "$NEW_USER_PASSWORD")
254
-	if [ ${#NEW_USER_PASSWORD_HASH} -lt 8 ]; then
255
-		echo $'Blog admin password could not be hashed'
256
-		exit 783528
257
-	fi
258
-	echo ';Password' > /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
259
-	echo "password = $NEW_USER_PASSWORD_HASH" >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
260
-	echo 'encryption = password_hash' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
261
-	echo ';Role' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
262
-	echo 'role = admin' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
263
-	echo "$MY_USERNAME added as a blog user"
250
+	userdel -r $MY_USERNAME
251
+	exit 9
252
+    fi
253
+    NEW_USER_PASSWORD_HASH=$(${PROJECT_NAME}-sec --bloghash "$NEW_USER_PASSWORD")
254
+    if [ ${#NEW_USER_PASSWORD_HASH} -lt 8 ]; then
255
+	echo $'Blog admin password could not be hashed'
256
+	exit 783528
257
+    fi
258
+    echo ';Password' > /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
259
+    echo "password = $NEW_USER_PASSWORD_HASH" >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
260
+    echo 'encryption = password_hash' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
261
+    echo ';Role' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
262
+    echo 'role = admin' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
263
+    echo "$MY_USERNAME added as a blog user"
264 264
 fi
265 265
 
266 266
 if grep -q "install_sip" $COMPLETION_FILE; then
267
-	SIP_EXTENSION=$(${PROJECT_NAME}-sipfreeext)
268
-	${PROJECT_NAME}-addsipuser -u $MY_USERNAME -e $SIP_EXTENSION -p "$NEW_USER_PASSWORD"
269
-	if [ ! "$?" = "0" ]; then
270
-		echo $'SIP user could not be added. Ensure that extension numbers are in order and do no exceed 299'
271
-		if grep -q "install_xmpp" $COMPLETION_FILE; then
272
-			${PROJECT_NAME}-rmxmpp -e "$MY_USERNAME@$HOSTNAME"
273
-		fi
274
-		if grep -q "Blog domain" $COMPLETION_FILE; then
275
-			if [ -f /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini ]; then
276
-				rm /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
277
-			fi
278
-		fi
279
-		userdel -r $MY_USERNAME
280
-		exit 10
267
+    SIP_EXTENSION=$(${PROJECT_NAME}-sipfreeext)
268
+    ${PROJECT_NAME}-addsipuser -u $MY_USERNAME -e $SIP_EXTENSION -p "$NEW_USER_PASSWORD"
269
+    if [ ! "$?" = "0" ]; then
270
+	echo $'SIP user could not be added. Ensure that extension numbers are in order and do no exceed 299'
271
+	if grep -q "install_xmpp" $COMPLETION_FILE; then
272
+	    ${PROJECT_NAME}-rmxmpp -e "$MY_USERNAME@$HOSTNAME"
281 273
 	fi
274
+	if grep -q "Blog domain" $COMPLETION_FILE; then
275
+	    if [ -f /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini ]; then
276
+		rm /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
277
+	    fi
278
+	fi
279
+	userdel -r $MY_USERNAME
280
+	exit 10
281
+    fi
282 282
 fi
283 283
 
284 284
 if grep -q "install_gnusocial" $COMPLETION_FILE; then
285
-	MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
286
-	if [ -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
287
-		cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
288
-		php scripts/registeruser.php -n $MY_USERNAME -w "$NEW_USER_PASSWORD" -e "$MY_USERNAME@$HOSTNAME"
289
-		${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$MICROBLOG_DOMAIN_NAME" -g gnusocial --public no
290
-		echo $'Created GNU Social user'
291
-	else
292
-		echo $"Unable to find GNU Social installation at /var/www/$MICROBLOG_DOMAIN_NAME/htdocs"
293
-		userdel -r $MY_USERNAME
294
-		exit 11
295
-	fi
285
+    MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
286
+    if [ -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
287
+	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
288
+	php scripts/registeruser.php -n $MY_USERNAME -w "$NEW_USER_PASSWORD" -e "$MY_USERNAME@$HOSTNAME"
289
+	${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$MICROBLOG_DOMAIN_NAME" -g gnusocial --public no
290
+	echo $'Created GNU Social user'
291
+    else
292
+	echo $"Unable to find GNU Social installation at /var/www/$MICROBLOG_DOMAIN_NAME/htdocs"
293
+	userdel -r $MY_USERNAME
294
+	exit 11
295
+    fi
296 296
 fi
297 297
 
298 298
 if grep -q "install_irc_client" $COMPLETION_FILE; then
299
-	IRC_PORT=6697
300
-	if grep -q "IRC_PORT" $CONFIGURATION_FILE; then
301
-		IRC_PORT=$(grep "IRC_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
302
-	fi
303
-	IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
304
-	if [ ${#IRC_PASSWORD} -lt 2 ]; then
305
-		IRC_PASSWORD=
306
-	fi
307
-
308
-	if [ ! -d /home/$MY_USERNAME/.irssi ]; then
309
-		mkdir /home/$MY_USERNAME/.irssi
310
-	fi
311
-
312
-	echo 'servers = (' > /home/$MY_USERNAME/.irssi/config
313
-	echo '  {' >> /home/$MY_USERNAME/.irssi/config
314
-	echo '    address = "chat.freenode.net";' >> /home/$MY_USERNAME/.irssi/config
315
-	echo '    chatnet = "Freenode";' >> /home/$MY_USERNAME/.irssi/config
316
-	echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
317
-	echo '    autoconnect = "no";' >> /home/$MY_USERNAME/.irssi/config
318
-	echo '  },' >> /home/$MY_USERNAME/.irssi/config
319
-	echo '  {' >> /home/$MY_USERNAME/.irssi/config
320
-	echo '    address = "irc.oftc.net";' >> /home/$MY_USERNAME/.irssi/config
321
-	echo '    chatnet = "OFTC";' >> /home/$MY_USERNAME/.irssi/config
322
-	echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
323
-	echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
324
-	echo '  },' >> /home/$MY_USERNAME/.irssi/config
325
-	echo '  {' >> /home/$MY_USERNAME/.irssi/config
326
-	echo "    address = \"${HOSTNAME}\";" >> /home/$MY_USERNAME/.irssi/config
327
-	echo '    chatnet = "Freedombone";' >> /home/$MY_USERNAME/.irssi/config
328
-	echo "    port = \"${IRC_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
329
-	echo '    use_ssl = "yes";' >> /home/$MY_USERNAME/.irssi/config
330
-	echo '    ssl_verify = "no";' >> /home/$MY_USERNAME/.irssi/config
331
-	echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
332
-
333
-	echo '  }' >> /home/$MY_USERNAME/.irssi/config
334
-	echo ');' >> /home/$MY_USERNAME/.irssi/config
335
-	echo '' >> /home/$MY_USERNAME/.irssi/config
336
-	echo 'chatnets = {' >> /home/$MY_USERNAME/.irssi/config
337
-	echo '  Freedombone = {' >> /home/$MY_USERNAME/.irssi/config
338
-	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
339
-	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
340
-	echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
341
-	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
342
-	echo '  };' >> /home/$MY_USERNAME/.irssi/config
343
-	echo '  Freenode = {' >> /home/$MY_USERNAME/.irssi/config
344
-	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
345
-	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
346
-	echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
347
-	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
348
-	echo '  };' >> /home/$MY_USERNAME/.irssi/config
349
-	echo '  OFTC = {' >> /home/$MY_USERNAME/.irssi/config
350
-	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
351
-	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
352
-	echo '    max_msgs = "1";' >> /home/$MY_USERNAME/.irssi/config
353
-	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
354
-	echo '  };' >> /home/$MY_USERNAME/.irssi/config
355
-	echo '};' >> /home/$MY_USERNAME/.irssi/config
356
-	echo '' >> /home/$MY_USERNAME/.irssi/config
357
-	echo 'channels = (' >> /home/$MY_USERNAME/.irssi/config
358
-	echo '  { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/$MY_USERNAME/.irssi/config
359
-	echo ');' >> /home/$MY_USERNAME/.irssi/config
360
-	echo '' >> /home/$MY_USERNAME/.irssi/config
361
-	echo 'settings = {' >> /home/$MY_USERNAME/.irssi/config
362
-	echo "  core = { real_name = \"$MY_NAME\"; user_name = \"$MY_USERNAME\"; nick = \"$MY_USERNAME\"; };" >> /home/$MY_USERNAME/.irssi/config
363
-	echo '  "fe-text" = { actlist_sort = "refnum"; };' >> /home/$MY_USERNAME/.irssi/config
364
-	echo '};' >> /home/$MY_USERNAME/.irssi/config
365
-	echo 'ignores = ( { level = "CTCPS"; } );' >> /home/$MY_USERNAME/.irssi/config
366
-
367
-	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.irssi
299
+    IRC_PORT=6697
300
+    if grep -q "IRC_PORT" $CONFIGURATION_FILE; then
301
+	IRC_PORT=$(grep "IRC_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
302
+    fi
303
+    IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
304
+    if [ ${#IRC_PASSWORD} -lt 2 ]; then
305
+	IRC_PASSWORD=
306
+    fi
307
+
308
+    if [ ! -d /home/$MY_USERNAME/.irssi ]; then
309
+	mkdir /home/$MY_USERNAME/.irssi
310
+    fi
311
+
312
+    echo 'servers = (' > /home/$MY_USERNAME/.irssi/config
313
+    echo '  {' >> /home/$MY_USERNAME/.irssi/config
314
+    echo '    address = "chat.freenode.net";' >> /home/$MY_USERNAME/.irssi/config
315
+    echo '    chatnet = "Freenode";' >> /home/$MY_USERNAME/.irssi/config
316
+    echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
317
+    echo '    autoconnect = "no";' >> /home/$MY_USERNAME/.irssi/config
318
+    echo '  },' >> /home/$MY_USERNAME/.irssi/config
319
+    echo '  {' >> /home/$MY_USERNAME/.irssi/config
320
+    echo '    address = "irc.oftc.net";' >> /home/$MY_USERNAME/.irssi/config
321
+    echo '    chatnet = "OFTC";' >> /home/$MY_USERNAME/.irssi/config
322
+    echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
323
+    echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
324
+    echo '  },' >> /home/$MY_USERNAME/.irssi/config
325
+    echo '  {' >> /home/$MY_USERNAME/.irssi/config
326
+    echo "    address = \"${HOSTNAME}\";" >> /home/$MY_USERNAME/.irssi/config
327
+    echo '    chatnet = "Freedombone";' >> /home/$MY_USERNAME/.irssi/config
328
+    echo "    port = \"${IRC_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
329
+    echo '    use_ssl = "yes";' >> /home/$MY_USERNAME/.irssi/config
330
+    echo '    ssl_verify = "no";' >> /home/$MY_USERNAME/.irssi/config
331
+    echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
332
+
333
+    echo '  }' >> /home/$MY_USERNAME/.irssi/config
334
+    echo ');' >> /home/$MY_USERNAME/.irssi/config
335
+    echo '' >> /home/$MY_USERNAME/.irssi/config
336
+    echo 'chatnets = {' >> /home/$MY_USERNAME/.irssi/config
337
+    echo '  Freedombone = {' >> /home/$MY_USERNAME/.irssi/config
338
+    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
339
+    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
340
+    echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
341
+    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
342
+    echo '  };' >> /home/$MY_USERNAME/.irssi/config
343
+    echo '  Freenode = {' >> /home/$MY_USERNAME/.irssi/config
344
+    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
345
+    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
346
+    echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
347
+    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
348
+    echo '  };' >> /home/$MY_USERNAME/.irssi/config
349
+    echo '  OFTC = {' >> /home/$MY_USERNAME/.irssi/config
350
+    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
351
+    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
352
+    echo '    max_msgs = "1";' >> /home/$MY_USERNAME/.irssi/config
353
+    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
354
+    echo '  };' >> /home/$MY_USERNAME/.irssi/config
355
+    echo '};' >> /home/$MY_USERNAME/.irssi/config
356
+    echo '' >> /home/$MY_USERNAME/.irssi/config
357
+    echo 'channels = (' >> /home/$MY_USERNAME/.irssi/config
358
+    echo '  { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/$MY_USERNAME/.irssi/config
359
+    echo ');' >> /home/$MY_USERNAME/.irssi/config
360
+    echo '' >> /home/$MY_USERNAME/.irssi/config
361
+    echo 'settings = {' >> /home/$MY_USERNAME/.irssi/config
362
+    echo "  core = { real_name = \"$MY_NAME\"; user_name = \"$MY_USERNAME\"; nick = \"$MY_USERNAME\"; };" >> /home/$MY_USERNAME/.irssi/config
363
+    echo '  "fe-text" = { actlist_sort = "refnum"; };' >> /home/$MY_USERNAME/.irssi/config
364
+    echo '};' >> /home/$MY_USERNAME/.irssi/config
365
+    echo 'ignores = ( { level = "CTCPS"; } );' >> /home/$MY_USERNAME/.irssi/config
366
+
367
+    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.irssi
368 368
 fi
369 369
 
370 370
 if [ -f /etc/nginx/.htpasswd ]; then
371
-	if ! grep "${MY_USERNAME}:" /etc/nginx/.htpasswd; then
372
-		echo "$NEW_USER_PASSWORD" | htpasswd -i -s /etc/nginx/.htpasswd $MY_USERNAME
373
-	fi
371
+    if ! grep "${MY_USERNAME}:" /etc/nginx/.htpasswd; then
372
+	echo "$NEW_USER_PASSWORD" | htpasswd -i -s /etc/nginx/.htpasswd $MY_USERNAME
373
+    fi
374 374
 fi
375 375
 
376 376
 # add user to the sipwitch group
377 377
 if [ -f /etc/sipwitch.conf ]; then
378
-	usermod -aG sipwitch $MY_USERNAME
378
+    usermod -aG sipwitch $MY_USERNAME
379 379
 fi
380 380
 
381 381
 # add user for SIP STUN/TURN
382 382
 if [ -d /etc/turnserver ]; then
383
-	if grep -q "DEFAULT_DOMAIN_NAME" $CONFIGURATION_FILE; then
384
-		DEFAULT_DOMAIN_NAME=$(grep "DEFAULT_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
385
-		echo "${MY_USERNAME}:${NEW_USER_PASSWORD}:${DEFAULT_DOMAIN_NAME}:authorized" >> /etc/turnserver/turnusers.txt
386
-	fi
383
+    if grep -q "DEFAULT_DOMAIN_NAME" $CONFIGURATION_FILE; then
384
+	DEFAULT_DOMAIN_NAME=$(grep "DEFAULT_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
385
+	echo "${MY_USERNAME}:${NEW_USER_PASSWORD}:${DEFAULT_DOMAIN_NAME}:authorized" >> /etc/turnserver/turnusers.txt
386
+    fi
387 387
 fi
388 388
 
389 389
 # add user menu on ssh login
390 390
 if ! grep -q 'control' /home/$MY_USERNAME/.bashrc; then
391
-	echo 'control' >> /home/$MY_USERNAME/.bashrc
391
+    echo 'control' >> /home/$MY_USERNAME/.bashrc
392 392
 fi
393 393
 
394 394
 clear
395 395
 echo $"New user $MY_USERNAME was created"
396 396
 if [ $SIP_EXTENSION ]; then
397
-	echo $"Their SIP phone extension is $SIP_EXTENSION"
397
+    echo $"Their SIP phone extension is $SIP_EXTENSION"
398 398
 fi
399 399
 echo $"Their login password is $NEW_USER_PASSWORD"
400 400
 echo ''

+ 18
- 18
src/freedombone-addxmpp Voir le fichier

@@ -46,25 +46,25 @@ function show_help {
46 46
 
47 47
 while [[ $# > 1 ]]
48 48
 do
49
-key="$1"
49
+    key="$1"
50 50
 
51
-case $key in
52
-    -h|--help)
53
-    show_help
54
-    ;;
55
-    -e|--email)
56
-    shift
57
-    EMAIL_ADDRESS="$1"
58
-    ;;
59
-    -p|--password|--passphrase)
51
+    case $key in
52
+	-h|--help)
53
+	    show_help
54
+	    ;;
55
+	-e|--email)
56
+	    shift
57
+	    EMAIL_ADDRESS="$1"
58
+	    ;;
59
+	-p|--password|--passphrase)
60
+	    shift
61
+	    NEW_USER_PASSWORD="$1"
62
+	    ;;
63
+	*)
64
+	    # unknown option
65
+	    ;;
66
+    esac
60 67
     shift
61
-    NEW_USER_PASSWORD="$1"
62
-    ;;
63
-    *)
64
-    # unknown option
65
-    ;;
66
-esac
67
-shift
68 68
 done
69 69
 
70 70
 if [ ! -d /etc/prosody ]; then
@@ -84,7 +84,7 @@ else
84 84
     DOMAIN_NAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $2}')
85 85
     prosodyctl register $USERNAME $DOMAIN_NAME "$NEW_USER_PASSWORD"
86 86
     if [ ! "$?" = "0" ]; then
87
-        exit 2
87
+	exit 2
88 88
     fi
89 89
 fi
90 90
 

+ 88
- 88
src/freedombone-app-batman Voir le fichier

@@ -34,16 +34,16 @@ ENABLE_BATMAN="no"
34 34
 BATMAN_CELLID='any'
35 35
 
36 36
 function configure_firewall_for_batma {
37
-	if grep -Fxq "configure_firewall_for_batman" $COMPLETION_FILE; then
38
-		return
39
-	fi
40
-	if [[ $ENABLE_BATMAN != "yes" ]]; then
41
-		return
42
-	fi
43
-
44
-	function_check save_firewall_settings
45
-	save_firewall_settings
46
-	echo 'configure_firewall_for_batman' >> $COMPLETION_FILE
37
+    if grep -Fxq "configure_firewall_for_batman" $COMPLETION_FILE; then
38
+	return
39
+    fi
40
+    if [[ $ENABLE_BATMAN != "yes" ]]; then
41
+	return
42
+    fi
43
+
44
+    function_check save_firewall_settings
45
+    save_firewall_settings
46
+    echo 'configure_firewall_for_batman' >> $COMPLETION_FILE
47 47
 }
48 48
 
49 49
 function reconfigure_batman {
@@ -71,90 +71,90 @@ function restore_remote_batman {
71 71
 }
72 72
 
73 73
 function remove_batman {
74
-	if ! grep -Fxq "install_batman" $COMPLETION_FILE; then
75
-		return
76
-	fi
77
-
78
-	${PROJECT_NAME}-mesh-install -f batman --remove yes
79
-	if [ ! "$?" = "0" ]; then
80
-		echo $'Failed to remove batman'
81
-		exit 79353
82
-	fi
83
-	sed -i '/install_batman/d' $COMPLETION_FILE
84
-	sed -i '/configure_firewall_for_batman/d' $COMPLETION_FILE
74
+    if ! grep -Fxq "install_batman" $COMPLETION_FILE; then
75
+	return
76
+    fi
77
+
78
+    ${PROJECT_NAME}-mesh-install -f batman --remove yes
79
+    if [ ! "$?" = "0" ]; then
80
+	echo $'Failed to remove batman'
81
+	exit 79353
82
+    fi
83
+    sed -i '/install_batman/d' $COMPLETION_FILE
84
+    sed -i '/configure_firewall_for_batman/d' $COMPLETION_FILE
85 85
 }
86 86
 
87 87
 function mesh_install_batman {
88
-	chroot "$rootdir" apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
89
-	chroot "$rootdir" apt-get -y install python-dev libevent-dev ebtables python-pip git
90
-	chroot "$rootdir" apt-get -y install wireless-tools rfkill
91
-
92
-	if ! grep -q "batman_adv" $rootdir/etc/modules; then
93
-		echo 'batman_adv' >> $rootdir/etc/modules
94
-	fi
95
-
96
-	BATMAN_SCRIPT=$rootdir/var/lib/batman
97
-
98
-	if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
99
-		cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
100
-	else
101
-		cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
102
-	fi
103
-
104
-	BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
105
-	echo '[Unit]' > $BATMAN_DAEMON
106
-	echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
107
-	echo 'After=network.target' >> $BATMAN_DAEMON
108
-	echo '' >> $BATMAN_DAEMON
109
-	echo '[Service]' >> $BATMAN_DAEMON
110
-	echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
111
-	echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
112
-	echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
113
-	echo 'Restart=on-failure' >> $BATMAN_DAEMON
114
-	echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
115
-	echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
116
-	echo '' >> $BATMAN_DAEMON
117
-	echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
118
-	echo 'TimeoutSec=300' >> $BATMAN_DAEMON
119
-	echo '' >> $BATMAN_DAEMON
120
-	echo '[Install]' >> $BATMAN_DAEMON
121
-	echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
122
-	chroot "$rootdir" systemctl enable batman
88
+    chroot "$rootdir" apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
89
+    chroot "$rootdir" apt-get -y install python-dev libevent-dev ebtables python-pip git
90
+    chroot "$rootdir" apt-get -y install wireless-tools rfkill
91
+
92
+    if ! grep -q "batman_adv" $rootdir/etc/modules; then
93
+	echo 'batman_adv' >> $rootdir/etc/modules
94
+    fi
95
+
96
+    BATMAN_SCRIPT=$rootdir/var/lib/batman
97
+
98
+    if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
99
+	cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
100
+    else
101
+	cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
102
+    fi
103
+
104
+    BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
105
+    echo '[Unit]' > $BATMAN_DAEMON
106
+    echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
107
+    echo 'After=network.target' >> $BATMAN_DAEMON
108
+    echo '' >> $BATMAN_DAEMON
109
+    echo '[Service]' >> $BATMAN_DAEMON
110
+    echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
111
+    echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
112
+    echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
113
+    echo 'Restart=on-failure' >> $BATMAN_DAEMON
114
+    echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
115
+    echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
116
+    echo '' >> $BATMAN_DAEMON
117
+    echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
118
+    echo 'TimeoutSec=300' >> $BATMAN_DAEMON
119
+    echo '' >> $BATMAN_DAEMON
120
+    echo '[Install]' >> $BATMAN_DAEMON
121
+    echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
122
+    chroot "$rootdir" systemctl enable batman
123 123
 }
124 124
 
125 125
 function install_batman {
126
-	if [ $INSTALLING_MESH ]; then
127
-		mesh_install_batman
128
-		return
129
-	fi
130
-	if grep -Fxq "install_batman" $COMPLETION_FILE; then
131
-		return
132
-	fi
133
-	if [[ $ENABLE_BATMAN != "yes" ]]; then
134
-		return
135
-	fi
136
-
137
-	${PROJECT_NAME}-mesh-install -f batman
138
-	if [ ! "$?" = "0" ]; then
139
-		echo $'Failed to install batman'
140
-		exit 72524
141
-	fi
142
-
143
-	if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
144
-		echo '' >> /home/$MY_USERNAME/README
145
-		echo '' >> /home/$MY_USERNAME/README
146
-		echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
147
-		echo '=============================' >> /home/$MY_USERNAME/README
148
-		echo "Mesh ESSID: $WIFI_SSID" >> /home/$MY_USERNAME/README
149
-		echo "Mesh cell ID: $BATMAN_CELLID" >> /home/$MY_USERNAME/README
150
-		echo "Mesh wifi channel: $WIFI_CHANNEL" >> /home/$MY_USERNAME/README
151
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
152
-		chmod 600 /home/$MY_USERNAME/README
153
-	fi
154
-
155
-	function_check configure_firewall_for_batman
156
-	configure_firewall_for_batman
157
-	echo 'install_batman' >> $COMPLETION_FILE
126
+    if [ $INSTALLING_MESH ]; then
127
+	mesh_install_batman
128
+	return
129
+    fi
130
+    if grep -Fxq "install_batman" $COMPLETION_FILE; then
131
+	return
132
+    fi
133
+    if [[ $ENABLE_BATMAN != "yes" ]]; then
134
+	return
135
+    fi
136
+
137
+    ${PROJECT_NAME}-mesh-install -f batman
138
+    if [ ! "$?" = "0" ]; then
139
+	echo $'Failed to install batman'
140
+	exit 72524
141
+    fi
142
+
143
+    if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
144
+	echo '' >> /home/$MY_USERNAME/README
145
+	echo '' >> /home/$MY_USERNAME/README
146
+	echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
147
+	echo '=============================' >> /home/$MY_USERNAME/README
148
+	echo "Mesh ESSID: $WIFI_SSID" >> /home/$MY_USERNAME/README
149
+	echo "Mesh cell ID: $BATMAN_CELLID" >> /home/$MY_USERNAME/README
150
+	echo "Mesh wifi channel: $WIFI_CHANNEL" >> /home/$MY_USERNAME/README
151
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
152
+	chmod 600 /home/$MY_USERNAME/README
153
+    fi
154
+
155
+    function_check configure_firewall_for_batman
156
+    configure_firewall_for_batman
157
+    echo 'install_batman' >> $COMPLETION_FILE
158 158
 }
159 159
 
160 160
 # NOTE: deliberately no exit 0

+ 425
- 425
src/freedombone-app-cjdns Voir le fichier

@@ -42,498 +42,498 @@ CJDCMD_REPO="https://github.com/inhies/cjdcmd"
42 42
 CJDCMD_COMMIT='973cca6ed0eecf9041c3403a40193c0b1291b808'
43 43
 
44 44
 function reconfigure_cjdns {
45
-	echo -n ''
45
+    echo -n ''
46 46
 }
47 47
 
48 48
 function upgrade_cjdns {
49
-	if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
50
-		return
51
-	fi
52
-	function_check set_repo_commit
53
-	set_repo_commit /etc/cjdns "cjdns commit" "$CJDNS_COMMIT" $CJDNS_REPO
49
+    if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
50
+	return
51
+    fi
52
+    function_check set_repo_commit
53
+    set_repo_commit /etc/cjdns "cjdns commit" "$CJDNS_COMMIT" $CJDNS_REPO
54 54
 }
55 55
 
56 56
 function configure_firewall_for_cjdns {
57
-	if grep -Fxq "configure_firewall_for_cjdns" $COMPLETION_FILE; then
58
-		return
59
-	fi
60
-	if [[ $ENABLE_CJDNS != "yes" ]]; then
61
-		return
62
-	fi
63
-	ip6tables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
64
-	ip6tables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
65
-	ip6tables -A INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
66
-	ip6tables -A INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
67
-
68
-	function_check save_firewall_settings
69
-	save_firewall_settings
70
-	echo 'configure_firewall_for_cjdns' >> $COMPLETION_FILE
57
+    if grep -Fxq "configure_firewall_for_cjdns" $COMPLETION_FILE; then
58
+	return
59
+    fi
60
+    if [[ $ENABLE_CJDNS != "yes" ]]; then
61
+	return
62
+    fi
63
+    ip6tables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
64
+    ip6tables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
65
+    ip6tables -A INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
66
+    ip6tables -A INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
67
+
68
+    function_check save_firewall_settings
69
+    save_firewall_settings
70
+    echo 'configure_firewall_for_cjdns' >> $COMPLETION_FILE
71 71
 }
72 72
 
73 73
 function get_cjdns_public_key {
74
-	if [ -f /home/$MY_USERNAME/README ]; then
75
-		if grep -q "cjdns public key" /home/$MY_USERNAME/README; then
76
-			if [ ! $CJDNS_PUBLIC_KEY ]; then
77
-				CJDNS_PUBLIC_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns public key" | awk -F ':' '{print $2}' | sed 's/^ *//')
78
-			fi
79
-		fi
74
+    if [ -f /home/$MY_USERNAME/README ]; then
75
+	if grep -q "cjdns public key" /home/$MY_USERNAME/README; then
76
+	    if [ ! $CJDNS_PUBLIC_KEY ]; then
77
+		CJDNS_PUBLIC_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns public key" | awk -F ':' '{print $2}' | sed 's/^ *//')
78
+	    fi
80 79
 	fi
80
+    fi
81 81
 }
82 82
 
83 83
 function get_cjdns_private_key {
84
-	if [ -f /home/$MY_USERNAME/README ]; then
85
-		if grep -q "cjdns private key" /home/$MY_USERNAME/README; then
86
-			if [ ! $CJDNS_PRIVATE_KEY ]; then
87
-				CJDNS_PRIVATE_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns private key" | awk -F ':' '{print $2}' | sed 's/^ *//')
88
-			fi
89
-		fi
84
+    if [ -f /home/$MY_USERNAME/README ]; then
85
+	if grep -q "cjdns private key" /home/$MY_USERNAME/README; then
86
+	    if [ ! $CJDNS_PRIVATE_KEY ]; then
87
+		CJDNS_PRIVATE_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns private key" | awk -F ':' '{print $2}' | sed 's/^ *//')
88
+	    fi
90 89
 	fi
90
+    fi
91 91
 }
92 92
 
93 93
 function get_cjdns_ipv6_address {
94
-	if [ -f /home/$MY_USERNAME/README ]; then
95
-		if grep -q "cjdns IPv6 address" /home/$MY_USERNAME/README; then
96
-			if [ ! $CJDNS_IPV6 ]; then
97
-				CJDNS_IPV6=$(cat /home/$MY_USERNAME/README | grep "cjdns IPv6 address" | awk -F ':' '{print $2}' | sed 's/^ *//')
98
-			fi
99
-		fi
94
+    if [ -f /home/$MY_USERNAME/README ]; then
95
+	if grep -q "cjdns IPv6 address" /home/$MY_USERNAME/README; then
96
+	    if [ ! $CJDNS_IPV6 ]; then
97
+		CJDNS_IPV6=$(cat /home/$MY_USERNAME/README | grep "cjdns IPv6 address" | awk -F ':' '{print $2}' | sed 's/^ *//')
98
+	    fi
100 99
 	fi
100
+    fi
101 101
 }
102 102
 
103 103
 function get_cjdns_port {
104
-	if [ -f /home/$MY_USERNAME/README ]; then
105
-		if grep -q "cjdns port" /home/$MY_USERNAME/README; then
106
-			if [ ! $CJDNS_PORT ]; then
107
-				CJDNS_PORT=$(cat /home/$MY_USERNAME/README | grep "cjdns port" | awk -F ':' '{print $2}' | sed 's/^ *//')
108
-			fi
109
-		fi
104
+    if [ -f /home/$MY_USERNAME/README ]; then
105
+	if grep -q "cjdns port" /home/$MY_USERNAME/README; then
106
+	    if [ ! $CJDNS_PORT ]; then
107
+		CJDNS_PORT=$(cat /home/$MY_USERNAME/README | grep "cjdns port" | awk -F ':' '{print $2}' | sed 's/^ *//')
108
+	    fi
110 109
 	fi
110
+    fi
111 111
 }
112 112
 
113 113
 function get_cjdns_password {
114
-	if [ -f /home/$MY_USERNAME/README ]; then
115
-		if grep -q "cjdns password" /home/$MY_USERNAME/README; then
116
-			if [ ! $CJDNS_PASSWORD ]; then
117
-				CJDNS_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "cjdns password" | awk -F ':' '{print $2}' | sed 's/^ *//')
118
-			fi
119
-		fi
114
+    if [ -f /home/$MY_USERNAME/README ]; then
115
+	if grep -q "cjdns password" /home/$MY_USERNAME/README; then
116
+	    if [ ! $CJDNS_PASSWORD ]; then
117
+		CJDNS_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "cjdns password" | awk -F ':' '{print $2}' | sed 's/^ *//')
118
+	    fi
120 119
 	fi
120
+    fi
121 121
 }
122 122
 
123 123
 function backup_local_cjdns {
124
-	echo -n ''
124
+    echo -n ''
125 125
 }
126 126
 
127 127
 function restore_local_cjdns {
128
-	if [ -d $USB_MOUNT/backup/cjdns ]; then
129
-		echo $"Restoring cjdns installation"
130
-		temp_restore_dir=/root/tempcjdns
131
-		function_check restore_directory_from_usb
132
-		restore_directory_from_usb $temp_restore_dir cjdns
133
-		rm -rf /etc/cjdns
134
-		cp -r $temp_restore_dir/etc/cjdns /etc/
135
-		if [ ! "$?" = "0" ]; then
136
-			function_check set_user_permissions
137
-			set_user_permissions
138
-			function_check backup_unmount_drive
139
-			backup_unmount_drive
140
-			exit 8472
141
-		fi
142
-		rm -rf $temp_restore_dir
143
-	fi
128
+    if [ -d $USB_MOUNT/backup/cjdns ]; then
129
+	echo $"Restoring cjdns installation"
130
+	temp_restore_dir=/root/tempcjdns
131
+	function_check restore_directory_from_usb
132
+	restore_directory_from_usb $temp_restore_dir cjdns
133
+	rm -rf /etc/cjdns
134
+	cp -r $temp_restore_dir/etc/cjdns /etc/
135
+	if [ ! "$?" = "0" ]; then
136
+	    function_check set_user_permissions
137
+	    set_user_permissions
138
+	    function_check backup_unmount_drive
139
+	    backup_unmount_drive
140
+	    exit 8472
141
+	fi
142
+	rm -rf $temp_restore_dir
143
+    fi
144 144
 }
145 145
 
146 146
 function backup_remote_cjdns {
147
-	echo -n ''
147
+    echo -n ''
148 148
 }
149 149
 
150 150
 function restore_remote_cjdns {
151
-	if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
152
-		echo $"Restoring cjdns installation"
153
-		temp_restore_dir=/root/tempcjdns
154
-		function_check restore_directory_from_friend
155
-		restore_directory_from_friend $temp_restore_dir cjdns
156
-		rm -rf /etc/cjdns
157
-		cp -r $temp_restore_dir/etc/cjdns /etc/
158
-		if [ ! "$?" = "0" ]; then
159
-			exit 7438
160
-		fi
161
-		rm -rf $temp_restore_dir
151
+    if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
152
+	echo $"Restoring cjdns installation"
153
+	temp_restore_dir=/root/tempcjdns
154
+	function_check restore_directory_from_friend
155
+	restore_directory_from_friend $temp_restore_dir cjdns
156
+	rm -rf /etc/cjdns
157
+	cp -r $temp_restore_dir/etc/cjdns /etc/
158
+	if [ ! "$?" = "0" ]; then
159
+	    exit 7438
162 160
 	fi
161
+	rm -rf $temp_restore_dir
162
+    fi
163 163
 }
164 164
 
165 165
 function remove_cjdns {
166
-	if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
167
-		return
168
-	fi
169
-	service cjdns stop
170
-	ip6tables -D nat -D POSTROUTING -o tun0 -j MASQUERADE
171
-	ip6tables -D FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
172
-	ip6tables -D INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
173
-	ip6tables -D INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
174
-	function_check save_firewall_settings
175
-	save_firewall_settings
176
-
177
-	rm -rf /etc/cjdns
178
-	sed -i '/install_cjdns/d' $COMPLETION_FILE
179
-	sed -i '/cjdns /d' $COMPLETION_FILE
180
-	sed -i '/configure_firewall_for_cjdns/d' $COMPLETION_FILE
166
+    if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
167
+	return
168
+    fi
169
+    service cjdns stop
170
+    ip6tables -D nat -D POSTROUTING -o tun0 -j MASQUERADE
171
+    ip6tables -D FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
172
+    ip6tables -D INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
173
+    ip6tables -D INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
174
+    function_check save_firewall_settings
175
+    save_firewall_settings
176
+
177
+    rm -rf /etc/cjdns
178
+    sed -i '/install_cjdns/d' $COMPLETION_FILE
179
+    sed -i '/cjdns /d' $COMPLETION_FILE
180
+    sed -i '/configure_firewall_for_cjdns/d' $COMPLETION_FILE
181 181
 }
182 182
 
183 183
 function install_cjdns_main {
184
-	if [[ $ENABLE_CJDNS != "yes" ]]; then
185
-		return
186
-	fi
187
-
188
-	if grep -Fxq "install_cjdns_main" $COMPLETION_FILE; then
189
-		return
190
-	fi
184
+    if [[ $ENABLE_CJDNS != "yes" ]]; then
185
+	return
186
+    fi
191 187
 
192
-	apt-get -y install nodejs git build-essential nmap
188
+    if grep -Fxq "install_cjdns_main" $COMPLETION_FILE; then
189
+	return
190
+    fi
193 191
 
194
-	# if a README exists then obtain the cjdns parameters
195
-	function_check get_cjdns_ipv6_address
196
-	get_cjdns_ipv6_address
192
+    apt-get -y install nodejs git build-essential nmap
197 193
 
198
-	function_check get_cjdns_public_key
199
-	get_cjdns_public_key
194
+    # if a README exists then obtain the cjdns parameters
195
+    function_check get_cjdns_ipv6_address
196
+    get_cjdns_ipv6_address
200 197
 
201
-	function_check get_cjdns_private_key
202
-	get_cjdns_private_key
198
+    function_check get_cjdns_public_key
199
+    get_cjdns_public_key
203 200
 
204
-	function_check get_cjdns_port
205
-	get_cjdns_port
201
+    function_check get_cjdns_private_key
202
+    get_cjdns_private_key
206 203
 
207
-	function_check get_cjdns_password
208
-	get_cjdns_password
204
+    function_check get_cjdns_port
205
+    get_cjdns_port
209 206
 
210
-	# special compile settings for running ./do on the Beaglebone Black
211
-	if [[ $INSTALLING_ON_BBB == "yes" ]]; then
212
-		CFLAGS="-O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -ffast-math -mfloat-abi=hard -marm -Wno-error=maybe-uninitialized"
213
-		export LDFLAGS="$CFLAGS"
214
-	fi
207
+    function_check get_cjdns_password
208
+    get_cjdns_password
215 209
 
216
-	if [ ! -d /etc/cjdns ]; then
217
-		function_check git_pull
218
-		git_clone $CJDNS_REPO /etc/cjdns
219
-		cd /etc/cjdns
220
-
221
-		git checkout $CJDNS_COMMIT -b $CJDNS_COMMIT
222
-		if ! grep -q "cjdns commit" $COMPLETION_FILE; then
223
-			echo "cjdns commit:$CJDNS_COMMIT" >> $COMPLETION_FILE
224
-		else
225
-			sed -i "s/cjdns commit.*/cjdns commit:$CJDNS_COMMIT/g" $COMPLETION_FILE
226
-		fi
227
-
228
-		./do
229
-		if [ ! "$?" = "0" ]; then
230
-			exit 7439
231
-		fi
232
-		# create a configuration
233
-		if [ ! -f /etc/cjdns/cjdroute.conf ]; then
234
-			./cjdroute --genconf > /etc/cjdns/cjdroute.conf
235
-			if [ ! "$?" = "0" ]; then
236
-				exit 5922
237
-			fi
238
-		fi
239
-		# create a user to run as
240
-		useradd cjdns
241
-	else
242
-		cd /etc/cjdns
243
-		function_check git_pull
244
-		git_pull $CJDNS_REPO
245
-		./do
246
-		if [ ! "$?" = "0" ]; then
247
-			exit 9926
248
-		fi
249
-	fi
210
+    # special compile settings for running ./do on the Beaglebone Black
211
+    if [[ $INSTALLING_ON_BBB == "yes" ]]; then
212
+	CFLAGS="-O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -ffast-math -mfloat-abi=hard -marm -Wno-error=maybe-uninitialized"
213
+	export LDFLAGS="$CFLAGS"
214
+    fi
250 215
 
251
-	# set permissions
252
-	chown -R cjdns:cjdns /etc/cjdns
253
-	chmod 600 /etc/cjdns/cjdroute.conf
216
+    if [ ! -d /etc/cjdns ]; then
217
+	function_check git_pull
218
+	git_clone $CJDNS_REPO /etc/cjdns
219
+	cd /etc/cjdns
254 220
 
255
-	/sbin/ip tuntap add mode tun user cjdns dev cjdroute0
256
-
257
-	# insert values into the configuration file
258
-	if [ $CJDNS_PRIVATE_KEY ]; then
259
-		sed -i "s/\"privateKey\":.*/\"privateKey\": \"$CJDNS_PRIVATE_KEY\",/g" /etc/cjdns/cjdroute.conf
260
-	else
261
-		CJDNS_PRIVATE_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"privateKey"' | awk -F '"' '{print $4}' | sed -n 1p)
262
-	fi
263
-	if [ $CJDNS_PUBLIC_KEY ]; then
264
-		sed -i "s/\"publicKey\":.*/\"publicKey\": \"$CJDNS_PUBLIC_KEY\",/g" /etc/cjdns/cjdroute.conf
265
-	else
266
-		CJDNS_PUBLIC_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"publicKey"' | awk -F '"' '{print $4}' | sed -n 1p)
267
-	fi
268
-	if [ $CJDNS_IPV6 ]; then
269
-		sed -i "s/\"ipv6\":.*/\"ipv6\": \"$CJDNS_IPV6\",/g" /etc/cjdns/cjdroute.conf
270
-	else
271
-		CJDNS_IPV6=$(cat /etc/cjdns/cjdroute.conf | grep '"ipv6"' | awk -F '"' '{print $4}' | sed -n 1p)
272
-	fi
273
-	if [ $CJDNS_PASSWORD ]; then
274
-		sed -i "0,/{\"password\":.*/s//{\"password\": \"$CJDNS_PASSWORD\"}/g" /etc/cjdns/cjdroute.conf
275
-	else
276
-		CJDNS_PASSWORD=$(cat /etc/cjdns/cjdroute.conf | grep '"password"' | awk -F '"' '{print $4}' | sed -n 1p)
277
-	fi
278
-	if [ $CJDNS_PORT ]; then
279
-		sed -i "s/\"bind\": \"0.0.0.0:.*/\"bind\": \"0.0.0.0:$CJDNS_PORT\",/g" /etc/cjdns/cjdroute.conf
221
+	git checkout $CJDNS_COMMIT -b $CJDNS_COMMIT
222
+	if ! grep -q "cjdns commit" $COMPLETION_FILE; then
223
+	    echo "cjdns commit:$CJDNS_COMMIT" >> $COMPLETION_FILE
280 224
 	else
281
-		CJDNS_PORT=$(cat /etc/cjdns/cjdroute.conf | grep '"bind": "0.0.0.0:' | awk -F '"' '{print $4}' | awk -F ':' '{print $2}' | sed -n 1p)
225
+	    sed -i "s/cjdns commit.*/cjdns commit:$CJDNS_COMMIT/g" $COMPLETION_FILE
282 226
 	fi
283 227
 
284
-	function_check enable_ipv6
285
-	enable_ipv6
286
-
287
-	echo '#!/bin/sh -e' > /etc/init.d/cjdns
288
-	echo '### BEGIN INIT INFO' >> /etc/init.d/cjdns
289
-	echo '# hyperboria.sh - An init script (/etc/init.d/) for cjdns' >> /etc/init.d/cjdns
290
-	echo '# Provides:          cjdroute' >> /etc/init.d/cjdns
291
-	echo '# Required-Start:    $remote_fs $network' >> /etc/init.d/cjdns
292
-	echo '# Required-Stop:     $remote_fs $network' >> /etc/init.d/cjdns
293
-	echo '# Default-Start:     2 3 4 5' >> /etc/init.d/cjdns
294
-	echo '# Default-Stop:      0 1 6' >> /etc/init.d/cjdns
295
-	echo '# Short-Description: Cjdns router' >> /etc/init.d/cjdns
296
-	echo '# Description:       A routing engine designed for security, scalability, speed and ease of use.' >> /etc/init.d/cjdns
297
-	echo '# cjdns git repo:    https://github.com/cjdelisle/cjdns/' >> /etc/init.d/cjdns
298
-	echo '### END INIT INFO' >> /etc/init.d/cjdns
299
-	echo '' >> /etc/init.d/cjdns
300
-	echo 'PROG="cjdroute"' >> /etc/init.d/cjdns
301
-	echo 'GIT_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
302
-	echo 'PROG_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
303
-	echo 'CJDNS_CONFIG="cjdroute.conf"' >> /etc/init.d/cjdns
304
-	echo 'CJDNS_USER="cjdns"' >> /etc/init.d/cjdns
305
-	echo "CJDNS_IP='$CJDNS_IPV6'" >> /etc/init.d/cjdns
306
-	echo '' >> /etc/init.d/cjdns
307
-	echo 'start() {' >> /etc/init.d/cjdns
308
-	echo '     # Start it up with the user cjdns' >> /etc/init.d/cjdns
309
-	echo '     if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
310
-	echo '     then' >> /etc/init.d/cjdns
311
-	echo '         echo "cjdroute is already running. Doing nothing..."' >> /etc/init.d/cjdns
312
-	echo '     else' >> /etc/init.d/cjdns
313
-	echo '         echo " * Starting cjdroute"' >> /etc/init.d/cjdns
314
-	echo '         su -c "$PROG_PATH/$PROG < $PROG_PATH/$CJDNS_CONFIG" - $CJDNS_USER' >> /etc/init.d/cjdns
315
-	echo '         /sbin/ip addr add $CJDNS_IP/8 dev tun0' >> /etc/init.d/cjdns
316
-	echo '         /sbin/ip link set mtu 1312 dev tun0' >> /etc/init.d/cjdns
317
-	echo '         /sbin/ip link set tun0 up' >> /etc/init.d/cjdns
318
-	echo '         /sbin/ip tuntap add mode tun user cjdns dev tun0' >> /etc/init.d/cjdns
319
-	echo '     fi' >> /etc/init.d/cjdns
320
-	echo '}' >> /etc/init.d/cjdns
321
-	echo '' >> /etc/init.d/cjdns
322
-	echo 'stop() {' >> /etc/init.d/cjdns
323
-	echo '' >> /etc/init.d/cjdns
324
-	echo '     if [ $(pgrep cjdroute | wc -l) != 2 ];' >> /etc/init.d/cjdns
325
-	echo '     then' >> /etc/init.d/cjdns
326
-	echo '         echo "cjdns isnt running."' >> /etc/init.d/cjdns
327
-	echo '     else' >> /etc/init.d/cjdns
328
-	echo '         echo "Killing cjdroute"' >> /etc/init.d/cjdns
329
-	echo '         killall cjdroute' >> /etc/init.d/cjdns
330
-	echo '     fi' >> /etc/init.d/cjdns
331
-	echo '}' >> /etc/init.d/cjdns
332
-	echo '' >> /etc/init.d/cjdns
333
-	echo 'status() {' >> /etc/init.d/cjdns
334
-	echo '     if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
335
-	echo '     then' >> /etc/init.d/cjdns
336
-	echo '         echo "Cjdns is running"' >> /etc/init.d/cjdns
337
-	echo '     else' >> /etc/init.d/cjdns
338
-	echo '         echo "Cjdns is not running"' >> /etc/init.d/cjdns
339
-	echo '     fi' >> /etc/init.d/cjdns
340
-	echo '}' >> /etc/init.d/cjdns
341
-	echo '' >> /etc/init.d/cjdns
342
-	echo ' update() {' >> /etc/init.d/cjdns
343
-	echo '     cd $GIT_PATH' >> /etc/init.d/cjdns
344
-	echo '     echo "Updating..."' >> /etc/init.d/cjdns
345
-	echo '     git pull' >> /etc/init.d/cjdns
346
-	echo '     ./do' >> /etc/init.d/cjdns
347
-	echo '}' >> /etc/init.d/cjdns
348
-	echo '' >> /etc/init.d/cjdns
349
-	echo '## Check to see if we are running as root first.' >> /etc/init.d/cjdns
350
-	echo 'if [ "$(id -u)" != "0" ]; then' >> /etc/init.d/cjdns
351
-	echo '    echo "This script must be run as root" 1>&2' >> /etc/init.d/cjdns
352
-	echo '    exit 1' >> /etc/init.d/cjdns
353
-	echo 'fi' >> /etc/init.d/cjdns
354
-	echo '' >> /etc/init.d/cjdns
355
-	echo 'case $1 in' >> /etc/init.d/cjdns
356
-	echo '     start)' >> /etc/init.d/cjdns
357
-	echo '         start' >> /etc/init.d/cjdns
358
-	echo '         exit 0' >> /etc/init.d/cjdns
359
-	echo '     ;;' >> /etc/init.d/cjdns
360
-	echo '     stop)' >> /etc/init.d/cjdns
361
-	echo '         stop' >> /etc/init.d/cjdns
362
-	echo '         exit 0' >> /etc/init.d/cjdns
363
-	echo '     ;;' >> /etc/init.d/cjdns
364
-	echo '     reload|restart|force-reload)' >> /etc/init.d/cjdns
365
-	echo '         stop' >> /etc/init.d/cjdns
366
-	echo '         sleep 1' >> /etc/init.d/cjdns
367
-	echo '         start' >> /etc/init.d/cjdns
368
-	echo '         exit 0' >> /etc/init.d/cjdns
369
-	echo '     ;;' >> /etc/init.d/cjdns
370
-	echo '     status)' >> /etc/init.d/cjdns
371
-	echo '         status' >> /etc/init.d/cjdns
372
-	echo '         exit 0' >> /etc/init.d/cjdns
373
-	echo '     ;;' >> /etc/init.d/cjdns
374
-	echo '     update|upgrade)' >> /etc/init.d/cjdns
375
-	echo '         update' >> /etc/init.d/cjdns
376
-	echo '         stop' >> /etc/init.d/cjdns
377
-	echo '         sleep 2' >> /etc/init.d/cjdns
378
-	echo '         start' >> /etc/init.d/cjdns
379
-	echo '         exit 0' >> /etc/init.d/cjdns
380
-	echo '     ;;' >> /etc/init.d/cjdns
381
-	echo '     **)' >> /etc/init.d/cjdns
382
-	echo '         echo "Usage: $0 (start|stop|restart|status|update)" 1>&2' >> /etc/init.d/cjdns
383
-	echo '         exit 1' >> /etc/init.d/cjdns
384
-	echo '     ;;' >> /etc/init.d/cjdns
385
-	echo 'esac' >> /etc/init.d/cjdns
386
-	chmod +x /etc/init.d/cjdns
387
-	update-rc.d cjdns defaults
388
-	service cjdns start
228
+	./do
389 229
 	if [ ! "$?" = "0" ]; then
390
-		systemctl status cjdns.service
391
-		exit 8260
392
-	fi
393
-
394
-	apt-get -y install radvd
395
-	echo 'interface eth0' > /etc/radvd.conf
396
-	echo '{' >> /etc/radvd.conf
397
-	echo '    AdvSendAdvert on;' >> /etc/radvd.conf
398
-	echo '    prefix fdfc::1/64' >> /etc/radvd.conf
399
-	echo '    {' >> /etc/radvd.conf
400
-	echo '        AdvRouterAddr on;' >> /etc/radvd.conf
401
-	echo '    };' >> /etc/radvd.conf
402
-	echo '};' >> /etc/radvd.conf
403
-	systemctl restart radvd
230
+	    exit 7439
231
+	fi
232
+	# create a configuration
233
+	if [ ! -f /etc/cjdns/cjdroute.conf ]; then
234
+	    ./cjdroute --genconf > /etc/cjdns/cjdroute.conf
235
+	    if [ ! "$?" = "0" ]; then
236
+		exit 5922
237
+	    fi
238
+	fi
239
+	# create a user to run as
240
+	useradd cjdns
241
+    else
242
+	cd /etc/cjdns
243
+	function_check git_pull
244
+	git_pull $CJDNS_REPO
245
+	./do
404 246
 	if [ ! "$?" = "0" ]; then
405
-		systemctl status radvd.service
406
-		exit 4395
407
-	fi
408
-
409
-	if ! grep -q "# Mesh Networking (cjdns)" /etc/network/interfaces; then
410
-		echo '' >> /etc/network/interfaces
411
-		echo '# Mesh Networking (cjdns)' >> /etc/network/interfaces
412
-		echo 'iface eth0 inet6 static' >> /etc/network/interfaces
413
-		echo '    pre-up modprobe ipv6' >> /etc/network/interfaces
414
-		echo '    address fdfc:0000:0000:0000:0000:0000:0000:0001' >> /etc/network/interfaces
415
-		echo '    netmask 64' >> /etc/network/interfaces
416
-		service network-manager restart
417
-		if [ ! "$?" = "0" ]; then
418
-			systemctl status networking.service
419
-			exit 6949
420
-		fi
421
-	fi
422
-
423
-	if ! grep -q $"Mesh Networking (cjdns)" /home/$MY_USERNAME/README; then
424
-		CURRENT_IP_ADDRESS=$(ip addr show | grep "inet " | sed -n 2p | awk -F ' ' '{print $2}' | awk -F '/' '{print $1}')
425
-
426
-		echo '' >> /home/$MY_USERNAME/README
427
-		echo '' >> /home/$MY_USERNAME/README
428
-		echo $'Mesh Networking (cjdns)' >> /home/$MY_USERNAME/README
429
-		echo '=======================' >> /home/$MY_USERNAME/README
430
-		echo $"cjdns IPv6 address: $CJDNS_IPV6" >> /home/$MY_USERNAME/README
431
-		echo $"cjdns public key: $CJDNS_PUBLIC_KEY" >> /home/$MY_USERNAME/README
432
-		echo $"cjdns private key: $CJDNS_PRIVATE_KEY" >> /home/$MY_USERNAME/README
433
-		echo $"cjdns password: $CJDNS_PASSWORD" >> /home/$MY_USERNAME/README
434
-		echo $"cjdns port: $CJDNS_PORT" >> /home/$MY_USERNAME/README
435
-		echo '' >> /home/$MY_USERNAME/README
436
-		echo $"Forward port $CJDNS_PORT from your internet router to the ${PROJECT_NAME}" >> /home/$MY_USERNAME/README
437
-		echo '' >> /home/$MY_USERNAME/README
438
-		echo $'Below is an example of your connection credentials' >> /home/$MY_USERNAME/README
439
-		echo $'that you can give to other people so they can connect' >> /home/$MY_USERNAME/README
440
-		echo $'to you using your default password' >> /home/$MY_USERNAME/README
441
-		echo $'Adding a unique password for each user is advisable' >> /home/$MY_USERNAME/README
442
-		echo $'so that leaks can be isolated.' >> /home/$MY_USERNAME/README
443
-		echo '' >> /home/$MY_USERNAME/README
444
-		echo "\"$CURRENT_IP_ADDRESS:$CJDNS_PORT\":{\"password\":\"$CJDNS_PASSWORD\",\"publicKey\":\"$CJDNS_PUBLIC_KEY\"}" >> /home/$MY_USERNAME/README
445
-		echo '' >> /home/$MY_USERNAME/README
446
-		echo $'More is not better. 3-5 cjdns peers is good. 30 peers is bad.' >> /home/$MY_USERNAME/README
447
-		echo '' >> /home/$MY_USERNAME/README
448
-		echo $'NEVER USE A PUBLIC PEER. These degrade the network and make it centralized.' >> /home/$MY_USERNAME/README
449
-		echo $'Each node can handle many peers, but no node can handle the entire internet.' >> /home/$MY_USERNAME/README
450
-		echo $'As this network grows any public peer will simply become saturated and' >> /home/$MY_USERNAME/README
451
-		echo $'useless causing issues for the entire network.' >> /home/$MY_USERNAME/README
452
-		echo $'Please report anyone offering you a public peer as they are promoting shared' >> /home/$MY_USERNAME/README
453
-		echo $'passwords which could lead to people pretending to be you. A peering pass' >> /home/$MY_USERNAME/README
454
-		echo $'should not contain someone elses nickname or info but should contain yours' >> /home/$MY_USERNAME/README
455
-		echo $'to ensure it is not shared. It also helps when editing the conf to know who' >> /home/$MY_USERNAME/README
456
-		echo $'each password is for.' >> /home/$MY_USERNAME/README
457
-		echo '' >> /home/$MY_USERNAME/README
458
-		echo $'Possible cjdns destinations of interest:' >> /home/$MY_USERNAME/README
459
-		echo '    http://transitiontech.ca/faq' >> /home/$MY_USERNAME/README
460
-		echo '    http://cjdns.ca/hypeirc.txt' >> /home/$MY_USERNAME/README
461
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
462
-		chmod 600 /home/$MY_USERNAME/README
463
-	fi
464
-
465
-	function_check configure_firewall_for_cjdns
466
-	configure_firewall_for_cjdns
467
-
468
-	echo 'install_cjdns_main' >> $COMPLETION_FILE
247
+	    exit 9926
248
+	fi
249
+    fi
250
+
251
+    # set permissions
252
+    chown -R cjdns:cjdns /etc/cjdns
253
+    chmod 600 /etc/cjdns/cjdroute.conf
254
+
255
+    /sbin/ip tuntap add mode tun user cjdns dev cjdroute0
256
+
257
+    # insert values into the configuration file
258
+    if [ $CJDNS_PRIVATE_KEY ]; then
259
+	sed -i "s/\"privateKey\":.*/\"privateKey\": \"$CJDNS_PRIVATE_KEY\",/g" /etc/cjdns/cjdroute.conf
260
+    else
261
+	CJDNS_PRIVATE_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"privateKey"' | awk -F '"' '{print $4}' | sed -n 1p)
262
+    fi
263
+    if [ $CJDNS_PUBLIC_KEY ]; then
264
+	sed -i "s/\"publicKey\":.*/\"publicKey\": \"$CJDNS_PUBLIC_KEY\",/g" /etc/cjdns/cjdroute.conf
265
+    else
266
+	CJDNS_PUBLIC_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"publicKey"' | awk -F '"' '{print $4}' | sed -n 1p)
267
+    fi
268
+    if [ $CJDNS_IPV6 ]; then
269
+	sed -i "s/\"ipv6\":.*/\"ipv6\": \"$CJDNS_IPV6\",/g" /etc/cjdns/cjdroute.conf
270
+    else
271
+	CJDNS_IPV6=$(cat /etc/cjdns/cjdroute.conf | grep '"ipv6"' | awk -F '"' '{print $4}' | sed -n 1p)
272
+    fi
273
+    if [ $CJDNS_PASSWORD ]; then
274
+	sed -i "0,/{\"password\":.*/s//{\"password\": \"$CJDNS_PASSWORD\"}/g" /etc/cjdns/cjdroute.conf
275
+    else
276
+	CJDNS_PASSWORD=$(cat /etc/cjdns/cjdroute.conf | grep '"password"' | awk -F '"' '{print $4}' | sed -n 1p)
277
+    fi
278
+    if [ $CJDNS_PORT ]; then
279
+	sed -i "s/\"bind\": \"0.0.0.0:.*/\"bind\": \"0.0.0.0:$CJDNS_PORT\",/g" /etc/cjdns/cjdroute.conf
280
+    else
281
+	CJDNS_PORT=$(cat /etc/cjdns/cjdroute.conf | grep '"bind": "0.0.0.0:' | awk -F '"' '{print $4}' | awk -F ':' '{print $2}' | sed -n 1p)
282
+    fi
283
+
284
+    function_check enable_ipv6
285
+    enable_ipv6
286
+
287
+    echo '#!/bin/sh -e' > /etc/init.d/cjdns
288
+    echo '### BEGIN INIT INFO' >> /etc/init.d/cjdns
289
+    echo '# hyperboria.sh - An init script (/etc/init.d/) for cjdns' >> /etc/init.d/cjdns
290
+    echo '# Provides:          cjdroute' >> /etc/init.d/cjdns
291
+    echo '# Required-Start:    $remote_fs $network' >> /etc/init.d/cjdns
292
+    echo '# Required-Stop:     $remote_fs $network' >> /etc/init.d/cjdns
293
+    echo '# Default-Start:     2 3 4 5' >> /etc/init.d/cjdns
294
+    echo '# Default-Stop:      0 1 6' >> /etc/init.d/cjdns
295
+    echo '# Short-Description: Cjdns router' >> /etc/init.d/cjdns
296
+    echo '# Description:       A routing engine designed for security, scalability, speed and ease of use.' >> /etc/init.d/cjdns
297
+    echo '# cjdns git repo:    https://github.com/cjdelisle/cjdns/' >> /etc/init.d/cjdns
298
+    echo '### END INIT INFO' >> /etc/init.d/cjdns
299
+    echo '' >> /etc/init.d/cjdns
300
+    echo 'PROG="cjdroute"' >> /etc/init.d/cjdns
301
+    echo 'GIT_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
302
+    echo 'PROG_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
303
+    echo 'CJDNS_CONFIG="cjdroute.conf"' >> /etc/init.d/cjdns
304
+    echo 'CJDNS_USER="cjdns"' >> /etc/init.d/cjdns
305
+    echo "CJDNS_IP='$CJDNS_IPV6'" >> /etc/init.d/cjdns
306
+    echo '' >> /etc/init.d/cjdns
307
+    echo 'start() {' >> /etc/init.d/cjdns
308
+    echo '     # Start it up with the user cjdns' >> /etc/init.d/cjdns
309
+    echo '     if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
310
+    echo '     then' >> /etc/init.d/cjdns
311
+    echo '         echo "cjdroute is already running. Doing nothing..."' >> /etc/init.d/cjdns
312
+    echo '     else' >> /etc/init.d/cjdns
313
+    echo '         echo " * Starting cjdroute"' >> /etc/init.d/cjdns
314
+    echo '         su -c "$PROG_PATH/$PROG < $PROG_PATH/$CJDNS_CONFIG" - $CJDNS_USER' >> /etc/init.d/cjdns
315
+    echo '         /sbin/ip addr add $CJDNS_IP/8 dev tun0' >> /etc/init.d/cjdns
316
+    echo '         /sbin/ip link set mtu 1312 dev tun0' >> /etc/init.d/cjdns
317
+    echo '         /sbin/ip link set tun0 up' >> /etc/init.d/cjdns
318
+    echo '         /sbin/ip tuntap add mode tun user cjdns dev tun0' >> /etc/init.d/cjdns
319
+    echo '     fi' >> /etc/init.d/cjdns
320
+    echo '}' >> /etc/init.d/cjdns
321
+    echo '' >> /etc/init.d/cjdns
322
+    echo 'stop() {' >> /etc/init.d/cjdns
323
+    echo '' >> /etc/init.d/cjdns
324
+    echo '     if [ $(pgrep cjdroute | wc -l) != 2 ];' >> /etc/init.d/cjdns
325
+    echo '     then' >> /etc/init.d/cjdns
326
+    echo '         echo "cjdns isnt running."' >> /etc/init.d/cjdns
327
+    echo '     else' >> /etc/init.d/cjdns
328
+    echo '         echo "Killing cjdroute"' >> /etc/init.d/cjdns
329
+    echo '         killall cjdroute' >> /etc/init.d/cjdns
330
+    echo '     fi' >> /etc/init.d/cjdns
331
+    echo '}' >> /etc/init.d/cjdns
332
+    echo '' >> /etc/init.d/cjdns
333
+    echo 'status() {' >> /etc/init.d/cjdns
334
+    echo '     if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
335
+    echo '     then' >> /etc/init.d/cjdns
336
+    echo '         echo "Cjdns is running"' >> /etc/init.d/cjdns
337
+    echo '     else' >> /etc/init.d/cjdns
338
+    echo '         echo "Cjdns is not running"' >> /etc/init.d/cjdns
339
+    echo '     fi' >> /etc/init.d/cjdns
340
+    echo '}' >> /etc/init.d/cjdns
341
+    echo '' >> /etc/init.d/cjdns
342
+    echo ' update() {' >> /etc/init.d/cjdns
343
+    echo '     cd $GIT_PATH' >> /etc/init.d/cjdns
344
+    echo '     echo "Updating..."' >> /etc/init.d/cjdns
345
+    echo '     git pull' >> /etc/init.d/cjdns
346
+    echo '     ./do' >> /etc/init.d/cjdns
347
+    echo '}' >> /etc/init.d/cjdns
348
+    echo '' >> /etc/init.d/cjdns
349
+    echo '## Check to see if we are running as root first.' >> /etc/init.d/cjdns
350
+    echo 'if [ "$(id -u)" != "0" ]; then' >> /etc/init.d/cjdns
351
+    echo '    echo "This script must be run as root" 1>&2' >> /etc/init.d/cjdns
352
+    echo '    exit 1' >> /etc/init.d/cjdns
353
+    echo 'fi' >> /etc/init.d/cjdns
354
+    echo '' >> /etc/init.d/cjdns
355
+    echo 'case $1 in' >> /etc/init.d/cjdns
356
+    echo '     start)' >> /etc/init.d/cjdns
357
+    echo '         start' >> /etc/init.d/cjdns
358
+    echo '         exit 0' >> /etc/init.d/cjdns
359
+    echo '     ;;' >> /etc/init.d/cjdns
360
+    echo '     stop)' >> /etc/init.d/cjdns
361
+    echo '         stop' >> /etc/init.d/cjdns
362
+    echo '         exit 0' >> /etc/init.d/cjdns
363
+    echo '     ;;' >> /etc/init.d/cjdns
364
+    echo '     reload|restart|force-reload)' >> /etc/init.d/cjdns
365
+    echo '         stop' >> /etc/init.d/cjdns
366
+    echo '         sleep 1' >> /etc/init.d/cjdns
367
+    echo '         start' >> /etc/init.d/cjdns
368
+    echo '         exit 0' >> /etc/init.d/cjdns
369
+    echo '     ;;' >> /etc/init.d/cjdns
370
+    echo '     status)' >> /etc/init.d/cjdns
371
+    echo '         status' >> /etc/init.d/cjdns
372
+    echo '         exit 0' >> /etc/init.d/cjdns
373
+    echo '     ;;' >> /etc/init.d/cjdns
374
+    echo '     update|upgrade)' >> /etc/init.d/cjdns
375
+    echo '         update' >> /etc/init.d/cjdns
376
+    echo '         stop' >> /etc/init.d/cjdns
377
+    echo '         sleep 2' >> /etc/init.d/cjdns
378
+    echo '         start' >> /etc/init.d/cjdns
379
+    echo '         exit 0' >> /etc/init.d/cjdns
380
+    echo '     ;;' >> /etc/init.d/cjdns
381
+    echo '     **)' >> /etc/init.d/cjdns
382
+    echo '         echo "Usage: $0 (start|stop|restart|status|update)" 1>&2' >> /etc/init.d/cjdns
383
+    echo '         exit 1' >> /etc/init.d/cjdns
384
+    echo '     ;;' >> /etc/init.d/cjdns
385
+    echo 'esac' >> /etc/init.d/cjdns
386
+    chmod +x /etc/init.d/cjdns
387
+    update-rc.d cjdns defaults
388
+    service cjdns start
389
+    if [ ! "$?" = "0" ]; then
390
+	systemctl status cjdns.service
391
+	exit 8260
392
+    fi
393
+
394
+    apt-get -y install radvd
395
+    echo 'interface eth0' > /etc/radvd.conf
396
+    echo '{' >> /etc/radvd.conf
397
+    echo '    AdvSendAdvert on;' >> /etc/radvd.conf
398
+    echo '    prefix fdfc::1/64' >> /etc/radvd.conf
399
+    echo '    {' >> /etc/radvd.conf
400
+    echo '        AdvRouterAddr on;' >> /etc/radvd.conf
401
+    echo '    };' >> /etc/radvd.conf
402
+    echo '};' >> /etc/radvd.conf
403
+    systemctl restart radvd
404
+    if [ ! "$?" = "0" ]; then
405
+	systemctl status radvd.service
406
+	exit 4395
407
+    fi
408
+
409
+    if ! grep -q "# Mesh Networking (cjdns)" /etc/network/interfaces; then
410
+	echo '' >> /etc/network/interfaces
411
+	echo '# Mesh Networking (cjdns)' >> /etc/network/interfaces
412
+	echo 'iface eth0 inet6 static' >> /etc/network/interfaces
413
+	echo '    pre-up modprobe ipv6' >> /etc/network/interfaces
414
+	echo '    address fdfc:0000:0000:0000:0000:0000:0000:0001' >> /etc/network/interfaces
415
+	echo '    netmask 64' >> /etc/network/interfaces
416
+	service network-manager restart
417
+	if [ ! "$?" = "0" ]; then
418
+	    systemctl status networking.service
419
+	    exit 6949
420
+	fi
421
+    fi
422
+
423
+    if ! grep -q $"Mesh Networking (cjdns)" /home/$MY_USERNAME/README; then
424
+	CURRENT_IP_ADDRESS=$(ip addr show | grep "inet " | sed -n 2p | awk -F ' ' '{print $2}' | awk -F '/' '{print $1}')
425
+
426
+	echo '' >> /home/$MY_USERNAME/README
427
+	echo '' >> /home/$MY_USERNAME/README
428
+	echo $'Mesh Networking (cjdns)' >> /home/$MY_USERNAME/README
429
+	echo '=======================' >> /home/$MY_USERNAME/README
430
+	echo $"cjdns IPv6 address: $CJDNS_IPV6" >> /home/$MY_USERNAME/README
431
+	echo $"cjdns public key: $CJDNS_PUBLIC_KEY" >> /home/$MY_USERNAME/README
432
+	echo $"cjdns private key: $CJDNS_PRIVATE_KEY" >> /home/$MY_USERNAME/README
433
+	echo $"cjdns password: $CJDNS_PASSWORD" >> /home/$MY_USERNAME/README
434
+	echo $"cjdns port: $CJDNS_PORT" >> /home/$MY_USERNAME/README
435
+	echo '' >> /home/$MY_USERNAME/README
436
+	echo $"Forward port $CJDNS_PORT from your internet router to the ${PROJECT_NAME}" >> /home/$MY_USERNAME/README
437
+	echo '' >> /home/$MY_USERNAME/README
438
+	echo $'Below is an example of your connection credentials' >> /home/$MY_USERNAME/README
439
+	echo $'that you can give to other people so they can connect' >> /home/$MY_USERNAME/README
440
+	echo $'to you using your default password' >> /home/$MY_USERNAME/README
441
+	echo $'Adding a unique password for each user is advisable' >> /home/$MY_USERNAME/README
442
+	echo $'so that leaks can be isolated.' >> /home/$MY_USERNAME/README
443
+	echo '' >> /home/$MY_USERNAME/README
444
+	echo "\"$CURRENT_IP_ADDRESS:$CJDNS_PORT\":{\"password\":\"$CJDNS_PASSWORD\",\"publicKey\":\"$CJDNS_PUBLIC_KEY\"}" >> /home/$MY_USERNAME/README
445
+	echo '' >> /home/$MY_USERNAME/README
446
+	echo $'More is not better. 3-5 cjdns peers is good. 30 peers is bad.' >> /home/$MY_USERNAME/README
447
+	echo '' >> /home/$MY_USERNAME/README
448
+	echo $'NEVER USE A PUBLIC PEER. These degrade the network and make it centralized.' >> /home/$MY_USERNAME/README
449
+	echo $'Each node can handle many peers, but no node can handle the entire internet.' >> /home/$MY_USERNAME/README
450
+	echo $'As this network grows any public peer will simply become saturated and' >> /home/$MY_USERNAME/README
451
+	echo $'useless causing issues for the entire network.' >> /home/$MY_USERNAME/README
452
+	echo $'Please report anyone offering you a public peer as they are promoting shared' >> /home/$MY_USERNAME/README
453
+	echo $'passwords which could lead to people pretending to be you. A peering pass' >> /home/$MY_USERNAME/README
454
+	echo $'should not contain someone elses nickname or info but should contain yours' >> /home/$MY_USERNAME/README
455
+	echo $'to ensure it is not shared. It also helps when editing the conf to know who' >> /home/$MY_USERNAME/README
456
+	echo $'each password is for.' >> /home/$MY_USERNAME/README
457
+	echo '' >> /home/$MY_USERNAME/README
458
+	echo $'Possible cjdns destinations of interest:' >> /home/$MY_USERNAME/README
459
+	echo '    http://transitiontech.ca/faq' >> /home/$MY_USERNAME/README
460
+	echo '    http://cjdns.ca/hypeirc.txt' >> /home/$MY_USERNAME/README
461
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
462
+	chmod 600 /home/$MY_USERNAME/README
463
+    fi
464
+
465
+    function_check configure_firewall_for_cjdns
466
+    configure_firewall_for_cjdns
467
+
468
+    echo 'install_cjdns_main' >> $COMPLETION_FILE
469 469
 }
470 470
 
471 471
 function install_cjdns_tools {
472
-	if grep -Fxq "install_cjdns_tools" $COMPLETION_FILE; then
473
-		return
474
-	fi
475
-	if [[ $ENABLE_CJDNS != "yes" ]]; then
476
-		return
477
-	fi
478
-	if [ ! -d /etc/cjdns ]; then
479
-		install_cjdns
480
-	fi
481
-
482
-	function_check select_go_version
483
-	select_go_version
484
-
485
-	apt-get -y install golang mercurial
486
-	if [ ! -f ~/.bashrc ]; then
487
-		touch ~/.bashrc
488
-	fi
489
-
490
-	if [ ! -d /home/git ]; then
491
-		# add a gogs user account
492
-		adduser --disabled-login --gecos 'Gogs' git
493
-
494
-		# install Go
495
-		if ! grep -q "export GOPATH=" ~/.bashrc; then
496
-			echo "export GOPATH=$GOPATH" >> ~/.bashrc
497
-		fi
498
-		systemctl set-environment GOPATH=$GOPATH
499
-		if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
500
-			echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
501
-		fi
502
-		if [ ! -d $GOPATH ]; then
503
-			mkdir -p $GOPATH
504
-		fi
505
-	fi
506
-
472
+    if grep -Fxq "install_cjdns_tools" $COMPLETION_FILE; then
473
+	return
474
+    fi
475
+    if [[ $ENABLE_CJDNS != "yes" ]]; then
476
+	return
477
+    fi
478
+    if [ ! -d /etc/cjdns ]; then
479
+	install_cjdns
480
+    fi
481
+
482
+    function_check select_go_version
483
+    select_go_version
484
+
485
+    apt-get -y install golang mercurial
486
+    if [ ! -f ~/.bashrc ]; then
487
+	touch ~/.bashrc
488
+    fi
489
+
490
+    if [ ! -d /home/git ]; then
491
+	# add a gogs user account
492
+	adduser --disabled-login --gecos 'Gogs' git
493
+
494
+	# install Go
507 495
 	if ! grep -q "export GOPATH=" ~/.bashrc; then
508
-		echo "export GOPATH=$GOPATH" >> ~/.bashrc
509
-	fi
510
-	expected_go_path='export PATH=$PATH:'${GOPATH}'/bin'
511
-	export PATH=$PATH:${GOPATH}/bin
512
-	if ! grep -q "$expected_go_path" ~/.bashrc; then
513
-		echo "$expected_go_path" >> ~/.bashrc
514
-	fi
515
-	export PATH=$PATH:$GOPATH/bin
516
-	CJDCMD_REPO2=$(echo "$CJDCMD_REPO" | sed 's|https://||g')
517
-	go get $CJDCMD_REPO2
518
-	if [ ! -f $GOPATH/bin/cjdcmd ]; then
519
-		echo $'cjdcmd was not compiled. Check your golang installation'
520
-		exit 7439
521
-	fi
522
-	cp $GOPATH/bin/cjdcmd /usr/bin
523
-
524
-	# initialise from the cjdns config
525
-	/usr/bin/cjdcmd cjdnsadmin -file /etc/cjdns/cjdroute.conf
526
-
527
-	echo 'install_cjdns_tools' >> $COMPLETION_FILE
496
+	    echo "export GOPATH=$GOPATH" >> ~/.bashrc
497
+	fi
498
+	systemctl set-environment GOPATH=$GOPATH
499
+	if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
500
+	    echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
501
+	fi
502
+	if [ ! -d $GOPATH ]; then
503
+	    mkdir -p $GOPATH
504
+	fi
505
+    fi
506
+
507
+    if ! grep -q "export GOPATH=" ~/.bashrc; then
508
+	echo "export GOPATH=$GOPATH" >> ~/.bashrc
509
+    fi
510
+    expected_go_path='export PATH=$PATH:'${GOPATH}'/bin'
511
+    export PATH=$PATH:${GOPATH}/bin
512
+    if ! grep -q "$expected_go_path" ~/.bashrc; then
513
+	echo "$expected_go_path" >> ~/.bashrc
514
+    fi
515
+    export PATH=$PATH:$GOPATH/bin
516
+    CJDCMD_REPO2=$(echo "$CJDCMD_REPO" | sed 's|https://||g')
517
+    go get $CJDCMD_REPO2
518
+    if [ ! -f $GOPATH/bin/cjdcmd ]; then
519
+	echo $'cjdcmd was not compiled. Check your golang installation'
520
+	exit 7439
521
+    fi
522
+    cp $GOPATH/bin/cjdcmd /usr/bin
523
+
524
+    # initialise from the cjdns config
525
+    /usr/bin/cjdcmd cjdnsadmin -file /etc/cjdns/cjdroute.conf
526
+
527
+    echo 'install_cjdns_tools' >> $COMPLETION_FILE
528 528
 }
529 529
 
530 530
 function install_cjdns {
531
-	if grep -Fxq "install_cjdns" $COMPLETION_FILE; then
532
-		return
533
-	fi
534
-	install_cjdns_main
535
-	install_cjdns_tools
536
-	echo 'install_cjdns' >> $COMPLETION_FILE
531
+    if grep -Fxq "install_cjdns" $COMPLETION_FILE; then
532
+	return
533
+    fi
534
+    install_cjdns_main
535
+    install_cjdns_tools
536
+    echo 'install_cjdns' >> $COMPLETION_FILE
537 537
 }
538 538
 
539 539
 # NOTE: deliberately no exit 0

+ 167
- 167
src/freedombone-app-dlna Voir le fichier

@@ -31,205 +31,205 @@
31 31
 VARIANTS='full media'
32 32
 
33 33
 function reconfigure_dlna {
34
-	echo ''
34
+    echo ''
35 35
 }
36 36
 
37 37
 function upgrade_dlna {
38
-	echo ''
38
+    echo ''
39 39
 }
40 40
 
41 41
 function configure_firewall_for_dlna {
42
-	if grep -Fxq "configure_firewall_for_dlna" $COMPLETION_FILE; then
43
-		return
44
-	fi
45
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
46
-		# docker does its own firewalling
47
-		return
48
-	fi
49
-	iptables -A INPUT -p udp --dport 1900 -j ACCEPT
50
-	iptables -A INPUT -p tcp --dport 8200 -j ACCEPT
51
-	function_check save_firewall_settings
52
-	save_firewall_settings
53
-
54
-	OPEN_PORTS+=('DLNA     1900')
55
-	OPEN_PORTS+=('DLNA     8200')
56
-	echo 'configure_firewall_for_dlna' >> $COMPLETION_FILE
42
+    if grep -Fxq "configure_firewall_for_dlna" $COMPLETION_FILE; then
43
+	return
44
+    fi
45
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
46
+	# docker does its own firewalling
47
+	return
48
+    fi
49
+    iptables -A INPUT -p udp --dport 1900 -j ACCEPT
50
+    iptables -A INPUT -p tcp --dport 8200 -j ACCEPT
51
+    function_check save_firewall_settings
52
+    save_firewall_settings
53
+
54
+    OPEN_PORTS+=('DLNA     1900')
55
+    OPEN_PORTS+=('DLNA     8200')
56
+    echo 'configure_firewall_for_dlna' >> $COMPLETION_FILE
57 57
 }
58 58
 
59 59
 function backup_local_dlna {
60
-	source_directory=/var/cache/minidlna
61
-	if [ -d $source_directory ]; then
62
-		dest_directory=dlna
63
-		echo $"Backing up $source_directory to $dest_directory"
60
+    source_directory=/var/cache/minidlna
61
+    if [ -d $source_directory ]; then
62
+	dest_directory=dlna
63
+	echo $"Backing up $source_directory to $dest_directory"
64 64
 
65
-		function_check backup_directory_to_usb
66
-		backup_directory_to_usb $source_directory $dest_directory
65
+	function_check backup_directory_to_usb
66
+	backup_directory_to_usb $source_directory $dest_directory
67 67
 
68
-		echo $"Backup to $dest_directory complete"
69
-	fi
68
+	echo $"Backup to $dest_directory complete"
69
+    fi
70 70
 }
71 71
 
72 72
 function restore_local_dlna {
73
-	if [ -d /var/cache/minidlna ]; then
74
-		if [ -d $USB_MOUNT/backup/dlna ]; then
75
-			echo $"Restoring DLNA cache"
76
-			temp_restore_dir=/root/tempdlna
77
-			function_check restore_directory_from_usb
78
-			restore_directory_from_usb $temp_restore_dir dlna
79
-			cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
80
-			if [ ! "$?" = "0" ]; then
81
-				rm -rf $temp_restore_dir
82
-				function_check set_user_permissions
83
-				set_user_permissions
84
-				function_check backup_unmount_drive
85
-				backup_unmount_drive
86
-				exit 982572
87
-			fi
88
-			rm -rf $temp_restore_dir
89
-		fi
90
-	fi
73
+    if [ -d /var/cache/minidlna ]; then
74
+	if [ -d $USB_MOUNT/backup/dlna ]; then
75
+	    echo $"Restoring DLNA cache"
76
+	    temp_restore_dir=/root/tempdlna
77
+	    function_check restore_directory_from_usb
78
+	    restore_directory_from_usb $temp_restore_dir dlna
79
+	    cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
80
+	    if [ ! "$?" = "0" ]; then
81
+		rm -rf $temp_restore_dir
82
+		function_check set_user_permissions
83
+		set_user_permissions
84
+		function_check backup_unmount_drive
85
+		backup_unmount_drive
86
+		exit 982572
87
+	    fi
88
+	    rm -rf $temp_restore_dir
89
+	fi
90
+    fi
91 91
 }
92 92
 
93 93
 function backup_remote_dlna {
94
-	if [ -d /var/cache/minidlna ]; then
95
-		echo $"Backing up DLNA cache"
96
-		backup_directory_to_friend /var/cache/minidlna dlna
97
-		echo $"Backup of DLNA cache complete"
98
-	fi
94
+    if [ -d /var/cache/minidlna ]; then
95
+	echo $"Backing up DLNA cache"
96
+	backup_directory_to_friend /var/cache/minidlna dlna
97
+	echo $"Backup of DLNA cache complete"
98
+    fi
99 99
 }
100 100
 
101 101
 function restore_remote_dlna {
102
-	if [ -d /var/cache/minidlna ]; then
103
-		if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
104
-			echo $"Restoring DLNA cache"
105
-			temp_restore_dir=/root/tempdlna
106
-			function_check restore_directory_from_friend
107
-			restore_directory_from_friend $temp_restore_dir dlna
108
-			cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
109
-			if [ ! "$?" = "0" ]; then
110
-				exit 982
111
-			fi
112
-			rm -rf $temp_restore_dir
113
-			echo $"Restore of DLNA complete"
114
-		fi
115
-	fi
102
+    if [ -d /var/cache/minidlna ]; then
103
+	if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
104
+	    echo $"Restoring DLNA cache"
105
+	    temp_restore_dir=/root/tempdlna
106
+	    function_check restore_directory_from_friend
107
+	    restore_directory_from_friend $temp_restore_dir dlna
108
+	    cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
109
+	    if [ ! "$?" = "0" ]; then
110
+		exit 982
111
+	    fi
112
+	    rm -rf $temp_restore_dir
113
+	    echo $"Restore of DLNA complete"
114
+	fi
115
+    fi
116 116
 }
117 117
 
118 118
 function remove_dlna {
119
-	if ! grep -Fxq "install_dlna" $COMPLETION_FILE; then
120
-		return
121
-	fi
122
-	service minidlna stop
123
-	apt-get -y remove --purge minidlna
124
-	if [ -f /etc/minidlna.conf ]; then
125
-		rm /etc/minidlna.conf
126
-	fi
127
-	iptables -D INPUT -p udp --dport 1900 -j ACCEPT
128
-	iptables -D INPUT -p tcp --dport 8200 -j ACCEPT
129
-	function_check save_firewall_settings
130
-	save_firewall_settings
131
-	sed -i '/install_dlna/d' $COMPLETION_FILE
119
+    if ! grep -Fxq "install_dlna" $COMPLETION_FILE; then
120
+	return
121
+    fi
122
+    service minidlna stop
123
+    apt-get -y remove --purge minidlna
124
+    if [ -f /etc/minidlna.conf ]; then
125
+	rm /etc/minidlna.conf
126
+    fi
127
+    iptables -D INPUT -p udp --dport 1900 -j ACCEPT
128
+    iptables -D INPUT -p tcp --dport 8200 -j ACCEPT
129
+    function_check save_firewall_settings
130
+    save_firewall_settings
131
+    sed -i '/install_dlna/d' $COMPLETION_FILE
132 132
 }
133 133
 
134 134
 function install_dlna_main {
135
-	if grep -Fxq "install_dlna_main" $COMPLETION_FILE; then
136
-		return
137
-	fi
138
-
139
-	apt-get -y install minidlna
140
-
141
-	if [ ! -f /etc/minidlna.conf ]; then
142
-		echo $"ERROR: minidlna does not appear to have installed. $CHECK_MESSAGE"
143
-		exit 55
144
-	fi
145
-
146
-	sed -i "s|media_dir=/var/lib/minidlna|media_dir=A,/home/$MY_USERNAME/Music|g" /etc/minidlna.conf
147
-	if ! grep -q "/home/$MY_USERNAME/Pictures" /etc/minidlna.conf; then
148
-		echo "media_dir=P,/home/$MY_USERNAME/Pictures" >> /etc/minidlna.conf
149
-	fi
150
-	if ! grep -q "/home/$MY_USERNAME/Videos" /etc/minidlna.conf; then
151
-		echo "media_dir=V,/home/$MY_USERNAME/Videos" >> /etc/minidlna.conf
152
-	fi
153
-	if ! grep -q "$USB_MOUNT/Music" /etc/minidlna.conf; then
154
-		echo "media_dir=A,$USB_MOUNT/Music" >> /etc/minidlna.conf
155
-	fi
156
-	if ! grep -q "$USB_MOUNT/Pictures" /etc/minidlna.conf; then
157
-		echo "media_dir=P,$USB_MOUNT/Pictures" >> /etc/minidlna.conf
158
-	fi
159
-	if ! grep -q "$USB_MOUNT/Videos" /etc/minidlna.conf; then
160
-		echo "media_dir=V,$USB_MOUNT/Videos" >> /etc/minidlna.conf
161
-	fi
162
-	sed -i 's/#root_container=./root_container=B/g' /etc/minidlna.conf
163
-	if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
164
-		sed -i 's/#network_interface=/network_interface=eth0/g' /etc/minidlna.conf
165
-	else
166
-		sed -i 's/#network_interface=/network_interface=$WIFI_INTERFACE/g' /etc/minidlna.conf
167
-	fi
168
-	sed -i "s/#friendly_name=/friendly_name=\"${PROJECT_NAME} Media\"/g" /etc/minidlna.conf
169
-	sed -i 's|#db_dir=/var/cache/minidlna|db_dir=/var/cache/minidlna|g' /etc/minidlna.conf
170
-	sed -i 's/#inotify=yes/inotify=yes/g' /etc/minidlna.conf
171
-	sed -i 's/#notify_interval=895/notify_interval=300/g' /etc/minidlna.conf
172
-	sed -i "s|#presentation_url=/|presentation_url=http://localhost:8200|g" /etc/minidlna.conf
173
-	service minidlna force-reload
174
-	service minidlna reload
175
-
176
-	sed -i 's/fs.inotify.max_user_watches*/fs.inotify.max_user_watches=65536/g' /etc/sysctl.conf
177
-	if ! grep -q "max_user_watches" $COMPLETION_FILE; then
178
-		echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
179
-	fi
180
-	/sbin/sysctl -p
181
-
182
-	function_check configure_firewall_for_dlna
183
-	configure_firewall_for_dlna
184
-	echo 'install_dlna_main' >> $COMPLETION_FILE
135
+    if grep -Fxq "install_dlna_main" $COMPLETION_FILE; then
136
+	return
137
+    fi
138
+
139
+    apt-get -y install minidlna
140
+
141
+    if [ ! -f /etc/minidlna.conf ]; then
142
+	echo $"ERROR: minidlna does not appear to have installed. $CHECK_MESSAGE"
143
+	exit 55
144
+    fi
145
+
146
+    sed -i "s|media_dir=/var/lib/minidlna|media_dir=A,/home/$MY_USERNAME/Music|g" /etc/minidlna.conf
147
+    if ! grep -q "/home/$MY_USERNAME/Pictures" /etc/minidlna.conf; then
148
+	echo "media_dir=P,/home/$MY_USERNAME/Pictures" >> /etc/minidlna.conf
149
+    fi
150
+    if ! grep -q "/home/$MY_USERNAME/Videos" /etc/minidlna.conf; then
151
+	echo "media_dir=V,/home/$MY_USERNAME/Videos" >> /etc/minidlna.conf
152
+    fi
153
+    if ! grep -q "$USB_MOUNT/Music" /etc/minidlna.conf; then
154
+	echo "media_dir=A,$USB_MOUNT/Music" >> /etc/minidlna.conf
155
+    fi
156
+    if ! grep -q "$USB_MOUNT/Pictures" /etc/minidlna.conf; then
157
+	echo "media_dir=P,$USB_MOUNT/Pictures" >> /etc/minidlna.conf
158
+    fi
159
+    if ! grep -q "$USB_MOUNT/Videos" /etc/minidlna.conf; then
160
+	echo "media_dir=V,$USB_MOUNT/Videos" >> /etc/minidlna.conf
161
+    fi
162
+    sed -i 's/#root_container=./root_container=B/g' /etc/minidlna.conf
163
+    if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
164
+	sed -i 's/#network_interface=/network_interface=eth0/g' /etc/minidlna.conf
165
+    else
166
+	sed -i 's/#network_interface=/network_interface=$WIFI_INTERFACE/g' /etc/minidlna.conf
167
+    fi
168
+    sed -i "s/#friendly_name=/friendly_name=\"${PROJECT_NAME} Media\"/g" /etc/minidlna.conf
169
+    sed -i 's|#db_dir=/var/cache/minidlna|db_dir=/var/cache/minidlna|g' /etc/minidlna.conf
170
+    sed -i 's/#inotify=yes/inotify=yes/g' /etc/minidlna.conf
171
+    sed -i 's/#notify_interval=895/notify_interval=300/g' /etc/minidlna.conf
172
+    sed -i "s|#presentation_url=/|presentation_url=http://localhost:8200|g" /etc/minidlna.conf
173
+    service minidlna force-reload
174
+    service minidlna reload
175
+
176
+    sed -i 's/fs.inotify.max_user_watches*/fs.inotify.max_user_watches=65536/g' /etc/sysctl.conf
177
+    if ! grep -q "max_user_watches" $COMPLETION_FILE; then
178
+	echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
179
+    fi
180
+    /sbin/sysctl -p
181
+
182
+    function_check configure_firewall_for_dlna
183
+    configure_firewall_for_dlna
184
+    echo 'install_dlna_main' >> $COMPLETION_FILE
185 185
 }
186 186
 
187 187
 function script_for_attaching_usb_drive {
188
-	if grep -Fxq "script_for_attaching_usb_drive" $COMPLETION_FILE; then
189
-		return
190
-	fi
191
-	echo '#!/bin/bash' > /usr/bin/attach-music
192
-	echo 'remove-music' >> /usr/bin/attach-music
193
-	echo "if [ ! -d $USB_MOUNT ]; then" >> /usr/bin/attach-music
194
-	echo "  mkdir $USB_MOUNT" >> /usr/bin/attach-music
195
-	echo 'fi' >> /usr/bin/attach-music
196
-	echo "mount /dev/sda1 $USB_MOUNT" >> /usr/bin/attach-music
197
-	echo "chown root:root $USB_MOUNT" >> /usr/bin/attach-music
198
-	echo "chown -R minidlna:minidlna $USB_MOUNT/*" >> /usr/bin/attach-music
199
-	echo 'service minidlna restart' >> /usr/bin/attach-music
200
-	echo 'minidlnad -R' >> /usr/bin/attach-music
201
-	chmod +x /usr/bin/attach-music
202
-	ln -s /usr/bin/attach-music /usr/bin/attach-usb
203
-	ln -s /usr/bin/attach-music /usr/bin/attach-videos
204
-	ln -s /usr/bin/attach-music /usr/bin/attach-pictures
205
-	ln -s /usr/bin/attach-music /usr/bin/attach-media
206
-
207
-	echo '#!/bin/bash' > /usr/bin/remove-music
208
-	echo "if [ -d $USB_MOUNT ]; then" >> /usr/bin/remove-music
209
-	echo "  umount $USB_MOUNT" >> /usr/bin/remove-music
210
-	echo "  rm -rf $USB_MOUNT" >> /usr/bin/remove-music
211
-	echo 'fi' >> /usr/bin/remove-music
212
-	chmod +x /usr/bin/remove-music
213
-	ln -s /usr/bin/remove-music /usr/bin/detach-music
214
-	ln -s /usr/bin/remove-music /usr/bin/detach-usb
215
-	ln -s /usr/bin/remove-music /usr/bin/remove-usb
216
-	ln -s /usr/bin/remove-music /usr/bin/detach-media
217
-	ln -s /usr/bin/remove-music /usr/bin/remove-media
218
-	ln -s /usr/bin/remove-music /usr/bin/detach-videos
219
-	ln -s /usr/bin/remove-music /usr/bin/remove-videos
220
-	ln -s /usr/bin/remove-music /usr/bin/detach-pictures
221
-	ln -s /usr/bin/remove-music /usr/bin/remove-pictures
222
-
223
-	echo 'script_for_attaching_usb_drive' >> $COMPLETION_FILE
188
+    if grep -Fxq "script_for_attaching_usb_drive" $COMPLETION_FILE; then
189
+	return
190
+    fi
191
+    echo '#!/bin/bash' > /usr/bin/attach-music
192
+    echo 'remove-music' >> /usr/bin/attach-music
193
+    echo "if [ ! -d $USB_MOUNT ]; then" >> /usr/bin/attach-music
194
+    echo "  mkdir $USB_MOUNT" >> /usr/bin/attach-music
195
+    echo 'fi' >> /usr/bin/attach-music
196
+    echo "mount /dev/sda1 $USB_MOUNT" >> /usr/bin/attach-music
197
+    echo "chown root:root $USB_MOUNT" >> /usr/bin/attach-music
198
+    echo "chown -R minidlna:minidlna $USB_MOUNT/*" >> /usr/bin/attach-music
199
+    echo 'service minidlna restart' >> /usr/bin/attach-music
200
+    echo 'minidlnad -R' >> /usr/bin/attach-music
201
+    chmod +x /usr/bin/attach-music
202
+    ln -s /usr/bin/attach-music /usr/bin/attach-usb
203
+    ln -s /usr/bin/attach-music /usr/bin/attach-videos
204
+    ln -s /usr/bin/attach-music /usr/bin/attach-pictures
205
+    ln -s /usr/bin/attach-music /usr/bin/attach-media
206
+
207
+    echo '#!/bin/bash' > /usr/bin/remove-music
208
+    echo "if [ -d $USB_MOUNT ]; then" >> /usr/bin/remove-music
209
+    echo "  umount $USB_MOUNT" >> /usr/bin/remove-music
210
+    echo "  rm -rf $USB_MOUNT" >> /usr/bin/remove-music
211
+    echo 'fi' >> /usr/bin/remove-music
212
+    chmod +x /usr/bin/remove-music
213
+    ln -s /usr/bin/remove-music /usr/bin/detach-music
214
+    ln -s /usr/bin/remove-music /usr/bin/detach-usb
215
+    ln -s /usr/bin/remove-music /usr/bin/remove-usb
216
+    ln -s /usr/bin/remove-music /usr/bin/detach-media
217
+    ln -s /usr/bin/remove-music /usr/bin/remove-media
218
+    ln -s /usr/bin/remove-music /usr/bin/detach-videos
219
+    ln -s /usr/bin/remove-music /usr/bin/remove-videos
220
+    ln -s /usr/bin/remove-music /usr/bin/detach-pictures
221
+    ln -s /usr/bin/remove-music /usr/bin/remove-pictures
222
+
223
+    echo 'script_for_attaching_usb_drive' >> $COMPLETION_FILE
224 224
 }
225 225
 
226 226
 function install_dlna {
227
-	if grep -Fxq "install_dlna" $COMPLETION_FILE; then
228
-		return
229
-	fi
230
-	install_dlna_main
231
-	script_for_attaching_usb_drive
232
-	echo 'install_dlna' >> $COMPLETION_FILE
227
+    if grep -Fxq "install_dlna" $COMPLETION_FILE; then
228
+	return
229
+    fi
230
+    install_dlna_main
231
+    script_for_attaching_usb_drive
232
+    echo 'install_dlna' >> $COMPLETION_FILE
233 233
 }
234 234
 
235 235
 # NOTE: deliberately no exit 0

+ 124
- 124
src/freedombone-app-emacs Voir le fichier

@@ -31,154 +31,154 @@
31 31
 VARIANTS='all'
32 32
 
33 33
 function reconfigure_emacs {
34
-	echo -n ''
34
+    echo -n ''
35 35
 }
36 36
 
37 37
 function upgrade_emacs {
38
-	echo -n ''
38
+    echo -n ''
39 39
 }
40 40
 
41 41
 function backup_local_emacs {
42
-	for d in /home/*/ ; do
43
-		USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
44
-		if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
45
-			if [ -d /home/$USERNAME/.emacs.d ]; then
46
-				echo $"Backing up Emacs config for $USERNAME"
47
-				if [ -f /home/$USERNAME/.emacs ]; then
48
-					cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
49
-				fi
50
-				function_check backup_directory_to_usb
51
-				backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
52
-			fi
42
+    for d in /home/*/ ; do
43
+	USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
44
+	if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
45
+	    if [ -d /home/$USERNAME/.emacs.d ]; then
46
+		echo $"Backing up Emacs config for $USERNAME"
47
+		if [ -f /home/$USERNAME/.emacs ]; then
48
+		    cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
53 49
 		fi
54
-	done
50
+		function_check backup_directory_to_usb
51
+		backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
52
+	    fi
53
+	fi
54
+    done
55 55
 }
56 56
 
57 57
 function restore_local_emacs {
58
-	temp_restore_dir=/root/tempemacs
59
-	if [ -d $USB_MOUNT/backup/emacs ]; then
60
-		for d in $USB_MOUNT/backup/emacs/*/ ; do
61
-			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
62
-			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
63
-				if [ ! -d /home/$USERNAME ]; then
64
-					${PROJECT_NAME}-adduser $USERNAME
65
-				fi
66
-				echo $"Restoring Emacs config for $USERNAME"
67
-				function_check restore_directory_from_usb
68
-				restore_directory_from_usb $temp_restore_dir emacs/$USERNAME
69
-				cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
70
-				if [ ! "$?" = "0" ]; then
71
-					rm -rf $temp_restore_dir
72
-					function_check set_user_permissions
73
-					set_user_permissions
74
-					function_check backup_unmount_drive
75
-					backup_unmount_drive
76
-					exit 664
77
-				fi
78
-				cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
79
-				rm -rf $temp_restore_dir
80
-			fi
81
-		done
82
-	fi
58
+    temp_restore_dir=/root/tempemacs
59
+    if [ -d $USB_MOUNT/backup/emacs ]; then
60
+	for d in $USB_MOUNT/backup/emacs/*/ ; do
61
+	    USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
62
+	    if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
63
+		if [ ! -d /home/$USERNAME ]; then
64
+		    ${PROJECT_NAME}-adduser $USERNAME
65
+		fi
66
+		echo $"Restoring Emacs config for $USERNAME"
67
+		function_check restore_directory_from_usb
68
+		restore_directory_from_usb $temp_restore_dir emacs/$USERNAME
69
+		cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
70
+		if [ ! "$?" = "0" ]; then
71
+		    rm -rf $temp_restore_dir
72
+		    function_check set_user_permissions
73
+		    set_user_permissions
74
+		    function_check backup_unmount_drive
75
+		    backup_unmount_drive
76
+		    exit 664
77
+		fi
78
+		cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
79
+		rm -rf $temp_restore_dir
80
+	    fi
81
+	done
82
+    fi
83 83
 }
84 84
 
85 85
 function backup_remote_emacs {
86
-	echo -n ''
86
+    echo -n ''
87 87
 }
88 88
 
89 89
 function restore_remote_emacs {
90
-	echo -n ''
90
+    echo -n ''
91 91
 }
92 92
 
93 93
 function remove_emacs {
94
-	if ! grep -Fxq "install_emacs" $COMPLETION_FILE; then
95
-		return
96
-	fi
97
-	apt-get -y remove --purge emacs24
98
-	update-alternatives --set editor /usr/bin/nano
99
-	sed -i '/install_emacs/d' $COMPLETION_FILE
94
+    if ! grep -Fxq "install_emacs" $COMPLETION_FILE; then
95
+	return
96
+    fi
97
+    apt-get -y remove --purge emacs24
98
+    update-alternatives --set editor /usr/bin/nano
99
+    sed -i '/install_emacs/d' $COMPLETION_FILE
100 100
 }
101 101
 
102 102
 function install_emacs {
103
-	if grep -Fxq "install_emacs" $COMPLETION_FILE; then
104
-		return
105
-	fi
106
-	update-alternatives --set editor /usr/bin/emacs24
103
+    if grep -Fxq "install_emacs" $COMPLETION_FILE; then
104
+	return
105
+    fi
106
+    update-alternatives --set editor /usr/bin/emacs24
107 107
 
108
-	# A minimal emacs configuration
109
-	#echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
110
-	#echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
111
-	#echo '' >> /home/$MY_USERNAME/.emacs
112
-	echo $';; ===== Remove trailing whitepace ======================================' >> /home/$MY_USERNAME/.emacs
113
-	echo '' >> /home/$MY_USERNAME/.emacs
114
-	echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)" >> /home/$MY_USERNAME/.emacs
115
-	echo '' >> /home/$MY_USERNAME/.emacs
116
-	echo ';; Goto a line number with CTRL-l' >> /home/$MY_USERNAME/.emacs
117
-	echo -n '(global-set-key "\C-l" ' >> /home/$MY_USERNAME/.emacs
118
-	echo "'goto-line)" >> /home/$MY_USERNAME/.emacs
119
-	echo '' >> /home/$MY_USERNAME/.emacs
120
-	echo $';; ===== Show line numbers ==============================================' >> /home/$MY_USERNAME/.emacs
121
-	echo '' >> /home/$MY_USERNAME/.emacs
122
-	echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))" >> /home/$MY_USERNAME/.emacs
123
-	echo '' >> /home/$MY_USERNAME/.emacs
124
-	echo $';; ===== Enable line wrapping in org-mode ===============================' >> /home/$MY_USERNAME/.emacs
125
-	echo '' >> /home/$MY_USERNAME/.emacs
126
-	echo " (add-hook 'org-mode-hook" >> /home/$MY_USERNAME/.emacs
127
-	echo "           '(lambda ()" >> /home/$MY_USERNAME/.emacs
128
-	echo "              (visual-line-mode 1)))" >> /home/$MY_USERNAME/.emacs
129
-	echo '' >> /home/$MY_USERNAME/.emacs
130
-	echo $';; ===== Enable shift select in org mode ================================' >> /home/$MY_USERNAME/.emacs
131
-	echo '' >> /home/$MY_USERNAME/.emacs
132
-	echo '(setq org-support-shift-select t)' >> /home/$MY_USERNAME/.emacs
133
-	echo '' >> /home/$MY_USERNAME/.emacs
134
-	echo $';; ===== Set standard indent to 4 rather that 4 =========================' >> /home/$MY_USERNAME/.emacs
135
-	echo '' >> /home/$MY_USERNAME/.emacs
136
-	echo '(setq standard-indent 4)' >> /home/$MY_USERNAME/.emacs
137
-	echo '(setq-default tab-width 4)' >> /home/$MY_USERNAME/.emacs
138
-	echo '(setq c-basic-offset 4)' >> /home/$MY_USERNAME/.emacs
139
-	echo '' >> /home/$MY_USERNAME/.emacs
140
-	echo $';; ===== Support Wheel Mouse Scrolling ==================================' >> /home/$MY_USERNAME/.emacs
141
-	echo '' >> /home/$MY_USERNAME/.emacs
142
-	echo '(mouse-wheel-mode t)' >> /home/$MY_USERNAME/.emacs
143
-	echo '' >> /home/$MY_USERNAME/.emacs
144
-	echo $';; ===== Place Backup Files in Specific Directory =======================' >> /home/$MY_USERNAME/.emacs
145
-	echo '' >> /home/$MY_USERNAME/.emacs
146
-	echo '(setq make-backup-files t)' >> /home/$MY_USERNAME/.emacs
147
-	echo '(setq version-control t)' >> /home/$MY_USERNAME/.emacs
148
-	echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$MY_USERNAME/.emacs
149
-	echo '' >> /home/$MY_USERNAME/.emacs
150
-	echo $';; ===== Make Text mode the default mode for new buffers ================' >> /home/$MY_USERNAME/.emacs
151
-	echo '' >> /home/$MY_USERNAME/.emacs
152
-	echo "(setq default-major-mode 'text-mode)" >> /home/$MY_USERNAME/.emacs
153
-	echo '' >> /home/$MY_USERNAME/.emacs
154
-	echo $';; ===== Line length ====================================================' >> /home/$MY_USERNAME/.emacs
155
-	echo '' >> /home/$MY_USERNAME/.emacs
156
-	echo '(setq-default fill-column 72)' >> /home/$MY_USERNAME/.emacs
157
-	echo '' >> /home/$MY_USERNAME/.emacs
158
-	echo $';; ===== Enable Line and Column Numbering ===============================' >> /home/$MY_USERNAME/.emacs
159
-	echo '' >> /home/$MY_USERNAME/.emacs
160
-	echo '(line-number-mode 1)' >> /home/$MY_USERNAME/.emacs
161
-	echo '(column-number-mode 1)' >> /home/$MY_USERNAME/.emacs
162
-	echo '' >> /home/$MY_USERNAME/.emacs
163
-	echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============' >> /home/$MY_USERNAME/.emacs
164
-	echo '' >> /home/$MY_USERNAME/.emacs
165
-	echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of' >> /home/$MY_USERNAME/.emacs
166
-	echo ';; newlines when the cursor goes over the column limit.' >> /home/$MY_USERNAME/.emacs
167
-	echo '' >> /home/$MY_USERNAME/.emacs
168
-	echo ';; This should actually turn on auto-fill-mode by default in all major' >> /home/$MY_USERNAME/.emacs
169
-	echo ';; modes. The other way to do this is to turn on the fill for specific modes' >> /home/$MY_USERNAME/.emacs
170
-	echo ';; via hooks.' >> /home/$MY_USERNAME/.emacs
171
-	echo '' >> /home/$MY_USERNAME/.emacs
172
-	echo '(setq auto-fill-mode 1)' >> /home/$MY_USERNAME/.emacs
173
-	echo '' >> /home/$MY_USERNAME/.emacs
174
-	echo $';; ===== Enable GPG encryption =========================================' >> /home/$MY_USERNAME/.emacs
175
-	echo '' >> /home/$MY_USERNAME/.emacs
176
-	echo "(require 'epa)" >> /home/$MY_USERNAME/.emacs
177
-	echo '(epa-file-enable)' >> /home/$MY_USERNAME/.emacs
178
-	cp /home/$MY_USERNAME/.emacs /root/.emacs
179
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
108
+    # A minimal emacs configuration
109
+    #echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
110
+    #echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
111
+    #echo '' >> /home/$MY_USERNAME/.emacs
112
+    echo $';; ===== Remove trailing whitepace ======================================' >> /home/$MY_USERNAME/.emacs
113
+    echo '' >> /home/$MY_USERNAME/.emacs
114
+    echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)" >> /home/$MY_USERNAME/.emacs
115
+    echo '' >> /home/$MY_USERNAME/.emacs
116
+    echo ';; Goto a line number with CTRL-l' >> /home/$MY_USERNAME/.emacs
117
+    echo -n '(global-set-key "\C-l" ' >> /home/$MY_USERNAME/.emacs
118
+    echo "'goto-line)" >> /home/$MY_USERNAME/.emacs
119
+    echo '' >> /home/$MY_USERNAME/.emacs
120
+    echo $';; ===== Show line numbers ==============================================' >> /home/$MY_USERNAME/.emacs
121
+    echo '' >> /home/$MY_USERNAME/.emacs
122
+    echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))" >> /home/$MY_USERNAME/.emacs
123
+    echo '' >> /home/$MY_USERNAME/.emacs
124
+    echo $';; ===== Enable line wrapping in org-mode ===============================' >> /home/$MY_USERNAME/.emacs
125
+    echo '' >> /home/$MY_USERNAME/.emacs
126
+    echo " (add-hook 'org-mode-hook" >> /home/$MY_USERNAME/.emacs
127
+    echo "           '(lambda ()" >> /home/$MY_USERNAME/.emacs
128
+    echo "              (visual-line-mode 1)))" >> /home/$MY_USERNAME/.emacs
129
+    echo '' >> /home/$MY_USERNAME/.emacs
130
+    echo $';; ===== Enable shift select in org mode ================================' >> /home/$MY_USERNAME/.emacs
131
+    echo '' >> /home/$MY_USERNAME/.emacs
132
+    echo '(setq org-support-shift-select t)' >> /home/$MY_USERNAME/.emacs
133
+    echo '' >> /home/$MY_USERNAME/.emacs
134
+    echo $';; ===== Set standard indent to 4 rather that 4 =========================' >> /home/$MY_USERNAME/.emacs
135
+    echo '' >> /home/$MY_USERNAME/.emacs
136
+    echo '(setq standard-indent 4)' >> /home/$MY_USERNAME/.emacs
137
+    echo '(setq-default tab-width 4)' >> /home/$MY_USERNAME/.emacs
138
+    echo '(setq c-basic-offset 4)' >> /home/$MY_USERNAME/.emacs
139
+    echo '' >> /home/$MY_USERNAME/.emacs
140
+    echo $';; ===== Support Wheel Mouse Scrolling ==================================' >> /home/$MY_USERNAME/.emacs
141
+    echo '' >> /home/$MY_USERNAME/.emacs
142
+    echo '(mouse-wheel-mode t)' >> /home/$MY_USERNAME/.emacs
143
+    echo '' >> /home/$MY_USERNAME/.emacs
144
+    echo $';; ===== Place Backup Files in Specific Directory =======================' >> /home/$MY_USERNAME/.emacs
145
+    echo '' >> /home/$MY_USERNAME/.emacs
146
+    echo '(setq make-backup-files t)' >> /home/$MY_USERNAME/.emacs
147
+    echo '(setq version-control t)' >> /home/$MY_USERNAME/.emacs
148
+    echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$MY_USERNAME/.emacs
149
+    echo '' >> /home/$MY_USERNAME/.emacs
150
+    echo $';; ===== Make Text mode the default mode for new buffers ================' >> /home/$MY_USERNAME/.emacs
151
+    echo '' >> /home/$MY_USERNAME/.emacs
152
+    echo "(setq default-major-mode 'text-mode)" >> /home/$MY_USERNAME/.emacs
153
+    echo '' >> /home/$MY_USERNAME/.emacs
154
+    echo $';; ===== Line length ====================================================' >> /home/$MY_USERNAME/.emacs
155
+    echo '' >> /home/$MY_USERNAME/.emacs
156
+    echo '(setq-default fill-column 72)' >> /home/$MY_USERNAME/.emacs
157
+    echo '' >> /home/$MY_USERNAME/.emacs
158
+    echo $';; ===== Enable Line and Column Numbering ===============================' >> /home/$MY_USERNAME/.emacs
159
+    echo '' >> /home/$MY_USERNAME/.emacs
160
+    echo '(line-number-mode 1)' >> /home/$MY_USERNAME/.emacs
161
+    echo '(column-number-mode 1)' >> /home/$MY_USERNAME/.emacs
162
+    echo '' >> /home/$MY_USERNAME/.emacs
163
+    echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============' >> /home/$MY_USERNAME/.emacs
164
+    echo '' >> /home/$MY_USERNAME/.emacs
165
+    echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of' >> /home/$MY_USERNAME/.emacs
166
+    echo ';; newlines when the cursor goes over the column limit.' >> /home/$MY_USERNAME/.emacs
167
+    echo '' >> /home/$MY_USERNAME/.emacs
168
+    echo ';; This should actually turn on auto-fill-mode by default in all major' >> /home/$MY_USERNAME/.emacs
169
+    echo ';; modes. The other way to do this is to turn on the fill for specific modes' >> /home/$MY_USERNAME/.emacs
170
+    echo ';; via hooks.' >> /home/$MY_USERNAME/.emacs
171
+    echo '' >> /home/$MY_USERNAME/.emacs
172
+    echo '(setq auto-fill-mode 1)' >> /home/$MY_USERNAME/.emacs
173
+    echo '' >> /home/$MY_USERNAME/.emacs
174
+    echo $';; ===== Enable GPG encryption =========================================' >> /home/$MY_USERNAME/.emacs
175
+    echo '' >> /home/$MY_USERNAME/.emacs
176
+    echo "(require 'epa)" >> /home/$MY_USERNAME/.emacs
177
+    echo '(epa-file-enable)' >> /home/$MY_USERNAME/.emacs
178
+    cp /home/$MY_USERNAME/.emacs /root/.emacs
179
+    chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
180 180
 
181
-	echo 'install_emacs' >> $COMPLETION_FILE
181
+    echo 'install_emacs' >> $COMPLETION_FILE
182 182
 }
183 183
 
184 184
 # NOTE: deliberately no exit 0

+ 503
- 503
src/freedombone-app-gogs
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 418
- 418
src/freedombone-app-hubzilla Voir le fichier

@@ -41,461 +41,461 @@ HUBZILLA_COMMIT='2d79e75788aa71664a379c4cea0b6bfe3ab87ad0'
41 41
 HUBZILLA_ADDONS_COMMIT='67b40c7a40f328a93ee030eb15e9e1261f3cba64'
42 42
 
43 43
 function reconfigure_hubzilla {
44
-	echo -n ''
44
+    echo -n ''
45 45
 }
46 46
 
47 47
 function upgrade_hubzilla {
48
-	if ! grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
49
-		return
50
-	fi
51
-	HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
52
-
53
-	function_check set_repo_commit
54
-	set_repo_commit $HUBZILLA_PATH "Hubzilla commit" "$HUBZILLA_COMMIT" $HUBZILLA_REPO
55
-	set_repo_commit $HUBZILLA_PATH/addon "Hubzilla addons commit" "$HUBZILLA_ADDONS_COMMIT" $HUBZILLA_ADDONS_REPO
56
-	if [ -d $HUBZILLA_PATH/redmatrix-themes1 ]; then
57
-		cd $HUBZILLA_PATH/redmatrix-themes1
58
-		git stash
59
-		git pull
60
-		cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
61
-		chown -R www-data:www-data $HUBZILLA_PATH
62
-	fi
48
+    if ! grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
49
+	return
50
+    fi
51
+    HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
52
+
53
+    function_check set_repo_commit
54
+    set_repo_commit $HUBZILLA_PATH "Hubzilla commit" "$HUBZILLA_COMMIT" $HUBZILLA_REPO
55
+    set_repo_commit $HUBZILLA_PATH/addon "Hubzilla addons commit" "$HUBZILLA_ADDONS_COMMIT" $HUBZILLA_ADDONS_REPO
56
+    if [ -d $HUBZILLA_PATH/redmatrix-themes1 ]; then
57
+	cd $HUBZILLA_PATH/redmatrix-themes1
58
+	git stash
59
+	git pull
60
+	cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
61
+	chown -R www-data:www-data $HUBZILLA_PATH
62
+    fi
63 63
 }
64 64
 
65 65
 function backup_local_hubzilla {
66
-	if grep -q "Hubzilla domain" $COMPLETION_FILE; then
67
-		HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
68
-		hubzilla_path=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
69
-		if [ -d $hubzilla_path ]; then
70
-			echo $"Backing up Hubzilla"
71
-			function_check backup_database_to_usb
72
-			backup_database_to_usb hubzilla
73
-
74
-			backup_directory_to_usb $hubzilla_path hubzilla
75
-
76
-			echo $"Hubzilla backup complete"
77
-		fi
66
+    if grep -q "Hubzilla domain" $COMPLETION_FILE; then
67
+	HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
68
+	hubzilla_path=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
69
+	if [ -d $hubzilla_path ]; then
70
+	    echo $"Backing up Hubzilla"
71
+	    function_check backup_database_to_usb
72
+	    backup_database_to_usb hubzilla
73
+
74
+	    backup_directory_to_usb $hubzilla_path hubzilla
75
+
76
+	    echo $"Hubzilla backup complete"
78 77
 	fi
78
+    fi
79 79
 }
80 80
 
81 81
 function restore_local_hubzilla {
82
-	if ! grep -q "Hubzilla domain" $COMPLETION_FILE; then
83
-		return
84
-	fi
85
-	HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
86
-	if [ $HUBZILLA_DOMAIN_NAME ]; then
87
-		echo $"Restoring Hubzilla"
88
-		temp_restore_dir=/root/temphubzilla
89
-		hubzilla_dir=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
90
-		restore_database hubzilla ${HUBZILLA_DOMAIN_NAME}
91
-		if [ -d $USB_MOUNT/backup/hubzilla ]; then
92
-			if [ ! -d $hubzilla_dir/store/[data]/smarty3 ]; then
93
-				mkdir -p $hubzilla_dir/store/[data]/smarty3
94
-			fi
95
-			chmod 777 $hubzilla_dir/store/[data]/smarty3
96
-			chown -R www-data:www-data $hubzilla_dir/*
97
-			if [ -d $temp_restore_dir ]; then
98
-				rm -rf $temp_restore_dir
99
-			fi
100
-		fi
101
-		echo $"Restore of Hubzilla complete"
82
+    if ! grep -q "Hubzilla domain" $COMPLETION_FILE; then
83
+	return
84
+    fi
85
+    HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
86
+    if [ $HUBZILLA_DOMAIN_NAME ]; then
87
+	echo $"Restoring Hubzilla"
88
+	temp_restore_dir=/root/temphubzilla
89
+	hubzilla_dir=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
90
+	restore_database hubzilla ${HUBZILLA_DOMAIN_NAME}
91
+	if [ -d $USB_MOUNT/backup/hubzilla ]; then
92
+	    if [ ! -d $hubzilla_dir/store/[data]/smarty3 ]; then
93
+		mkdir -p $hubzilla_dir/store/[data]/smarty3
94
+	    fi
95
+	    chmod 777 $hubzilla_dir/store/[data]/smarty3
96
+	    chown -R www-data:www-data $hubzilla_dir/*
97
+	    if [ -d $temp_restore_dir ]; then
98
+		rm -rf $temp_restore_dir
99
+	    fi
102 100
 	fi
101
+	echo $"Restore of Hubzilla complete"
102
+    fi
103 103
 }
104 104
 
105 105
 function backup_remote_hubzilla {
106
-	if grep -q "Hubzilla domain" $COMPLETION_FILE; then
107
-		HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
108
-		temp_backup_dir=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
109
-		if [ -d $temp_backup_dir ]; then
110
-			suspend_site ${HUBZILLA_DOMAIN_NAME}
111
-			backup_database_to_friend hubzilla
112
-			echo "Backing up Hubzilla installation"
113
-			backup_directory_to_friend $temp_backup_dir hubzilla
114
-			restart_site
115
-			echo "Backup of Hubzilla complete"
116
-		else
117
-			echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}"
118
-			exit 2578
119
-		fi
106
+    if grep -q "Hubzilla domain" $COMPLETION_FILE; then
107
+	HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
108
+	temp_backup_dir=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
109
+	if [ -d $temp_backup_dir ]; then
110
+	    suspend_site ${HUBZILLA_DOMAIN_NAME}
111
+	    backup_database_to_friend hubzilla
112
+	    echo "Backing up Hubzilla installation"
113
+	    backup_directory_to_friend $temp_backup_dir hubzilla
114
+	    restart_site
115
+	    echo "Backup of Hubzilla complete"
116
+	else
117
+	    echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}"
118
+	    exit 2578
120 119
 	fi
120
+    fi
121 121
 }
122 122
 
123 123
 function restore_remote_hubzilla {
124
-	if grep -q "Hubzilla domain" $COMPLETION_FILE; then
125
-		echo $"Restoring Hubzilla"
126
-		HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
127
-		function_check restore_database_from_friend
128
-		restore_database_from_friend hubzilla ${HUBZILLA_DOMAIN_NAME}
129
-		if [ -d $SERVER_DIRECTORY/backup/hubzilla ]; then
130
-			if [ ! -d /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 ]; then
131
-				mkdir -p /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
132
-			fi
133
-			chmod 777 /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
134
-			chown -R www-data:www-data /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/*
135
-		fi
136
-		if [ -d /root/temphubzilla ]; then
137
-			rm -rf /root/temphubzilla
138
-		fi
139
-		echo $"Restore of Hubzilla complete"
124
+    if grep -q "Hubzilla domain" $COMPLETION_FILE; then
125
+	echo $"Restoring Hubzilla"
126
+	HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
127
+	function_check restore_database_from_friend
128
+	restore_database_from_friend hubzilla ${HUBZILLA_DOMAIN_NAME}
129
+	if [ -d $SERVER_DIRECTORY/backup/hubzilla ]; then
130
+	    if [ ! -d /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 ]; then
131
+		mkdir -p /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
132
+	    fi
133
+	    chmod 777 /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
134
+	    chown -R www-data:www-data /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/*
135
+	fi
136
+	if [ -d /root/temphubzilla ]; then
137
+	    rm -rf /root/temphubzilla
140 138
 	fi
139
+	echo $"Restore of Hubzilla complete"
140
+    fi
141 141
 }
142 142
 
143 143
 function remove_hubzilla {
144
-	if ! grep -Fxq "Hubzilla domain" $COMPLETION_FILE; then
145
-		return
146
-	fi
147
-	echo $'Removing Hubzilla'
148
-	HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
149
-	nginx_dissite $HUBZILLA_DOMAIN_NAME
150
-	if [ -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
151
-		rm -rf /var/www/$HUBZILLA_DOMAIN_NAME
152
-	fi
153
-	if [ -f /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME ]; then
154
-		rm /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
155
-	fi
156
-	function_check drop_database
157
-	drop_database hubzilla
158
-	function_check remove_onion_service
159
-	remove_onion_service hubzilla ${HUBZILLA_ONION_PORT}
160
-	sed -i '/install_hubzilla/d' $COMPLETION_FILE
161
-	sed -i '/Hubzilla /d' $COMPLETION_FILE
162
-	echo $'Hubzilla was removed'
144
+    if ! grep -Fxq "Hubzilla domain" $COMPLETION_FILE; then
145
+	return
146
+    fi
147
+    echo $'Removing Hubzilla'
148
+    HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
149
+    nginx_dissite $HUBZILLA_DOMAIN_NAME
150
+    if [ -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
151
+	rm -rf /var/www/$HUBZILLA_DOMAIN_NAME
152
+    fi
153
+    if [ -f /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME ]; then
154
+	rm /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
155
+    fi
156
+    function_check drop_database
157
+    drop_database hubzilla
158
+    function_check remove_onion_service
159
+    remove_onion_service hubzilla ${HUBZILLA_ONION_PORT}
160
+    sed -i '/install_hubzilla/d' $COMPLETION_FILE
161
+    sed -i '/Hubzilla /d' $COMPLETION_FILE
162
+    echo $'Hubzilla was removed'
163 163
 }
164 164
 
165 165
 function install_hubzilla {
166
-	if [ ! $HUBZILLA_DOMAIN_NAME ]; then
167
-		return
168
-	fi
169
-
170
-	if [[ $ONION_ONLY != "no" ]]; then
171
-		return
172
-	fi
173
-
174
-	if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
175
-		return
176
-	fi
177
-
178
-	HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
179
-
180
-	function_check install_mariadb
181
-	install_mariadb
182
-
183
-	function_check get_mariadb_password
184
-	get_mariadb_password
185
-
186
-	function_check repair_databases_script
187
-	repair_databases_script
188
-
189
-	apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
190
-	apt-get -y install php5-dev imagemagick php5-imagick
191
-	apt-get -y install php5-memcached
192
-
193
-	if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
194
-		mkdir /var/www/$HUBZILLA_DOMAIN_NAME
195
-	fi
196
-	if [ ! -d $HUBZILLA_PATH ]; then
197
-		mkdir $HUBZILLA_PATH
198
-	fi
199
-
200
-	if [ ! -f $HUBZILLA_PATH/index.php ]; then
201
-		cd $INSTALL_DIR
202
-		function_check git_clone
203
-		git_clone $HUBZILLA_REPO hubzilla
204
-		git checkout $HUBZILLA_COMMIT -b $HUBZILLA_COMMIT
205
-		if ! grep -q "Hubzilla commit" $COMPLETION_FILE; then
206
-			echo "Hubzilla commit:$HUBZILLA_COMMIT" >> $COMPLETION_FILE
207
-		else
208
-			sed -i "s/Hubzilla commit.*/Hubzilla commit:$HUBZILLA_COMMIT/g" $COMPLETION_FILE
209
-		fi
210
-
211
-		rm -rf $HUBZILLA_PATH
212
-		mv hubzilla $HUBZILLA_PATH
213
-
214
-		git_clone $HUBZILLA_ADDONS_REPO $HUBZILLA_PATH/addon
215
-		cd $HUBZILLA_PATH/addon
216
-		git checkout $HUBZILLA_ADDONS_COMMIT -b $HUBZILLA_ADDONS_COMMIT
217
-		if ! grep -q "Hubzilla addons commit" $COMPLETION_FILE; then
218
-			echo "Hubzilla addons commit:$HUBZILLA_ADDONS_COMMIT" >> $COMPLETION_FILE
219
-		else
220
-			sed -i "s/Hubzilla addons commit.*/Hubzilla addons commit:$HUBZILLA_ADDONS_COMMIT/g" $COMPLETION_FILE
221
-		fi
222
-
223
-		# some extra themes
224
-		git_clone $HUBZILLA_THEMES_REPO $HUBZILLA_PATH/redmatrix-themes1
225
-		cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
226
-
227
-		chown -R www-data:www-data $HUBZILLA_PATH
228
-	fi
229
-
230
-	HUBZILLA_ONION_HOSTNAME=
231
-	if [[ $ONION_ONLY != "no" ]]; then
232
-		HUBZILLA_ONION_HOSTNAME=$(add_onion_service hubzilla 80 ${HUBZILLA_ONION_PORT})
233
-		echo "Hubzilla onion domain:${HUBZILLA_ONION_HOSTNAME}" >> $COMPLETION_FILE
234
-	fi
235
-
236
-	function_check get_mariadb_hubzilla_admin_password
237
-	get_mariadb_hubzilla_admin_password
238
-	if [ ! $HUBZILLA_ADMIN_PASSWORD ]; then
239
-		if [ -f $IMAGE_PASSWORD_FILE ]; then
240
-			HUBZILLA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
241
-		else
242
-			HUBZILLA_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
243
-		fi
244
-		echo '' >> /home/$MY_USERNAME/README
245
-		echo '' >> /home/$MY_USERNAME/README
246
-		echo 'Hubzilla' >> /home/$MY_USERNAME/README
247
-		echo '========' >> /home/$MY_USERNAME/README
248
-		if [[ $ONION_ONLY == 'no' ]]; then
249
-			echo $"Open https://$HUBZILLA_DOMAIN_NAME and register a new user" >> /home/$MY_USERNAME/README
250
-		else
251
-			echo $"Open http://$HUBZILLA_ONION_HOSTNAME and register a new user" >> /home/$MY_USERNAME/README
252
-		fi
253
-		echo $"Your MariaDB Hubzilla admin password is: $HUBZILLA_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
254
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
255
-		chmod 600 /home/$MY_USERNAME/README
256
-	fi
257
-
258
-	function_check create_database
259
-	create_database hubzilla "$HUBZILLA_ADMIN_PASSWORD"
260
-
261
-	if ! grep -q "$HUBZILLA_PATH" /etc/crontab; then
262
-		echo "12,22,32,42,52 * *   *   *   root cd $HUBZILLA_PATH; /usr/bin/timeout 500 /usr/bin/php include/poller.php" >> /etc/crontab
263
-	fi
264
-
265
-	function_check add_ddns_domain
266
-	add_ddns_domain $HUBZILLA_DOMAIN_NAME
267
-
268
-	if [[ $ONION_ONLY == "no" ]]; then
269
-		function_check nginx_http_redirect
270
-		nginx_http_redirect $HUBZILLA_DOMAIN_NAME
271
-		echo 'server {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
272
-		echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
273
-		echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
274
-		echo "    server_name $HUBZILLA_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
275
-		echo "    error_log /var/log/nginx/${HUBZILLA_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
276
-		echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
277
-		echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
278
-		echo '    access_log off;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
279
-		function_check nginx_limits
280
-		nginx_limits $HUBZILLA_DOMAIN_NAME
281
-		function_check nginx_ssl
282
-		nginx_ssl $HUBZILLA_DOMAIN_NAME
283
-		function_check nginx_disable_sniffing
284
-		nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
285
-		echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
286
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
287
-		echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
288
-		echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
289
-		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
290
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
291
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
292
-		echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
293
-		echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
294
-		echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
295
-		echo '        allow all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
296
-		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
297
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
298
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
299
-		echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
300
-		echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
301
-		echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
302
-		echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
303
-		echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
304
-		echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
305
-		echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
306
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
307
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
308
-		echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
309
-		echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
310
-		echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
311
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
312
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
313
-		echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
314
-		echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
315
-		echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
316
-		echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
317
-		echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
318
-		echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
319
-		echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
320
-		echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
321
-		echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
322
-		echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
323
-		echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
324
-		echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
325
-		echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
326
-		echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
327
-		echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
328
-		echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
329
-		echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
330
-		echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
331
-		echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
332
-		echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
333
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
334
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
335
-		echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
336
-		echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
337
-		echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
338
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
339
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
340
-		echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
341
-		echo '      deny  all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
342
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
343
-		echo '}' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
344
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
166
+    if [ ! $HUBZILLA_DOMAIN_NAME ]; then
167
+	return
168
+    fi
169
+
170
+    if [[ $ONION_ONLY != "no" ]]; then
171
+	return
172
+    fi
173
+
174
+    if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
175
+	return
176
+    fi
177
+
178
+    HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
179
+
180
+    function_check install_mariadb
181
+    install_mariadb
182
+
183
+    function_check get_mariadb_password
184
+    get_mariadb_password
185
+
186
+    function_check repair_databases_script
187
+    repair_databases_script
188
+
189
+    apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
190
+    apt-get -y install php5-dev imagemagick php5-imagick
191
+    apt-get -y install php5-memcached
192
+
193
+    if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
194
+	mkdir /var/www/$HUBZILLA_DOMAIN_NAME
195
+    fi
196
+    if [ ! -d $HUBZILLA_PATH ]; then
197
+	mkdir $HUBZILLA_PATH
198
+    fi
199
+
200
+    if [ ! -f $HUBZILLA_PATH/index.php ]; then
201
+	cd $INSTALL_DIR
202
+	function_check git_clone
203
+	git_clone $HUBZILLA_REPO hubzilla
204
+	git checkout $HUBZILLA_COMMIT -b $HUBZILLA_COMMIT
205
+	if ! grep -q "Hubzilla commit" $COMPLETION_FILE; then
206
+	    echo "Hubzilla commit:$HUBZILLA_COMMIT" >> $COMPLETION_FILE
345 207
 	else
346
-		echo 'server {' > /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
347
-		echo "    listen 127.0.0.1:${HUBZILLA_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
348
-		echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
349
-		echo "    server_name $HUBZILLA_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
350
-		echo "    error_log /var/log/nginx/${HUBZILLA_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
351
-		echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
352
-		echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
353
-		echo '    access_log off;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
354
-		nginx_limits $HUBZILLA_DOMAIN_NAME
355
-		nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
356
-		echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
357
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
358
-		echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
359
-		echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
360
-		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
361
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
362
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
363
-		echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
364
-		echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
365
-		echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
366
-		echo '        allow all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
367
-		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
368
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
369
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
370
-		echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
371
-		echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
372
-		echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
373
-		echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
374
-		echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
375
-		echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
376
-		echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
377
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
378
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
379
-		echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
380
-		echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
381
-		echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
382
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
383
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
384
-		echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
385
-		echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
386
-		echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
387
-		echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
388
-		echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
389
-		echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
390
-		echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
391
-		echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
392
-		echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
393
-		echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
394
-		echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
395
-		echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
396
-		echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
397
-		echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
398
-		echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
399
-		echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
400
-		echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
401
-		echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
402
-		echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
403
-		echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
404
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
405
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
406
-		echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
407
-		echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
408
-		echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
409
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
410
-		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
411
-		echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
412
-		echo '      deny  all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
413
-		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
414
-		echo '}' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
208
+	    sed -i "s/Hubzilla commit.*/Hubzilla commit:$HUBZILLA_COMMIT/g" $COMPLETION_FILE
415 209
 	fi
416 210
 
417
-	function_check configure_php
418
-	configure_php
211
+	rm -rf $HUBZILLA_PATH
212
+	mv hubzilla $HUBZILLA_PATH
419 213
 
420
-	function_check create_site_certificate
421
-	create_site_certificate $HUBZILLA_DOMAIN_NAME 'yes'
422
-
423
-	if [ ! -d $HUBZILLA_PATH/view/tpl/smarty3 ]; then
424
-		mkdir $HUBZILLA_PATH/view/tpl/smarty3
425
-	fi
426
-	if [ ! -d "$HUBZILLA_PATH/store" ]; then
427
-		mkdir "$HUBZILLA_PATH/store"
428
-	fi
429
-	if [ ! -d "$HUBZILLA_PATH/store/[data]" ]; then
430
-		mkdir "$HUBZILLA_PATH/store/[data]"
431
-	fi
432
-	if [ ! -d "$HUBZILLA_PATH/store/[data]/smarty3" ]; then
433
-		mkdir "$HUBZILLA_PATH/store/[data]/smarty3"
434
-		chmod 777 "$HUBZILLA_PATH/store/[data]/smarty3"
214
+	git_clone $HUBZILLA_ADDONS_REPO $HUBZILLA_PATH/addon
215
+	cd $HUBZILLA_PATH/addon
216
+	git checkout $HUBZILLA_ADDONS_COMMIT -b $HUBZILLA_ADDONS_COMMIT
217
+	if ! grep -q "Hubzilla addons commit" $COMPLETION_FILE; then
218
+	    echo "Hubzilla addons commit:$HUBZILLA_ADDONS_COMMIT" >> $COMPLETION_FILE
219
+	else
220
+	    sed -i "s/Hubzilla addons commit.*/Hubzilla addons commit:$HUBZILLA_ADDONS_COMMIT/g" $COMPLETION_FILE
435 221
 	fi
436
-	chmod 777 $HUBZILLA_PATH/view/tpl
437
-	chown -R www-data:www-data "$HUBZILLA_PATH/store"
438
-	chmod 777 $HUBZILLA_PATH/view/tpl/smarty3
439
-
440
-	# Ensure that the database gets backed up locally, if remote
441
-	# backups are not being used
442
-	function_check backup_databases_script_header
443
-	backup_databases_script_header
444 222
 
445
-	function_check backup_database_local
446
-	backup_database_local hubzilla
223
+	# some extra themes
224
+	git_clone $HUBZILLA_THEMES_REPO $HUBZILLA_PATH/redmatrix-themes1
225
+	cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
447 226
 
448 227
 	chown -R www-data:www-data $HUBZILLA_PATH
449
-
450
-	function_check nginx_ensite
451
-	nginx_ensite $HUBZILLA_DOMAIN_NAME
452
-
453
-	# initialize the database
454
-	if [ ! -f $HUBZILLA_PATH/install/schema_mysql.sql ]; then
455
-		echo $'No database schema found for hubzilla'
456
-		exit 252782
228
+    fi
229
+
230
+    HUBZILLA_ONION_HOSTNAME=
231
+    if [[ $ONION_ONLY != "no" ]]; then
232
+	HUBZILLA_ONION_HOSTNAME=$(add_onion_service hubzilla 80 ${HUBZILLA_ONION_PORT})
233
+	echo "Hubzilla onion domain:${HUBZILLA_ONION_HOSTNAME}" >> $COMPLETION_FILE
234
+    fi
235
+
236
+    function_check get_mariadb_hubzilla_admin_password
237
+    get_mariadb_hubzilla_admin_password
238
+    if [ ! $HUBZILLA_ADMIN_PASSWORD ]; then
239
+	if [ -f $IMAGE_PASSWORD_FILE ]; then
240
+	    HUBZILLA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
241
+	else
242
+	    HUBZILLA_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
457 243
 	fi
458
-	function_check initialise_database
459
-	initialise_database hubzilla $HUBZILLA_PATH/install/schema_mysql.sql
460
-
461
-	# create the config file
462
-	echo '<?php' > $HUBZILLA_PATH/.htconfig.php
463
-	echo "\$db_host = 'localhost';" >> $HUBZILLA_PATH/.htconfig.php
464
-	echo "\$db_port = '0';" >> $HUBZILLA_PATH/.htconfig.php
465
-	echo "\$db_user = 'root';" >> $HUBZILLA_PATH/.htconfig.php
466
-	echo "\$db_pass = '${MARIADB_PASSWORD}';" >> $HUBZILLA_PATH/.htconfig.php
467
-	echo "\$db_data = 'hubzilla';" >> $HUBZILLA_PATH/.htconfig.php
468
-	echo "\$db_type = '0';" >> $HUBZILLA_PATH/.htconfig.php
469
-	echo "\$default_timezone = 'Europe/London';" >> $HUBZILLA_PATH/.htconfig.php
244
+	echo '' >> /home/$MY_USERNAME/README
245
+	echo '' >> /home/$MY_USERNAME/README
246
+	echo 'Hubzilla' >> /home/$MY_USERNAME/README
247
+	echo '========' >> /home/$MY_USERNAME/README
470 248
 	if [[ $ONION_ONLY == 'no' ]]; then
471
-		echo "\$a->config['system']['baseurl'] = 'https://${HUBZILLA_DOMAIN_NAME}';" >> $HUBZILLA_PATH/.htconfig.php
249
+	    echo $"Open https://$HUBZILLA_DOMAIN_NAME and register a new user" >> /home/$MY_USERNAME/README
472 250
 	else
473
-		echo "\$a->config['system']['baseurl'] = 'http://${HUBZILLA_ONION_HOSTNAME}';" >> $HUBZILLA_PATH/.htconfig.php
251
+	    echo $"Open http://$HUBZILLA_ONION_HOSTNAME and register a new user" >> /home/$MY_USERNAME/README
474 252
 	fi
475
-	echo "\$a->config['system']['sitename'] = \"Hubzilla\";" >> $HUBZILLA_PATH/.htconfig.php
476
-	HUBZILLA_LOCATION_HASH="$(create_password 30)"
477
-	echo "\$a->config['system']['location_hash'] = '${HUBZILLA_LOCATION_HASH}';" >> $HUBZILLA_PATH/.htconfig.php
478
-	echo "\$a->config['system']['register_policy'] = REGISTER_OPEN;" >> $HUBZILLA_PATH/.htconfig.php
479
-	echo "\$a->config['system']['register_text'] = '';" >> $HUBZILLA_PATH/.htconfig.php
480
-	echo "\$a->config['system']['admin_email'] = '${MY_EMAIL_ADDRESS}';" >> $HUBZILLA_PATH/.htconfig.php
481
-	echo "\$a->config['system']['verify_email'] = 1;" >> $HUBZILLA_PATH/.htconfig.php
482
-	echo "\$a->config['system']['access_policy'] = ACCESS_PRIVATE;" >> $HUBZILLA_PATH/.htconfig.php
483
-	echo "\$a->config['system']['sellpage'] = '';" >> $HUBZILLA_PATH/.htconfig.php
484
-	echo "\$a->config['system']['max_import_size'] = 200000;" >> $HUBZILLA_PATH/.htconfig.php
485
-	echo "\$a->config['system']['php_path'] = '/usr/bin/php';" >> $HUBZILLA_PATH/.htconfig.php
486
-	echo "\$a->config['system']['directory_mode']  = DIRECTORY_MODE_NORMAL;" >> $HUBZILLA_PATH/.htconfig.php
487
-	echo "\$a->config['system']['theme'] = 'redbasic';" >> $HUBZILLA_PATH/.htconfig.php
488
-	chown www-data:www-data $HUBZILLA_PATH/.htconfig.php
489
-	chmod 755 $HUBZILLA_PATH/.htconfig.php
490
-
491
-	systemctl restart php5-fpm
492
-	systemctl restart nginx
493
-	systemctl restart cron
494
-
495
-	${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$HUBZILLA_DOMAIN_NAME" -g hubzilla --public no
496
-
497
-	echo "Hubzilla domain:${HUBZILLA_DOMAIN_NAME}" >> $COMPLETION_FILE
498
-	echo 'install_hubzilla' >> $COMPLETION_FILE
253
+	echo $"Your MariaDB Hubzilla admin password is: $HUBZILLA_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
254
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
255
+	chmod 600 /home/$MY_USERNAME/README
256
+    fi
257
+
258
+    function_check create_database
259
+    create_database hubzilla "$HUBZILLA_ADMIN_PASSWORD"
260
+
261
+    if ! grep -q "$HUBZILLA_PATH" /etc/crontab; then
262
+	echo "12,22,32,42,52 * *   *   *   root cd $HUBZILLA_PATH; /usr/bin/timeout 500 /usr/bin/php include/poller.php" >> /etc/crontab
263
+    fi
264
+
265
+    function_check add_ddns_domain
266
+    add_ddns_domain $HUBZILLA_DOMAIN_NAME
267
+
268
+    if [[ $ONION_ONLY == "no" ]]; then
269
+	function_check nginx_http_redirect
270
+	nginx_http_redirect $HUBZILLA_DOMAIN_NAME
271
+	echo 'server {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
272
+	echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
273
+	echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
274
+	echo "    server_name $HUBZILLA_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
275
+	echo "    error_log /var/log/nginx/${HUBZILLA_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
276
+	echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
277
+	echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
278
+	echo '    access_log off;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
279
+	function_check nginx_limits
280
+	nginx_limits $HUBZILLA_DOMAIN_NAME
281
+	function_check nginx_ssl
282
+	nginx_ssl $HUBZILLA_DOMAIN_NAME
283
+	function_check nginx_disable_sniffing
284
+	nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
285
+	echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
286
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
287
+	echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
288
+	echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
289
+	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
290
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
291
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
292
+	echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
293
+	echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
294
+	echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
295
+	echo '        allow all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
296
+	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
297
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
298
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
299
+	echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
300
+	echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
301
+	echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
302
+	echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
303
+	echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
304
+	echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
305
+	echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
306
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
307
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
308
+	echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
309
+	echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
310
+	echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
311
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
312
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
313
+	echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
314
+	echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
315
+	echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
316
+	echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
317
+	echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
318
+	echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
319
+	echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
320
+	echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
321
+	echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
322
+	echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
323
+	echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
324
+	echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
325
+	echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
326
+	echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
327
+	echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
328
+	echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
329
+	echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
330
+	echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
331
+	echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
332
+	echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
333
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
334
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
335
+	echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
336
+	echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
337
+	echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
338
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
339
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
340
+	echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
341
+	echo '      deny  all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
342
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
343
+	echo '}' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
344
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
345
+    else
346
+	echo 'server {' > /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
347
+	echo "    listen 127.0.0.1:${HUBZILLA_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
348
+	echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
349
+	echo "    server_name $HUBZILLA_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
350
+	echo "    error_log /var/log/nginx/${HUBZILLA_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
351
+	echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
352
+	echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
353
+	echo '    access_log off;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
354
+	nginx_limits $HUBZILLA_DOMAIN_NAME
355
+	nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
356
+	echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
357
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
358
+	echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
359
+	echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
360
+	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
361
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
362
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
363
+	echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
364
+	echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
365
+	echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
366
+	echo '        allow all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
367
+	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
368
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
369
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
370
+	echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
371
+	echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
372
+	echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
373
+	echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
374
+	echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
375
+	echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
376
+	echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
377
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
378
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
379
+	echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
380
+	echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
381
+	echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
382
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
383
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
384
+	echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
385
+	echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
386
+	echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
387
+	echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
388
+	echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
389
+	echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
390
+	echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
391
+	echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
392
+	echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
393
+	echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
394
+	echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
395
+	echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
396
+	echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
397
+	echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
398
+	echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
399
+	echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
400
+	echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
401
+	echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
402
+	echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
403
+	echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
404
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
405
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
406
+	echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
407
+	echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
408
+	echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
409
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
410
+	echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
411
+	echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
412
+	echo '      deny  all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
413
+	echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
414
+	echo '}' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
415
+    fi
416
+
417
+    function_check configure_php
418
+    configure_php
419
+
420
+    function_check create_site_certificate
421
+    create_site_certificate $HUBZILLA_DOMAIN_NAME 'yes'
422
+
423
+    if [ ! -d $HUBZILLA_PATH/view/tpl/smarty3 ]; then
424
+	mkdir $HUBZILLA_PATH/view/tpl/smarty3
425
+    fi
426
+    if [ ! -d "$HUBZILLA_PATH/store" ]; then
427
+	mkdir "$HUBZILLA_PATH/store"
428
+    fi
429
+    if [ ! -d "$HUBZILLA_PATH/store/[data]" ]; then
430
+	mkdir "$HUBZILLA_PATH/store/[data]"
431
+    fi
432
+    if [ ! -d "$HUBZILLA_PATH/store/[data]/smarty3" ]; then
433
+	mkdir "$HUBZILLA_PATH/store/[data]/smarty3"
434
+	chmod 777 "$HUBZILLA_PATH/store/[data]/smarty3"
435
+    fi
436
+    chmod 777 $HUBZILLA_PATH/view/tpl
437
+    chown -R www-data:www-data "$HUBZILLA_PATH/store"
438
+    chmod 777 $HUBZILLA_PATH/view/tpl/smarty3
439
+
440
+    # Ensure that the database gets backed up locally, if remote
441
+    # backups are not being used
442
+    function_check backup_databases_script_header
443
+    backup_databases_script_header
444
+
445
+    function_check backup_database_local
446
+    backup_database_local hubzilla
447
+
448
+    chown -R www-data:www-data $HUBZILLA_PATH
449
+
450
+    function_check nginx_ensite
451
+    nginx_ensite $HUBZILLA_DOMAIN_NAME
452
+
453
+    # initialize the database
454
+    if [ ! -f $HUBZILLA_PATH/install/schema_mysql.sql ]; then
455
+	echo $'No database schema found for hubzilla'
456
+	exit 252782
457
+    fi
458
+    function_check initialise_database
459
+    initialise_database hubzilla $HUBZILLA_PATH/install/schema_mysql.sql
460
+
461
+    # create the config file
462
+    echo '<?php' > $HUBZILLA_PATH/.htconfig.php
463
+    echo "\$db_host = 'localhost';" >> $HUBZILLA_PATH/.htconfig.php
464
+    echo "\$db_port = '0';" >> $HUBZILLA_PATH/.htconfig.php
465
+    echo "\$db_user = 'root';" >> $HUBZILLA_PATH/.htconfig.php
466
+    echo "\$db_pass = '${MARIADB_PASSWORD}';" >> $HUBZILLA_PATH/.htconfig.php
467
+    echo "\$db_data = 'hubzilla';" >> $HUBZILLA_PATH/.htconfig.php
468
+    echo "\$db_type = '0';" >> $HUBZILLA_PATH/.htconfig.php
469
+    echo "\$default_timezone = 'Europe/London';" >> $HUBZILLA_PATH/.htconfig.php
470
+    if [[ $ONION_ONLY == 'no' ]]; then
471
+	echo "\$a->config['system']['baseurl'] = 'https://${HUBZILLA_DOMAIN_NAME}';" >> $HUBZILLA_PATH/.htconfig.php
472
+    else
473
+	echo "\$a->config['system']['baseurl'] = 'http://${HUBZILLA_ONION_HOSTNAME}';" >> $HUBZILLA_PATH/.htconfig.php
474
+    fi
475
+    echo "\$a->config['system']['sitename'] = \"Hubzilla\";" >> $HUBZILLA_PATH/.htconfig.php
476
+    HUBZILLA_LOCATION_HASH="$(create_password 30)"
477
+    echo "\$a->config['system']['location_hash'] = '${HUBZILLA_LOCATION_HASH}';" >> $HUBZILLA_PATH/.htconfig.php
478
+    echo "\$a->config['system']['register_policy'] = REGISTER_OPEN;" >> $HUBZILLA_PATH/.htconfig.php
479
+    echo "\$a->config['system']['register_text'] = '';" >> $HUBZILLA_PATH/.htconfig.php
480
+    echo "\$a->config['system']['admin_email'] = '${MY_EMAIL_ADDRESS}';" >> $HUBZILLA_PATH/.htconfig.php
481
+    echo "\$a->config['system']['verify_email'] = 1;" >> $HUBZILLA_PATH/.htconfig.php
482
+    echo "\$a->config['system']['access_policy'] = ACCESS_PRIVATE;" >> $HUBZILLA_PATH/.htconfig.php
483
+    echo "\$a->config['system']['sellpage'] = '';" >> $HUBZILLA_PATH/.htconfig.php
484
+    echo "\$a->config['system']['max_import_size'] = 200000;" >> $HUBZILLA_PATH/.htconfig.php
485
+    echo "\$a->config['system']['php_path'] = '/usr/bin/php';" >> $HUBZILLA_PATH/.htconfig.php
486
+    echo "\$a->config['system']['directory_mode']  = DIRECTORY_MODE_NORMAL;" >> $HUBZILLA_PATH/.htconfig.php
487
+    echo "\$a->config['system']['theme'] = 'redbasic';" >> $HUBZILLA_PATH/.htconfig.php
488
+    chown www-data:www-data $HUBZILLA_PATH/.htconfig.php
489
+    chmod 755 $HUBZILLA_PATH/.htconfig.php
490
+
491
+    systemctl restart php5-fpm
492
+    systemctl restart nginx
493
+    systemctl restart cron
494
+
495
+    ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$HUBZILLA_DOMAIN_NAME" -g hubzilla --public no
496
+
497
+    echo "Hubzilla domain:${HUBZILLA_DOMAIN_NAME}" >> $COMPLETION_FILE
498
+    echo 'install_hubzilla' >> $COMPLETION_FILE
499 499
 }
500 500
 
501 501
 # NOTE: deliberately there is no "exit 0"

+ 207
- 207
src/freedombone-app-ipfs Voir le fichier

@@ -35,251 +35,251 @@ IPFS_COMMIT='20b06a4cbce8884f5b194da6e98cb11f2c77f166'
35 35
 IPFS_PORT=4001
36 36
 
37 37
 function reconfigure_ipfs {
38
-	echo -n ''
38
+    echo -n ''
39 39
 }
40 40
 
41 41
 function upgrade_ipfs {
42
-	if ! grep -Fxq "install_ipfs" $COMPLETION_FILE; then
43
-		return
44
-	fi
42
+    if ! grep -Fxq "install_ipfs" $COMPLETION_FILE; then
43
+	return
44
+    fi
45 45
 
46
-	function_check select_go_version
47
-	select_go_version
46
+    function_check select_go_version
47
+    select_go_version
48 48
 
49
-	function_check set_repo_commit
50
-	set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
49
+    function_check set_repo_commit
50
+    set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
51 51
 }
52 52
 
53 53
 function backup_local_ipfs {
54
-	if ! grep -q "Admin user" $COMPLETION_FILE; then
55
-		return
56
-	fi
57
-	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
58
-	source_directory=/home/$ADMIN_USERNAME/.ipfs
59
-	if [ -d $source_directory ]; then
60
-		dest_directory=ipfs
61
-		echo $"Backing up $source_directory to $dest_directory"
62
-
63
-		function_check backup_directory_to_usb
64
-		backup_directory_to_usb $source_directory $dest_directory
65
-
66
-		echo $"Backup to $dest_directory complete"
67
-	fi
54
+    if ! grep -q "Admin user" $COMPLETION_FILE; then
55
+	return
56
+    fi
57
+    ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
58
+    source_directory=/home/$ADMIN_USERNAME/.ipfs
59
+    if [ -d $source_directory ]; then
60
+	dest_directory=ipfs
61
+	echo $"Backing up $source_directory to $dest_directory"
62
+
63
+	function_check backup_directory_to_usb
64
+	backup_directory_to_usb $source_directory $dest_directory
65
+
66
+	echo $"Backup to $dest_directory complete"
67
+    fi
68 68
 }
69 69
 
70 70
 function restore_local_ipfs {
71
-	if ! grep -q "Admin user" $COMPLETION_FILE; then
72
-		return
73
-	fi
74
-	if [ -d $USB_MOUNT/backup/ipfs ]; then
75
-		echo $"Restoring IPFS"
76
-		temp_restore_dir=/root/tempipfs
77
-		function_check restore_directory_from_usb
78
-		restore_directory_from_usb $temp_restore_dir ipfs
79
-		ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
80
-		cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
81
-		if [ ! "$?" = "0" ]; then
82
-			rm -rf $temp_restore_dir
83
-			function_check set_user_permissions
84
-			set_user_permissions
85
-			function_check backup_unmount_drive
86
-			backup_unmount_drive
87
-			exit 27627
88
-		fi
89
-		rm -rf $temp_restore_dir
90
-		echo $"Restore of IPFS complete"
71
+    if ! grep -q "Admin user" $COMPLETION_FILE; then
72
+	return
73
+    fi
74
+    if [ -d $USB_MOUNT/backup/ipfs ]; then
75
+	echo $"Restoring IPFS"
76
+	temp_restore_dir=/root/tempipfs
77
+	function_check restore_directory_from_usb
78
+	restore_directory_from_usb $temp_restore_dir ipfs
79
+	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
80
+	cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
81
+	if [ ! "$?" = "0" ]; then
82
+	    rm -rf $temp_restore_dir
83
+	    function_check set_user_permissions
84
+	    set_user_permissions
85
+	    function_check backup_unmount_drive
86
+	    backup_unmount_drive
87
+	    exit 27627
91 88
 	fi
89
+	rm -rf $temp_restore_dir
90
+	echo $"Restore of IPFS complete"
91
+    fi
92 92
 }
93 93
 
94 94
 function backup_remote_ipfs {
95
-	if ! grep -q "Admin user" $COMPLETION_FILE; then
96
-		return
97
-	fi
98
-	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
99
-	if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then
100
-		echo $"Backing up IPFS"
101
-		backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs
102
-		echo $"Backup of IPFS complete"
103
-	fi
95
+    if ! grep -q "Admin user" $COMPLETION_FILE; then
96
+	return
97
+    fi
98
+    ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
99
+    if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then
100
+	echo $"Backing up IPFS"
101
+	backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs
102
+	echo $"Backup of IPFS complete"
103
+    fi
104 104
 }
105 105
 
106 106
 function restore_remote_ipfs {
107
-	if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
108
-		echo $"Restoring IPFS"
109
-		temp_restore_dir=/root/tempipfs
110
-		function_check restore_directory_from_friend
111
-		restore_directory_from_friend $temp_restore_dir ipfs
112
-		cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
113
-		if [ ! "$?" = "0" ]; then
114
-			function_check set_user_permissions
115
-			set_user_permissions
116
-			rm -rf $temp_restore_dir
117
-			exit 276357
118
-		fi
119
-		rm -rf $temp_restore_dir
120
-		echo $"Restore of IPFS complete"
107
+    if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
108
+	echo $"Restoring IPFS"
109
+	temp_restore_dir=/root/tempipfs
110
+	function_check restore_directory_from_friend
111
+	restore_directory_from_friend $temp_restore_dir ipfs
112
+	cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
113
+	if [ ! "$?" = "0" ]; then
114
+	    function_check set_user_permissions
115
+	    set_user_permissions
116
+	    rm -rf $temp_restore_dir
117
+	    exit 276357
121 118
 	fi
119
+	rm -rf $temp_restore_dir
120
+	echo $"Restore of IPFS complete"
121
+    fi
122 122
 }
123 123
 
124 124
 function remove_ipfs {
125
-	if ! grep -Fxq "install_ipfs" $COMPLETION_FILE; then
126
-		return
127
-	fi
128
-	function_check select_go_version
129
-	select_go_version
130
-	systemctl stop ipfs
131
-	systemctl disable ipfs
132
-	systemctl daemon-reload
133
-	rm /etc/systemd/system/ipfs.service
134
-	rm -rf $GOPATH/src/github.com/ipfs
135
-	iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
136
-	function_check save_firewall_settings
137
-	save_firewall_settings
138
-	sed -i '/install_ipfs/d' $COMPLETION_FILE
139
-	sed -i '/ipfs /d' $COMPLETION_FILE
140
-	sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
125
+    if ! grep -Fxq "install_ipfs" $COMPLETION_FILE; then
126
+	return
127
+    fi
128
+    function_check select_go_version
129
+    select_go_version
130
+    systemctl stop ipfs
131
+    systemctl disable ipfs
132
+    systemctl daemon-reload
133
+    rm /etc/systemd/system/ipfs.service
134
+    rm -rf $GOPATH/src/github.com/ipfs
135
+    iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
136
+    function_check save_firewall_settings
137
+    save_firewall_settings
138
+    sed -i '/install_ipfs/d' $COMPLETION_FILE
139
+    sed -i '/ipfs /d' $COMPLETION_FILE
140
+    sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
141 141
 }
142 142
 
143 143
 function configure_firewall_for_ipfs {
144
-	if grep -Fxq "configure_firewall_for_ipfs" $COMPLETION_FILE; then
145
-		return
146
-	fi
147
-	if [[ $ONION_ONLY != "no" ]]; then
148
-		return
149
-	fi
150
-	iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
151
-	function_check save_firewall_settings
152
-	save_firewall_settings
153
-
154
-	OPEN_PORTS+=("IPFS     $IPFS_PORT")
155
-	echo 'configure_firewall_for_ipfs' >> $COMPLETION_FILE
144
+    if grep -Fxq "configure_firewall_for_ipfs" $COMPLETION_FILE; then
145
+	return
146
+    fi
147
+    if [[ $ONION_ONLY != "no" ]]; then
148
+	return
149
+    fi
150
+    iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
151
+    function_check save_firewall_settings
152
+    save_firewall_settings
153
+
154
+    OPEN_PORTS+=("IPFS     $IPFS_PORT")
155
+    echo 'configure_firewall_for_ipfs' >> $COMPLETION_FILE
156 156
 }
157 157
 
158 158
 function install_ipfs {
159
-	if grep -Fxq "install_ipfs" $COMPLETION_FILE; then
160
-		return
161
-	fi
162
-
163
-	function_check select_go_version
164
-	select_go_version
165
-
166
-	apt-get -y install golang libpam0g-dev fuse
167
-
168
-	if [ ! -d /home/git ]; then
169
-		# add a gogs user account
170
-		adduser --disabled-login --gecos 'Gogs' git
171
-
172
-		# install Go
173
-		if ! grep -q "export GOPATH=" ~/.bashrc; then
174
-			echo "export GOPATH=$GOPATH" >> ~/.bashrc
175
-		else
176
-			sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
177
-		fi
178
-		systemctl set-environment GOPATH=$GOPATH
179
-		if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
180
-			echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
181
-		else
182
-			sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
183
-		fi
184
-		if [ ! -d $GOPATH ]; then
185
-			mkdir -p $GOPATH
186
-		fi
187
-	fi
159
+    if grep -Fxq "install_ipfs" $COMPLETION_FILE; then
160
+	return
161
+    fi
188 162
 
189
-	IPFS_PATH=$GOPATH/bin
190
-	export PATH="$GOPATH/bin:$PATH:"
191
-	if ! grep -q 'GOPATH/bin' ~/.bashrc; then
192
-		echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
193
-	else
194
-		sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
195
-	fi
163
+    function_check select_go_version
164
+    select_go_version
196 165
 
197
-	# set gopath for the user
198
-	if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
199
-		echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
200
-		echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
201
-	else
202
-		sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" /home/$MY_USERNAME/.bashrc
203
-	fi
204
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
166
+    apt-get -y install golang libpam0g-dev fuse
205 167
 
206
-	IPFS_GO_REPO2=$(echo "$IPFS_GO_REPO" | sed 's|https://||g')
207
-	go get -u ${IPFS_GO_REPO2}/cmd/ipfs
208
-	if [ ! "$?" = "0" ]; then
209
-		exit 8242
210
-	fi
168
+    if [ ! -d /home/git ]; then
169
+	# add a gogs user account
170
+	adduser --disabled-login --gecos 'Gogs' git
211 171
 
212
-	cd $GOPATH/src/$IPFS_GO_REPO2
213
-	git checkout $IPFS_COMMIT -b $IPFS_COMMIT
214
-	if ! grep -q "ipfs commit" $COMPLETION_FILE; then
215
-		echo "ipfs commit:$IPFS_COMMIT" >> $COMPLETION_FILE
172
+	# install Go
173
+	if ! grep -q "export GOPATH=" ~/.bashrc; then
174
+	    echo "export GOPATH=$GOPATH" >> ~/.bashrc
216 175
 	else
217
-		sed -i "s/ipfs commit.*/ipfs commit:$IPFS_COMMIT/g" $COMPLETION_FILE
218
-	fi
219
-
220
-	# initialise
221
-	su -c "$IPFS_PATH/ipfs init -b 4096" - $MY_USERNAME
222
-	if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
223
-		echo "IPFS could not be initialised for user $MY_USERNAME"
224
-		exit 7358
176
+	    sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
225 177
 	fi
226
-
227
-	# directories to mount to
228
-	if [ ! -d /ipfs ]; then
229
-		mkdir /ipfs
230
-		mkdir /ipns
231
-		chown $MY_USERNAME:$MY_USERNAME /ipfs
232
-		chown $MY_USERNAME:$MY_USERNAME /ipns
178
+	systemctl set-environment GOPATH=$GOPATH
179
+	if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
180
+	    echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
181
+	else
182
+	    sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
233 183
 	fi
234
-
235
-	if [ -f /etc/fuse.conf ]; then
236
-		chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
184
+	if [ ! -d $GOPATH ]; then
185
+	    mkdir -p $GOPATH
237 186
 	fi
238
-	if [ -f /dev/fuse ]; then
239
-		chown $MY_USERNAME:$MY_USERNAME /dev/fuse
187
+    fi
188
+
189
+    IPFS_PATH=$GOPATH/bin
190
+    export PATH="$GOPATH/bin:$PATH:"
191
+    if ! grep -q 'GOPATH/bin' ~/.bashrc; then
192
+	echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
193
+    else
194
+	sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
195
+    fi
196
+
197
+    # set gopath for the user
198
+    if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
199
+	echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
200
+	echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
201
+    else
202
+	sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" /home/$MY_USERNAME/.bashrc
203
+    fi
204
+    chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
205
+
206
+    IPFS_GO_REPO2=$(echo "$IPFS_GO_REPO" | sed 's|https://||g')
207
+    go get -u ${IPFS_GO_REPO2}/cmd/ipfs
208
+    if [ ! "$?" = "0" ]; then
209
+	exit 8242
210
+    fi
211
+
212
+    cd $GOPATH/src/$IPFS_GO_REPO2
213
+    git checkout $IPFS_COMMIT -b $IPFS_COMMIT
214
+    if ! grep -q "ipfs commit" $COMPLETION_FILE; then
215
+	echo "ipfs commit:$IPFS_COMMIT" >> $COMPLETION_FILE
216
+    else
217
+	sed -i "s/ipfs commit.*/ipfs commit:$IPFS_COMMIT/g" $COMPLETION_FILE
218
+    fi
219
+
220
+    # initialise
221
+    su -c "$IPFS_PATH/ipfs init -b 4096" - $MY_USERNAME
222
+    if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
223
+	echo "IPFS could not be initialised for user $MY_USERNAME"
224
+	exit 7358
225
+    fi
226
+
227
+    # directories to mount to
228
+    if [ ! -d /ipfs ]; then
229
+	mkdir /ipfs
230
+	mkdir /ipns
231
+	chown $MY_USERNAME:$MY_USERNAME /ipfs
232
+	chown $MY_USERNAME:$MY_USERNAME /ipns
233
+    fi
234
+
235
+    if [ -f /etc/fuse.conf ]; then
236
+	chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
237
+    fi
238
+    if [ -f /dev/fuse ]; then
239
+	chown $MY_USERNAME:$MY_USERNAME /dev/fuse
240
+    fi
241
+
242
+    echo '[Unit]' > /etc/systemd/system/ipfs.service
243
+    echo 'Description=IPFS daemon' >> /etc/systemd/system/ipfs.service
244
+    echo 'After=syslog.target' >> /etc/systemd/system/ipfs.service
245
+    echo 'After=network.target' >> /etc/systemd/system/ipfs.service
246
+    echo '' >> /etc/systemd/system/ipfs.service
247
+    echo '[Service]' >> /etc/systemd/system/ipfs.service
248
+    echo 'Type=simple' >> /etc/systemd/system/ipfs.service
249
+    echo "User=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
250
+    echo "Group=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
251
+    echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
252
+    echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
253
+    echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
254
+    echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/ipfs.service
255
+    echo '' >> /etc/systemd/system/ipfs.service
256
+    echo '[Install]' >> /etc/systemd/system/ipfs.service
257
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service
258
+
259
+    systemctl enable ipfs
260
+    systemctl daemon-reload
261
+    systemctl restart ipfs
262
+
263
+    if [ -d /etc/avahi ]; then
264
+	su -c "echo $($IPFS_PATH/ipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
265
+	if [ ! -f /tmp/ipfsid ]; then
266
+	    echo 'No IPFS identity was created'
267
+	    exit 37895
240 268
 	fi
241
-
242
-	echo '[Unit]' > /etc/systemd/system/ipfs.service
243
-	echo 'Description=IPFS daemon' >> /etc/systemd/system/ipfs.service
244
-	echo 'After=syslog.target' >> /etc/systemd/system/ipfs.service
245
-	echo 'After=network.target' >> /etc/systemd/system/ipfs.service
246
-	echo '' >> /etc/systemd/system/ipfs.service
247
-	echo '[Service]' >> /etc/systemd/system/ipfs.service
248
-	echo 'Type=simple' >> /etc/systemd/system/ipfs.service
249
-	echo "User=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
250
-	echo "Group=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
251
-	echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
252
-	echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
253
-	echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
254
-	echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/ipfs.service
255
-	echo '' >> /etc/systemd/system/ipfs.service
256
-	echo '[Install]' >> /etc/systemd/system/ipfs.service
257
-	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service
258
-
259
-	systemctl enable ipfs
260
-	systemctl daemon-reload
261
-	systemctl restart ipfs
262
-
263
-	if [ -d /etc/avahi ]; then
264
-		su -c "echo $($IPFS_PATH/ipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
265
-		if [ ! -f /tmp/ipfsid ]; then
266
-			echo 'No IPFS identity was created'
267
-			exit 37895
268
-		fi
269
-		IPFS_PEER_ID=$(cat /tmp/ipfsid)
270
-		if [ ${#IPFS_PEER_ID} -lt 10 ]; then
271
-			echo 'Invalid IPFS peer ID'
272
-			echo "$IPFS_PEER_ID"
273
-			exit 74782
274
-		fi
275
-		# Add an avahi service
276
-		function_check create_avahi_service
277
-		create_avahi_service ipfs "ipfs" udp $IPFS_PORT "$IPFS_PEER_ID"
278
-		rm /tmp/ipfsid
269
+	IPFS_PEER_ID=$(cat /tmp/ipfsid)
270
+	if [ ${#IPFS_PEER_ID} -lt 10 ]; then
271
+	    echo 'Invalid IPFS peer ID'
272
+	    echo "$IPFS_PEER_ID"
273
+	    exit 74782
279 274
 	fi
275
+	# Add an avahi service
276
+	function_check create_avahi_service
277
+	create_avahi_service ipfs "ipfs" udp $IPFS_PORT "$IPFS_PEER_ID"
278
+	rm /tmp/ipfsid
279
+    fi
280 280
 
281
-	function_check configure_firewall_for_ipfs
282
-	configure_firewall_for_ipfs
281
+    function_check configure_firewall_for_ipfs
282
+    configure_firewall_for_ipfs
283 283
 
284
-	echo 'install_ipfs' >> $COMPLETION_FILE
284
+    echo 'install_ipfs' >> $COMPLETION_FILE
285 285
 }

+ 222
- 222
src/freedombone-app-irc Voir le fichier

@@ -45,268 +45,268 @@ function upgrade_irc {
45 45
 }
46 46
 
47 47
 function backup_local_irc {
48
-	echo -n ''
48
+    echo -n ''
49 49
 }
50 50
 
51 51
 function restore_local_irc {
52
-	echo -n ''
52
+    echo -n ''
53 53
 }
54 54
 
55 55
 function backup_remote_irc {
56
-	echo -n ''
56
+    echo -n ''
57 57
 }
58 58
 
59 59
 function restore_remote_irc {
60
-	echo -n ''
60
+    echo -n ''
61 61
 }
62 62
 
63 63
 function remove_irc {
64
-	if ! grep -Fxq "install_irc" $COMPLETION_FILE; then
65
-		return
66
-	fi
67
-	systemctl stop ngircd
68
-	apt-get -y remove --purge ngircd
69
-	apt-get -y remove --purge irssi
70
-	if [ -d /etc/ngircd ]; then
71
-		rm -rf /etc/ngircd
72
-	fi
73
-	iptables -D INPUT -p tcp --dport $IRC_PORT  -j ACCEPT
74
-	iptables -D INPUT -p tcp --dport 1024:65535 --sport $IRC_PORT -j ACCEPT
75
-	function_check save_firewall_settings
76
-	save_firewall_settings
77
-	function_check remove_onion_service
78
-	remove_onion_service irc ${IRC_ONION_PORT}
79
-	sed -i '/install_irc/d' $COMPLETION_FILE
80
-	sed -i '/IRC /d' $COMPLETION_FILE
81
-	sed -i '/configure_firewall_for_irc/d' $COMPLETION_FILE
64
+    if ! grep -Fxq "install_irc" $COMPLETION_FILE; then
65
+	return
66
+    fi
67
+    systemctl stop ngircd
68
+    apt-get -y remove --purge ngircd
69
+    apt-get -y remove --purge irssi
70
+    if [ -d /etc/ngircd ]; then
71
+	rm -rf /etc/ngircd
72
+    fi
73
+    iptables -D INPUT -p tcp --dport $IRC_PORT  -j ACCEPT
74
+    iptables -D INPUT -p tcp --dport 1024:65535 --sport $IRC_PORT -j ACCEPT
75
+    function_check save_firewall_settings
76
+    save_firewall_settings
77
+    function_check remove_onion_service
78
+    remove_onion_service irc ${IRC_ONION_PORT}
79
+    sed -i '/install_irc/d' $COMPLETION_FILE
80
+    sed -i '/IRC /d' $COMPLETION_FILE
81
+    sed -i '/configure_firewall_for_irc/d' $COMPLETION_FILE
82 82
 }
83 83
 
84 84
 function configure_firewall_for_irc {
85
-	if [ ! -d /etc/ngircd ]; then
86
-		return
87
-	fi
88
-	if grep -Fxq "configure_firewall_for_irc" $COMPLETION_FILE; then
89
-		return
90
-	fi
91
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
92
-		# docker does its own firewalling
93
-		return
94
-	fi
95
-	if [[ $ONION_ONLY != "no" ]]; then
96
-		return
97
-	fi
98
-	iptables -A INPUT -p tcp --dport $IRC_PORT  -j ACCEPT
99
-	iptables -I INPUT -p tcp --dport 1024:65535 --sport $IRC_PORT -j ACCEPT
100
-	function_check save_firewall_settings
101
-	save_firewall_settings
85
+    if [ ! -d /etc/ngircd ]; then
86
+	return
87
+    fi
88
+    if grep -Fxq "configure_firewall_for_irc" $COMPLETION_FILE; then
89
+	return
90
+    fi
91
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
92
+	# docker does its own firewalling
93
+	return
94
+    fi
95
+    if [[ $ONION_ONLY != "no" ]]; then
96
+	return
97
+    fi
98
+    iptables -A INPUT -p tcp --dport $IRC_PORT  -j ACCEPT
99
+    iptables -I INPUT -p tcp --dport 1024:65535 --sport $IRC_PORT -j ACCEPT
100
+    function_check save_firewall_settings
101
+    save_firewall_settings
102 102
 
103
-	OPEN_PORTS+=("IRC      $IRC_PORT")
104
-	echo 'configure_firewall_for_irc' >> $COMPLETION_FILE
103
+    OPEN_PORTS+=("IRC      $IRC_PORT")
104
+    echo 'configure_firewall_for_irc' >> $COMPLETION_FILE
105 105
 }
106 106
 
107 107
 function install_irc_server {
108
-	if grep -Fxq "install_irc_server" $COMPLETION_FILE; then
109
-		return
110
-	fi
111
-	apt-get -y install ngircd
108
+    if grep -Fxq "install_irc_server" $COMPLETION_FILE; then
109
+	return
110
+    fi
111
+    apt-get -y install ngircd
112 112
 
113
-	if [ ! -d /etc/ngircd ]; then
114
-		echo $"ERROR: ngircd does not appear to have installed. $CHECK_MESSAGE"
115
-		exit 53
116
-	fi
113
+    if [ ! -d /etc/ngircd ]; then
114
+	echo $"ERROR: ngircd does not appear to have installed. $CHECK_MESSAGE"
115
+	exit 53
116
+    fi
117 117
 
118
-	if [ ! -f /etc/ssl/certs/ngircd.dhparam ]; then
119
-		${PROJECT_NAME}-addcert -h ngircd --dhkey $DH_KEYLENGTH
120
-		function_check check_certificates
121
-		check_certificates ngircd
122
-	fi
118
+    if [ ! -f /etc/ssl/certs/ngircd.dhparam ]; then
119
+	${PROJECT_NAME}-addcert -h ngircd --dhkey $DH_KEYLENGTH
120
+	function_check check_certificates
121
+	check_certificates ngircd
122
+    fi
123 123
 
124
-	DEFAULTDOMAIN=$DEFAULT_DOMAIN_NAME
125
-	if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
126
-		DEFAULTDOMAIN="${DEFAULT_DOMAIN_NAME}.local"
127
-	fi
124
+    DEFAULTDOMAIN=$DEFAULT_DOMAIN_NAME
125
+    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
126
+	DEFAULTDOMAIN="${DEFAULT_DOMAIN_NAME}.local"
127
+    fi
128 128
 
129
-	# create a login password if needed
130
-	if [ ! $IRC_PASSWORD ]; then
131
-		IRC_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
132
-	fi
129
+    # create a login password if needed
130
+    if [ ! $IRC_PASSWORD ]; then
131
+	IRC_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
132
+    fi
133 133
 
134
-	echo '**************************************************' > /etc/ngircd/motd
135
-	echo $'*           F R E E D O M B O N E   I R C        *' >> /etc/ngircd/motd
136
-	echo '*                                                *' >> /etc/ngircd/motd
137
-	echo $'*               Freedom in the Cloud             *' >> /etc/ngircd/motd
138
-	echo '**************************************************' >> /etc/ngircd/motd
139
-	sed -i 's|MotdFile = /etc/ngircd/ngircd.motd|MotdFile = /etc/ngircd/motd|g' /etc/ngircd/ngircd.conf
140
-	sed -i "s/irc@irc.example.com/$MY_EMAIL_ADDRESS/g" /etc/ngircd/ngircd.conf
141
-	sed -i "s/irc.example.net/$DEFAULTDOMAIN/g" /etc/ngircd/ngircd.conf
142
-	sed -i "s|Yet another IRC Server running on Debian GNU/Linux|IRC Server of $DEFAULTDOMAIN|g" /etc/ngircd/ngircd.conf
143
-	sed -i 's/;Password = wealllikedebian/Password =/g' /etc/ngircd/ngircd.conf
144
-	sed -i 's|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/ngircd.crt|g' /etc/ngircd/ngircd.conf
145
-	sed -i 's|;DHFile = /etc/ngircd/dhparams.pem|DHFile = /etc/ssl/certs/ngircd.dhparam|g' /etc/ngircd/ngircd.conf
146
-	sed -i 's|;KeyFile = /etc/ssl/private/server.key|KeyFile = /etc/ssl/private/ngircd.key|g' /etc/ngircd/ngircd.conf
147
-	sed -i "s/;Ports =.*/Ports = $IRC_PORT/1" /etc/ngircd/ngircd.conf
148
-	sed -i "s/;Ports =.*/Ports = $IRC_PORT/2" /etc/ngircd/ngircd.conf
149
-	sed -i "s/;Name = #ngircd/Name = #${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
150
-	sed -i "s/;Topic = Our ngircd testing channel/Topic = ${PROJECT_NAME} chat channel/g" /etc/ngircd/ngircd.conf
151
-	sed -i 's/;MaxUsers = 23/MaxUsers = 23/g' /etc/ngircd/ngircd.conf
152
-	sed -i "s|;KeyFile = /etc/ngircd/#chan.key|KeyFile = /etc/ngircd/#${PROJECT_NAME}.key|g" /etc/ngircd/ngircd.conf
153
-	sed -i "s/;CloakHost = cloaked.host/CloakHost = ${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
154
-	IRC_SALT="$(create_password 30)"
155
-	if [ -f $IMAGE_PASSWORD_FILE ]; then
156
-		IRC_OPERATOR_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
157
-	else
158
-		IRC_OPERATOR_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
159
-	fi
160
-	sed -i "s|;CloakHostSalt = abcdefghijklmnopqrstuvwxyz|CloakHostSalt = $IRC_SALT|g" /etc/ngircd/ngircd.conf
161
-	sed -i 's/;ConnectIPv4 = yes/ConnectIPv4 = yes/g' /etc/ngircd/ngircd.conf
162
-	sed -i 's/;MorePrivacy = no/MorePrivacy = yes/g' /etc/ngircd/ngircd.conf
163
-	sed -i 's/;RequireAuthPing = no/RequireAuthPing = no/g' /etc/ngircd/ngircd.conf
164
-	sed -i "s/;Name = TheOper/Name = $MY_USERNAME/g" /etc/ngircd/ngircd.conf
165
-	sed -i "s/;Password = ThePwd/Password = $IRC_OPERATOR_PASSWORD/g" /etc/ngircd/ngircd.conf
166
-	sed -i 's|;Listen =.*|Listen = 0.0.0.0,0.0.0.0:9050,127.0.0.1,127.0.0.1:9050|g' /etc/ngircd/ngircd.conf
167
-	if [ $IRC_PASSWORD ]; then
168
-		sed -i "0,/RE/s/Password =.*/Password =$IRC_PASSWORD/" /etc/ngircd/ngircd.conf
169
-	fi
170
-	# If we are on a mesh then DNS is not available
171
-	if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
172
-		sed -i "s/;DNS =.*/DNS = no/g" /etc/ngircd/ngircd.conf
173
-	fi
174
-	# upgrade a cypher
175
-	sed -i 's|SECURE128|SECURE256|g' /etc/ngircd/ngircd.conf
176
-	mkdir /var/run/ircd
177
-	chown -R irc:irc /var/run/ircd
178
-	mkdir /var/run/ngircd
179
-	touch /var/run/ngircd/ngircd.pid
180
-	chown -R irc:irc /var/run/ngircd
134
+    echo '**************************************************' > /etc/ngircd/motd
135
+    echo $'*           F R E E D O M B O N E   I R C        *' >> /etc/ngircd/motd
136
+    echo '*                                                *' >> /etc/ngircd/motd
137
+    echo $'*               Freedom in the Cloud             *' >> /etc/ngircd/motd
138
+    echo '**************************************************' >> /etc/ngircd/motd
139
+    sed -i 's|MotdFile = /etc/ngircd/ngircd.motd|MotdFile = /etc/ngircd/motd|g' /etc/ngircd/ngircd.conf
140
+    sed -i "s/irc@irc.example.com/$MY_EMAIL_ADDRESS/g" /etc/ngircd/ngircd.conf
141
+    sed -i "s/irc.example.net/$DEFAULTDOMAIN/g" /etc/ngircd/ngircd.conf
142
+    sed -i "s|Yet another IRC Server running on Debian GNU/Linux|IRC Server of $DEFAULTDOMAIN|g" /etc/ngircd/ngircd.conf
143
+    sed -i 's/;Password = wealllikedebian/Password =/g' /etc/ngircd/ngircd.conf
144
+    sed -i 's|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/ngircd.crt|g' /etc/ngircd/ngircd.conf
145
+    sed -i 's|;DHFile = /etc/ngircd/dhparams.pem|DHFile = /etc/ssl/certs/ngircd.dhparam|g' /etc/ngircd/ngircd.conf
146
+    sed -i 's|;KeyFile = /etc/ssl/private/server.key|KeyFile = /etc/ssl/private/ngircd.key|g' /etc/ngircd/ngircd.conf
147
+    sed -i "s/;Ports =.*/Ports = $IRC_PORT/1" /etc/ngircd/ngircd.conf
148
+    sed -i "s/;Ports =.*/Ports = $IRC_PORT/2" /etc/ngircd/ngircd.conf
149
+    sed -i "s/;Name = #ngircd/Name = #${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
150
+    sed -i "s/;Topic = Our ngircd testing channel/Topic = ${PROJECT_NAME} chat channel/g" /etc/ngircd/ngircd.conf
151
+    sed -i 's/;MaxUsers = 23/MaxUsers = 23/g' /etc/ngircd/ngircd.conf
152
+    sed -i "s|;KeyFile = /etc/ngircd/#chan.key|KeyFile = /etc/ngircd/#${PROJECT_NAME}.key|g" /etc/ngircd/ngircd.conf
153
+    sed -i "s/;CloakHost = cloaked.host/CloakHost = ${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
154
+    IRC_SALT="$(create_password 30)"
155
+    if [ -f $IMAGE_PASSWORD_FILE ]; then
156
+	IRC_OPERATOR_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
157
+    else
158
+	IRC_OPERATOR_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
159
+    fi
160
+    sed -i "s|;CloakHostSalt = abcdefghijklmnopqrstuvwxyz|CloakHostSalt = $IRC_SALT|g" /etc/ngircd/ngircd.conf
161
+    sed -i 's/;ConnectIPv4 = yes/ConnectIPv4 = yes/g' /etc/ngircd/ngircd.conf
162
+    sed -i 's/;MorePrivacy = no/MorePrivacy = yes/g' /etc/ngircd/ngircd.conf
163
+    sed -i 's/;RequireAuthPing = no/RequireAuthPing = no/g' /etc/ngircd/ngircd.conf
164
+    sed -i "s/;Name = TheOper/Name = $MY_USERNAME/g" /etc/ngircd/ngircd.conf
165
+    sed -i "s/;Password = ThePwd/Password = $IRC_OPERATOR_PASSWORD/g" /etc/ngircd/ngircd.conf
166
+    sed -i 's|;Listen =.*|Listen = 0.0.0.0,0.0.0.0:9050,127.0.0.1,127.0.0.1:9050|g' /etc/ngircd/ngircd.conf
167
+    if [ $IRC_PASSWORD ]; then
168
+	sed -i "0,/RE/s/Password =.*/Password =$IRC_PASSWORD/" /etc/ngircd/ngircd.conf
169
+    fi
170
+    # If we are on a mesh then DNS is not available
171
+    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
172
+	sed -i "s/;DNS =.*/DNS = no/g" /etc/ngircd/ngircd.conf
173
+    fi
174
+    # upgrade a cypher
175
+    sed -i 's|SECURE128|SECURE256|g' /etc/ngircd/ngircd.conf
176
+    mkdir /var/run/ircd
177
+    chown -R irc:irc /var/run/ircd
178
+    mkdir /var/run/ngircd
179
+    touch /var/run/ngircd/ngircd.pid
180
+    chown -R irc:irc /var/run/ngircd
181 181
 
182
-	IRC_ONION_HOSTNAME=$(add_onion_service irc ${IRC_PORT} ${IRC_ONION_PORT})
183
-	if ! grep -q $"IRC onion domain" $COMPLETION_FILE; then
184
-		echo "IRC onion domain:$IRC_ONION_HOSTNAME" >> $COMPLETION_FILE
185
-	fi
182
+    IRC_ONION_HOSTNAME=$(add_onion_service irc ${IRC_PORT} ${IRC_ONION_PORT})
183
+    if ! grep -q $"IRC onion domain" $COMPLETION_FILE; then
184
+	echo "IRC onion domain:$IRC_ONION_HOSTNAME" >> $COMPLETION_FILE
185
+    fi
186 186
 
187
-	systemctl restart ngircd
187
+    systemctl restart ngircd
188 188
 
189
-	# keep the daemon running
190
-	echo '' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
191
-	echo '# keep irc daemon running' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
192
-	echo 'IRC_RUNNING=$(pgrep ngircd > /dev/null && echo Running)' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
193
-	echo 'if [ ! $IRC_RUNNING ]; then' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
194
-	echo '  systemctl start ngircd' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
195
-	echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
196
-	echo '  echo " IRC daemon restarted" >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
197
-	echo 'fi' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
189
+    # keep the daemon running
190
+    echo '' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
191
+    echo '# keep irc daemon running' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
192
+    echo 'IRC_RUNNING=$(pgrep ngircd > /dev/null && echo Running)' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
193
+    echo 'if [ ! $IRC_RUNNING ]; then' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
194
+    echo '  systemctl start ngircd' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
195
+    echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
196
+    echo '  echo " IRC daemon restarted" >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
197
+    echo 'fi' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
198 198
 
199
-	if ! grep -q $"IRC Server" /home/$MY_USERNAME/README; then
200
-		echo '' >> /home/$MY_USERNAME/README
201
-		echo '' >> /home/$MY_USERNAME/README
202
-		echo $'IRC Server' >> /home/$MY_USERNAME/README
203
-		echo '==========' >> /home/$MY_USERNAME/README
204
-		echo $'To connect to your IRC server in irssi:' >> /home/$MY_USERNAME/README
205
-		echo '' >> /home/$MY_USERNAME/README
206
-		if [[ $ONION_ONLY != 'yes' ]]; then
207
-			echo "  irssi" >> /home/$MY_USERNAME/README
208
-			echo "  /server add -auto -ssl $DEFAULTDOMAIN $IRC_PORT" >> /home/$MY_USERNAME/README
209
-			echo "  /connect $DEFAULT_DOMAIN_NAME" >> /home/$MY_USERNAME/README
210
-		else
211
-			echo "  usetorwith irssi" >> /home/$MY_USERNAME/README
212
-			echo "  /server add -auto $IRC_ONION_HOSTNAME $IRC_PORT" >> /home/$MY_USERNAME/README
213
-			echo "  /connect $IRC_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
214
-		fi
215
-		echo "  /join #${PROJECT_NAME}" >> /home/$MY_USERNAME/README
216
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
217
-		chmod 600 /home/$MY_USERNAME/README
199
+    if ! grep -q $"IRC Server" /home/$MY_USERNAME/README; then
200
+	echo '' >> /home/$MY_USERNAME/README
201
+	echo '' >> /home/$MY_USERNAME/README
202
+	echo $'IRC Server' >> /home/$MY_USERNAME/README
203
+	echo '==========' >> /home/$MY_USERNAME/README
204
+	echo $'To connect to your IRC server in irssi:' >> /home/$MY_USERNAME/README
205
+	echo '' >> /home/$MY_USERNAME/README
206
+	if [[ $ONION_ONLY != 'yes' ]]; then
207
+	    echo "  irssi" >> /home/$MY_USERNAME/README
208
+	    echo "  /server add -auto -ssl $DEFAULTDOMAIN $IRC_PORT" >> /home/$MY_USERNAME/README
209
+	    echo "  /connect $DEFAULT_DOMAIN_NAME" >> /home/$MY_USERNAME/README
210
+	else
211
+	    echo "  usetorwith irssi" >> /home/$MY_USERNAME/README
212
+	    echo "  /server add -auto $IRC_ONION_HOSTNAME $IRC_PORT" >> /home/$MY_USERNAME/README
213
+	    echo "  /connect $IRC_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
218 214
 	fi
215
+	echo "  /join #${PROJECT_NAME}" >> /home/$MY_USERNAME/README
216
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
217
+	chmod 600 /home/$MY_USERNAME/README
218
+    fi
219 219
 
220
-	function_check configure_firewall_for_irc
221
-	configure_firewall_for_irc
222
-	echo 'install_irc_server' >> $COMPLETION_FILE
220
+    function_check configure_firewall_for_irc
221
+    configure_firewall_for_irc
222
+    echo 'install_irc_server' >> $COMPLETION_FILE
223 223
 }
224 224
 
225 225
 function install_irc_client {
226
-	if grep -Fxq "install_irc_client" $COMPLETION_FILE; then
227
-		return
228
-	fi
229
-	apt-get -y install irssi
226
+    if grep -Fxq "install_irc_client" $COMPLETION_FILE; then
227
+	return
228
+    fi
229
+    apt-get -y install irssi
230 230
 
231
-	if [ ! -d /home/$MY_USERNAME/.irssi ]; then
232
-		mkdir /home/$MY_USERNAME/.irssi
233
-	fi
231
+    if [ ! -d /home/$MY_USERNAME/.irssi ]; then
232
+	mkdir /home/$MY_USERNAME/.irssi
233
+    fi
234 234
 
235
-	echo 'servers = (' > /home/$MY_USERNAME/.irssi/config
236
-	echo '  {' >> /home/$MY_USERNAME/.irssi/config
237
-	echo '    address = "chat.freenode.net";' >> /home/$MY_USERNAME/.irssi/config
238
-	echo '    chatnet = "Freenode";' >> /home/$MY_USERNAME/.irssi/config
239
-	echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
240
-	echo '    autoconnect = "no";' >> /home/$MY_USERNAME/.irssi/config
241
-	echo '  },' >> /home/$MY_USERNAME/.irssi/config
242
-	echo '  {' >> /home/$MY_USERNAME/.irssi/config
243
-	echo '    address = "irc.oftc.net";' >> /home/$MY_USERNAME/.irssi/config
244
-	echo '    chatnet = "OFTC";' >> /home/$MY_USERNAME/.irssi/config
245
-	echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
246
-	echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
247
-	echo '  },' >> /home/$MY_USERNAME/.irssi/config
248
-	echo '  {' >> /home/$MY_USERNAME/.irssi/config
249
-	echo "    address = \"127.0.0.1\";" >> /home/$MY_USERNAME/.irssi/config
250
-	if [[ $ONION_ONLY == 'no' ]]; then
251
-		echo "    port = \"${IRC_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
252
-		echo '    use_ssl = "yes";' >> /home/$MY_USERNAME/.irssi/config
253
-	else
254
-		IRC_ONION_HOSTNAME=$(cat $COMPLETION_FILE | grep "IRC onion domain" | awk -F ':' '{print $2}')
255
-		echo "    port = \"${IRC_ONION_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
256
-		echo '    use_ssl = "no";' >> /home/$MY_USERNAME/.irssi/config
257
-	fi
258
-	echo '    chatnet = "Freedombone";' >> /home/$MY_USERNAME/.irssi/config
259
-	echo '    ssl_verify = "no";' >> /home/$MY_USERNAME/.irssi/config
260
-	echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
261
-	if [ $IRC_PASSWORD ]; then
262
-		echo "    password = \"${IRC_PASSWORD}\";" >> /home/$MY_USERNAME/.irssi/config
263
-	fi
264
-	echo '  }' >> /home/$MY_USERNAME/.irssi/config
265
-	echo ');' >> /home/$MY_USERNAME/.irssi/config
266
-	echo '' >> /home/$MY_USERNAME/.irssi/config
267
-	echo 'chatnets = {' >> /home/$MY_USERNAME/.irssi/config
268
-	echo '  Freedombone = {' >> /home/$MY_USERNAME/.irssi/config
269
-	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
270
-	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
271
-	echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
272
-	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
273
-	echo '  };' >> /home/$MY_USERNAME/.irssi/config
274
-	echo '  Freenode = {' >> /home/$MY_USERNAME/.irssi/config
275
-	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
276
-	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
277
-	echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
278
-	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
279
-	echo '  };' >> /home/$MY_USERNAME/.irssi/config
280
-	echo '  OFTC = {' >> /home/$MY_USERNAME/.irssi/config
281
-	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
282
-	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
283
-	echo '    max_msgs = "1";' >> /home/$MY_USERNAME/.irssi/config
284
-	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
285
-	echo '  };' >> /home/$MY_USERNAME/.irssi/config
286
-	echo '};' >> /home/$MY_USERNAME/.irssi/config
287
-	echo '' >> /home/$MY_USERNAME/.irssi/config
288
-	echo 'channels = (' >> /home/$MY_USERNAME/.irssi/config
289
-	echo '  { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/$MY_USERNAME/.irssi/config
290
-	echo ');' >> /home/$MY_USERNAME/.irssi/config
291
-	echo '' >> /home/$MY_USERNAME/.irssi/config
292
-	echo 'settings = {' >> /home/$MY_USERNAME/.irssi/config
293
-	echo "  core = { real_name = \"$MY_NAME\"; user_name = \"$MY_USERNAME\"; nick = \"$MY_USERNAME\"; };" >> /home/$MY_USERNAME/.irssi/config
294
-	echo '  "fe-text" = { actlist_sort = "refnum"; };' >> /home/$MY_USERNAME/.irssi/config
295
-	echo '};' >> /home/$MY_USERNAME/.irssi/config
296
-	echo 'ignores = ( { level = "CTCPS"; } );' >> /home/$MY_USERNAME/.irssi/config
235
+    echo 'servers = (' > /home/$MY_USERNAME/.irssi/config
236
+    echo '  {' >> /home/$MY_USERNAME/.irssi/config
237
+    echo '    address = "chat.freenode.net";' >> /home/$MY_USERNAME/.irssi/config
238
+    echo '    chatnet = "Freenode";' >> /home/$MY_USERNAME/.irssi/config
239
+    echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
240
+    echo '    autoconnect = "no";' >> /home/$MY_USERNAME/.irssi/config
241
+    echo '  },' >> /home/$MY_USERNAME/.irssi/config
242
+    echo '  {' >> /home/$MY_USERNAME/.irssi/config
243
+    echo '    address = "irc.oftc.net";' >> /home/$MY_USERNAME/.irssi/config
244
+    echo '    chatnet = "OFTC";' >> /home/$MY_USERNAME/.irssi/config
245
+    echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
246
+    echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
247
+    echo '  },' >> /home/$MY_USERNAME/.irssi/config
248
+    echo '  {' >> /home/$MY_USERNAME/.irssi/config
249
+    echo "    address = \"127.0.0.1\";" >> /home/$MY_USERNAME/.irssi/config
250
+    if [[ $ONION_ONLY == 'no' ]]; then
251
+	echo "    port = \"${IRC_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
252
+	echo '    use_ssl = "yes";' >> /home/$MY_USERNAME/.irssi/config
253
+    else
254
+	IRC_ONION_HOSTNAME=$(cat $COMPLETION_FILE | grep "IRC onion domain" | awk -F ':' '{print $2}')
255
+	echo "    port = \"${IRC_ONION_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
256
+	echo '    use_ssl = "no";' >> /home/$MY_USERNAME/.irssi/config
257
+    fi
258
+    echo '    chatnet = "Freedombone";' >> /home/$MY_USERNAME/.irssi/config
259
+    echo '    ssl_verify = "no";' >> /home/$MY_USERNAME/.irssi/config
260
+    echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
261
+    if [ $IRC_PASSWORD ]; then
262
+	echo "    password = \"${IRC_PASSWORD}\";" >> /home/$MY_USERNAME/.irssi/config
263
+    fi
264
+    echo '  }' >> /home/$MY_USERNAME/.irssi/config
265
+    echo ');' >> /home/$MY_USERNAME/.irssi/config
266
+    echo '' >> /home/$MY_USERNAME/.irssi/config
267
+    echo 'chatnets = {' >> /home/$MY_USERNAME/.irssi/config
268
+    echo '  Freedombone = {' >> /home/$MY_USERNAME/.irssi/config
269
+    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
270
+    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
271
+    echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
272
+    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
273
+    echo '  };' >> /home/$MY_USERNAME/.irssi/config
274
+    echo '  Freenode = {' >> /home/$MY_USERNAME/.irssi/config
275
+    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
276
+    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
277
+    echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
278
+    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
279
+    echo '  };' >> /home/$MY_USERNAME/.irssi/config
280
+    echo '  OFTC = {' >> /home/$MY_USERNAME/.irssi/config
281
+    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
282
+    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
283
+    echo '    max_msgs = "1";' >> /home/$MY_USERNAME/.irssi/config
284
+    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
285
+    echo '  };' >> /home/$MY_USERNAME/.irssi/config
286
+    echo '};' >> /home/$MY_USERNAME/.irssi/config
287
+    echo '' >> /home/$MY_USERNAME/.irssi/config
288
+    echo 'channels = (' >> /home/$MY_USERNAME/.irssi/config
289
+    echo '  { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/$MY_USERNAME/.irssi/config
290
+    echo ');' >> /home/$MY_USERNAME/.irssi/config
291
+    echo '' >> /home/$MY_USERNAME/.irssi/config
292
+    echo 'settings = {' >> /home/$MY_USERNAME/.irssi/config
293
+    echo "  core = { real_name = \"$MY_NAME\"; user_name = \"$MY_USERNAME\"; nick = \"$MY_USERNAME\"; };" >> /home/$MY_USERNAME/.irssi/config
294
+    echo '  "fe-text" = { actlist_sort = "refnum"; };' >> /home/$MY_USERNAME/.irssi/config
295
+    echo '};' >> /home/$MY_USERNAME/.irssi/config
296
+    echo 'ignores = ( { level = "CTCPS"; } );' >> /home/$MY_USERNAME/.irssi/config
297 297
 
298
-	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.irssi
298
+    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.irssi
299 299
 
300
-	echo 'install_irc_client' >> $COMPLETION_FILE
300
+    echo 'install_irc_client' >> $COMPLETION_FILE
301 301
 }
302 302
 
303 303
 function install_irc {
304
-	if grep -Fxq "install_irc" $COMPLETION_FILE; then
305
-		return
306
-	fi
307
-	install_irc_server
308
-	install_irc_client
309
-	echo 'install_irc' >> $COMPLETION_FILE
304
+    if grep -Fxq "install_irc" $COMPLETION_FILE; then
305
+	return
306
+    fi
307
+    install_irc_server
308
+    install_irc_client
309
+    echo 'install_irc' >> $COMPLETION_FILE
310 310
 }
311 311
 
312 312
 # NOTE: deliberately no exit 0

+ 293
- 293
src/freedombone-app-mediagoblin Voir le fichier

@@ -38,311 +38,242 @@ MEDIAGOBLIN_ADMIN_PASSWORD=
38 38
 MEDIAGOBLIN_ONION_PORT=8096
39 39
 
40 40
 function reconfigure_mediagoblin {
41
-	echo -n ''
41
+    echo -n ''
42 42
 }
43 43
 
44 44
 function upgrade_mediagoblin {
45
-	echo -n ''
45
+    echo -n ''
46 46
 }
47 47
 
48 48
 function backup_local_mediagoblin {
49
-	echo -n ''
49
+    echo -n ''
50 50
 }
51 51
 
52 52
 function restore_local_mediagoblin {
53
-	echo -n ''
53
+    echo -n ''
54 54
 }
55 55
 
56 56
 function backup_remote_mediagoblin {
57
-	if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
58
-		MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
59
-		function_check suspend_site
60
-		suspend_site ${MEDIAGOBLIN_DOMAIN_NAME}
57
+    if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
58
+	MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
59
+	function_check suspend_site
60
+	suspend_site ${MEDIAGOBLIN_DOMAIN_NAME}
61 61
 
62
-		echo $"Backing up Mediagoblin"
62
+	echo $"Backing up Mediagoblin"
63 63
 
64
-		backup_directory_to_friend /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs mediagoblin
64
+	backup_directory_to_friend /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs mediagoblin
65 65
 
66
-		function_check restart_site
67
-		restart_site
66
+	function_check restart_site
67
+	restart_site
68 68
 
69
-		echo $"Backup of Mediagoblin complete"
70
-	fi
69
+	echo $"Backup of Mediagoblin complete"
70
+    fi
71 71
 }
72 72
 
73 73
 function restore_remote_mediagoblin {
74
-	if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
75
-		MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
76
-		if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
77
-			echo $"Restoring Mediagoblin installation"
78
-			temp_restore_dir=/root/tempmediagoblin
79
-			function_check restore_directory_from_friend
80
-			restore_directory_from_friend $temp_restore_dir mediagoblin
81
-			cp -r $temp_restore_dir/* /
82
-			if [ ! "$?" = "0" ]; then
83
-				exit 5626
84
-			fi
85
-			rm -rf $temp_restore_dir
86
-			echo $"Restore of Mediagoblin complete"
87
-		fi
88
-		chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
74
+    if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
75
+	MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
76
+	if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
77
+	    echo $"Restoring Mediagoblin installation"
78
+	    temp_restore_dir=/root/tempmediagoblin
79
+	    function_check restore_directory_from_friend
80
+	    restore_directory_from_friend $temp_restore_dir mediagoblin
81
+	    cp -r $temp_restore_dir/* /
82
+	    if [ ! "$?" = "0" ]; then
83
+		exit 5626
84
+	    fi
85
+	    rm -rf $temp_restore_dir
86
+	    echo $"Restore of Mediagoblin complete"
89 87
 	fi
88
+	chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
89
+    fi
90 90
 }
91 91
 
92 92
 function remove_mediagoblin {
93
-	echo -n ''
93
+    echo -n ''
94 94
 }
95 95
 
96 96
 function install_mediagoblin {
97
-	if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
98
-		return
99
-	fi
100
-
101
-	MEDIAGOBLIN_WORKING_DIRECTORY=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
102
-
103
-	# update to a new commit if needed
104
-	function_check set_repo_commit
105
-	set_repo_commit $MEDIAGOBLIN_WORKING_DIRECTORY "Mediagoblin commit" "$MEDIAGOBLIN_COMMIT" $MEDIAGOBLIN_REPO
106
-	if [ -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
107
-		chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
108
-	fi
109
-
110
-	if grep -Fxq "install_mediagoblin" $COMPLETION_FILE; then
111
-		return
112
-	fi
113
-
114
-	apt-get -y install git-core python python-dev python-lxml python-pil
115
-	apt-get -y install python-virtualenv npm nodejs-legacy automake
116
-	apt-get -y install fcgiwrap
117
-
118
-	#apt-get -y install postgresql postgresql-client python-psycopg2
119
-	#apt-get -y install python-gst-1.0 libjpeg62-turbo-dev gstreamer1.0-plugins-base python-gobject
120
-	#apt-get -y install gstreamer1.0-plugins-good gstreamer1.0-libav libav-tools gstreamer0.10-tools
121
-	#apt-get -y install python-numpy python-scipy libsndfile1-dev python-gst0.10-dev
122
-	#apt-get -y install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer1.0-tools
123
-	#su -c "createuser -A -D mediagoblin" - postgres
124
-	#su -c "createdb -E UNICODE -O mediagoblin mediagoblin" - postgres
125
-
126
-	useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
127
-	groupadd mediagoblin
128
-	usermod --append -G mediagoblin mediagoblin
129
-
130
-	if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
131
-		mkdir -p $MEDIAGOBLIN_WORKING_DIRECTORY
132
-	fi
133
-
134
-	function_check git_clone
135
-	git_clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_WORKING_DIRECTORY
136
-	cd $MEDIAGOBLIN_WORKING_DIRECTORY
137
-	git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT
138
-	git submodule init
139
-	git submodule update
140
-
141
-	if ! grep -q "Mediagoblin commit" $COMPLETION_FILE; then
142
-		echo "Mediagoblin commit:$MEDIAGOBLIN_COMMIT" >> $COMPLETION_FILE
143
-	else
144
-		sed -i "s/Mediagoblin commit.*/Mediagoblin commit:$MEDIAGOBLIN_COMMIT/g" $COMPLETION_FILE
145
-	fi
146
-
147
-	chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
148
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bootstrap.sh" - mediagoblin
149
-	if [ ! "$?" = "0" ]; then
150
-		exit 278826
151
-	fi
152
-
153
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./configure" - mediagoblin
154
-	if [ ! "$?" = "0" ]; then
155
-		exit 462826
156
-	fi
97
+    if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
98
+	return
99
+    fi
157 100
 
158
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && make" - mediagoblin
159
-	if [ ! "$?" = "0" ]; then
160
-		exit 738229
161
-	fi
162
-
163
-	if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev ]; then
164
-		mkdir $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
165
-	fi
166
-	chmod 750 $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
167
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install flup==1.0.3.dev-20110405" - mediagoblin
168
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade billiard" - mediagoblin
169
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Paste" - mediagoblin
170
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade amqp" - mediagoblin
171
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade anyjson" - mediagoblin
172
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py-bcrypt" - mediagoblin
173
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade wtforms" - mediagoblin
174
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade python-dateutil" - mediagoblin
175
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alembic" - mediagoblin
176
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade waitress" - mediagoblin
177
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade imagesize" - mediagoblin
178
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alabaster" - mediagoblin
179
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade snowballstemmer" - mediagoblin
180
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade docutils" - mediagoblin
181
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Pygments" - mediagoblin
182
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade beautifulsoup4" - mediagoblin
183
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade WebOb" - mediagoblin
184
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py" - mediagoblin
185
-	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade execnet" - mediagoblin
186
-
187
-	# create some directories
188
-	mkdir /var/log/mediagoblin
189
-	chown -hR mediagoblin:www-data /var/log/mediagoblin
190
-	mkdir /var/run/mediagoblin
191
-	chown -hR mediagoblin:www-data /var/run/mediagoblin
192
-
193
-	if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin.ini ]; then
194
-		echo $'mediagoblin.ini not found'
195
-		exit 737529
196
-	fi
197
-	if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/paste.ini ]; then
198
-		echo $'paste.ini not found'
199
-		exit 52762
200
-	fi
201
-
202
-	cp -av mediagoblin.ini mediagoblin_local.ini
203
-	cp -av paste.ini paste_local.ini
101
+    MEDIAGOBLIN_WORKING_DIRECTORY=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
204 102
 
103
+    # update to a new commit if needed
104
+    function_check set_repo_commit
105
+    set_repo_commit $MEDIAGOBLIN_WORKING_DIRECTORY "Mediagoblin commit" "$MEDIAGOBLIN_COMMIT" $MEDIAGOBLIN_REPO
106
+    if [ -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
205 107
 	chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
206
-
207
-	# init with systemd
208
-	echo '[Unit]' > /etc/systemd/system/mediagoblin-celeryd.service
209
-	echo 'Description=Mediagoblin Celeryd' >> /etc/systemd/system/mediagoblin-celeryd.service
210
-	echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-celeryd.service
211
-	echo 'After=network.target' >> /etc/systemd/system/mediagoblin-celeryd.service
212
-	echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
213
-	echo '[Service]' >> /etc/systemd/system/mediagoblin-celeryd.service
214
-	echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
215
-	echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
216
-	echo 'Type=simple' >> /etc/systemd/system/mediagoblin-celeryd.service
217
-	echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-celeryd.service
218
-	echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin_local.ini \\" >> /etc/systemd/system/mediagoblin-celeryd.service
219
-	echo '    CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery' >> /etc/systemd/system/mediagoblin-celeryd.service
220
-	echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/celery worker \\" >> /etc/systemd/system/mediagoblin-celeryd.service
221
-	echo '    --logfile=/var/log/mediagoblin/celery.log \' >> /etc/systemd/system/mediagoblin-celeryd.service
222
-	echo '    --loglevel=INFO' >> /etc/systemd/system/mediagoblin-celeryd.service
223
-	echo 'PIDFile=/var/run/mediagoblin/mediagoblin-celeryd.pid' >> /etc/systemd/system/mediagoblin-celeryd.service
224
-	echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
225
-	echo '[Install]' >> /etc/systemd/system/mediagoblin-celeryd.service
226
-	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-celeryd.service
227
-
228
-	echo '[Unit]' > /etc/systemd/system/mediagoblin-paster.service
229
-	echo 'Description=Mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
230
-	echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-paster.service
231
-	echo 'After=network.target' >> /etc/systemd/system/mediagoblin-paster.service
232
-	echo '' >> /etc/systemd/system/mediagoblin-paster.service
233
-	echo '[Service]' >> /etc/systemd/system/mediagoblin-paster.service
234
-	echo 'Type=forking' >> /etc/systemd/system/mediagoblin-paster.service
235
-	echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
236
-	echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
237
-	echo 'Environment=CELERY_ALWAYS_EAGER=false' >> /etc/systemd/system/mediagoblin-paster.service
238
-	echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-paster.service
239
-	echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
240
-	echo "    $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini \\" >> /etc/systemd/system/mediagoblin-paster.service
241
-	echo '    --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
242
-	echo '    --log-file=/var/log/mediagoblin/mediagoblin.log \' >> /etc/systemd/system/mediagoblin-paster.service
243
-	echo '    --daemon \' >> /etc/systemd/system/mediagoblin-paster.service
244
-	echo '    --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543' >> /etc/systemd/system/mediagoblin-paster.service
245
-	echo "ExecStop=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
246
-	echo '    --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
247
-	echo "    $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini stop" >> /etc/systemd/system/mediagoblin-paster.service
248
-	echo 'PIDFile=/var/run/mediagoblin/mediagoblin.pid' >> /etc/systemd/system/mediagoblin-paster.service
249
-	echo '' >> /etc/systemd/system/mediagoblin-paster.service
250
-	echo '[Install]' >> /etc/systemd/system/mediagoblin-paster.service
251
-	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-paster.service
252
-	systemctl daemon-reload
253
-	systemctl enable mediagoblin-celeryd
254
-	systemctl enable mediagoblin-paster
255
-	systemctl daemon-reload
256
-	systemctl start mediagoblin-celeryd
257
-	systemctl start mediagoblin-paster
258
-
259
-	MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
260
-	if ! grep -q "Mediagoblin onion domain" $COMPLETION_FILE; then
261
-		echo "Mediagoblin onion domain:${MEDIAGOBLIN_ONION_HOSTNAME}" >> $COMPLETION_FILE
262
-	else
263
-		sed -i "s|Mediagoblin onion domain.*|Mediagoblin onion domain:${MEDIAGOBLIN_ONION_HOSTNAME}|g" $COMPLETION_FILE
264
-	fi
265
-	if [[ $MEDIAGOBLIN_ONION_HOSTNAME == *"not found"* ]]; then
266
-		echo $'Problem creating onion address for mediagoblin'
267
-		exit 672652
268
-	fi
269
-
270
-	# web config
271
-	MEDIAGOBLIN_VIRTUAL_HOST=/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
272
-	function_check nginx_http_redirect
273
-	nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
274
-	if [[ $ONION_ONLY == 'no' ]]; then
275
-		echo 'server {' >> $MEDIAGOBLIN_VIRTUAL_HOST
276
-		echo '  listen 443 ssl;' >> $MEDIAGOBLIN_VIRTUAL_HOST
277
-		echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
278
-		echo '  # Stock useful config options, but ignore them :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
279
-		echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
280
-		echo '  include /etc/nginx/mime.types;' >> $MEDIAGOBLIN_VIRTUAL_HOST
281
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
282
-		echo '  autoindex off;' >> $MEDIAGOBLIN_VIRTUAL_HOST
283
-		echo '  default_type  application/octet-stream;' >> $MEDIAGOBLIN_VIRTUAL_HOST
284
-		echo '  sendfile on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
285
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
286
-		function_check nginx_limits
287
-		nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
288
-		function_check nginx_ssl
289
-		nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
290
-		function_check nginx_disable_sniffing
291
-		nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
292
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
293
-		echo '  # Gzip' >> $MEDIAGOBLIN_VIRTUAL_HOST
294
-		echo '  gzip on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
295
-		echo '  gzip_min_length 1024;' >> $MEDIAGOBLIN_VIRTUAL_HOST
296
-		echo '  gzip_buffers 4 32k;' >> $MEDIAGOBLIN_VIRTUAL_HOST
297
-		echo '  gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> $MEDIAGOBLIN_VIRTUAL_HOST
298
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
299
-		echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
300
-		echo '  # Mounting MediaGoblin stuff' >> $MEDIAGOBLIN_VIRTUAL_HOST
301
-		echo '  # This is the section you should read' >> $MEDIAGOBLIN_VIRTUAL_HOST
302
-		echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
303
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
304
-		echo "  server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
305
-		echo '  access_log /var/log/nginx/mediagoblin.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
306
-		echo '  error_log /var/log/nginx/mediagoblin.error.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
307
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
308
-		echo '  # MediaGoblins stock static files: CSS, JS, etc.' >> $MEDIAGOBLIN_VIRTUAL_HOST
309
-		echo '  location /mgoblin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
310
-		echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin/static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
311
-		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
312
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
313
-		echo '  # Instance specific media:' >> $MEDIAGOBLIN_VIRTUAL_HOST
314
-		echo '  location /mgoblin_media/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
315
-		echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/media/public/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
316
-		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
317
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
318
-		echo '  # Theme static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
319
-		echo '  location /theme_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
320
-		echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/theme_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
321
-		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
322
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
323
-		echo '  # Plugin static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
324
-		echo '  location /plugin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
325
-		echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/plugin_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
326
-		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
327
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
328
-		echo '  # Mounting MediaGoblin itself via FastCGI.' >> $MEDIAGOBLIN_VIRTUAL_HOST
329
-		echo '  location / {' >> $MEDIAGOBLIN_VIRTUAL_HOST
330
-		echo '    fastcgi_pass 127.0.0.1:26543;' >> $MEDIAGOBLIN_VIRTUAL_HOST
331
-		echo '    include /etc/nginx/fastcgi_params;' >> $MEDIAGOBLIN_VIRTUAL_HOST
332
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
333
-		echo '    # our understanding vs nginxs handling of script_name vs' >> $MEDIAGOBLIN_VIRTUAL_HOST
334
-		echo '      # path_info dont match :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
335
-		echo '    fastcgi_param PATH_INFO $fastcgi_script_name;' >> $MEDIAGOBLIN_VIRTUAL_HOST
336
-		echo '    fastcgi_param SCRIPT_NAME "";' >> $MEDIAGOBLIN_VIRTUAL_HOST
337
-		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
338
-		echo '}' >> $MEDIAGOBLIN_VIRTUAL_HOST
339
-		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
340
-	else
341
-		echo -n '' > $MEDIAGOBLIN_VIRTUAL_HOST
342
-	fi
343
-
108
+    fi
109
+
110
+    if grep -Fxq "install_mediagoblin" $COMPLETION_FILE; then
111
+	return
112
+    fi
113
+
114
+    apt-get -y install git-core python python-dev python-lxml python-pil
115
+    apt-get -y install python-virtualenv npm nodejs-legacy automake
116
+    apt-get -y install fcgiwrap
117
+
118
+    #apt-get -y install postgresql postgresql-client python-psycopg2
119
+    #apt-get -y install python-gst-1.0 libjpeg62-turbo-dev gstreamer1.0-plugins-base python-gobject
120
+    #apt-get -y install gstreamer1.0-plugins-good gstreamer1.0-libav libav-tools gstreamer0.10-tools
121
+    #apt-get -y install python-numpy python-scipy libsndfile1-dev python-gst0.10-dev
122
+    #apt-get -y install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer1.0-tools
123
+    #su -c "createuser -A -D mediagoblin" - postgres
124
+    #su -c "createdb -E UNICODE -O mediagoblin mediagoblin" - postgres
125
+
126
+    useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
127
+    groupadd mediagoblin
128
+    usermod --append -G mediagoblin mediagoblin
129
+
130
+    if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
131
+	mkdir -p $MEDIAGOBLIN_WORKING_DIRECTORY
132
+    fi
133
+
134
+    function_check git_clone
135
+    git_clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_WORKING_DIRECTORY
136
+    cd $MEDIAGOBLIN_WORKING_DIRECTORY
137
+    git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT
138
+    git submodule init
139
+    git submodule update
140
+
141
+    if ! grep -q "Mediagoblin commit" $COMPLETION_FILE; then
142
+	echo "Mediagoblin commit:$MEDIAGOBLIN_COMMIT" >> $COMPLETION_FILE
143
+    else
144
+	sed -i "s/Mediagoblin commit.*/Mediagoblin commit:$MEDIAGOBLIN_COMMIT/g" $COMPLETION_FILE
145
+    fi
146
+
147
+    chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
148
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bootstrap.sh" - mediagoblin
149
+    if [ ! "$?" = "0" ]; then
150
+	exit 278826
151
+    fi
152
+
153
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./configure" - mediagoblin
154
+    if [ ! "$?" = "0" ]; then
155
+	exit 462826
156
+    fi
157
+
158
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && make" - mediagoblin
159
+    if [ ! "$?" = "0" ]; then
160
+	exit 738229
161
+    fi
162
+
163
+    if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev ]; then
164
+	mkdir $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
165
+    fi
166
+    chmod 750 $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
167
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install flup==1.0.3.dev-20110405" - mediagoblin
168
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade billiard" - mediagoblin
169
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Paste" - mediagoblin
170
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade amqp" - mediagoblin
171
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade anyjson" - mediagoblin
172
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py-bcrypt" - mediagoblin
173
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade wtforms" - mediagoblin
174
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade python-dateutil" - mediagoblin
175
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alembic" - mediagoblin
176
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade waitress" - mediagoblin
177
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade imagesize" - mediagoblin
178
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alabaster" - mediagoblin
179
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade snowballstemmer" - mediagoblin
180
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade docutils" - mediagoblin
181
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Pygments" - mediagoblin
182
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade beautifulsoup4" - mediagoblin
183
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade WebOb" - mediagoblin
184
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py" - mediagoblin
185
+    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade execnet" - mediagoblin
186
+
187
+    # create some directories
188
+    mkdir /var/log/mediagoblin
189
+    chown -hR mediagoblin:www-data /var/log/mediagoblin
190
+    mkdir /var/run/mediagoblin
191
+    chown -hR mediagoblin:www-data /var/run/mediagoblin
192
+
193
+    if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin.ini ]; then
194
+	echo $'mediagoblin.ini not found'
195
+	exit 737529
196
+    fi
197
+    if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/paste.ini ]; then
198
+	echo $'paste.ini not found'
199
+	exit 52762
200
+    fi
201
+
202
+    cp -av mediagoblin.ini mediagoblin_local.ini
203
+    cp -av paste.ini paste_local.ini
204
+
205
+    chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
206
+
207
+    # init with systemd
208
+    echo '[Unit]' > /etc/systemd/system/mediagoblin-celeryd.service
209
+    echo 'Description=Mediagoblin Celeryd' >> /etc/systemd/system/mediagoblin-celeryd.service
210
+    echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-celeryd.service
211
+    echo 'After=network.target' >> /etc/systemd/system/mediagoblin-celeryd.service
212
+    echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
213
+    echo '[Service]' >> /etc/systemd/system/mediagoblin-celeryd.service
214
+    echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
215
+    echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
216
+    echo 'Type=simple' >> /etc/systemd/system/mediagoblin-celeryd.service
217
+    echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-celeryd.service
218
+    echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin_local.ini \\" >> /etc/systemd/system/mediagoblin-celeryd.service
219
+    echo '    CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery' >> /etc/systemd/system/mediagoblin-celeryd.service
220
+    echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/celery worker \\" >> /etc/systemd/system/mediagoblin-celeryd.service
221
+    echo '    --logfile=/var/log/mediagoblin/celery.log \' >> /etc/systemd/system/mediagoblin-celeryd.service
222
+    echo '    --loglevel=INFO' >> /etc/systemd/system/mediagoblin-celeryd.service
223
+    echo 'PIDFile=/var/run/mediagoblin/mediagoblin-celeryd.pid' >> /etc/systemd/system/mediagoblin-celeryd.service
224
+    echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
225
+    echo '[Install]' >> /etc/systemd/system/mediagoblin-celeryd.service
226
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-celeryd.service
227
+
228
+    echo '[Unit]' > /etc/systemd/system/mediagoblin-paster.service
229
+    echo 'Description=Mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
230
+    echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-paster.service
231
+    echo 'After=network.target' >> /etc/systemd/system/mediagoblin-paster.service
232
+    echo '' >> /etc/systemd/system/mediagoblin-paster.service
233
+    echo '[Service]' >> /etc/systemd/system/mediagoblin-paster.service
234
+    echo 'Type=forking' >> /etc/systemd/system/mediagoblin-paster.service
235
+    echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
236
+    echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
237
+    echo 'Environment=CELERY_ALWAYS_EAGER=false' >> /etc/systemd/system/mediagoblin-paster.service
238
+    echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-paster.service
239
+    echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
240
+    echo "    $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini \\" >> /etc/systemd/system/mediagoblin-paster.service
241
+    echo '    --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
242
+    echo '    --log-file=/var/log/mediagoblin/mediagoblin.log \' >> /etc/systemd/system/mediagoblin-paster.service
243
+    echo '    --daemon \' >> /etc/systemd/system/mediagoblin-paster.service
244
+    echo '    --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543' >> /etc/systemd/system/mediagoblin-paster.service
245
+    echo "ExecStop=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
246
+    echo '    --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
247
+    echo "    $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini stop" >> /etc/systemd/system/mediagoblin-paster.service
248
+    echo 'PIDFile=/var/run/mediagoblin/mediagoblin.pid' >> /etc/systemd/system/mediagoblin-paster.service
249
+    echo '' >> /etc/systemd/system/mediagoblin-paster.service
250
+    echo '[Install]' >> /etc/systemd/system/mediagoblin-paster.service
251
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-paster.service
252
+    systemctl daemon-reload
253
+    systemctl enable mediagoblin-celeryd
254
+    systemctl enable mediagoblin-paster
255
+    systemctl daemon-reload
256
+    systemctl start mediagoblin-celeryd
257
+    systemctl start mediagoblin-paster
258
+
259
+    MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
260
+    if ! grep -q "Mediagoblin onion domain" $COMPLETION_FILE; then
261
+	echo "Mediagoblin onion domain:${MEDIAGOBLIN_ONION_HOSTNAME}" >> $COMPLETION_FILE
262
+    else
263
+	sed -i "s|Mediagoblin onion domain.*|Mediagoblin onion domain:${MEDIAGOBLIN_ONION_HOSTNAME}|g" $COMPLETION_FILE
264
+    fi
265
+    if [[ $MEDIAGOBLIN_ONION_HOSTNAME == *"not found"* ]]; then
266
+	echo $'Problem creating onion address for mediagoblin'
267
+	exit 672652
268
+    fi
269
+
270
+    # web config
271
+    MEDIAGOBLIN_VIRTUAL_HOST=/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
272
+    function_check nginx_http_redirect
273
+    nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
274
+    if [[ $ONION_ONLY == 'no' ]]; then
344 275
 	echo 'server {' >> $MEDIAGOBLIN_VIRTUAL_HOST
345
-	echo "  listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> $MEDIAGOBLIN_VIRTUAL_HOST
276
+	echo '  listen 443 ssl;' >> $MEDIAGOBLIN_VIRTUAL_HOST
346 277
 	echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
347 278
 	echo '  # Stock useful config options, but ignore them :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
348 279
 	echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
@@ -354,6 +285,8 @@ function install_mediagoblin {
354 285
 	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
355 286
 	function_check nginx_limits
356 287
 	nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
288
+	function_check nginx_ssl
289
+	nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
357 290
 	function_check nginx_disable_sniffing
358 291
 	nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
359 292
 	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
@@ -368,7 +301,7 @@ function install_mediagoblin {
368 301
 	echo '  # This is the section you should read' >> $MEDIAGOBLIN_VIRTUAL_HOST
369 302
 	echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
370 303
 	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
371
-	echo "  server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
304
+	echo "  server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
372 305
 	echo '  access_log /var/log/nginx/mediagoblin.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
373 306
 	echo '  error_log /var/log/nginx/mediagoblin.error.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
374 307
 	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
@@ -403,23 +336,90 @@ function install_mediagoblin {
403 336
 	echo '    fastcgi_param SCRIPT_NAME "";' >> $MEDIAGOBLIN_VIRTUAL_HOST
404 337
 	echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
405 338
 	echo '}' >> $MEDIAGOBLIN_VIRTUAL_HOST
406
-
407
-	function_check create_site_certificate
408
-	create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME
409
-
410
-	nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
411
-	systemctl restart php5-fpm
412
-	systemctl restart nginx
413
-
414
-	add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
415
-
416
-	if ! grep -q "Mediagoblin domain" $COMPLETION_FILE; then
417
-		echo "Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME" >> $COMPLETION_FILE
418
-	else
419
-		sed -i "s/Mediagoblin domain.*/Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME/g" $COMPLETION_FILE
420
-	fi
421
-
422
-	echo 'install_mediagoblin' >> $COMPLETION_FILE
339
+	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
340
+    else
341
+	echo -n '' > $MEDIAGOBLIN_VIRTUAL_HOST
342
+    fi
343
+
344
+    echo 'server {' >> $MEDIAGOBLIN_VIRTUAL_HOST
345
+    echo "  listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> $MEDIAGOBLIN_VIRTUAL_HOST
346
+    echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
347
+    echo '  # Stock useful config options, but ignore them :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
348
+    echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
349
+    echo '  include /etc/nginx/mime.types;' >> $MEDIAGOBLIN_VIRTUAL_HOST
350
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
351
+    echo '  autoindex off;' >> $MEDIAGOBLIN_VIRTUAL_HOST
352
+    echo '  default_type  application/octet-stream;' >> $MEDIAGOBLIN_VIRTUAL_HOST
353
+    echo '  sendfile on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
354
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
355
+    function_check nginx_limits
356
+    nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
357
+    function_check nginx_disable_sniffing
358
+    nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
359
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
360
+    echo '  # Gzip' >> $MEDIAGOBLIN_VIRTUAL_HOST
361
+    echo '  gzip on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
362
+    echo '  gzip_min_length 1024;' >> $MEDIAGOBLIN_VIRTUAL_HOST
363
+    echo '  gzip_buffers 4 32k;' >> $MEDIAGOBLIN_VIRTUAL_HOST
364
+    echo '  gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> $MEDIAGOBLIN_VIRTUAL_HOST
365
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
366
+    echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
367
+    echo '  # Mounting MediaGoblin stuff' >> $MEDIAGOBLIN_VIRTUAL_HOST
368
+    echo '  # This is the section you should read' >> $MEDIAGOBLIN_VIRTUAL_HOST
369
+    echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
370
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
371
+    echo "  server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
372
+    echo '  access_log /var/log/nginx/mediagoblin.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
373
+    echo '  error_log /var/log/nginx/mediagoblin.error.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
374
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
375
+    echo '  # MediaGoblins stock static files: CSS, JS, etc.' >> $MEDIAGOBLIN_VIRTUAL_HOST
376
+    echo '  location /mgoblin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
377
+    echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin/static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
378
+    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
379
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
380
+    echo '  # Instance specific media:' >> $MEDIAGOBLIN_VIRTUAL_HOST
381
+    echo '  location /mgoblin_media/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
382
+    echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/media/public/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
383
+    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
384
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
385
+    echo '  # Theme static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
386
+    echo '  location /theme_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
387
+    echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/theme_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
388
+    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
389
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
390
+    echo '  # Plugin static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
391
+    echo '  location /plugin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
392
+    echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/plugin_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
393
+    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
394
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
395
+    echo '  # Mounting MediaGoblin itself via FastCGI.' >> $MEDIAGOBLIN_VIRTUAL_HOST
396
+    echo '  location / {' >> $MEDIAGOBLIN_VIRTUAL_HOST
397
+    echo '    fastcgi_pass 127.0.0.1:26543;' >> $MEDIAGOBLIN_VIRTUAL_HOST
398
+    echo '    include /etc/nginx/fastcgi_params;' >> $MEDIAGOBLIN_VIRTUAL_HOST
399
+    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
400
+    echo '    # our understanding vs nginxs handling of script_name vs' >> $MEDIAGOBLIN_VIRTUAL_HOST
401
+    echo '      # path_info dont match :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
402
+    echo '    fastcgi_param PATH_INFO $fastcgi_script_name;' >> $MEDIAGOBLIN_VIRTUAL_HOST
403
+    echo '    fastcgi_param SCRIPT_NAME "";' >> $MEDIAGOBLIN_VIRTUAL_HOST
404
+    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
405
+    echo '}' >> $MEDIAGOBLIN_VIRTUAL_HOST
406
+
407
+    function_check create_site_certificate
408
+    create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME
409
+
410
+    nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
411
+    systemctl restart php5-fpm
412
+    systemctl restart nginx
413
+
414
+    add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
415
+
416
+    if ! grep -q "Mediagoblin domain" $COMPLETION_FILE; then
417
+	echo "Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME" >> $COMPLETION_FILE
418
+    else
419
+	sed -i "s/Mediagoblin domain.*/Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME/g" $COMPLETION_FILE
420
+    fi
421
+
422
+    echo 'install_mediagoblin' >> $COMPLETION_FILE
423 423
 }
424 424
 
425 425
 # NOTE: deliberately no exit 0

+ 450
- 450
src/freedombone-app-rss Voir le fichier

@@ -43,508 +43,508 @@ RSS_READER_GNUSOCIAL_REPO="https://github.com/bashrc/ttrss-gnusocial"
43 43
 RSS_READER_GNUSOCIAL_COMMIT='8b92b8f5db7b0d12459c7bd86a50f48815efe642'
44 44
 
45 45
 function reconfigure_rss {
46
-	echo -n ''
46
+    echo -n ''
47 47
 }
48 48
 
49 49
 function upgrade_rss {
50
-	if grep -Fxq "install_rss" $COMPLETION_FILE; then
51
-		function_check set_repo_commit
52
-		set_repo_commit $RSS_READER_PATH "RSS reader commit" "$RSS_READER_COMMIT" $RSS_READER_REPO
50
+    if grep -Fxq "install_rss" $COMPLETION_FILE; then
51
+	function_check set_repo_commit
52
+	set_repo_commit $RSS_READER_PATH "RSS reader commit" "$RSS_READER_COMMIT" $RSS_READER_REPO
53
+    fi
54
+
55
+    if grep -Fxq "install_rss_mobile_reader" $COMPLETION_FILE; then
56
+	if [ ! $RSS_READER_PATH ]; then
57
+	    RSS_READER_PATH=/etc/share/tt-rss
53 58
 	fi
54 59
 
55
-	if grep -Fxq "install_rss_mobile_reader" $COMPLETION_FILE; then
56
-		if [ ! $RSS_READER_PATH ]; then
57
-			RSS_READER_PATH=/etc/share/tt-rss
58
-		fi
59
-
60
-		if [ ! -d $RSS_READER_PATH ]; then
61
-			echo $'tt-rss is not installed, so the mobile version cannot be installed'
62
-			exit 63452
63
-		fi
64
-
65
-		RSS_MOBILE_READER_PATH=/etc/share/ttrss-mobile
66
-
67
-		# remove any previous install
68
-		if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
69
-			if grep -Fxq "install_rss_mobile_reader" $COMPLETION_FILE; then
70
-				sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
71
-				sed -i '/RSS mobile reader commit/d' $COMPLETION_FILE
72
-				rm -rf $RSS_READER_PATH/g2ttree-mobile
73
-			fi
74
-		fi
75
-
76
-		# update to the next commit
77
-		function_check set_repo_commit
78
-		set_repo_commit $RSS_MOBILE_READER_PATH "RSS mobile reader commit" "$RSS_MOBILE_READER_COMMIT" $RSS_MOBILE_READER_REPO
60
+	if [ ! -d $RSS_READER_PATH ]; then
61
+	    echo $'tt-rss is not installed, so the mobile version cannot be installed'
62
+	    exit 63452
63
+	fi
64
+
65
+	RSS_MOBILE_READER_PATH=/etc/share/ttrss-mobile
66
+
67
+	# remove any previous install
68
+	if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
69
+	    if grep -Fxq "install_rss_mobile_reader" $COMPLETION_FILE; then
70
+		sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
71
+		sed -i '/RSS mobile reader commit/d' $COMPLETION_FILE
72
+		rm -rf $RSS_READER_PATH/g2ttree-mobile
73
+	    fi
79 74
 	fi
75
+
76
+	# update to the next commit
77
+	function_check set_repo_commit
78
+	set_repo_commit $RSS_MOBILE_READER_PATH "RSS mobile reader commit" "$RSS_MOBILE_READER_COMMIT" $RSS_MOBILE_READER_REPO
79
+    fi
80 80
 }
81 81
 
82 82
 function backup_local_rss {
83
-	RSS_READER_DOMAIN_NAME='ttrss'
84
-	if grep -q "RSS reader domain" $COMPLETION_FILE; then
85
-		RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
86
-	fi
83
+    RSS_READER_DOMAIN_NAME='ttrss'
84
+    if grep -q "RSS reader domain" $COMPLETION_FILE; then
85
+	RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
86
+    fi
87 87
 
88
-	if grep -q "RSS reader domain" $COMPLETION_FILE; then
89
-		if [ -d /etc/share/tt-rss ]; then
90
-			RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
88
+    if grep -q "RSS reader domain" $COMPLETION_FILE; then
89
+	if [ -d /etc/share/tt-rss ]; then
90
+	    RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
91 91
 
92
-			echo $"Backing up ttrss"
92
+	    echo $"Backing up ttrss"
93 93
 
94
-			function_check backup_database_to_usb
95
-			backup_database_to_usb ttrss
94
+	    function_check backup_database_to_usb
95
+	    backup_database_to_usb ttrss
96 96
 
97
-			backup_directory_to_usb /etc/share/tt-rss ttrss
97
+	    backup_directory_to_usb /etc/share/tt-rss ttrss
98 98
 
99
-			echo $"ttrss backup complete"
100
-		fi
99
+	    echo $"ttrss backup complete"
101 100
 	fi
101
+    fi
102 102
 }
103 103
 
104 104
 function restore_local_rss {
105
-	if ! grep -q "RSS reader domain" $COMPLETION_FILE; then
106
-		return
107
-	fi
108
-	RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
109
-	if [ $RSS_READER_DOMAIN_NAME ]; then
110
-		echo $"Restoring ttrss"
111
-		temp_restore_dir=/root/tempttrss
112
-		restore_database ttrss ${RSS_READER_DOMAIN_NAME}
113
-		if [ -d $USB_MOUNT/backup/ttrss ]; then
114
-			chown -R www-data:www-data /etc/share/tt-rss
115
-			if [ -d $temp_restore_dir ]; then
116
-				rm -rf $temp_restore_dir
117
-			fi
118
-		fi
119
-		echo $"Restore of ttrss complete"
120
-	fi
105
+    if ! grep -q "RSS reader domain" $COMPLETION_FILE; then
106
+	return
107
+    fi
108
+    RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
109
+    if [ $RSS_READER_DOMAIN_NAME ]; then
110
+	echo $"Restoring ttrss"
111
+	temp_restore_dir=/root/tempttrss
112
+	restore_database ttrss ${RSS_READER_DOMAIN_NAME}
113
+	if [ -d $USB_MOUNT/backup/ttrss ]; then
114
+	    chown -R www-data:www-data /etc/share/tt-rss
115
+	    if [ -d $temp_restore_dir ]; then
116
+		rm -rf $temp_restore_dir
117
+	    fi
118
+	fi
119
+	echo $"Restore of ttrss complete"
120
+    fi
121 121
 }
122 122
 
123 123
 function backup_remote_rss {
124
-	if grep -q "RSS reader domain" $COMPLETION_FILE; then
125
-		RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
126
-		if [ -d /etc/share/tt-rss ]; then
127
-			function_check suspend_site
128
-			suspend_site ${RSS_READER_DOMAIN_NAME}
124
+    if grep -q "RSS reader domain" $COMPLETION_FILE; then
125
+	RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
126
+	if [ -d /etc/share/tt-rss ]; then
127
+	    function_check suspend_site
128
+	    suspend_site ${RSS_READER_DOMAIN_NAME}
129 129
 
130
-			function_check backup_database_to_friend
131
-			backup_database_to_friend ttrss
130
+	    function_check backup_database_to_friend
131
+	    backup_database_to_friend ttrss
132 132
 
133
-			echo $"Backing up RSS reader installation"
133
+	    echo $"Backing up RSS reader installation"
134 134
 
135
-			function_check backup_directory_to_friend
136
-			backup_directory_to_friend /etc/share/tt-rss ttrss
135
+	    function_check backup_directory_to_friend
136
+	    backup_directory_to_friend /etc/share/tt-rss ttrss
137 137
 
138
-			function_check restart_site
139
-			restart_site
140
-		else
141
-			echo $"RSS reader domain specified but not found in /etc/share/ttrss}"
142
-		fi
138
+	    function_check restart_site
139
+	    restart_site
140
+	else
141
+	    echo $"RSS reader domain specified but not found in /etc/share/ttrss}"
143 142
 	fi
143
+    fi
144 144
 }
145 145
 
146 146
 function restore_remote_rss {
147
-	if grep -q "RSS reader domain" $COMPLETION_FILE; then
148
-		echo $"Restoring ttrss"
149
-		RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
150
-		function_check restore_database_from_friend
151
-		restore_database_from_friend ttrss ${RSS_READER_DOMAIN_NAME}
152
-		if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then
153
-			chown -R www-data:www-data /etc/share/tt-rss
154
-		fi
155
-		if [ -d /root/tempttrss ]; then
156
-			rm -rf /root/tempttrss
157
-		fi
158
-		echo $"Restore of ttrss complete"
147
+    if grep -q "RSS reader domain" $COMPLETION_FILE; then
148
+	echo $"Restoring ttrss"
149
+	RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}')
150
+	function_check restore_database_from_friend
151
+	restore_database_from_friend ttrss ${RSS_READER_DOMAIN_NAME}
152
+	if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then
153
+	    chown -R www-data:www-data /etc/share/tt-rss
159 154
 	fi
155
+	if [ -d /root/tempttrss ]; then
156
+	    rm -rf /root/tempttrss
157
+	fi
158
+	echo $"Restore of ttrss complete"
159
+    fi
160 160
 }
161 161
 
162 162
 function remove_rss {
163
-	if ! grep -Fxq "install_rss" $COMPLETION_FILE; then
164
-		return
165
-	fi
166
-	nginx_dissite $RSS_READER_DOMAIN_NAME
167
-	function_check remove_onion_service
168
-	remove_onion_service ttrss ${RSS_READER_ONION_PORT} ${RSS_MOBILE_READER_ONION_PORT}
169
-	if [ -f /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME ]; then
170
-		rm /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
171
-	fi
172
-	if [ -d $RSS_READER_PATH ]; then
173
-		rm -rf $RSS_READER_PATH
174
-	fi
175
-	function_check drop_database
176
-	drop_database ttrss
177
-	sed -i '/install_rss/d' $COMPLETION_FILE
178
-	sed -i '/RSS /d' $COMPLETION_FILE
163
+    if ! grep -Fxq "install_rss" $COMPLETION_FILE; then
164
+	return
165
+    fi
166
+    nginx_dissite $RSS_READER_DOMAIN_NAME
167
+    function_check remove_onion_service
168
+    remove_onion_service ttrss ${RSS_READER_ONION_PORT} ${RSS_MOBILE_READER_ONION_PORT}
169
+    if [ -f /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME ]; then
170
+	rm /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
171
+    fi
172
+    if [ -d $RSS_READER_PATH ]; then
173
+	rm -rf $RSS_READER_PATH
174
+    fi
175
+    function_check drop_database
176
+    drop_database ttrss
177
+    sed -i '/install_rss/d' $COMPLETION_FILE
178
+    sed -i '/RSS /d' $COMPLETION_FILE
179 179
 }
180 180
 
181 181
 function rss_modifications {
182
-	# modify the rss reader to use a socks5 proxy rather than a http proxy
183
-	if [ ! -d $RSS_READER_PATH ]; then
184
-		return
185
-	fi
186
-
187
-	# ensure that socks5 proxy is used
188
-	if ! grep -q "CURLOPT_PROXYTYPE" $RSS_READER_PATH/plugins/af_unburn/init.php; then
189
-		sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/plugins/af_unburn/init.php
190
-	fi
191
-	if ! grep -q "CURLOPT_PROXYTYPE" $RSS_READER_PATH/include/functions.php; then
192
-		sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/include/functions.php
193
-	fi
194
-	chown -R www-data:www-data $RSS_READER_PATH
195
-	chmod a+x $RSS_READER_PATH
182
+    # modify the rss reader to use a socks5 proxy rather than a http proxy
183
+    if [ ! -d $RSS_READER_PATH ]; then
184
+	return
185
+    fi
186
+
187
+    # ensure that socks5 proxy is used
188
+    if ! grep -q "CURLOPT_PROXYTYPE" $RSS_READER_PATH/plugins/af_unburn/init.php; then
189
+	sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/plugins/af_unburn/init.php
190
+    fi
191
+    if ! grep -q "CURLOPT_PROXYTYPE" $RSS_READER_PATH/include/functions.php; then
192
+	sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/include/functions.php
193
+    fi
194
+    chown -R www-data:www-data $RSS_READER_PATH
195
+    chmod a+x $RSS_READER_PATH
196 196
 }
197 197
 
198 198
 function install_rss_main {
199
-	if grep -Fxq "install_rss_main" $COMPLETION_FILE; then
200
-		return
201
-	fi
202
-
203
-	apt-get -y install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
204
-
205
-	if [ ! -d /etc/share ]; then
206
-		mkdir /etc/share
207
-	fi
208
-	cd /etc/share
209
-	function_check git_clone
210
-	git_clone $RSS_READER_REPO tt-rss
211
-	if [ ! -d $RSS_READER_PATH ]; then
212
-		echo $'Could not clone RSS reader repo'
213
-		exit 52925
214
-	fi
215
-	cd $RSS_READER_PATH
216
-	git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
217
-	if ! grep -q "RSS reader commit" $COMPLETION_FILE; then
218
-		echo "RSS reader commit:$RSS_READER_COMMIT" >> $COMPLETION_FILE
219
-	fi
220
-
221
-	function_check install_mariadb
222
-	install_mariadb
223
-
224
-	function_check get_mariadb_password
225
-	get_mariadb_password
226
-
227
-	function_check repair_databases_script
228
-	repair_databases_script
229
-
230
-	function_check get_mariadb_rss_admin_password
231
-	get_mariadb_rss_admin_password
232
-	if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
233
-		if [ -f $IMAGE_PASSWORD_FILE ]; then
234
-			RSS_READER_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
235
-		else
236
-			RSS_READER_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
237
-		fi
238
-	fi
239
-
240
-	function_check create_database
241
-	create_database ttrss "$RSS_READER_ADMIN_PASSWORD" $MY_USERNAME
242
-
243
-	RSS_READER_ONION_HOSTNAME=$(add_onion_service ttrss 80 ${RSS_READER_ONION_PORT})
244
-	RSS_MOBILE_READER_ONION_HOSTNAME=$(add_onion_service ttrss 80 ${RSS_MOBILE_READER_ONION_PORT})
245
-
246
-	echo 'server {' > /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
247
-	echo "  listen 127.0.0.1:$RSS_MOBILE_READER_ONION_PORT;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
248
-	echo "  server_name $RSS_MOBILE_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
249
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
250
-	echo '  access_log off;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
251
-	echo '  error_log off;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
252
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
253
-	echo '  root /etc/share/ttrss-mobile;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
254
-	echo '  index index.html index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
255
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
256
-	echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
257
-	echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
258
-	echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
259
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
260
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
261
-	echo '  location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
262
-	echo '    try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
263
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
264
-	echo '  location /tt-rss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
265
-	echo '    try_files $uri $uri/ @ttrss_base;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
266
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
267
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
268
-	echo '  location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
269
-	echo '    rewrite ^(.*)$ /index.html?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
270
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
271
-	echo '  location @ttrss_base {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
272
-	echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
273
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
274
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
275
-	echo '  location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
276
-	echo '    deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
277
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
278
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
279
-	echo '  add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
280
-	echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
281
-	echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
282
-	echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
283
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
284
-	echo 'server {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
285
-	echo "  listen 127.0.0.1:$RSS_READER_ONION_PORT default_server;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
286
-	echo "  server_name $RSS_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
287
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
288
-	echo '  access_log off;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
289
-	echo '  error_log off;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
290
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
291
-	echo '  root /etc/share/tt-rss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
292
-	echo '  index index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
293
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
294
-	echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
295
-	echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
296
-	echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
297
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
298
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
299
-	echo '  set $mobile_rewrite do_not_perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
300
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
301
-	echo '  ## chi http_user_agent for mobile / smart phones ##' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
302
-	echo '  if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
303
-	echo '    set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
304
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
305
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
306
-	echo '  if ($http_user_agent ~* "^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-)") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
307
-	echo '    set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
308
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
309
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
310
-	echo '  if ($mobile_rewrite = perform) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
311
-	echo "    rewrite ^/(.*) http://$RSS_MOBILE_READER_ONION_HOSTNAME permanent;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
312
-	echo '    break;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
313
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
314
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
315
-	echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
316
-	echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
317
-	echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
318
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
319
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
320
-	echo '  location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
321
-	echo '    try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
322
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
323
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
324
-	echo '  location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
325
-	echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
326
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
327
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
328
-	echo '  location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
329
-	echo '    deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
330
-	echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
331
-	echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
332
-	echo '  add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
333
-	echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
334
-	echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
335
-	echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
336
-
337
-	if [ ! -f $RSS_READER_PATH/config.php ]; then
338
-		# generate a config file
339
-		RSS_FEED_CRYPT_KEY="$(create_password 24)"
340
-		echo '<?php' > $RSS_READER_PATH/config.php
341
-		echo "  define ('_CURL_HTTP_PROXY', '127.0.0.1:9050');" >> $RSS_READER_PATH/config.php
342
-		echo "  define('DB_TYPE', 'mysql');" >> $RSS_READER_PATH/config.php
343
-		echo "  define('DB_HOST', 'localhost');" >> $RSS_READER_PATH/config.php
344
-		echo "  define('DB_USER', 'root');" >> $RSS_READER_PATH/config.php
345
-		echo "  define('DB_NAME', 'ttrss');" >> $RSS_READER_PATH/config.php
346
-		echo "  define('DB_PASS', '${MARIADB_PASSWORD}');" >> $RSS_READER_PATH/config.php
347
-		echo "  define('DB_PORT', '3306');" >> $RSS_READER_PATH/config.php
348
-		echo "  define('MYSQL_CHARSET', 'UTF8');" >> $RSS_READER_PATH/config.php
349
-		echo "  define('SELF_URL_PATH', 'http://${RSS_READER_ONION_HOSTNAME}/');" >> $RSS_READER_PATH/config.php
350
-		echo "  define('FEED_CRYPT_KEY', '${RSS_FEED_CRYPT_KEY}');" >> $RSS_READER_PATH/config.php
351
-		echo "  define('SINGLE_USER_MODE', false);" >> $RSS_READER_PATH/config.php
352
-		echo "  define('SIMPLE_UPDATE_MODE', false);" >> $RSS_READER_PATH/config.php
353
-		echo "  define('PHP_EXECUTABLE', '/usr/bin/php');" >> $RSS_READER_PATH/config.php
354
-		echo "  define('LOCK_DIRECTORY', 'lock');" >> $RSS_READER_PATH/config.php
355
-		echo "  define('CACHE_DIR', 'cache');" >> $RSS_READER_PATH/config.php
356
-		echo "  define('ICONS_DIR', \"feed-icons\");" >> $RSS_READER_PATH/config.php
357
-		echo "  define('ICONS_URL', \"feed-icons\");" >> $RSS_READER_PATH/config.php
358
-		echo "  define('AUTH_AUTO_CREATE', true);" >> $RSS_READER_PATH/config.php
359
-		echo "  define('AUTH_AUTO_LOGIN', true);" >> $RSS_READER_PATH/config.php
360
-		echo "  define('FORCE_ARTICLE_PURGE', 0);" >> $RSS_READER_PATH/config.php
361
-		echo "  define('PUBSUBHUBBUB_HUB', '');" >> $RSS_READER_PATH/config.php
362
-		echo "  define('PUBSUBHUBBUB_ENABLED', false);" >> $RSS_READER_PATH/config.php
363
-		echo "  define('SPHINX_SERVER', 'localhost:9312');" >> $RSS_READER_PATH/config.php
364
-		echo "  define('SPHINX_INDEX', 'ttrss, delta');" >> $RSS_READER_PATH/config.php
365
-		echo "  define('ENABLE_REGISTRATION', false);" >> $RSS_READER_PATH/config.php
366
-		echo "  define('REG_NOTIFY_ADDRESS', '${MY_EMAIL_ADDRESS}');" >> $RSS_READER_PATH/config.php
367
-		echo "  define('REG_MAX_USERS', 10);" >> $RSS_READER_PATH/config.php
368
-		echo "  define('SESSION_COOKIE_LIFETIME', 86400);" >> $RSS_READER_PATH/config.php
369
-		echo "  define('SMTP_FROM_NAME', 'Tiny Tiny RSS');" >> $RSS_READER_PATH/config.php
370
-		echo "  define('SMTP_FROM_ADDRESS', 'noreply@${RSS_READER_ONION_HOSTNAME}');" >> $RSS_READER_PATH/config.php
371
-		echo "  define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');" >> $RSS_READER_PATH/config.php
372
-		echo "  define('SMTP_SERVER', '');" >> $RSS_READER_PATH/config.php
373
-		echo "  define('SMTP_LOGIN', '');" >> $RSS_READER_PATH/config.php
374
-		echo "  define('SMTP_PASSWORD', '');" >> $RSS_READER_PATH/config.php
375
-		echo "  define('SMTP_SECURE', '');" >> $RSS_READER_PATH/config.php
376
-		echo "  define('CHECK_FOR_UPDATES', false);" >> $RSS_READER_PATH/config.php
377
-		echo "  define('ENABLE_GZIP_OUTPUT', false);" >> $RSS_READER_PATH/config.php
378
-		echo "  define('PLUGINS', 'auth_internal, note, gnusocial');" >> $RSS_READER_PATH/config.php
379
-		echo "  define('LOG_DESTINATION', 'sql');" >> $RSS_READER_PATH/config.php
380
-		echo "  define('CONFIG_VERSION', 26);" >> $RSS_READER_PATH/config.php
381
-	fi
382
-
383
-	# initialize the database
384
-	if [ ! -f $RSS_READER_PATH/schema/ttrss_schema_mysql.sql ]; then
385
-		echo $'No database schema found for rss reader'
386
-		exit 52926
387
-	fi
388
-	initialise_database ttrss $RSS_READER_PATH/schema/ttrss_schema_mysql.sql
389
-
390
-	# change the password from the default
391
-	RSS_READER_ADMIN_PASSWORD_HASH=$(echo -n "${RSS_READER_ADMIN_PASSWORD}" | sha1sum | awk -F ' ' '{print $1}')
392
-
393
-	function_check run_query
394
-	run_query ttrss "update ttrss_users set pwd_hash = 'SHA1:${RSS_READER_ADMIN_PASSWORD_HASH}', salt= '' WHERE login = 'admin';"
395
-
396
-	function_check rss_modifications
397
-	rss_modifications
398
-
399
-	function_check configure_php
400
-	configure_php
401
-
402
-	nginx_ensite $RSS_READER_DOMAIN_NAME
403
-	systemctl restart php5-fpm
404
-	systemctl restart nginx
405
-
406
-	if ! grep -q "RSS reader onion domain" $COMPLETION_FILE; then
407
-		echo "RSS reader onion domain:${RSS_READER_ONION_HOSTNAME}" >> $COMPLETION_FILE
408
-	fi
409
-	if ! grep -q "RSS reader domain" $COMPLETION_FILE; then
410
-		echo "RSS reader domain:${RSS_READER_DOMAIN_NAME}" >> $COMPLETION_FILE
411
-	fi
412
-
413
-	# daemon to update feeds
414
-	echo '[Unit]' > /etc/systemd/system/ttrss.service
415
-	echo 'Description=ttrss_backend' >> /etc/systemd/system/ttrss.service
416
-	echo 'After=network.target mysql.service' >> /etc/systemd/system/ttrss.service
417
-	echo 'After=tor.service' >> /etc/systemd/system/ttrss.service
418
-	echo '' >> /etc/systemd/system/ttrss.service
419
-	echo '[Service]' >> /etc/systemd/system/ttrss.service
420
-	echo 'User=www-data' >> /etc/systemd/system/ttrss.service
421
-	echo "ExecStart=/usr/bin/php $RSS_READER_PATH/update.php --daemon" >> /etc/systemd/system/ttrss.service
422
-	echo '' >> /etc/systemd/system/ttrss.service
423
-	echo '[Install]' >> /etc/systemd/system/ttrss.service
424
-	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ttrss.service
425
-	systemctl enable ttrss
426
-	systemctl daemon-reload
427
-	systemctl start ttrss
428
-
429
-	# some post-install instructions for the user
430
-	if ! grep -q $"RSS Reader" /home/$MY_USERNAME/README; then
431
-		echo '' >> /home/$MY_USERNAME/README
432
-		echo '' >> /home/$MY_USERNAME/README
433
-		echo $'RSS Reader' >> /home/$MY_USERNAME/README
434
-		echo '==========' >> /home/$MY_USERNAME/README
435
-		echo $"RSS reader domain: ${RSS_READER_DOMAIN_NAME}" >> /home/$MY_USERNAME/README
436
-		echo $"RSS reader onion domain: ${RSS_READER_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
437
-		echo $"RSS reader admin username: admin" >> /home/$MY_USERNAME/README
438
-		echo $"RSS reader admin password: ${RSS_READER_ADMIN_PASSWORD}" >> /home/$MY_USERNAME/README
439
-		echo '' >> /home/$MY_USERNAME/README
440
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
441
-		chmod 600 /home/$MY_USERNAME/README
442
-	fi
443
-
444
-	echo 'install_rss_main' >> $COMPLETION_FILE
199
+    if grep -Fxq "install_rss_main" $COMPLETION_FILE; then
200
+	return
201
+    fi
202
+
203
+    apt-get -y install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
204
+
205
+    if [ ! -d /etc/share ]; then
206
+	mkdir /etc/share
207
+    fi
208
+    cd /etc/share
209
+    function_check git_clone
210
+    git_clone $RSS_READER_REPO tt-rss
211
+    if [ ! -d $RSS_READER_PATH ]; then
212
+	echo $'Could not clone RSS reader repo'
213
+	exit 52925
214
+    fi
215
+    cd $RSS_READER_PATH
216
+    git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
217
+    if ! grep -q "RSS reader commit" $COMPLETION_FILE; then
218
+	echo "RSS reader commit:$RSS_READER_COMMIT" >> $COMPLETION_FILE
219
+    fi
220
+
221
+    function_check install_mariadb
222
+    install_mariadb
223
+
224
+    function_check get_mariadb_password
225
+    get_mariadb_password
226
+
227
+    function_check repair_databases_script
228
+    repair_databases_script
229
+
230
+    function_check get_mariadb_rss_admin_password
231
+    get_mariadb_rss_admin_password
232
+    if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
233
+	if [ -f $IMAGE_PASSWORD_FILE ]; then
234
+	    RSS_READER_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
235
+	else
236
+	    RSS_READER_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
237
+	fi
238
+    fi
239
+
240
+    function_check create_database
241
+    create_database ttrss "$RSS_READER_ADMIN_PASSWORD" $MY_USERNAME
242
+
243
+    RSS_READER_ONION_HOSTNAME=$(add_onion_service ttrss 80 ${RSS_READER_ONION_PORT})
244
+    RSS_MOBILE_READER_ONION_HOSTNAME=$(add_onion_service ttrss 80 ${RSS_MOBILE_READER_ONION_PORT})
245
+
246
+    echo 'server {' > /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
247
+    echo "  listen 127.0.0.1:$RSS_MOBILE_READER_ONION_PORT;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
248
+    echo "  server_name $RSS_MOBILE_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
249
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
250
+    echo '  access_log off;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
251
+    echo '  error_log off;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
252
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
253
+    echo '  root /etc/share/ttrss-mobile;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
254
+    echo '  index index.html index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
255
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
256
+    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
257
+    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
258
+    echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
259
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
260
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
261
+    echo '  location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
262
+    echo '    try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
263
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
264
+    echo '  location /tt-rss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
265
+    echo '    try_files $uri $uri/ @ttrss_base;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
266
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
267
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
268
+    echo '  location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
269
+    echo '    rewrite ^(.*)$ /index.html?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
270
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
271
+    echo '  location @ttrss_base {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
272
+    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
273
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
274
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
275
+    echo '  location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
276
+    echo '    deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
277
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
278
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
279
+    echo '  add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
280
+    echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
281
+    echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
282
+    echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
283
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
284
+    echo 'server {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
285
+    echo "  listen 127.0.0.1:$RSS_READER_ONION_PORT default_server;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
286
+    echo "  server_name $RSS_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
287
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
288
+    echo '  access_log off;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
289
+    echo '  error_log off;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
290
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
291
+    echo '  root /etc/share/tt-rss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
292
+    echo '  index index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
293
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
294
+    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
295
+    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
296
+    echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
297
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
298
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
299
+    echo '  set $mobile_rewrite do_not_perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
300
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
301
+    echo '  ## chi http_user_agent for mobile / smart phones ##' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
302
+    echo '  if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
303
+    echo '    set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
304
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
305
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
306
+    echo '  if ($http_user_agent ~* "^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-)") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
307
+    echo '    set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
308
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
309
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
310
+    echo '  if ($mobile_rewrite = perform) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
311
+    echo "    rewrite ^/(.*) http://$RSS_MOBILE_READER_ONION_HOSTNAME permanent;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
312
+    echo '    break;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
313
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
314
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
315
+    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
316
+    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
317
+    echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
318
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
319
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
320
+    echo '  location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
321
+    echo '    try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
322
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
323
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
324
+    echo '  location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
325
+    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
326
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
327
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
328
+    echo '  location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
329
+    echo '    deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
330
+    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
331
+    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
332
+    echo '  add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
333
+    echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
334
+    echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
335
+    echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
336
+
337
+    if [ ! -f $RSS_READER_PATH/config.php ]; then
338
+	# generate a config file
339
+	RSS_FEED_CRYPT_KEY="$(create_password 24)"
340
+	echo '<?php' > $RSS_READER_PATH/config.php
341
+	echo "  define ('_CURL_HTTP_PROXY', '127.0.0.1:9050');" >> $RSS_READER_PATH/config.php
342
+	echo "  define('DB_TYPE', 'mysql');" >> $RSS_READER_PATH/config.php
343
+	echo "  define('DB_HOST', 'localhost');" >> $RSS_READER_PATH/config.php
344
+	echo "  define('DB_USER', 'root');" >> $RSS_READER_PATH/config.php
345
+	echo "  define('DB_NAME', 'ttrss');" >> $RSS_READER_PATH/config.php
346
+	echo "  define('DB_PASS', '${MARIADB_PASSWORD}');" >> $RSS_READER_PATH/config.php
347
+	echo "  define('DB_PORT', '3306');" >> $RSS_READER_PATH/config.php
348
+	echo "  define('MYSQL_CHARSET', 'UTF8');" >> $RSS_READER_PATH/config.php
349
+	echo "  define('SELF_URL_PATH', 'http://${RSS_READER_ONION_HOSTNAME}/');" >> $RSS_READER_PATH/config.php
350
+	echo "  define('FEED_CRYPT_KEY', '${RSS_FEED_CRYPT_KEY}');" >> $RSS_READER_PATH/config.php
351
+	echo "  define('SINGLE_USER_MODE', false);" >> $RSS_READER_PATH/config.php
352
+	echo "  define('SIMPLE_UPDATE_MODE', false);" >> $RSS_READER_PATH/config.php
353
+	echo "  define('PHP_EXECUTABLE', '/usr/bin/php');" >> $RSS_READER_PATH/config.php
354
+	echo "  define('LOCK_DIRECTORY', 'lock');" >> $RSS_READER_PATH/config.php
355
+	echo "  define('CACHE_DIR', 'cache');" >> $RSS_READER_PATH/config.php
356
+	echo "  define('ICONS_DIR', \"feed-icons\");" >> $RSS_READER_PATH/config.php
357
+	echo "  define('ICONS_URL', \"feed-icons\");" >> $RSS_READER_PATH/config.php
358
+	echo "  define('AUTH_AUTO_CREATE', true);" >> $RSS_READER_PATH/config.php
359
+	echo "  define('AUTH_AUTO_LOGIN', true);" >> $RSS_READER_PATH/config.php
360
+	echo "  define('FORCE_ARTICLE_PURGE', 0);" >> $RSS_READER_PATH/config.php
361
+	echo "  define('PUBSUBHUBBUB_HUB', '');" >> $RSS_READER_PATH/config.php
362
+	echo "  define('PUBSUBHUBBUB_ENABLED', false);" >> $RSS_READER_PATH/config.php
363
+	echo "  define('SPHINX_SERVER', 'localhost:9312');" >> $RSS_READER_PATH/config.php
364
+	echo "  define('SPHINX_INDEX', 'ttrss, delta');" >> $RSS_READER_PATH/config.php
365
+	echo "  define('ENABLE_REGISTRATION', false);" >> $RSS_READER_PATH/config.php
366
+	echo "  define('REG_NOTIFY_ADDRESS', '${MY_EMAIL_ADDRESS}');" >> $RSS_READER_PATH/config.php
367
+	echo "  define('REG_MAX_USERS', 10);" >> $RSS_READER_PATH/config.php
368
+	echo "  define('SESSION_COOKIE_LIFETIME', 86400);" >> $RSS_READER_PATH/config.php
369
+	echo "  define('SMTP_FROM_NAME', 'Tiny Tiny RSS');" >> $RSS_READER_PATH/config.php
370
+	echo "  define('SMTP_FROM_ADDRESS', 'noreply@${RSS_READER_ONION_HOSTNAME}');" >> $RSS_READER_PATH/config.php
371
+	echo "  define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');" >> $RSS_READER_PATH/config.php
372
+	echo "  define('SMTP_SERVER', '');" >> $RSS_READER_PATH/config.php
373
+	echo "  define('SMTP_LOGIN', '');" >> $RSS_READER_PATH/config.php
374
+	echo "  define('SMTP_PASSWORD', '');" >> $RSS_READER_PATH/config.php
375
+	echo "  define('SMTP_SECURE', '');" >> $RSS_READER_PATH/config.php
376
+	echo "  define('CHECK_FOR_UPDATES', false);" >> $RSS_READER_PATH/config.php
377
+	echo "  define('ENABLE_GZIP_OUTPUT', false);" >> $RSS_READER_PATH/config.php
378
+	echo "  define('PLUGINS', 'auth_internal, note, gnusocial');" >> $RSS_READER_PATH/config.php
379
+	echo "  define('LOG_DESTINATION', 'sql');" >> $RSS_READER_PATH/config.php
380
+	echo "  define('CONFIG_VERSION', 26);" >> $RSS_READER_PATH/config.php
381
+    fi
382
+
383
+    # initialize the database
384
+    if [ ! -f $RSS_READER_PATH/schema/ttrss_schema_mysql.sql ]; then
385
+	echo $'No database schema found for rss reader'
386
+	exit 52926
387
+    fi
388
+    initialise_database ttrss $RSS_READER_PATH/schema/ttrss_schema_mysql.sql
389
+
390
+    # change the password from the default
391
+    RSS_READER_ADMIN_PASSWORD_HASH=$(echo -n "${RSS_READER_ADMIN_PASSWORD}" | sha1sum | awk -F ' ' '{print $1}')
392
+
393
+    function_check run_query
394
+    run_query ttrss "update ttrss_users set pwd_hash = 'SHA1:${RSS_READER_ADMIN_PASSWORD_HASH}', salt= '' WHERE login = 'admin';"
395
+
396
+    function_check rss_modifications
397
+    rss_modifications
398
+
399
+    function_check configure_php
400
+    configure_php
401
+
402
+    nginx_ensite $RSS_READER_DOMAIN_NAME
403
+    systemctl restart php5-fpm
404
+    systemctl restart nginx
405
+
406
+    if ! grep -q "RSS reader onion domain" $COMPLETION_FILE; then
407
+	echo "RSS reader onion domain:${RSS_READER_ONION_HOSTNAME}" >> $COMPLETION_FILE
408
+    fi
409
+    if ! grep -q "RSS reader domain" $COMPLETION_FILE; then
410
+	echo "RSS reader domain:${RSS_READER_DOMAIN_NAME}" >> $COMPLETION_FILE
411
+    fi
412
+
413
+    # daemon to update feeds
414
+    echo '[Unit]' > /etc/systemd/system/ttrss.service
415
+    echo 'Description=ttrss_backend' >> /etc/systemd/system/ttrss.service
416
+    echo 'After=network.target mysql.service' >> /etc/systemd/system/ttrss.service
417
+    echo 'After=tor.service' >> /etc/systemd/system/ttrss.service
418
+    echo '' >> /etc/systemd/system/ttrss.service
419
+    echo '[Service]' >> /etc/systemd/system/ttrss.service
420
+    echo 'User=www-data' >> /etc/systemd/system/ttrss.service
421
+    echo "ExecStart=/usr/bin/php $RSS_READER_PATH/update.php --daemon" >> /etc/systemd/system/ttrss.service
422
+    echo '' >> /etc/systemd/system/ttrss.service
423
+    echo '[Install]' >> /etc/systemd/system/ttrss.service
424
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ttrss.service
425
+    systemctl enable ttrss
426
+    systemctl daemon-reload
427
+    systemctl start ttrss
428
+
429
+    # some post-install instructions for the user
430
+    if ! grep -q $"RSS Reader" /home/$MY_USERNAME/README; then
431
+	echo '' >> /home/$MY_USERNAME/README
432
+	echo '' >> /home/$MY_USERNAME/README
433
+	echo $'RSS Reader' >> /home/$MY_USERNAME/README
434
+	echo '==========' >> /home/$MY_USERNAME/README
435
+	echo $"RSS reader domain: ${RSS_READER_DOMAIN_NAME}" >> /home/$MY_USERNAME/README
436
+	echo $"RSS reader onion domain: ${RSS_READER_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
437
+	echo $"RSS reader admin username: admin" >> /home/$MY_USERNAME/README
438
+	echo $"RSS reader admin password: ${RSS_READER_ADMIN_PASSWORD}" >> /home/$MY_USERNAME/README
439
+	echo '' >> /home/$MY_USERNAME/README
440
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
441
+	chmod 600 /home/$MY_USERNAME/README
442
+    fi
443
+
444
+    echo 'install_rss_main' >> $COMPLETION_FILE
445 445
 }
446 446
 
447 447
 function install_rss_gnusocial {
448
-	if [ ! $MICROBLOG_DOMAIN_NAME ]; then
449
-		return
450
-	fi
451
-
452
-	if [ ! $RSS_READER_PATH ]; then
453
-		RSS_READER_PATH=/etc/share/tt-rss
454
-	fi
455
-	RSS_READER_GNUSOCIAL_PATH=${RSS_READER_PATH}/plugins/gnusocial
456
-
457
-	# update to the next commit
458
-	function_check set_repo_commit
459
-	set_repo_commit $RSS_READER_GNUSOCIAL_PATH "RSS reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT" $RSS_READER_GNUSOCIAL_REPO
460
-	chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
461
-
462
-	if grep -Fxq "install_rss_gnusocial" $COMPLETION_FILE; then
463
-		return
464
-	fi
465
-
466
-	if [ ! -d $INSTALL_DIR ]; then
467
-		mkdir -p $INSTALL_DIR
468
-	fi
469
-
470
-	cd $INSTALL_DIR
471
-	function_check git_clone
472
-	git_clone $RSS_READER_GNUSOCIAL_REPO ttrss-gnusocial
473
-	if [ ! -d $INSTALL_DIR/ttrss-gnusocial ]; then
474
-		echo $'Could not clone repo for RSS reader GNU Social plugin'
475
-		exit 52838
476
-	fi
477
-	cp -r $INSTALL_DIR/ttrss-gnusocial $RSS_READER_GNUSOCIAL_PATH
478
-	cd $RSS_READER_GNUSOCIAL_PATH
479
-	git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
480
-	if ! grep -q "RSS reader gnusocial commit" $COMPLETION_FILE; then
481
-		echo "RSS reader gnusocial commit:$RSS_READER_GNUSOCIAL_COMMIT" >> $COMPLETION_FILE
482
-	fi
483
-	chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
484
-
485
-	echo 'install_rss_gnusocial' >> $COMPLETION_FILE
448
+    if [ ! $MICROBLOG_DOMAIN_NAME ]; then
449
+	return
450
+    fi
451
+
452
+    if [ ! $RSS_READER_PATH ]; then
453
+	RSS_READER_PATH=/etc/share/tt-rss
454
+    fi
455
+    RSS_READER_GNUSOCIAL_PATH=${RSS_READER_PATH}/plugins/gnusocial
456
+
457
+    # update to the next commit
458
+    function_check set_repo_commit
459
+    set_repo_commit $RSS_READER_GNUSOCIAL_PATH "RSS reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT" $RSS_READER_GNUSOCIAL_REPO
460
+    chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
461
+
462
+    if grep -Fxq "install_rss_gnusocial" $COMPLETION_FILE; then
463
+	return
464
+    fi
465
+
466
+    if [ ! -d $INSTALL_DIR ]; then
467
+	mkdir -p $INSTALL_DIR
468
+    fi
469
+
470
+    cd $INSTALL_DIR
471
+    function_check git_clone
472
+    git_clone $RSS_READER_GNUSOCIAL_REPO ttrss-gnusocial
473
+    if [ ! -d $INSTALL_DIR/ttrss-gnusocial ]; then
474
+	echo $'Could not clone repo for RSS reader GNU Social plugin'
475
+	exit 52838
476
+    fi
477
+    cp -r $INSTALL_DIR/ttrss-gnusocial $RSS_READER_GNUSOCIAL_PATH
478
+    cd $RSS_READER_GNUSOCIAL_PATH
479
+    git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
480
+    if ! grep -q "RSS reader gnusocial commit" $COMPLETION_FILE; then
481
+	echo "RSS reader gnusocial commit:$RSS_READER_GNUSOCIAL_COMMIT" >> $COMPLETION_FILE
482
+    fi
483
+    chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
484
+
485
+    echo 'install_rss_gnusocial' >> $COMPLETION_FILE
486 486
 }
487 487
 
488 488
 function install_rss_mobile_reader {
489
-	if [ ! $RSS_READER_PATH ]; then
490
-		RSS_READER_PATH=/etc/share/tt-rss
491
-	fi
489
+    if [ ! $RSS_READER_PATH ]; then
490
+	RSS_READER_PATH=/etc/share/tt-rss
491
+    fi
492 492
 
493
-	if [ ! -d $RSS_READER_PATH ]; then
494
-		echo $'tt-rss is not installed, so the mobile version cannot be installed'
495
-		exit 63452
496
-	fi
493
+    if [ ! -d $RSS_READER_PATH ]; then
494
+	echo $'tt-rss is not installed, so the mobile version cannot be installed'
495
+	exit 63452
496
+    fi
497 497
 
498
-	RSS_MOBILE_READER_PATH=/etc/share/ttrss-mobile
499
-
500
-	# remove any previous install
501
-	if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
502
-		if grep -Fxq "install_rss_mobile_reader" $COMPLETION_FILE; then
503
-			sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
504
-			sed -i '/RSS mobile reader commit/d' $COMPLETION_FILE
505
-			rm -rf $RSS_READER_PATH/g2ttree-mobile
506
-		fi
507
-	fi
498
+    RSS_MOBILE_READER_PATH=/etc/share/ttrss-mobile
508 499
 
500
+    # remove any previous install
501
+    if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
509 502
 	if grep -Fxq "install_rss_mobile_reader" $COMPLETION_FILE; then
510
-		return
511
-	fi
512
-
513
-	cd /etc/share
514
-	function_check git_clone
515
-	git_clone $RSS_MOBILE_READER_REPO ttrss-mobile
516
-	if [ ! -d $RSS_MOBILE_READER_PATH ]; then
517
-		echo $'Could not clone RSS mobile reader repo'
518
-		exit 24816
519
-	fi
520
-	cd $RSS_MOBILE_READER_PATH
521
-	git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
522
-	if ! grep -q "RSS mobile reader commit" $COMPLETION_FILE; then
523
-		echo "RSS mobile reader commit:$RSS_MOBILE_READER_COMMIT" >> $COMPLETION_FILE
524
-	fi
525
-
526
-	echo 'define({' > $RSS_MOBILE_READER_PATH/scripts/conf.js
527
-	echo '  apiPath: "/tt-rss/"' >> $RSS_MOBILE_READER_PATH/scripts/conf.js
528
-	echo '});' >> $RSS_MOBILE_READER_PATH/scripts/conf.js
529
-
530
-	# link to the main site
531
-	ln -s $RSS_READER_PATH $RSS_MOBILE_READER_PATH/tt-rss
532
-
533
-	chown -R www-data:www-data $RSS_MOBILE_READER_PATH
534
-	chown -R www-data:www-data $RSS_READER_PATH
535
-	chmod a+x $RSS_MOBILE_READER_PATH
536
-
537
-	echo 'install_rss_mobile_reader' >> $COMPLETION_FILE
503
+	    sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
504
+	    sed -i '/RSS mobile reader commit/d' $COMPLETION_FILE
505
+	    rm -rf $RSS_READER_PATH/g2ttree-mobile
506
+	fi
507
+    fi
508
+
509
+    if grep -Fxq "install_rss_mobile_reader" $COMPLETION_FILE; then
510
+	return
511
+    fi
512
+
513
+    cd /etc/share
514
+    function_check git_clone
515
+    git_clone $RSS_MOBILE_READER_REPO ttrss-mobile
516
+    if [ ! -d $RSS_MOBILE_READER_PATH ]; then
517
+	echo $'Could not clone RSS mobile reader repo'
518
+	exit 24816
519
+    fi
520
+    cd $RSS_MOBILE_READER_PATH
521
+    git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
522
+    if ! grep -q "RSS mobile reader commit" $COMPLETION_FILE; then
523
+	echo "RSS mobile reader commit:$RSS_MOBILE_READER_COMMIT" >> $COMPLETION_FILE
524
+    fi
525
+
526
+    echo 'define({' > $RSS_MOBILE_READER_PATH/scripts/conf.js
527
+    echo '  apiPath: "/tt-rss/"' >> $RSS_MOBILE_READER_PATH/scripts/conf.js
528
+    echo '});' >> $RSS_MOBILE_READER_PATH/scripts/conf.js
529
+
530
+    # link to the main site
531
+    ln -s $RSS_READER_PATH $RSS_MOBILE_READER_PATH/tt-rss
532
+
533
+    chown -R www-data:www-data $RSS_MOBILE_READER_PATH
534
+    chown -R www-data:www-data $RSS_READER_PATH
535
+    chmod a+x $RSS_MOBILE_READER_PATH
536
+
537
+    echo 'install_rss_mobile_reader' >> $COMPLETION_FILE
538 538
 }
539 539
 
540 540
 function install_rss {
541
-	if grep -Fxq "install_rss" $COMPLETION_FILE; then
542
-		return
543
-	fi
544
-	install_rss_main
545
-	install_rss_gnusocial
546
-	install_rss_mobile_reader
547
-	echo 'install_rss' >> $COMPLETION_FILE
541
+    if grep -Fxq "install_rss" $COMPLETION_FILE; then
542
+	return
543
+    fi
544
+    install_rss_main
545
+    install_rss_gnusocial
546
+    install_rss_mobile_reader
547
+    echo 'install_rss' >> $COMPLETION_FILE
548 548
 }
549 549
 
550 550
 # NOTE: deliberately no exit 0

+ 228
- 228
src/freedombone-app-searx Voir le fichier

@@ -43,254 +43,254 @@ function reconfigure_searx {
43 43
 }
44 44
 
45 45
 function upgrade_searx {
46
-	if ! grep -Fxq "install_searx" $COMPLETION_FILE; then
47
-		return
48
-	fi
49
-
50
-	set_repo_commit $SEARX_PATH/searx "Search engine commit" "$SEARX_COMMIT" $SEARX_REPO
51
-	if grep "Search engine key" $COMPLETION_FILE; then
52
-		if [ -f ${SEARX_PATH}/searx/searx/settings.yml ]; then
53
-			# note: this might change to a --tor option in a later version
54
-			if ! grep 'socks5://127.0.0.1:9050' ${SEARX_PATH}/searx/searx/settings.yml; then
55
-				echo 'outgoing: # communication with search engines' >> ${SEARX_PATH}/searx/searx/settings.yml
56
-				echo '    proxies:' >> ${SEARX_PATH}/searx/searx/settings.yml
57
-				echo '        http : socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
58
-				echo '        https: socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
59
-			fi
60
-			SEARX_SECRET_KEY=$(cat $COMPLETION_FILE | grep "Search engine key" | awk -F ':' '{print $2}')
61
-			sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings.yml
62
-			if [ -f /var/lib/tor/hidden_service_searx/hostname ]; then
63
-				SEARX_ONION_HOSTNAME=$(echo /var/lib/tor/hidden_service_searx/hostname)
64
-				sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings.yml
65
-			fi
66
-		fi
46
+    if ! grep -Fxq "install_searx" $COMPLETION_FILE; then
47
+	return
48
+    fi
49
+
50
+    set_repo_commit $SEARX_PATH/searx "Search engine commit" "$SEARX_COMMIT" $SEARX_REPO
51
+    if grep "Search engine key" $COMPLETION_FILE; then
52
+	if [ -f ${SEARX_PATH}/searx/searx/settings.yml ]; then
53
+	    # note: this might change to a --tor option in a later version
54
+	    if ! grep 'socks5://127.0.0.1:9050' ${SEARX_PATH}/searx/searx/settings.yml; then
55
+		echo 'outgoing: # communication with search engines' >> ${SEARX_PATH}/searx/searx/settings.yml
56
+		echo '    proxies:' >> ${SEARX_PATH}/searx/searx/settings.yml
57
+		echo '        http : socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
58
+		echo '        https: socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
59
+	    fi
60
+	    SEARX_SECRET_KEY=$(cat $COMPLETION_FILE | grep "Search engine key" | awk -F ':' '{print $2}')
61
+	    sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings.yml
62
+	    if [ -f /var/lib/tor/hidden_service_searx/hostname ]; then
63
+		SEARX_ONION_HOSTNAME=$(echo /var/lib/tor/hidden_service_searx/hostname)
64
+		sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings.yml
65
+	    fi
67 66
 	fi
67
+    fi
68 68
 }
69 69
 
70 70
 function backup_local_searx {
71
-	echo -n ''
71
+    echo -n ''
72 72
 }
73 73
 
74 74
 function restore_local_searx {
75
-	echo -n ''
75
+    echo -n ''
76 76
 }
77 77
 
78 78
 function backup_remote_searx {
79
-	echo -n ''
79
+    echo -n ''
80 80
 }
81 81
 
82 82
 function restore_remote_searx {
83
-	echo -n ''
83
+    echo -n ''
84 84
 }
85 85
 
86 86
 function remove_searx {
87
-	if ! grep -Fxq "install_searx" $COMPLETION_FILE; then
88
-		return
89
-	fi
90
-	systemctl stop searx
91
-	systemctl disable searx
92
-	rm /etc/systemd/system/searx.service
93
-	function_check remove_onion_service
94
-	remove_onion_service searx ${SEARX_ONION_PORT}
95
-	userdel -r searx
96
-	nginx_dissite searx
97
-	if [ -f /etc/nginx/sites-available/searx ]; then
98
-		rm /etc/nginx/sites-available/searx
99
-	fi
100
-	if [ -d ${SEARX_PATH}/searx ]; then
101
-		rm -rf ${SEARX_PATH}/searx
102
-	fi
103
-	sed -i '/install_searx/d' $COMPLETION_FILE
104
-	sed -i '/Search engine /d' $COMPLETION_FILE
87
+    if ! grep -Fxq "install_searx" $COMPLETION_FILE; then
88
+	return
89
+    fi
90
+    systemctl stop searx
91
+    systemctl disable searx
92
+    rm /etc/systemd/system/searx.service
93
+    function_check remove_onion_service
94
+    remove_onion_service searx ${SEARX_ONION_PORT}
95
+    userdel -r searx
96
+    nginx_dissite searx
97
+    if [ -f /etc/nginx/sites-available/searx ]; then
98
+	rm /etc/nginx/sites-available/searx
99
+    fi
100
+    if [ -d ${SEARX_PATH}/searx ]; then
101
+	rm -rf ${SEARX_PATH}/searx
102
+    fi
103
+    sed -i '/install_searx/d' $COMPLETION_FILE
104
+    sed -i '/Search engine /d' $COMPLETION_FILE
105 105
 }
106 106
 
107 107
 function install_searx {
108
-	# Note: currently socks5 outgoing proxies to other search engines does not work
109
-	if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
110
-		return
111
-	fi
112
-	if [ ! -d /etc/nginx ]; then
113
-		echo $'Webserver is not installed'
114
-		exit 62429
115
-	fi
116
-
117
-	if grep -Fxq "install_searx" $COMPLETION_FILE; then
118
-		return
108
+    # Note: currently socks5 outgoing proxies to other search engines does not work
109
+    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
110
+	return
111
+    fi
112
+    if [ ! -d /etc/nginx ]; then
113
+	echo $'Webserver is not installed'
114
+	exit 62429
115
+    fi
116
+
117
+    if grep -Fxq "install_searx" $COMPLETION_FILE; then
118
+	return
119
+    fi
120
+
121
+    apt-get -y install python-pip libyaml-dev python-werkzeug python-babel python-lxml apache2-utils
122
+    apt-get -y install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev uwsgi uwsgi-plugin-python libapache2-mod-uwsgi
123
+
124
+    pip install --upgrade pip
125
+
126
+    pip install certifi
127
+    if [ ! "$?" = "0" ]; then
128
+	echo $'Failed to install certifi'
129
+	exit 737692
130
+    fi
131
+
132
+    pip install pyyaml
133
+    if [ ! "$?" = "0" ]; then
134
+	echo $'Failed to install pyyaml'
135
+	exit 469242
136
+    fi
137
+
138
+    pip install flask --upgrade
139
+    if [ ! "$?" = "0" ]; then
140
+	echo $'Failed to install flask'
141
+	exit 888575
142
+    fi
143
+
144
+    pip install flask_restless --upgrade
145
+    if [ ! "$?" = "0" ]; then
146
+	echo $'Failed to install flask_restless'
147
+	exit 54835
148
+    fi
149
+
150
+    pip install flask_babel --upgrade
151
+    if [ ! "$?" = "0" ]; then
152
+	echo $'Failed to install flask_babel'
153
+	exit 63738
154
+    fi
155
+
156
+    if [ ! -d $SEARX_PATH ]; then
157
+	mkdir -p $SEARX_PATH
158
+    fi
159
+
160
+    # clone the repo
161
+    cd $SEARX_PATH
162
+    function_check git_clone
163
+    git_clone $SEARX_REPO searx
164
+    git checkout $SEARX_COMMIT -b $SEARX_COMMIT
165
+    if ! grep -q "Search engine commit" $COMPLETION_FILE; then
166
+	echo "Search engine commit:$SEARX_COMMIT" >> $COMPLETION_FILE
167
+    else
168
+	sed -i "s/Search engine commit.*/Search engine commit:$SEARX_COMMIT/g" $COMPLETION_FILE
169
+    fi
170
+
171
+    # create an onion service
172
+    SEARX_ONION_HOSTNAME=$(add_onion_service searx 80 ${SEARX_ONION_PORT})
173
+    if ! grep "Search engine onion domain" $COMPLETION_FILE; then
174
+	echo "Search engine onion domain:${SEARX_ONION_HOSTNAME}" >> $COMPLETION_FILE
175
+    else
176
+	sed -i "s|Search engine onion domain.*|Search engine onion domain:${SEARX_ONION_HOSTNAME}|g" $COMPLETION_FILE
177
+    fi
178
+
179
+    # an unprivileged user to run as
180
+    useradd -d ${SEARX_PATH}/searx/ -s /bin/false searx
181
+    adduser searx debian-tor
182
+
183
+    # daemon
184
+    echo '[Unit]' > /etc/systemd/system/searx.service
185
+    echo 'Description=Searx (search engine)' >> /etc/systemd/system/searx.service
186
+    echo 'After=syslog.target' >> /etc/systemd/system/searx.service
187
+    echo 'After=network.target' >> /etc/systemd/system/searx.service
188
+    echo '' >> /etc/systemd/system/searx.service
189
+    echo '[Service]' >> /etc/systemd/system/searx.service
190
+    echo 'Type=simple' >> /etc/systemd/system/searx.service
191
+    echo 'User=searx' >> /etc/systemd/system/searx.service
192
+    echo 'Group=searx' >> /etc/systemd/system/searx.service
193
+    echo "WorkingDirectory=${SEARX_PATH}/searx" >> /etc/systemd/system/searx.service
194
+    echo "ExecStart=/usr/bin/python ${SEARX_PATH}/searx/searx/webapp.py" >> /etc/systemd/system/searx.service
195
+    echo 'Restart=always' >> /etc/systemd/system/searx.service
196
+    echo 'Environment="USER=searx"' >> /etc/systemd/system/searx.service
197
+    echo '' >> /etc/systemd/system/searx.service
198
+    echo '[Install]' >> /etc/systemd/system/searx.service
199
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/searx.service
200
+
201
+    # create a webserver file
202
+    echo 'server {' > /etc/nginx/sites-available/searx
203
+    echo "    listen 127.0.0.1:${SEARX_ONION_PORT} default_server;" >> /etc/nginx/sites-available/searx
204
+    echo "    root ${SEARX_PATH}/searx;" >> /etc/nginx/sites-available/searx
205
+    echo "    server_name ${SEARX_ONION_HOSTNAME};" >> /etc/nginx/sites-available/searx
206
+    echo '    access_log off;' >> /etc/nginx/sites-available/searx
207
+    echo "    error_log /var/log/searx_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/searx
208
+    echo '' >> /etc/nginx/sites-available/searx
209
+    function_check nginx_limits
210
+    nginx_limits searx '1M'
211
+    function_check nginx_disable_sniffing
212
+    nginx_disable_sniffing searx
213
+    echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/searx
214
+    echo '' >> /etc/nginx/sites-available/searx
215
+    echo '    location / {' >> /etc/nginx/sites-available/searx
216
+    echo '        proxy_pass http://localhost:8888;' >> /etc/nginx/sites-available/searx
217
+    echo '        proxy_set_header Host $host;' >> /etc/nginx/sites-available/searx
218
+    echo '        proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/searx
219
+    echo '        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/searx
220
+    echo '        proxy_set_header X-Remote-Port $remote_port;' >> /etc/nginx/sites-available/searx
221
+    echo '        proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/searx
222
+    echo '        proxy_redirect off;' >> /etc/nginx/sites-available/searx
223
+
224
+    echo "        auth_basic \"${SEARX_LOGIN_TEXT}\";" >> /etc/nginx/sites-available/searx
225
+    echo '        auth_basic_user_file /etc/nginx/.htpasswd;' >> /etc/nginx/sites-available/searx
226
+    echo '    }' >> /etc/nginx/sites-available/searx
227
+    echo '' >> /etc/nginx/sites-available/searx
228
+    echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/searx
229
+    echo '' >> /etc/nginx/sites-available/searx
230
+    echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/searx
231
+    echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/searx
232
+    echo '' >> /etc/nginx/sites-available/searx
233
+    echo '    location = /robots.txt {' >> /etc/nginx/sites-available/searx
234
+    echo '        allow all;' >> /etc/nginx/sites-available/searx
235
+    echo '        log_not_found off;' >> /etc/nginx/sites-available/searx
236
+    echo '        access_log off;' >> /etc/nginx/sites-available/searx
237
+    echo '    }' >> /etc/nginx/sites-available/searx
238
+    echo '}' >> /etc/nginx/sites-available/searx
239
+
240
+    # replace the secret key
241
+    if ! grep "Search engine key" $COMPLETION_FILE; then
242
+	SEARX_SECRET_KEY="$(create_password 30)"
243
+	echo "Search engine key:${SEARX_SECRET_KEY}" >> $COMPLETION_FILE
244
+    else
245
+	SEARX_SECRET_KEY=$(cat $COMPLETION_FILE | grep "Search engine key" | awk -F ':' '{print $2}')
246
+    fi
247
+    sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings.yml
248
+    sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings_robot.yml
249
+    sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings.yml
250
+    sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings_robot.yml
251
+
252
+    # note: this might change to a --tor option in a later version
253
+    if ! grep 'socks5://127.0.0.1:9050' ${SEARX_PATH}/searx/searx/settings.yml; then
254
+	echo 'outgoing: # communication with search engines' >> ${SEARX_PATH}/searx/searx/settings.yml
255
+	echo '    proxies:' >> ${SEARX_PATH}/searx/searx/settings.yml
256
+	echo '        http : socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
257
+	echo '        https: socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
258
+    fi
259
+
260
+    chown -R searx:searx ${SEARX_PATH}/searx
261
+
262
+    # enable the site
263
+    nginx_ensite searx
264
+
265
+    # restart the web server
266
+    systemctl restart php5-fpm
267
+    systemctl restart nginx
268
+
269
+    # start the daemon
270
+    systemctl enable searx.service
271
+    systemctl daemon-reload
272
+    systemctl start searx.service
273
+
274
+    if ! grep -q "Your search engine password is" /home/$MY_USERNAME/README; then
275
+	if [ ${#SEARX_PASSWORD} -lt 8 ]; then
276
+	    if [ -f $IMAGE_PASSWORD_FILE ]; then
277
+		SEARX_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
278
+	    else
279
+		SEARX_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
280
+	    fi
119 281
 	fi
120
-
121
-	apt-get -y install python-pip libyaml-dev python-werkzeug python-babel python-lxml apache2-utils
122
-	apt-get -y install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev uwsgi uwsgi-plugin-python libapache2-mod-uwsgi
123
-
124
-	pip install --upgrade pip
125
-
126
-	pip install certifi
127
-	if [ ! "$?" = "0" ]; then
128
-		echo $'Failed to install certifi'
129
-		exit 737692
130
-	fi
131
-
132
-	pip install pyyaml
133
-	if [ ! "$?" = "0" ]; then
134
-		echo $'Failed to install pyyaml'
135
-		exit 469242
136
-	fi
137
-
138
-	pip install flask --upgrade
139
-	if [ ! "$?" = "0" ]; then
140
-		echo $'Failed to install flask'
141
-		exit 888575
142
-	fi
143
-
144
-	pip install flask_restless --upgrade
145
-	if [ ! "$?" = "0" ]; then
146
-		echo $'Failed to install flask_restless'
147
-		exit 54835
148
-	fi
149
-
150
-	pip install flask_babel --upgrade
151
-	if [ ! "$?" = "0" ]; then
152
-		echo $'Failed to install flask_babel'
153
-		exit 63738
154
-	fi
155
-
156
-	if [ ! -d $SEARX_PATH ]; then
157
-		mkdir -p $SEARX_PATH
158
-	fi
159
-
160
-	# clone the repo
161
-	cd $SEARX_PATH
162
-	function_check git_clone
163
-	git_clone $SEARX_REPO searx
164
-	git checkout $SEARX_COMMIT -b $SEARX_COMMIT
165
-	if ! grep -q "Search engine commit" $COMPLETION_FILE; then
166
-		echo "Search engine commit:$SEARX_COMMIT" >> $COMPLETION_FILE
167
-	else
168
-		sed -i "s/Search engine commit.*/Search engine commit:$SEARX_COMMIT/g" $COMPLETION_FILE
169
-	fi
170
-
171
-	# create an onion service
172
-	SEARX_ONION_HOSTNAME=$(add_onion_service searx 80 ${SEARX_ONION_PORT})
173
-	if ! grep "Search engine onion domain" $COMPLETION_FILE; then
174
-		echo "Search engine onion domain:${SEARX_ONION_HOSTNAME}" >> $COMPLETION_FILE
175
-	else
176
-		sed -i "s|Search engine onion domain.*|Search engine onion domain:${SEARX_ONION_HOSTNAME}|g" $COMPLETION_FILE
177
-	fi
178
-
179
-	# an unprivileged user to run as
180
-	useradd -d ${SEARX_PATH}/searx/ -s /bin/false searx
181
-	adduser searx debian-tor
182
-
183
-	# daemon
184
-	echo '[Unit]' > /etc/systemd/system/searx.service
185
-	echo 'Description=Searx (search engine)' >> /etc/systemd/system/searx.service
186
-	echo 'After=syslog.target' >> /etc/systemd/system/searx.service
187
-	echo 'After=network.target' >> /etc/systemd/system/searx.service
188
-	echo '' >> /etc/systemd/system/searx.service
189
-	echo '[Service]' >> /etc/systemd/system/searx.service
190
-	echo 'Type=simple' >> /etc/systemd/system/searx.service
191
-	echo 'User=searx' >> /etc/systemd/system/searx.service
192
-	echo 'Group=searx' >> /etc/systemd/system/searx.service
193
-	echo "WorkingDirectory=${SEARX_PATH}/searx" >> /etc/systemd/system/searx.service
194
-	echo "ExecStart=/usr/bin/python ${SEARX_PATH}/searx/searx/webapp.py" >> /etc/systemd/system/searx.service
195
-	echo 'Restart=always' >> /etc/systemd/system/searx.service
196
-	echo 'Environment="USER=searx"' >> /etc/systemd/system/searx.service
197
-	echo '' >> /etc/systemd/system/searx.service
198
-	echo '[Install]' >> /etc/systemd/system/searx.service
199
-	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/searx.service
200
-
201
-	# create a webserver file
202
-	echo 'server {' > /etc/nginx/sites-available/searx
203
-	echo "    listen 127.0.0.1:${SEARX_ONION_PORT} default_server;" >> /etc/nginx/sites-available/searx
204
-	echo "    root ${SEARX_PATH}/searx;" >> /etc/nginx/sites-available/searx
205
-	echo "    server_name ${SEARX_ONION_HOSTNAME};" >> /etc/nginx/sites-available/searx
206
-	echo '    access_log off;' >> /etc/nginx/sites-available/searx
207
-	echo "    error_log /var/log/searx_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/searx
208
-	echo '' >> /etc/nginx/sites-available/searx
209
-	function_check nginx_limits
210
-	nginx_limits searx '1M'
211
-	function_check nginx_disable_sniffing
212
-	nginx_disable_sniffing searx
213
-	echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/searx
214
-	echo '' >> /etc/nginx/sites-available/searx
215
-	echo '    location / {' >> /etc/nginx/sites-available/searx
216
-	echo '        proxy_pass http://localhost:8888;' >> /etc/nginx/sites-available/searx
217
-	echo '        proxy_set_header Host $host;' >> /etc/nginx/sites-available/searx
218
-	echo '        proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/searx
219
-	echo '        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/searx
220
-	echo '        proxy_set_header X-Remote-Port $remote_port;' >> /etc/nginx/sites-available/searx
221
-	echo '        proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/searx
222
-	echo '        proxy_redirect off;' >> /etc/nginx/sites-available/searx
223
-
224
-	echo "        auth_basic \"${SEARX_LOGIN_TEXT}\";" >> /etc/nginx/sites-available/searx
225
-	echo '        auth_basic_user_file /etc/nginx/.htpasswd;' >> /etc/nginx/sites-available/searx
226
-	echo '    }' >> /etc/nginx/sites-available/searx
227
-	echo '' >> /etc/nginx/sites-available/searx
228
-	echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/searx
229
-	echo '' >> /etc/nginx/sites-available/searx
230
-	echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/searx
231
-	echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/searx
232
-	echo '' >> /etc/nginx/sites-available/searx
233
-	echo '    location = /robots.txt {' >> /etc/nginx/sites-available/searx
234
-	echo '        allow all;' >> /etc/nginx/sites-available/searx
235
-	echo '        log_not_found off;' >> /etc/nginx/sites-available/searx
236
-	echo '        access_log off;' >> /etc/nginx/sites-available/searx
237
-	echo '    }' >> /etc/nginx/sites-available/searx
238
-	echo '}' >> /etc/nginx/sites-available/searx
239
-
240
-	# replace the secret key
241
-	if ! grep "Search engine key" $COMPLETION_FILE; then
242
-		SEARX_SECRET_KEY="$(create_password 30)"
243
-		echo "Search engine key:${SEARX_SECRET_KEY}" >> $COMPLETION_FILE
244
-	else
245
-		SEARX_SECRET_KEY=$(cat $COMPLETION_FILE | grep "Search engine key" | awk -F ':' '{print $2}')
246
-	fi
247
-	sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings.yml
248
-	sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings_robot.yml
249
-	sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings.yml
250
-	sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings_robot.yml
251
-
252
-	# note: this might change to a --tor option in a later version
253
-	if ! grep 'socks5://127.0.0.1:9050' ${SEARX_PATH}/searx/searx/settings.yml; then
254
-		echo 'outgoing: # communication with search engines' >> ${SEARX_PATH}/searx/searx/settings.yml
255
-		echo '    proxies:' >> ${SEARX_PATH}/searx/searx/settings.yml
256
-		echo '        http : socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
257
-		echo '        https: socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
258
-	fi
259
-
260
-	chown -R searx:searx ${SEARX_PATH}/searx
261
-
262
-	# enable the site
263
-	nginx_ensite searx
264
-
265
-	# restart the web server
266
-	systemctl restart php5-fpm
267
-	systemctl restart nginx
268
-
269
-	# start the daemon
270
-	systemctl enable searx.service
271
-	systemctl daemon-reload
272
-	systemctl start searx.service
273
-
274
-	if ! grep -q "Your search engine password is" /home/$MY_USERNAME/README; then
275
-		if [ ${#SEARX_PASSWORD} -lt 8 ]; then
276
-			if [ -f $IMAGE_PASSWORD_FILE ]; then
277
-				SEARX_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
278
-			else
279
-				SEARX_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
280
-			fi
281
-		fi
282
-		echo "$SEARX_PASSWORD" | htpasswd -i -s -c /etc/nginx/.htpasswd $MY_USERNAME
283
-		echo '' >> /home/$MY_USERNAME/README
284
-		echo '' >> /home/$MY_USERNAME/README
285
-		echo $'Search Engine' >> /home/$MY_USERNAME/README
286
-		echo '=============' >> /home/$MY_USERNAME/README
287
-		echo $"Search engine onion domain: ${SEARX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
288
-		echo $"Your search engine password is: $SEARX_PASSWORD" >> /home/$MY_USERNAME/README
289
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
290
-		chmod 600 /home/$MY_USERNAME/README
291
-	fi
292
-
293
-	echo 'install_searx' >> $COMPLETION_FILE
282
+	echo "$SEARX_PASSWORD" | htpasswd -i -s -c /etc/nginx/.htpasswd $MY_USERNAME
283
+	echo '' >> /home/$MY_USERNAME/README
284
+	echo '' >> /home/$MY_USERNAME/README
285
+	echo $'Search Engine' >> /home/$MY_USERNAME/README
286
+	echo '=============' >> /home/$MY_USERNAME/README
287
+	echo $"Search engine onion domain: ${SEARX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
288
+	echo $"Your search engine password is: $SEARX_PASSWORD" >> /home/$MY_USERNAME/README
289
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
290
+	chmod 600 /home/$MY_USERNAME/README
291
+    fi
292
+
293
+    echo 'install_searx' >> $COMPLETION_FILE
294 294
 }
295 295
 
296 296
 # NOTE: deliberately no exit 0

+ 361
- 361
src/freedombone-app-sip Voir le fichier

@@ -38,415 +38,415 @@ VOIP_TURN_TLS_PORT=5349
38 38
 VOIP_TURN_NONCE=
39 39
 
40 40
 function reconfigure_sip {
41
-	echo -n ''
41
+    echo -n ''
42 42
 }
43 43
 
44 44
 function upgrade_sip {
45
-	# remove the original sipwitch daemon if it exists
46
-	if [ -f /etc/init.d/sipwitch ]; then
47
-		rm -f /etc/init.d/sipwitch
48
-	fi
45
+    # remove the original sipwitch daemon if it exists
46
+    if [ -f /etc/init.d/sipwitch ]; then
47
+	rm -f /etc/init.d/sipwitch
48
+    fi
49 49
 }
50 50
 
51 51
 function backup_local_sip {
52
-	if [ -f /etc/sipwitch.conf ]; then
53
-		echo $"Backing up SIP settings"
54
-		temp_backup_dir=/root/tempsipbackup
55
-		if [ ! -d $temp_backup_dir ]; then
56
-			mkdir -p $temp_backup_dir
57
-		fi
58
-		cp -f /etc/sipwitch.conf $temp_backup_dir
59
-		backup_directory_to_usb $temp_backup_dir sip
60
-		echo $"SIP settings backup complete"
52
+    if [ -f /etc/sipwitch.conf ]; then
53
+	echo $"Backing up SIP settings"
54
+	temp_backup_dir=/root/tempsipbackup
55
+	if [ ! -d $temp_backup_dir ]; then
56
+	    mkdir -p $temp_backup_dir
61 57
 	fi
58
+	cp -f /etc/sipwitch.conf $temp_backup_dir
59
+	backup_directory_to_usb $temp_backup_dir sip
60
+	echo $"SIP settings backup complete"
61
+    fi
62 62
 }
63 63
 
64 64
 function restore_local_sip {
65
-	if [ -d $USB_MOUNT/backup/sip ]; then
66
-		echo $"Restoring SIP settings"
67
-		temp_restore_dir=/root/tempsip
68
-		function_check restore_directory_from_usb
69
-		restore_directory_from_usb $temp_restore_dir sip
70
-		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
71
-		if [ ! "$?" = "0" ]; then
72
-			rm -rf $temp_restore_dir
73
-			function_check set_user_permissions
74
-			set_user_permissions
75
-			backup_unmount_drive
76
-			exit 3679
77
-		fi
78
-		rm -rf $temp_restore_dir
79
-		service sipwitch restart
80
-		echo $"Restore of SIP settings complete"
65
+    if [ -d $USB_MOUNT/backup/sip ]; then
66
+	echo $"Restoring SIP settings"
67
+	temp_restore_dir=/root/tempsip
68
+	function_check restore_directory_from_usb
69
+	restore_directory_from_usb $temp_restore_dir sip
70
+	cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
71
+	if [ ! "$?" = "0" ]; then
72
+	    rm -rf $temp_restore_dir
73
+	    function_check set_user_permissions
74
+	    set_user_permissions
75
+	    backup_unmount_drive
76
+	    exit 3679
81 77
 	fi
78
+	rm -rf $temp_restore_dir
79
+	service sipwitch restart
80
+	echo $"Restore of SIP settings complete"
81
+    fi
82 82
 }
83 83
 
84 84
 function backup_remote_sip {
85
-	if [ -f /etc/sipwitch.conf ]; then
86
-		echo $"Backing up SIP settings"
87
-		temp_backup_dir=/root/tempsipbackup
88
-		if [ ! -d $temp_backup_dir ]; then
89
-			mkdir -p $temp_backup_dir
90
-		fi
91
-		cp -f /etc/sipwitch.conf $temp_backup_dir
92
-		backup_directory_to_friend $temp_backup_dir sip
93
-		echo $"Backup SIP settings complete"
85
+    if [ -f /etc/sipwitch.conf ]; then
86
+	echo $"Backing up SIP settings"
87
+	temp_backup_dir=/root/tempsipbackup
88
+	if [ ! -d $temp_backup_dir ]; then
89
+	    mkdir -p $temp_backup_dir
94 90
 	fi
91
+	cp -f /etc/sipwitch.conf $temp_backup_dir
92
+	backup_directory_to_friend $temp_backup_dir sip
93
+	echo $"Backup SIP settings complete"
94
+    fi
95 95
 }
96 96
 
97 97
 function restore_remote_sip {
98
-	echo -n ''
98
+    echo -n ''
99 99
 }
100 100
 
101 101
 function remove_sip {
102
-	if ! grep -Fxq "install_sip" $COMPLETION_FILE; then
103
-		return
104
-	fi
105
-	iptables -D INPUT -p udp --dport $VOIP_TURN_PORT -j ACCEPT
106
-	iptables -D INPUT -p tcp --dport $VOIP_TURN_PORT -j ACCEPT
107
-	iptables -D INPUT -p tcp --dport $VOIP_TURN_TLS_PORT -j ACCEPT
108
-	iptables -D INPUT -p udp --dport $SIP_PORT -j ACCEPT
109
-	iptables -D INPUT -p tcp --dport $SIP_PORT -j ACCEPT
110
-	iptables -D INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
111
-	iptables -D INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
112
-	function_check save_firewall_settings
113
-	save_firewall_settings
114
-
115
-	function_check remove_onion_service
116
-	remove_onion_service sip ${SIP_PORT}
117
-
118
-	apt-get -y remove --purge sipwitch
119
-	apt-get -y remove --purge turnserver
120
-	if [ -f /etc/sipwitch.conf ]; then
121
-		rm /etc/sipwitch.conf
122
-	fi
123
-	if [ -d /etc/turnserver ]; then
124
-		rm -rf /etc/turnserver
125
-	fi
126
-	sed -i '/install_sip/d' $COMPLETION_FILE
127
-	sed -i '/configure_firewall_for_voip_turn/d' $COMPLETION_FILE
128
-	sed -i '/configure_firewall_for_sip4/d' $COMPLETION_FILE
102
+    if ! grep -Fxq "install_sip" $COMPLETION_FILE; then
103
+	return
104
+    fi
105
+    iptables -D INPUT -p udp --dport $VOIP_TURN_PORT -j ACCEPT
106
+    iptables -D INPUT -p tcp --dport $VOIP_TURN_PORT -j ACCEPT
107
+    iptables -D INPUT -p tcp --dport $VOIP_TURN_TLS_PORT -j ACCEPT
108
+    iptables -D INPUT -p udp --dport $SIP_PORT -j ACCEPT
109
+    iptables -D INPUT -p tcp --dport $SIP_PORT -j ACCEPT
110
+    iptables -D INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
111
+    iptables -D INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
112
+    function_check save_firewall_settings
113
+    save_firewall_settings
114
+
115
+    function_check remove_onion_service
116
+    remove_onion_service sip ${SIP_PORT}
117
+
118
+    apt-get -y remove --purge sipwitch
119
+    apt-get -y remove --purge turnserver
120
+    if [ -f /etc/sipwitch.conf ]; then
121
+	rm /etc/sipwitch.conf
122
+    fi
123
+    if [ -d /etc/turnserver ]; then
124
+	rm -rf /etc/turnserver
125
+    fi
126
+    sed -i '/install_sip/d' $COMPLETION_FILE
127
+    sed -i '/configure_firewall_for_voip_turn/d' $COMPLETION_FILE
128
+    sed -i '/configure_firewall_for_sip4/d' $COMPLETION_FILE
129 129
 }
130 130
 
131 131
 function configure_firewall_for_voip_turn {
132
-	if grep -Fxq "configure_firewall_for_voip_turn" $COMPLETION_FILE; then
133
-		return
134
-	fi
135
-	if [[ $ONION_ONLY != "no" ]]; then
136
-		return
137
-	fi
138
-	iptables -A INPUT -p udp --dport $VOIP_TURN_PORT -j ACCEPT
139
-	iptables -A INPUT -p tcp --dport $VOIP_TURN_PORT -j ACCEPT
140
-	iptables -A INPUT -p tcp --dport $VOIP_TURN_TLS_PORT -j ACCEPT
141
-	function_check save_firewall_settings
142
-	save_firewall_settings
143
-
144
-	OPEN_PORTS+=("TURN     $VOIP_TURN_PORT")
145
-	OPEN_PORTS+=("TURN TLS $VOIP_TURN_TLS_PORT")
146
-	echo 'configure_firewall_for_voip_turn' >> $COMPLETION_FILE
132
+    if grep -Fxq "configure_firewall_for_voip_turn" $COMPLETION_FILE; then
133
+	return
134
+    fi
135
+    if [[ $ONION_ONLY != "no" ]]; then
136
+	return
137
+    fi
138
+    iptables -A INPUT -p udp --dport $VOIP_TURN_PORT -j ACCEPT
139
+    iptables -A INPUT -p tcp --dport $VOIP_TURN_PORT -j ACCEPT
140
+    iptables -A INPUT -p tcp --dport $VOIP_TURN_TLS_PORT -j ACCEPT
141
+    function_check save_firewall_settings
142
+    save_firewall_settings
143
+
144
+    OPEN_PORTS+=("TURN     $VOIP_TURN_PORT")
145
+    OPEN_PORTS+=("TURN TLS $VOIP_TURN_TLS_PORT")
146
+    echo 'configure_firewall_for_voip_turn' >> $COMPLETION_FILE
147 147
 }
148 148
 
149 149
 
150 150
 function configure_firewall_for_sip4 {
151
-	if grep -Fxq "configure_firewall_for_sip4" $COMPLETION_FILE; then
152
-		return
153
-	fi
154
-	if [[ $ONION_ONLY != "no" ]]; then
155
-		return
156
-	fi
157
-	iptables -A INPUT -p udp --dport $SIP_PORT -j ACCEPT
158
-	iptables -A INPUT -p tcp --dport $SIP_PORT -j ACCEPT
159
-	iptables -A INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
160
-	iptables -A INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
161
-	function_check save_firewall_settings
162
-	save_firewall_settings
163
-
164
-	OPEN_PORTS+=("SIP      $SIP_PORT")
165
-	OPEN_PORTS+=("SIP TLS  $SIP_TLS_PORT")
166
-	echo 'configure_firewall_for_sip4' >> $COMPLETION_FILE
151
+    if grep -Fxq "configure_firewall_for_sip4" $COMPLETION_FILE; then
152
+	return
153
+    fi
154
+    if [[ $ONION_ONLY != "no" ]]; then
155
+	return
156
+    fi
157
+    iptables -A INPUT -p udp --dport $SIP_PORT -j ACCEPT
158
+    iptables -A INPUT -p tcp --dport $SIP_PORT -j ACCEPT
159
+    iptables -A INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
160
+    iptables -A INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
161
+    function_check save_firewall_settings
162
+    save_firewall_settings
163
+
164
+    OPEN_PORTS+=("SIP      $SIP_PORT")
165
+    OPEN_PORTS+=("SIP TLS  $SIP_TLS_PORT")
166
+    echo 'configure_firewall_for_sip4' >> $COMPLETION_FILE
167 167
 }
168 168
 
169 169
 function get_sip_server_password {
170
-	if [ -f /home/$MY_USERNAME/README ]; then
171
-		if grep -q "SIP server password" /home/$MY_USERNAME/README; then
172
-			if [ ! $SIP_SERVER_PASSWORD ]; then
173
-				SIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "SIP server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
174
-			fi
175
-		fi
170
+    if [ -f /home/$MY_USERNAME/README ]; then
171
+	if grep -q "SIP server password" /home/$MY_USERNAME/README; then
172
+	    if [ ! $SIP_SERVER_PASSWORD ]; then
173
+		SIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "SIP server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
174
+	    fi
176 175
 	fi
176
+    fi
177 177
 }
178 178
 
179 179
 function update_sipwitch_daemon {
180
-	if [ ! -f /etc/init.d/sipwitch ]; then
181
-		return
182
-	fi
183
-	service sipwitch stop
184
-
185
-	# remove the original sipwitch daemon if it exists
186
-	if [ -f /etc/init.d/sipwitch ]; then
187
-		rm -f /etc/init.d/sipwitch
188
-	fi
189
-
190
-	# daemon
191
-	echo '[Unit]' > /etc/systemd/system/sipwitch.service
192
-	echo 'Description=GNU SIP Witch, a SIP telephony service daemon.' >> /etc/systemd/system/sipwitch.service
193
-	echo 'After=network.target' >> /etc/systemd/system/sipwitch.service
194
-	echo '' >> /etc/systemd/system/sipwitch.service
195
-	echo '[Service]' >> /etc/systemd/system/sipwitch.service
196
-	echo 'Type=simple' >> /etc/systemd/system/sipwitch.service
197
-	echo 'Group=sipwitch' >> /etc/systemd/system/sipwitch.service
198
-	echo 'PIDFile=/var/run/sipwitch/pidfile' >> /etc/systemd/system/sipwitch.service
199
-	echo 'EnvironmentFile=-/etc/conf.d/sipwitch' >> /etc/systemd/system/sipwitch.service
200
-	echo 'EnvironmentFile=-/etc/sipwitch.conf' >> /etc/systemd/system/sipwitch.service
201
-	echo 'EnvironmentFile=-/etc/default/sipwitch' >> /etc/systemd/system/sipwitch.service
202
-	echo 'ExecStartPre=-/bin/rm -f /var/run/sipwitch/control' >> /etc/systemd/system/sipwitch.service
203
-	echo "ExecStart=/usr/sbin/sipw -f \$OPTIONS -P$SIP_PORT" >> /etc/systemd/system/sipwitch.service
204
-	echo 'Restart=always' >> /etc/systemd/system/sipwitch.service
205
-	echo 'NotifyAccess=main' >> /etc/systemd/system/sipwitch.service
206
-	echo '' >> /etc/systemd/system/sipwitch.service
207
-	echo '[Install]' >> /etc/systemd/system/sipwitch.service
208
-	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/sipwitch.service
209
-
210
-	systemctl enable sipwitch
211
-	systemctl daemon-reload
212
-	systemctl start sipwitch
180
+    if [ ! -f /etc/init.d/sipwitch ]; then
181
+	return
182
+    fi
183
+    service sipwitch stop
184
+
185
+    # remove the original sipwitch daemon if it exists
186
+    if [ -f /etc/init.d/sipwitch ]; then
187
+	rm -f /etc/init.d/sipwitch
188
+    fi
189
+
190
+    # daemon
191
+    echo '[Unit]' > /etc/systemd/system/sipwitch.service
192
+    echo 'Description=GNU SIP Witch, a SIP telephony service daemon.' >> /etc/systemd/system/sipwitch.service
193
+    echo 'After=network.target' >> /etc/systemd/system/sipwitch.service
194
+    echo '' >> /etc/systemd/system/sipwitch.service
195
+    echo '[Service]' >> /etc/systemd/system/sipwitch.service
196
+    echo 'Type=simple' >> /etc/systemd/system/sipwitch.service
197
+    echo 'Group=sipwitch' >> /etc/systemd/system/sipwitch.service
198
+    echo 'PIDFile=/var/run/sipwitch/pidfile' >> /etc/systemd/system/sipwitch.service
199
+    echo 'EnvironmentFile=-/etc/conf.d/sipwitch' >> /etc/systemd/system/sipwitch.service
200
+    echo 'EnvironmentFile=-/etc/sipwitch.conf' >> /etc/systemd/system/sipwitch.service
201
+    echo 'EnvironmentFile=-/etc/default/sipwitch' >> /etc/systemd/system/sipwitch.service
202
+    echo 'ExecStartPre=-/bin/rm -f /var/run/sipwitch/control' >> /etc/systemd/system/sipwitch.service
203
+    echo "ExecStart=/usr/sbin/sipw -f \$OPTIONS -P$SIP_PORT" >> /etc/systemd/system/sipwitch.service
204
+    echo 'Restart=always' >> /etc/systemd/system/sipwitch.service
205
+    echo 'NotifyAccess=main' >> /etc/systemd/system/sipwitch.service
206
+    echo '' >> /etc/systemd/system/sipwitch.service
207
+    echo '[Install]' >> /etc/systemd/system/sipwitch.service
208
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/sipwitch.service
209
+
210
+    systemctl enable sipwitch
211
+    systemctl daemon-reload
212
+    systemctl start sipwitch
213 213
 }
214 214
 
215 215
 function install_sip_main {
216
-	if grep -Fxq "install_sip_main" $COMPLETION_FILE; then
217
-		return
218
-	fi
216
+    if grep -Fxq "install_sip_main" $COMPLETION_FILE; then
217
+	return
218
+    fi
219 219
 
220
-	apt-get -y install sipwitch
220
+    apt-get -y install sipwitch
221 221
 
222
-	function_check get_sip_server_password
223
-	get_sip_server_password
224
-	if [ ! $SIP_SERVER_PASSWORD ]; then
225
-		if [ -f $IMAGE_PASSWORD_FILE ]; then
226
-			SIP_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
227
-		else
228
-			SIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
229
-		fi
230
-	fi
231
-
232
-	echo '<?xml version="1.0"?>' > /etc/sipwitch.conf
233
-	echo '<sipwitch>' >> /etc/sipwitch.conf
234
-	echo '<provision>' >> /etc/sipwitch.conf
235
-
236
-	echo "<user id=\"$MY_USERNAME\">" >> /etc/sipwitch.conf
237
-	echo '<extension>201</extension>' >> /etc/sipwitch.conf
238
-	echo "<secret>$SIP_SERVER_PASSWORD</secret>" >> /etc/sipwitch.conf
239
-	echo "<display>$MY_USERNAME 201</display>" >> /etc/sipwitch.conf
240
-	echo '</user>' >> /etc/sipwitch.conf
241
-
242
-	echo '</provision>' >> /etc/sipwitch.conf
243
-	echo '<access>' >> /etc/sipwitch.conf
244
-	echo '</access>' >> /etc/sipwitch.conf
245
-	echo '<stack>' >> /etc/sipwitch.conf
246
-	echo "  <localnames>$DEFAULT_DOMAIN_NAME</localnames>" >> /etc/sipwitch.conf
247
-	echo '  <mapped>200</mapped>' >> /etc/sipwitch.conf
248
-	echo '  <threading>2</threading>' >> /etc/sipwitch.conf
249
-	echo '  <interface>*</interface>' >> /etc/sipwitch.conf
250
-	echo '  <dumping>false</dumping>' >> /etc/sipwitch.conf
251
-	echo '  <system>system</system>' >> /etc/sipwitch.conf
252
-	echo '  <anon>anonymous</anon>' >> /etc/sipwitch.conf
253
-	echo '</stack>' >> /etc/sipwitch.conf
254
-	echo '<timers>' >> /etc/sipwitch.conf
255
-	echo '  <!-- ring every 4 seconds -->' >> /etc/sipwitch.conf
256
-	echo '  <ring>4</ring>' >> /etc/sipwitch.conf
257
-	echo '  <!-- call forward no answer after x rings -->' >> /etc/sipwitch.conf
258
-	echo '  <cfna>4</cfna>' >> /etc/sipwitch.conf
259
-	echo '  <!-- call reset to clear cid in stack, 6 seconds -->' >> /etc/sipwitch.conf
260
-	echo '  <reset>6</reset>' >> /etc/sipwitch.conf
261
-	echo '</timers>' >> /etc/sipwitch.conf
262
-	echo '<!-- we have 2xx numbers plus space for external users -->' >> /etc/sipwitch.conf
263
-	echo '<registry>' >> /etc/sipwitch.conf
264
-	echo '  <prefix>200</prefix>' >> /etc/sipwitch.conf
265
-	echo '  <range>100</range>' >> /etc/sipwitch.conf
266
-	echo '  <keysize>77</keysize>' >> /etc/sipwitch.conf
267
-	echo '  <mapped>200</mapped>' >> /etc/sipwitch.conf
268
-	echo '  <!-- <realm>GNU Telephony</realm> -->' >> /etc/sipwitch.conf
269
-	echo '</registry>' >> /etc/sipwitch.conf
270
-	echo '<routing>' >> /etc/sipwitch.conf
271
-	echo '</routing>' >> /etc/sipwitch.conf
272
-	echo '</sipwitch>' >> /etc/sipwitch.conf
273
-
274
-	sed -i 's|#PLUGINS=|PLUGINS=|g' /etc/default/sipwitch
275
-	sed -i 's|PLUGINS=.*|PLUGINS="zeroconf subscriber forward"|g' /etc/default/sipwitch
276
-	groupadd sipwitch
277
-	usermod -aG sipwitch $MY_USERNAME
278
-
279
-	SIP_ONION_HOSTNAME=$(add_onion_service sip ${SIP_PORT} ${SIP_PORT})
280
-	if ! grep -q $"SIP onion domain" $COMPLETION_FILE; then
281
-		echo "SIP onion domain:$SIP_ONION_HOSTNAME" >> $COMPLETION_FILE
282
-	fi
283
-
284
-	if ! grep -q $"SIP Server" /home/$MY_USERNAME/README; then
285
-		echo '' >> /home/$MY_USERNAME/README
286
-		echo '' >> /home/$MY_USERNAME/README
287
-		echo $'SIP Server' >> /home/$MY_USERNAME/README
288
-		echo '==========' >> /home/$MY_USERNAME/README
289
-		echo $"SIP onion_domain: $SIP_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
290
-		echo $"SIP server username: $MY_USERNAME" >> /home/$MY_USERNAME/README
291
-		echo $"SIP server extension: 201" >> /home/$MY_USERNAME/README
292
-		echo $"SIP server password: $SIP_SERVER_PASSWORD" >> /home/$MY_USERNAME/README
293
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
294
-		chmod 600 /home/$MY_USERNAME/README
222
+    function_check get_sip_server_password
223
+    get_sip_server_password
224
+    if [ ! $SIP_SERVER_PASSWORD ]; then
225
+	if [ -f $IMAGE_PASSWORD_FILE ]; then
226
+	    SIP_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
227
+	else
228
+	    SIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
295 229
 	fi
296
-
297
-	function_check configure_firewall_for_sip4
298
-	configure_firewall_for_sip4
299
-	echo 'install_sip_main' >> $COMPLETION_FILE
230
+    fi
231
+
232
+    echo '<?xml version="1.0"?>' > /etc/sipwitch.conf
233
+    echo '<sipwitch>' >> /etc/sipwitch.conf
234
+    echo '<provision>' >> /etc/sipwitch.conf
235
+
236
+    echo "<user id=\"$MY_USERNAME\">" >> /etc/sipwitch.conf
237
+    echo '<extension>201</extension>' >> /etc/sipwitch.conf
238
+    echo "<secret>$SIP_SERVER_PASSWORD</secret>" >> /etc/sipwitch.conf
239
+    echo "<display>$MY_USERNAME 201</display>" >> /etc/sipwitch.conf
240
+    echo '</user>' >> /etc/sipwitch.conf
241
+
242
+    echo '</provision>' >> /etc/sipwitch.conf
243
+    echo '<access>' >> /etc/sipwitch.conf
244
+    echo '</access>' >> /etc/sipwitch.conf
245
+    echo '<stack>' >> /etc/sipwitch.conf
246
+    echo "  <localnames>$DEFAULT_DOMAIN_NAME</localnames>" >> /etc/sipwitch.conf
247
+    echo '  <mapped>200</mapped>' >> /etc/sipwitch.conf
248
+    echo '  <threading>2</threading>' >> /etc/sipwitch.conf
249
+    echo '  <interface>*</interface>' >> /etc/sipwitch.conf
250
+    echo '  <dumping>false</dumping>' >> /etc/sipwitch.conf
251
+    echo '  <system>system</system>' >> /etc/sipwitch.conf
252
+    echo '  <anon>anonymous</anon>' >> /etc/sipwitch.conf
253
+    echo '</stack>' >> /etc/sipwitch.conf
254
+    echo '<timers>' >> /etc/sipwitch.conf
255
+    echo '  <!-- ring every 4 seconds -->' >> /etc/sipwitch.conf
256
+    echo '  <ring>4</ring>' >> /etc/sipwitch.conf
257
+    echo '  <!-- call forward no answer after x rings -->' >> /etc/sipwitch.conf
258
+    echo '  <cfna>4</cfna>' >> /etc/sipwitch.conf
259
+    echo '  <!-- call reset to clear cid in stack, 6 seconds -->' >> /etc/sipwitch.conf
260
+    echo '  <reset>6</reset>' >> /etc/sipwitch.conf
261
+    echo '</timers>' >> /etc/sipwitch.conf
262
+    echo '<!-- we have 2xx numbers plus space for external users -->' >> /etc/sipwitch.conf
263
+    echo '<registry>' >> /etc/sipwitch.conf
264
+    echo '  <prefix>200</prefix>' >> /etc/sipwitch.conf
265
+    echo '  <range>100</range>' >> /etc/sipwitch.conf
266
+    echo '  <keysize>77</keysize>' >> /etc/sipwitch.conf
267
+    echo '  <mapped>200</mapped>' >> /etc/sipwitch.conf
268
+    echo '  <!-- <realm>GNU Telephony</realm> -->' >> /etc/sipwitch.conf
269
+    echo '</registry>' >> /etc/sipwitch.conf
270
+    echo '<routing>' >> /etc/sipwitch.conf
271
+    echo '</routing>' >> /etc/sipwitch.conf
272
+    echo '</sipwitch>' >> /etc/sipwitch.conf
273
+
274
+    sed -i 's|#PLUGINS=|PLUGINS=|g' /etc/default/sipwitch
275
+    sed -i 's|PLUGINS=.*|PLUGINS="zeroconf subscriber forward"|g' /etc/default/sipwitch
276
+    groupadd sipwitch
277
+    usermod -aG sipwitch $MY_USERNAME
278
+
279
+    SIP_ONION_HOSTNAME=$(add_onion_service sip ${SIP_PORT} ${SIP_PORT})
280
+    if ! grep -q $"SIP onion domain" $COMPLETION_FILE; then
281
+	echo "SIP onion domain:$SIP_ONION_HOSTNAME" >> $COMPLETION_FILE
282
+    fi
283
+
284
+    if ! grep -q $"SIP Server" /home/$MY_USERNAME/README; then
285
+	echo '' >> /home/$MY_USERNAME/README
286
+	echo '' >> /home/$MY_USERNAME/README
287
+	echo $'SIP Server' >> /home/$MY_USERNAME/README
288
+	echo '==========' >> /home/$MY_USERNAME/README
289
+	echo $"SIP onion_domain: $SIP_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
290
+	echo $"SIP server username: $MY_USERNAME" >> /home/$MY_USERNAME/README
291
+	echo $"SIP server extension: 201" >> /home/$MY_USERNAME/README
292
+	echo $"SIP server password: $SIP_SERVER_PASSWORD" >> /home/$MY_USERNAME/README
293
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
294
+	chmod 600 /home/$MY_USERNAME/README
295
+    fi
296
+
297
+    function_check configure_firewall_for_sip4
298
+    configure_firewall_for_sip4
299
+    echo 'install_sip_main' >> $COMPLETION_FILE
300 300
 }
301 301
 
302 302
 function install_sip_turn {
303
-	if grep -Fxq "install_sip_turn" $COMPLETION_FILE; then
304
-		return
303
+    if grep -Fxq "install_sip_turn" $COMPLETION_FILE; then
304
+	return
305
+    fi
306
+
307
+    apt-get -y install turnserver
308
+
309
+    # create a nonce if needed
310
+    if [ ! $VOIP_TURN_NONCE ]; then
311
+	VOIP_TURN_NONCE="$(create_password 30)"
312
+    fi
313
+
314
+    function_check create_site_certificate
315
+    create_site_certificate $DEFAULT_DOMAIN_NAME
316
+
317
+    echo '##' > /etc/turnserver/turnserver.conf
318
+    echo '# TurnServer configuration file.' >> /etc/turnserver/turnserver.conf
319
+    echo '#' >> /etc/turnserver/turnserver.conf
320
+    echo '' >> /etc/turnserver/turnserver.conf
321
+    echo '## Public IPv4 address of any relayed address (if not set, no relay for IPv4).' >> /etc/turnserver/turnserver.conf
322
+    echo '## To have multiple address, separate addresses with a comma' >> /etc/turnserver/turnserver.conf
323
+    echo '## (i.e. listen_address = { "172.16.0.1", "172.17.0.1" }).' >> /etc/turnserver/turnserver.conf
324
+    echo "listen_address = { \"192.168.0.1\" }" >> /etc/turnserver/turnserver.conf
325
+    echo '' >> /etc/turnserver/turnserver.conf
326
+    echo '## Public IPv6 address of any relayed address (if not set, no relay for IPv6).' >> /etc/turnserver/turnserver.conf
327
+    echo '## To have multiple address, separate address with a comma' >> /etc/turnserver/turnserver.conf
328
+    echo '## (i.e. listen_addressv6 = { "2001:db8:1::1", "2001:db8:2::1" }).' >> /etc/turnserver/turnserver.conf
329
+    echo "#listen_addressv6 = { \"2001:db8::1\" }" >> /etc/turnserver/turnserver.conf
330
+    echo '' >> /etc/turnserver/turnserver.conf
331
+    echo '## UDP listening port.' >> /etc/turnserver/turnserver.conf
332
+    echo "udp_port = $VOIP_TURN_PORT" >> /etc/turnserver/turnserver.conf
333
+    echo '' >> /etc/turnserver/turnserver.conf
334
+    echo '## TCP listening port.' >> /etc/turnserver/turnserver.conf
335
+    echo "tcp_port = $VOIP_TURN_PORT" >> /etc/turnserver/turnserver.conf
336
+    echo '' >> /etc/turnserver/turnserver.conf
337
+    echo '## TLS listening port.' >> /etc/turnserver/turnserver.conf
338
+    echo "tls_port = $VOIP_TURN_TLS_PORT" >> /etc/turnserver/turnserver.conf
339
+    echo '' >> /etc/turnserver/turnserver.conf
340
+    echo '## TLS support.' >> /etc/turnserver/turnserver.conf
341
+    echo 'tls = true' >> /etc/turnserver/turnserver.conf
342
+    echo '' >> /etc/turnserver/turnserver.conf
343
+    echo '## DTLS support. It is an experimental feature and is not defined in TURN' >> /etc/turnserver/turnserver.conf
344
+    echo '## standard.' >> /etc/turnserver/turnserver.conf
345
+    echo 'dtls = false' >> /etc/turnserver/turnserver.conf
346
+    echo '' >> /etc/turnserver/turnserver.conf
347
+    echo '## Maximum allocation port number.' >> /etc/turnserver/turnserver.conf
348
+    echo 'max_port = 65535' >> /etc/turnserver/turnserver.conf
349
+    echo '' >> /etc/turnserver/turnserver.conf
350
+    echo '## Minimum allocation port number.' >> /etc/turnserver/turnserver.conf
351
+    echo '' >> /etc/turnserver/turnserver.conf
352
+    echo 'min_port = 49152' >> /etc/turnserver/turnserver.conf
353
+    echo '' >> /etc/turnserver/turnserver.conf
354
+    echo '## TURN-TCP support.' >> /etc/turnserver/turnserver.conf
355
+    echo '' >> /etc/turnserver/turnserver.conf
356
+    echo 'turn_tcp = true' >> /etc/turnserver/turnserver.conf
357
+    echo '' >> /etc/turnserver/turnserver.conf
358
+    echo '## TURN-TCP buffering mode:' >> /etc/turnserver/turnserver.conf
359
+    echo '## - true, use userspace buffering;' >> /etc/turnserver/turnserver.conf
360
+    echo '## - false, use kernel buffering.' >> /etc/turnserver/turnserver.conf
361
+    echo 'tcp_buffer_userspace = true' >> /etc/turnserver/turnserver.conf
362
+    echo '' >> /etc/turnserver/turnserver.conf
363
+    echo '## TURN-TCP maximum buffer size.' >> /etc/turnserver/turnserver.conf
364
+    echo 'tcp_buffer_size = 32768' >> /etc/turnserver/turnserver.conf
365
+    echo '' >> /etc/turnserver/turnserver.conf
366
+    echo '## Daemon mode.' >> /etc/turnserver/turnserver.conf
367
+    echo 'daemon = true' >> /etc/turnserver/turnserver.conf
368
+    echo '' >> /etc/turnserver/turnserver.conf
369
+    echo '## Unprivileged user.' >> /etc/turnserver/turnserver.conf
370
+    echo '## If you want to use this feature create a system user.' >> /etc/turnserver/turnserver.conf
371
+    echo '## On Linux: adduser --system --group turnserver' >> /etc/turnserver/turnserver.conf
372
+    echo 'unpriv_user = turnserver' >> /etc/turnserver/turnserver.conf
373
+    echo '' >> /etc/turnserver/turnserver.conf
374
+    echo '## Realm value.' >> /etc/turnserver/turnserver.conf
375
+    echo "realm = \"$DEFAULT_DOMAIN_NAME\"" >> /etc/turnserver/turnserver.conf
376
+    echo '' >> /etc/turnserver/turnserver.conf
377
+    echo '## Nonce key.' >> /etc/turnserver/turnserver.conf
378
+    echo "nonce_key = \"$VOIP_TURN_NONCE\"" >> /etc/turnserver/turnserver.conf
379
+    echo '' >> /etc/turnserver/turnserver.conf
380
+    echo '## Max relay per username.' >> /etc/turnserver/turnserver.conf
381
+    echo 'max_relay_per_username = 5' >> /etc/turnserver/turnserver.conf
382
+    echo '' >> /etc/turnserver/turnserver.conf
383
+    echo '## Allocation lifetime.' >> /etc/turnserver/turnserver.conf
384
+    echo 'allocation_lifetime = 1800' >> /etc/turnserver/turnserver.conf
385
+    echo '' >> /etc/turnserver/turnserver.conf
386
+    echo '## Allocation bandwidth limitation (in KBytes/s).' >> /etc/turnserver/turnserver.conf
387
+    echo '## 0 value means bandwidth quota disabled.' >> /etc/turnserver/turnserver.conf
388
+    echo 'bandwidth_per_allocation = 150' >> /etc/turnserver/turnserver.conf
389
+    echo '' >> /etc/turnserver/turnserver.conf
390
+    echo '## Restricted user bandwidth (in KBytes/s).' >> /etc/turnserver/turnserver.conf
391
+    echo '## 0 value means bandwidth limitation disabled.' >> /etc/turnserver/turnserver.conf
392
+    echo 'restricted_bandwidth = 10' >> /etc/turnserver/turnserver.conf
393
+    echo '' >> /etc/turnserver/turnserver.conf
394
+    echo '## Denied addresses.' >> /etc/turnserver/turnserver.conf
395
+    echo '' >> /etc/turnserver/turnserver.conf
396
+    echo '# disallow relaying to localhost' >> /etc/turnserver/turnserver.conf
397
+    echo 'denied_address {' >> /etc/turnserver/turnserver.conf
398
+    echo '  address = "127.0.0.1"' >> /etc/turnserver/turnserver.conf
399
+    echo '  mask = "8"' >> /etc/turnserver/turnserver.conf
400
+    echo '  port = 0' >> /etc/turnserver/turnserver.conf
401
+    echo '}' >> /etc/turnserver/turnserver.conf
402
+    echo '' >> /etc/turnserver/turnserver.conf
403
+    echo '# disallow relaying to ip6-localhost' >> /etc/turnserver/turnserver.conf
404
+    echo 'denied_address {' >> /etc/turnserver/turnserver.conf
405
+    echo '  address = "::1"' >> /etc/turnserver/turnserver.conf
406
+    echo '  mask = "128"' >> /etc/turnserver/turnserver.conf
407
+    echo '  port = 0' >> /etc/turnserver/turnserver.conf
408
+    echo '}' >> /etc/turnserver/turnserver.conf
409
+    echo '' >> /etc/turnserver/turnserver.conf
410
+    echo '## Certification Authority file.' >> /etc/turnserver/turnserver.conf
411
+    echo "ca_file = \"/etc/ssl/certs/ca-certificates.crt\"" >> /etc/turnserver/turnserver.conf
412
+    echo '' >> /etc/turnserver/turnserver.conf
413
+    echo '## Server certificate file.' >> /etc/turnserver/turnserver.conf
414
+    if [ -f /etc/ssl/certs/$DEFAULT_DOMAIN_NAME.pem ]; then
415
+	echo "cert_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.pem\"" >> /etc/turnserver/turnserver.conf
416
+    else
417
+	if [ -f /etc/ssl/certs/$DEFAULT_DOMAIN_NAME.crt ]; then
418
+	    echo "cert_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.crt\"" >> /etc/turnserver/turnserver.conf
305 419
 	fi
306
-
307
-	apt-get -y install turnserver
308
-
309
-	# create a nonce if needed
310
-	if [ ! $VOIP_TURN_NONCE ]; then
311
-		VOIP_TURN_NONCE="$(create_password 30)"
312
-	fi
313
-
314
-	function_check create_site_certificate
315
-	create_site_certificate $DEFAULT_DOMAIN_NAME
316
-
317
-	echo '##' > /etc/turnserver/turnserver.conf
318
-	echo '# TurnServer configuration file.' >> /etc/turnserver/turnserver.conf
319
-	echo '#' >> /etc/turnserver/turnserver.conf
320
-	echo '' >> /etc/turnserver/turnserver.conf
321
-	echo '## Public IPv4 address of any relayed address (if not set, no relay for IPv4).' >> /etc/turnserver/turnserver.conf
322
-	echo '## To have multiple address, separate addresses with a comma' >> /etc/turnserver/turnserver.conf
323
-	echo '## (i.e. listen_address = { "172.16.0.1", "172.17.0.1" }).' >> /etc/turnserver/turnserver.conf
324
-	echo "listen_address = { \"192.168.0.1\" }" >> /etc/turnserver/turnserver.conf
325
-	echo '' >> /etc/turnserver/turnserver.conf
326
-	echo '## Public IPv6 address of any relayed address (if not set, no relay for IPv6).' >> /etc/turnserver/turnserver.conf
327
-	echo '## To have multiple address, separate address with a comma' >> /etc/turnserver/turnserver.conf
328
-	echo '## (i.e. listen_addressv6 = { "2001:db8:1::1", "2001:db8:2::1" }).' >> /etc/turnserver/turnserver.conf
329
-	echo "#listen_addressv6 = { \"2001:db8::1\" }" >> /etc/turnserver/turnserver.conf
330
-	echo '' >> /etc/turnserver/turnserver.conf
331
-	echo '## UDP listening port.' >> /etc/turnserver/turnserver.conf
332
-	echo "udp_port = $VOIP_TURN_PORT" >> /etc/turnserver/turnserver.conf
333
-	echo '' >> /etc/turnserver/turnserver.conf
334
-	echo '## TCP listening port.' >> /etc/turnserver/turnserver.conf
335
-	echo "tcp_port = $VOIP_TURN_PORT" >> /etc/turnserver/turnserver.conf
336
-	echo '' >> /etc/turnserver/turnserver.conf
337
-	echo '## TLS listening port.' >> /etc/turnserver/turnserver.conf
338
-	echo "tls_port = $VOIP_TURN_TLS_PORT" >> /etc/turnserver/turnserver.conf
339
-	echo '' >> /etc/turnserver/turnserver.conf
340
-	echo '## TLS support.' >> /etc/turnserver/turnserver.conf
341
-	echo 'tls = true' >> /etc/turnserver/turnserver.conf
342
-	echo '' >> /etc/turnserver/turnserver.conf
343
-	echo '## DTLS support. It is an experimental feature and is not defined in TURN' >> /etc/turnserver/turnserver.conf
344
-	echo '## standard.' >> /etc/turnserver/turnserver.conf
345
-	echo 'dtls = false' >> /etc/turnserver/turnserver.conf
346
-	echo '' >> /etc/turnserver/turnserver.conf
347
-	echo '## Maximum allocation port number.' >> /etc/turnserver/turnserver.conf
348
-	echo 'max_port = 65535' >> /etc/turnserver/turnserver.conf
349
-	echo '' >> /etc/turnserver/turnserver.conf
350
-	echo '## Minimum allocation port number.' >> /etc/turnserver/turnserver.conf
351
-	echo '' >> /etc/turnserver/turnserver.conf
352
-	echo 'min_port = 49152' >> /etc/turnserver/turnserver.conf
353
-	echo '' >> /etc/turnserver/turnserver.conf
354
-	echo '## TURN-TCP support.' >> /etc/turnserver/turnserver.conf
355
-	echo '' >> /etc/turnserver/turnserver.conf
356
-	echo 'turn_tcp = true' >> /etc/turnserver/turnserver.conf
357
-	echo '' >> /etc/turnserver/turnserver.conf
358
-	echo '## TURN-TCP buffering mode:' >> /etc/turnserver/turnserver.conf
359
-	echo '## - true, use userspace buffering;' >> /etc/turnserver/turnserver.conf
360
-	echo '## - false, use kernel buffering.' >> /etc/turnserver/turnserver.conf
361
-	echo 'tcp_buffer_userspace = true' >> /etc/turnserver/turnserver.conf
362
-	echo '' >> /etc/turnserver/turnserver.conf
363
-	echo '## TURN-TCP maximum buffer size.' >> /etc/turnserver/turnserver.conf
364
-	echo 'tcp_buffer_size = 32768' >> /etc/turnserver/turnserver.conf
365
-	echo '' >> /etc/turnserver/turnserver.conf
366
-	echo '## Daemon mode.' >> /etc/turnserver/turnserver.conf
367
-	echo 'daemon = true' >> /etc/turnserver/turnserver.conf
368
-	echo '' >> /etc/turnserver/turnserver.conf
369
-	echo '## Unprivileged user.' >> /etc/turnserver/turnserver.conf
370
-	echo '## If you want to use this feature create a system user.' >> /etc/turnserver/turnserver.conf
371
-	echo '## On Linux: adduser --system --group turnserver' >> /etc/turnserver/turnserver.conf
372
-	echo 'unpriv_user = turnserver' >> /etc/turnserver/turnserver.conf
373
-	echo '' >> /etc/turnserver/turnserver.conf
374
-	echo '## Realm value.' >> /etc/turnserver/turnserver.conf
375
-	echo "realm = \"$DEFAULT_DOMAIN_NAME\"" >> /etc/turnserver/turnserver.conf
376
-	echo '' >> /etc/turnserver/turnserver.conf
377
-	echo '## Nonce key.' >> /etc/turnserver/turnserver.conf
378
-	echo "nonce_key = \"$VOIP_TURN_NONCE\"" >> /etc/turnserver/turnserver.conf
379
-	echo '' >> /etc/turnserver/turnserver.conf
380
-	echo '## Max relay per username.' >> /etc/turnserver/turnserver.conf
381
-	echo 'max_relay_per_username = 5' >> /etc/turnserver/turnserver.conf
382
-	echo '' >> /etc/turnserver/turnserver.conf
383
-	echo '## Allocation lifetime.' >> /etc/turnserver/turnserver.conf
384
-	echo 'allocation_lifetime = 1800' >> /etc/turnserver/turnserver.conf
385
-	echo '' >> /etc/turnserver/turnserver.conf
386
-	echo '## Allocation bandwidth limitation (in KBytes/s).' >> /etc/turnserver/turnserver.conf
387
-	echo '## 0 value means bandwidth quota disabled.' >> /etc/turnserver/turnserver.conf
388
-	echo 'bandwidth_per_allocation = 150' >> /etc/turnserver/turnserver.conf
389
-	echo '' >> /etc/turnserver/turnserver.conf
390
-	echo '## Restricted user bandwidth (in KBytes/s).' >> /etc/turnserver/turnserver.conf
391
-	echo '## 0 value means bandwidth limitation disabled.' >> /etc/turnserver/turnserver.conf
392
-	echo 'restricted_bandwidth = 10' >> /etc/turnserver/turnserver.conf
393
-	echo '' >> /etc/turnserver/turnserver.conf
394
-	echo '## Denied addresses.' >> /etc/turnserver/turnserver.conf
395
-	echo '' >> /etc/turnserver/turnserver.conf
396
-	echo '# disallow relaying to localhost' >> /etc/turnserver/turnserver.conf
397
-	echo 'denied_address {' >> /etc/turnserver/turnserver.conf
398
-	echo '  address = "127.0.0.1"' >> /etc/turnserver/turnserver.conf
399
-	echo '  mask = "8"' >> /etc/turnserver/turnserver.conf
400
-	echo '  port = 0' >> /etc/turnserver/turnserver.conf
401
-	echo '}' >> /etc/turnserver/turnserver.conf
402
-	echo '' >> /etc/turnserver/turnserver.conf
403
-	echo '# disallow relaying to ip6-localhost' >> /etc/turnserver/turnserver.conf
404
-	echo 'denied_address {' >> /etc/turnserver/turnserver.conf
405
-	echo '  address = "::1"' >> /etc/turnserver/turnserver.conf
406
-	echo '  mask = "128"' >> /etc/turnserver/turnserver.conf
407
-	echo '  port = 0' >> /etc/turnserver/turnserver.conf
408
-	echo '}' >> /etc/turnserver/turnserver.conf
409
-	echo '' >> /etc/turnserver/turnserver.conf
410
-	echo '## Certification Authority file.' >> /etc/turnserver/turnserver.conf
411
-	echo "ca_file = \"/etc/ssl/certs/ca-certificates.crt\"" >> /etc/turnserver/turnserver.conf
412
-	echo '' >> /etc/turnserver/turnserver.conf
413
-	echo '## Server certificate file.' >> /etc/turnserver/turnserver.conf
414
-	if [ -f /etc/ssl/certs/$DEFAULT_DOMAIN_NAME.pem ]; then
415
-		echo "cert_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.pem\"" >> /etc/turnserver/turnserver.conf
416
-	else
417
-		if [ -f /etc/ssl/certs/$DEFAULT_DOMAIN_NAME.crt ]; then
418
-			echo "cert_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.crt\"" >> /etc/turnserver/turnserver.conf
419
-		fi
420
-	fi
421
-	echo '' >> /etc/turnserver/turnserver.conf
422
-	echo '## Private key file.' >> /etc/turnserver/turnserver.conf
423
-	echo "private_key_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.key\"" >> /etc/turnserver/turnserver.conf
424
-	echo '' >> /etc/turnserver/turnserver.conf
425
-	echo '## Account method.' >> /etc/turnserver/turnserver.conf
426
-	echo "account_method = \"file\"" >> /etc/turnserver/turnserver.conf
427
-	echo '' >> /etc/turnserver/turnserver.conf
428
-	echo '## Account file (if account_method = file).' >> /etc/turnserver/turnserver.conf
429
-	echo "account_file = \"/etc/turnserver/turnusers.txt\"" >> /etc/turnserver/turnserver.conf
430
-	echo '' >> /etc/turnserver/turnserver.conf
431
-	echo '## mod_tmpuser.' >> /etc/turnserver/turnserver.conf
432
-	echo 'mod_tmpuser = false' >> /etc/turnserver/turnserver.conf
433
-
434
-	echo "${MY_USERNAME}:password:${DEFAULT_DOMAIN_NAME}:authorized" > /etc/turnserver/turnusers.txt
435
-
436
-	systemctl restart turnserver
437
-
438
-	function_check configure_firewall_for_voip_turn
439
-	configure_firewall_for_voip_turn
440
-	echo 'install_sip_turn' >> $COMPLETION_FILE
420
+    fi
421
+    echo '' >> /etc/turnserver/turnserver.conf
422
+    echo '## Private key file.' >> /etc/turnserver/turnserver.conf
423
+    echo "private_key_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.key\"" >> /etc/turnserver/turnserver.conf
424
+    echo '' >> /etc/turnserver/turnserver.conf
425
+    echo '## Account method.' >> /etc/turnserver/turnserver.conf
426
+    echo "account_method = \"file\"" >> /etc/turnserver/turnserver.conf
427
+    echo '' >> /etc/turnserver/turnserver.conf
428
+    echo '## Account file (if account_method = file).' >> /etc/turnserver/turnserver.conf
429
+    echo "account_file = \"/etc/turnserver/turnusers.txt\"" >> /etc/turnserver/turnserver.conf
430
+    echo '' >> /etc/turnserver/turnserver.conf
431
+    echo '## mod_tmpuser.' >> /etc/turnserver/turnserver.conf
432
+    echo 'mod_tmpuser = false' >> /etc/turnserver/turnserver.conf
433
+
434
+    echo "${MY_USERNAME}:password:${DEFAULT_DOMAIN_NAME}:authorized" > /etc/turnserver/turnusers.txt
435
+
436
+    systemctl restart turnserver
437
+
438
+    function_check configure_firewall_for_voip_turn
439
+    configure_firewall_for_voip_turn
440
+    echo 'install_sip_turn' >> $COMPLETION_FILE
441 441
 }
442 442
 
443 443
 function install_sip {
444
-	if grep -Fxq "install_sip" $COMPLETION_FILE; then
445
-		return
446
-	fi
447
-	install_sip_main
448
-	update_sipwitch_daemon
449
-	echo 'install_sip' >> $COMPLETION_FILE
444
+    if grep -Fxq "install_sip" $COMPLETION_FILE; then
445
+	return
446
+    fi
447
+    install_sip_main
448
+    update_sipwitch_daemon
449
+    echo 'install_sip' >> $COMPLETION_FILE
450 450
 }
451 451
 
452 452
 # NOTE: deliberately no exit 0

+ 251
- 251
src/freedombone-app-syncthing Voir le fichier

@@ -40,300 +40,300 @@ SYNCTHING_SHARED_DATA=/var/lib/syncthing/SyncShared
40 40
 SYNCTHING_USER_IDS_FILE='.syncthingids'
41 41
 
42 42
 function reconfigure_syncthing {
43
-	echo -n ''
43
+    echo -n ''
44 44
 }
45 45
 
46 46
 function upgrade_syncthing {
47
-	echo -n ''
47
+    echo -n ''
48 48
 }
49 49
 
50 50
 function backup_local_syncthing {
51
-	if [ -d /var/lib/syncthing/SyncShared ]; then
52
-		echo $"Backing up syncthing"
51
+    if [ -d /var/lib/syncthing/SyncShared ]; then
52
+	echo $"Backing up syncthing"
53 53
 
54
-		function_check backup_directory_to_usb
55
-		backup_directory_to_usb /var/lib/syncthing/SyncShared syncthingshared
56
-		backup_directory_to_usb /root/.config/syncthing syncthingconfig
54
+	function_check backup_directory_to_usb
55
+	backup_directory_to_usb /var/lib/syncthing/SyncShared syncthingshared
56
+	backup_directory_to_usb /root/.config/syncthing syncthingconfig
57 57
 
58
-		echo $"Backup to syncthing complete"
59
-	fi
58
+	echo $"Backup to syncthing complete"
59
+    fi
60 60
 }
61 61
 
62 62
 function restore_local_syncthing {
63
-	if [ -f /etc/systemd/system/syncthing.service ]; then
64
-		systemctl stop syncthing
65
-		systemctl stop cron
63
+    if [ -f /etc/systemd/system/syncthing.service ]; then
64
+	systemctl stop syncthing
65
+	systemctl stop cron
66
+    fi
67
+
68
+    temp_restore_dir=/root/tempsyncthing
69
+    if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
70
+	echo $"Restoring syncthing configuration"
71
+	function_check restore_directory_from_usb
72
+	restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
73
+	cp -r ${temp_restore_dir}config/* /
74
+	if [ ! "$?" = "0" ]; then
75
+	    set_user_permissions
76
+	    backup_unmount_drive
77
+	    systemctl start syncthing
78
+	    systemctl start cron
79
+	    exit 6833
66 80
 	fi
67
-
68
-	temp_restore_dir=/root/tempsyncthing
69
-	if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
70
-		echo $"Restoring syncthing configuration"
71
-		function_check restore_directory_from_usb
72
-		restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
73
-		cp -r ${temp_restore_dir}config/* /
74
-		if [ ! "$?" = "0" ]; then
75
-			set_user_permissions
76
-			backup_unmount_drive
77
-			systemctl start syncthing
78
-			systemctl start cron
79
-			exit 6833
80
-		fi
81
-		rm -rf ${temp_restore_dir}config
81
+	rm -rf ${temp_restore_dir}config
82
+    fi
83
+
84
+    if [ -d $USB_MOUNT/backup/syncthingshared ]; then
85
+	echo $"Restoring syncthing shared files"
86
+	restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
87
+	cp -r ${temp_restore_dir}shared/* /
88
+	if [ ! "$?" = "0" ]; then
89
+	    set_user_permissions
90
+	    backup_unmount_drive
91
+	    systemctl start syncthing
92
+	    systemctl start cron
93
+	    exit 37904
82 94
 	fi
83
-
84
-	if [ -d $USB_MOUNT/backup/syncthingshared ]; then
85
-		echo $"Restoring syncthing shared files"
86
-		restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
87
-		cp -r ${temp_restore_dir}shared/* /
95
+	rm -rf ${temp_restore_dir}shared
96
+    fi
97
+
98
+    if [ -d $USB_MOUNT/backup/syncthing ]; then
99
+	for d in $USB_MOUNT/backup/syncthing/*/ ; do
100
+	    USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
101
+	    if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
102
+		if [ ! -d /home/$USERNAME ]; then
103
+		    ${PROJECT_NAME}-adduser $USERNAME
104
+		fi
105
+		echo $"Restoring syncthing files for $USERNAME"
106
+		restore_directory_from_usb ${temp_restore_dir} syncthing/$USERNAME
107
+		cp -r ${temp_restore_dir}/home/$USERNAME/Sync /home/$USERNAME/
88 108
 		if [ ! "$?" = "0" ]; then
89
-			set_user_permissions
90
-			backup_unmount_drive
91
-			systemctl start syncthing
92
-			systemctl start cron
93
-			exit 37904
109
+		    rm -rf ${temp_restore_dir}
110
+		    set_user_permissions
111
+		    backup_unmount_drive
112
+		    systemctl start syncthing
113
+		    systemctl start cron
114
+		    exit 68438
94 115
 		fi
95
-		rm -rf ${temp_restore_dir}shared
96
-	fi
116
+		rm -rf ${temp_restore_dir}
97 117
 
98
-	if [ -d $USB_MOUNT/backup/syncthing ]; then
99
-		for d in $USB_MOUNT/backup/syncthing/*/ ; do
100
-			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
101
-			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
102
-				if [ ! -d /home/$USERNAME ]; then
103
-					${PROJECT_NAME}-adduser $USERNAME
104
-				fi
105
-				echo $"Restoring syncthing files for $USERNAME"
106
-				restore_directory_from_usb ${temp_restore_dir} syncthing/$USERNAME
107
-				cp -r ${temp_restore_dir}/home/$USERNAME/Sync /home/$USERNAME/
108
-				if [ ! "$?" = "0" ]; then
109
-					rm -rf ${temp_restore_dir}
110
-					set_user_permissions
111
-					backup_unmount_drive
112
-					systemctl start syncthing
113
-					systemctl start cron
114
-					exit 68438
115
-				fi
116
-				rm -rf ${temp_restore_dir}
117
-
118
-				# restore device IDs from config settings
119
-				if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
120
-					cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
121
-					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
122
-				fi
123
-				if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
124
-					cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
125
-					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
126
-				fi
127
-			fi
128
-		done
129
-	fi
118
+		# restore device IDs from config settings
119
+		if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
120
+		    cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
121
+		    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
122
+		fi
123
+		if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
124
+		    cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
125
+		    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
126
+		fi
127
+	    fi
128
+	done
129
+    fi
130 130
 
131
-	if [ -f /etc/systemd/system/syncthing.service ]; then
132
-		systemctl start syncthing
133
-		systemctl start cron
134
-	fi
131
+    if [ -f /etc/systemd/system/syncthing.service ]; then
132
+	systemctl start syncthing
133
+	systemctl start cron
134
+    fi
135 135
 }
136 136
 
137 137
 function backup_remote_syncthing {
138
-	if [ -d /root/.config/syncthing ]; then
139
-		echo $"Backing up syncthing configuration"
140
-		function_check backup_directory_to_friend
141
-		backup_directory_to_friend /root/.config/syncthing syncthingconfig
142
-		echo $"Backup of syncthing configuration complete"
143
-	fi
144
-	if [ -d /var/lib/syncthing/SyncShared ]; then
145
-		echo $"Backing up syncthing shared files"
146
-		function_check backup_directory_to_friend
147
-		backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared
148
-		echo $"Backup of syncthing shared files complete"
149
-	fi
138
+    if [ -d /root/.config/syncthing ]; then
139
+	echo $"Backing up syncthing configuration"
140
+	function_check backup_directory_to_friend
141
+	backup_directory_to_friend /root/.config/syncthing syncthingconfig
142
+	echo $"Backup of syncthing configuration complete"
143
+    fi
144
+    if [ -d /var/lib/syncthing/SyncShared ]; then
145
+	echo $"Backing up syncthing shared files"
146
+	function_check backup_directory_to_friend
147
+	backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared
148
+	echo $"Backup of syncthing shared files complete"
149
+    fi
150 150
 }
151 151
 
152 152
 function restore_remote_syncthing {
153
-	if [ -f /etc/systemd/system/syncthing.service ]; then
154
-		systemctl stop syncthing
155
-		systemctl stop cron
153
+    if [ -f /etc/systemd/system/syncthing.service ]; then
154
+	systemctl stop syncthing
155
+	systemctl stop cron
156
+    fi
157
+
158
+    if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
159
+	echo $"Restoring syncthing configuration"
160
+	temp_restore_dir=/root/tempsyncthingconfig
161
+	function_check restore_directory_from_friend
162
+	restore_directory_from_friend $temp_restore_dir syncthingconfig
163
+	cp -r $temp_restore_dir/* /
164
+	if [ ! "$?" = "0" ]; then
165
+	    systemctl start syncthing
166
+	    systemctl start cron
167
+	    exit 6833
156 168
 	fi
157
-
158
-	if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
159
-		echo $"Restoring syncthing configuration"
160
-		temp_restore_dir=/root/tempsyncthingconfig
161
-		function_check restore_directory_from_friend
162
-		restore_directory_from_friend $temp_restore_dir syncthingconfig
163
-		cp -r $temp_restore_dir/* /
164
-		if [ ! "$?" = "0" ]; then
165
-			systemctl start syncthing
166
-			systemctl start cron
167
-			exit 6833
168
-		fi
169
-		rm -rf $temp_restore_dir
169
+	rm -rf $temp_restore_dir
170
+    fi
171
+
172
+    if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
173
+	echo $"Restoring syncthing shared files"
174
+	temp_restore_dir=/root/tempsyncthingshared
175
+	function_check restore_directory_from_friend
176
+	restore_directory_from_friend $temp_restore_dir syncthingshared
177
+	cp -r $temp_restore_dir/* /
178
+	if [ ! "$?" = "0" ]; then
179
+	    systemctl start syncthing
180
+	    systemctl start cron
181
+	    exit 37904
170 182
 	fi
171
-
172
-	if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
173
-		echo $"Restoring syncthing shared files"
174
-		temp_restore_dir=/root/tempsyncthingshared
183
+	rm -rf $temp_restore_dir
184
+    fi
185
+
186
+    if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
187
+	for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
188
+	    USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
189
+	    if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
190
+		if [ ! -d /home/$USERNAME ]; then
191
+		    ${PROJECT_NAME}-adduser $USERNAME
192
+		fi
193
+		echo $"Restoring syncthing files for $USERNAME"
194
+		temp_restore_dir=/root/tempsyncthing
175 195
 		function_check restore_directory_from_friend
176
-		restore_directory_from_friend $temp_restore_dir syncthingshared
177
-		cp -r $temp_restore_dir/* /
196
+		restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
197
+		cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
178 198
 		if [ ! "$?" = "0" ]; then
179
-			systemctl start syncthing
180
-			systemctl start cron
181
-			exit 37904
199
+		    rm -rf $temp_restore_dir
200
+		    systemctl start syncthing
201
+		    systemctl start cron
202
+		    exit 68438
182 203
 		fi
183 204
 		rm -rf $temp_restore_dir
184
-	fi
185 205
 
186
-	if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
187
-		for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
188
-			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
189
-			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
190
-				if [ ! -d /home/$USERNAME ]; then
191
-					${PROJECT_NAME}-adduser $USERNAME
192
-				fi
193
-				echo $"Restoring syncthing files for $USERNAME"
194
-				temp_restore_dir=/root/tempsyncthing
195
-				function_check restore_directory_from_friend
196
-				restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
197
-				cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
198
-				if [ ! "$?" = "0" ]; then
199
-					rm -rf $temp_restore_dir
200
-					systemctl start syncthing
201
-					systemctl start cron
202
-					exit 68438
203
-				fi
204
-				rm -rf $temp_restore_dir
205
-
206
-				# restore device IDs from config settings
207
-				if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
208
-					cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
209
-					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
210
-				fi
211
-				if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
212
-					cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
213
-					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
214
-				fi
215
-				echo $"Restore of syncthing files for $USERNAME complete"
216
-			fi
217
-		done
218
-	fi
206
+		# restore device IDs from config settings
207
+		if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
208
+		    cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
209
+		    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
210
+		fi
211
+		if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
212
+		    cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
213
+		    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
214
+		fi
215
+		echo $"Restore of syncthing files for $USERNAME complete"
216
+	    fi
217
+	done
218
+    fi
219 219
 
220
-	if [ -f /etc/systemd/system/syncthing.service ]; then
221
-		systemctl start syncthing
222
-		systemctl start cron
223
-	fi
220
+    if [ -f /etc/systemd/system/syncthing.service ]; then
221
+	systemctl start syncthing
222
+	systemctl start cron
223
+    fi
224 224
 }
225 225
 
226 226
 function remove_syncthing {
227
-	if ! grep -Fxq "install_syncthing" $COMPLETION_FILE; then
228
-		return
229
-	fi
230
-	iptables -D INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
231
-	iptables -D INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
232
-	function_check save_firewall_settings
233
-	save_firewall_settings
234
-
235
-	systemctl stop syncthing
236
-	systemctl disable syncthing
237
-	apt-get -y remove --purge syncthing
238
-	rm /etc/systemd/system/syncthing.service
239
-	sed -i "/${PROJECT_NAME}-syncthing/d" /etc/crontab
240
-	sed -i '/install_syncthing/d' $COMPLETION_FILE
241
-	sed -i '/configure_firewall_for_syncthing/d' $COMPLETION_FILE
242
-	systemctl restart cron
227
+    if ! grep -Fxq "install_syncthing" $COMPLETION_FILE; then
228
+	return
229
+    fi
230
+    iptables -D INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
231
+    iptables -D INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
232
+    function_check save_firewall_settings
233
+    save_firewall_settings
234
+
235
+    systemctl stop syncthing
236
+    systemctl disable syncthing
237
+    apt-get -y remove --purge syncthing
238
+    rm /etc/systemd/system/syncthing.service
239
+    sed -i "/${PROJECT_NAME}-syncthing/d" /etc/crontab
240
+    sed -i '/install_syncthing/d' $COMPLETION_FILE
241
+    sed -i '/configure_firewall_for_syncthing/d' $COMPLETION_FILE
242
+    systemctl restart cron
243 243
 }
244 244
 
245 245
 function configure_firewall_for_syncthing {
246
-	if grep -Fxq "configure_firewall_for_syncthing" $COMPLETION_FILE; then
247
-		return
248
-	fi
249
-	iptables -A INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
250
-	iptables -A INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
251
-	function_check save_firewall_settings
252
-	save_firewall_settings
253
-
254
-	OPEN_PORTS+=("Syncthing $SYNCTHING_PORT")
255
-	echo 'configure_firewall_for_syncthing' >> $COMPLETION_FILE
246
+    if grep -Fxq "configure_firewall_for_syncthing" $COMPLETION_FILE; then
247
+	return
248
+    fi
249
+    iptables -A INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
250
+    iptables -A INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
251
+    function_check save_firewall_settings
252
+    save_firewall_settings
253
+
254
+    OPEN_PORTS+=("Syncthing $SYNCTHING_PORT")
255
+    echo 'configure_firewall_for_syncthing' >> $COMPLETION_FILE
256 256
 }
257 257
 
258 258
 function mesh_install_syncthing {
259
-	chroot "$rootdir" wget -q https://syncthing.net/release-key.txt -O- | apt-key add -
260
-
261
-	echo "deb http://apt.syncthing.net/ syncthing release" | tee $rootdir/etc/apt/sources.list.d/syncthing.list
262
-	chroot "$rootdir" apt-get update
263
-	chroot "$rootdir" apt-get -y --force-yes install syncthing
264
-
265
-	# This probably does need to run as root so that it can access the Sync directories
266
-	# in each user's home directory
267
-	echo '[Unit]' > $rootdir/etc/systemd/system/syncthing.service
268
-	echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> $rootdir/etc/systemd/system/syncthing.service
269
-	echo 'Documentation=man:syncthing(1)' >> $rootdir/etc/systemd/system/syncthing.service
270
-	echo 'After=network.target' >> $rootdir/etc/systemd/system/syncthing.service
271
-	echo 'Wants=syncthing-inotify@.service' >> $rootdir/etc/systemd/system/syncthing.service
272
-	echo '' >> $rootdir/etc/systemd/system/syncthing.service
273
-	echo '[Service]' >> $rootdir/etc/systemd/system/syncthing.service
274
-	echo 'User=root' >> $rootdir/etc/systemd/system/syncthing.service
275
-	echo "Environment='all_proxy=socks5://localhost:9050'" >> $rootdir/etc/systemd/system/syncthing.service
276
-	echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> $rootdir/etc/systemd/system/syncthing.service
277
-	echo 'Restart=on-failure' >> $rootdir/etc/systemd/system/syncthing.service
278
-	echo 'SuccessExitStatus=3 4' >> $rootdir/etc/systemd/system/syncthing.service
279
-	echo 'RestartForceExitStatus=3 4' >> $rootdir/etc/systemd/system/syncthing.service
280
-	echo '' >> $rootdir/etc/systemd/system/syncthing.service
281
-	echo '[Install]' >> $rootdir/etc/systemd/system/syncthing.service
282
-	echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/syncthing.service
283
-	chroot "$rootdir" systemctl enable syncthing
284
-
285
-	if ! grep -q "syncthing" $rootdir/etc/crontab; then
286
-		echo "*/1            * *   *   *   root /usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null" >> $rootdir/etc/crontab
287
-	fi
288
-
289
-	echo 'mesh_install_syncthing'
259
+    chroot "$rootdir" wget -q https://syncthing.net/release-key.txt -O- | apt-key add -
260
+
261
+    echo "deb http://apt.syncthing.net/ syncthing release" | tee $rootdir/etc/apt/sources.list.d/syncthing.list
262
+    chroot "$rootdir" apt-get update
263
+    chroot "$rootdir" apt-get -y --force-yes install syncthing
264
+
265
+    # This probably does need to run as root so that it can access the Sync directories
266
+    # in each user's home directory
267
+    echo '[Unit]' > $rootdir/etc/systemd/system/syncthing.service
268
+    echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> $rootdir/etc/systemd/system/syncthing.service
269
+    echo 'Documentation=man:syncthing(1)' >> $rootdir/etc/systemd/system/syncthing.service
270
+    echo 'After=network.target' >> $rootdir/etc/systemd/system/syncthing.service
271
+    echo 'Wants=syncthing-inotify@.service' >> $rootdir/etc/systemd/system/syncthing.service
272
+    echo '' >> $rootdir/etc/systemd/system/syncthing.service
273
+    echo '[Service]' >> $rootdir/etc/systemd/system/syncthing.service
274
+    echo 'User=root' >> $rootdir/etc/systemd/system/syncthing.service
275
+    echo "Environment='all_proxy=socks5://localhost:9050'" >> $rootdir/etc/systemd/system/syncthing.service
276
+    echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> $rootdir/etc/systemd/system/syncthing.service
277
+    echo 'Restart=on-failure' >> $rootdir/etc/systemd/system/syncthing.service
278
+    echo 'SuccessExitStatus=3 4' >> $rootdir/etc/systemd/system/syncthing.service
279
+    echo 'RestartForceExitStatus=3 4' >> $rootdir/etc/systemd/system/syncthing.service
280
+    echo '' >> $rootdir/etc/systemd/system/syncthing.service
281
+    echo '[Install]' >> $rootdir/etc/systemd/system/syncthing.service
282
+    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/syncthing.service
283
+    chroot "$rootdir" systemctl enable syncthing
284
+
285
+    if ! grep -q "syncthing" $rootdir/etc/crontab; then
286
+	echo "*/1            * *   *   *   root /usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null" >> $rootdir/etc/crontab
287
+    fi
288
+
289
+    echo 'mesh_install_syncthing'
290 290
 }
291 291
 
292 292
 function install_syncthing {
293
-	if [ $INSTALLING_MESH ]; then
294
-		mesh_install_syncthing
295
-		return
296
-	fi
297
-
298
-	if grep -Fxq "install_syncthing" $COMPLETION_FILE; then
299
-		return
300
-	fi
301
-
302
-	apt-get -y install curl
303
-
304
-	curl -s https://syncthing.net/release-key.txt | apt-key add -
305
-	echo "deb http://apt.syncthing.net/ syncthing release" | tee /etc/apt/sources.list.d/syncthing.list
306
-	apt-get update
307
-	apt-get -y install syncthing
308
-
309
-	# This probably does need to run as root so that it can access the Sync directories
310
-	# in each user's home directory
311
-	echo '[Unit]' > /etc/systemd/system/syncthing.service
312
-	echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
313
-	echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
314
-	echo 'After=network.target' >> /etc/systemd/system/syncthing.service
315
-	echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
316
-	echo '' >> /etc/systemd/system/syncthing.service
317
-	echo '[Service]' >> /etc/systemd/system/syncthing.service
318
-	echo 'User=root' >> /etc/systemd/system/syncthing.service
319
-	echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
320
-	echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
321
-	echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
322
-	echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
323
-	echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
324
-	echo '' >> /etc/systemd/system/syncthing.service
325
-	echo '[Install]' >> /etc/systemd/system/syncthing.service
326
-	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
327
-	systemctl enable syncthing
328
-	systemctl daemon-reload
329
-	systemctl start syncthing
330
-
331
-	function_check cron_add_mins
332
-	cron_add_mins 1 "/usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null"
333
-
334
-	function_check configure_firewall_for_syncthing
335
-	configure_firewall_for_syncthing
336
-	echo 'install_syncthing' >> $COMPLETION_FILE
293
+    if [ $INSTALLING_MESH ]; then
294
+	mesh_install_syncthing
295
+	return
296
+    fi
297
+
298
+    if grep -Fxq "install_syncthing" $COMPLETION_FILE; then
299
+	return
300
+    fi
301
+
302
+    apt-get -y install curl
303
+
304
+    curl -s https://syncthing.net/release-key.txt | apt-key add -
305
+    echo "deb http://apt.syncthing.net/ syncthing release" | tee /etc/apt/sources.list.d/syncthing.list
306
+    apt-get update
307
+    apt-get -y install syncthing
308
+
309
+    # This probably does need to run as root so that it can access the Sync directories
310
+    # in each user's home directory
311
+    echo '[Unit]' > /etc/systemd/system/syncthing.service
312
+    echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
313
+    echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
314
+    echo 'After=network.target' >> /etc/systemd/system/syncthing.service
315
+    echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
316
+    echo '' >> /etc/systemd/system/syncthing.service
317
+    echo '[Service]' >> /etc/systemd/system/syncthing.service
318
+    echo 'User=root' >> /etc/systemd/system/syncthing.service
319
+    echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
320
+    echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
321
+    echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
322
+    echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
323
+    echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
324
+    echo '' >> /etc/systemd/system/syncthing.service
325
+    echo '[Install]' >> /etc/systemd/system/syncthing.service
326
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
327
+    systemctl enable syncthing
328
+    systemctl daemon-reload
329
+    systemctl start syncthing
330
+
331
+    function_check cron_add_mins
332
+    cron_add_mins 1 "/usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null"
333
+
334
+    function_check configure_firewall_for_syncthing
335
+    configure_firewall_for_syncthing
336
+    echo 'install_syncthing' >> $COMPLETION_FILE
337 337
 }
338 338
 
339 339
 # NOTE: deliberately no exit 0

+ 455
- 455
src/freedombone-app-tox
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 21
- 21
src/freedombone-app-vpn Voir le fichier

@@ -39,44 +39,44 @@ function upgrade_vpn {
39 39
 }
40 40
 
41 41
 function backup_local_vpn {
42
-	echo -n ''
42
+    echo -n ''
43 43
 }
44 44
 
45 45
 function restore_local_vpn {
46
-	echo -n ''
46
+    echo -n ''
47 47
 }
48 48
 
49 49
 function backup_remote_vpn {
50
-	echo -n ''
50
+    echo -n ''
51 51
 }
52 52
 
53 53
 function restore_remote_vpn {
54
-	echo -n ''
54
+    echo -n ''
55 55
 }
56 56
 
57 57
 function remove_vpn {
58
-	apt-get -y remove --purge fastd
59
-	sed -i '/install_vpn/d' $COMPLETION_FILE
58
+    apt-get -y remove --purge fastd
59
+    sed -i '/install_vpn/d' $COMPLETION_FILE
60 60
 }
61 61
 
62 62
 function install_vpn {
63
-	if grep -Fxq "install_vpn" $COMPLETION_FILE; then
64
-		return
63
+    if grep -Fxq "install_vpn" $COMPLETION_FILE; then
64
+	return
65
+    fi
66
+    if ! grep -q "repo.universe-factory.net" /etc/apt/sources.list; then
67
+	echo 'deb http://repo.universe-factory.net/debian/ sid main' >> /etc/apt/sources.list
68
+	gpg --keyserver pgpkeys.mit.edu --recv-key 16EF3F64CB201D9C
69
+	if [ ! "$?" = "0" ]; then
70
+	    exit 76272
65 71
 	fi
66
-	if ! grep -q "repo.universe-factory.net" /etc/apt/sources.list; then
67
-		echo 'deb http://repo.universe-factory.net/debian/ sid main' >> /etc/apt/sources.list
68
-		gpg --keyserver pgpkeys.mit.edu --recv-key 16EF3F64CB201D9C
69
-		if [ ! "$?" = "0" ]; then
70
-			exit 76272
71
-		fi
72
-		gpg -a --export 16EF3F64CB201D9C | sudo apt-key add -
73
-		apt-get update
74
-		apt-get -y install fastd
75
-		if [ ! "$?" = "0" ]; then
76
-			exit 52026
77
-		fi
72
+	gpg -a --export 16EF3F64CB201D9C | sudo apt-key add -
73
+	apt-get update
74
+	apt-get -y install fastd
75
+	if [ ! "$?" = "0" ]; then
76
+	    exit 52026
78 77
 	fi
79
-	echo 'install_vpn' >> $COMPLETION_FILE
78
+    fi
79
+    echo 'install_vpn' >> $COMPLETION_FILE
80 80
 }
81 81
 
82 82
 # NOTE: deliberately there is no "exit 0"

+ 166
- 166
src/freedombone-app-webmail Voir le fichier

@@ -43,198 +43,198 @@ function reconfigure_webmail {
43 43
 }
44 44
 
45 45
 function upgrade_webmail {
46
-	if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
47
-		return
48
-	fi
49
-	function_check set_repo_commit
50
-	set_repo_commit $WEBMAIL_PATH "Webmail commit" "$WEBMAIL_COMMIT" $WEBMAIL_REPO
46
+    if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
47
+	return
48
+    fi
49
+    function_check set_repo_commit
50
+    set_repo_commit $WEBMAIL_PATH "Webmail commit" "$WEBMAIL_COMMIT" $WEBMAIL_REPO
51 51
 }
52 52
 
53 53
 function backup_local_webmail {
54
-	if ! grep -q "install_webmail" $COMPLETION_FILE; then
55
-		return
56
-	fi
57
-	echo $"Backing up webmail"
54
+    if ! grep -q "install_webmail" $COMPLETION_FILE; then
55
+	return
56
+    fi
57
+    echo $"Backing up webmail"
58 58
 
59
-	function_check backup_database_to_usb
60
-	backup_database_to_usb webmail
59
+    function_check backup_database_to_usb
60
+    backup_database_to_usb webmail
61 61
 
62
-	echo $"Backing up webmail complete"
62
+    echo $"Backing up webmail complete"
63 63
 }
64 64
 
65 65
 function restore_local_webmail {
66
-	if ! grep -q "install_webmail" $COMPLETION_FILE; then
67
-		return
68
-	fi
69
-	echo $"Restoring webmail"
66
+    if ! grep -q "install_webmail" $COMPLETION_FILE; then
67
+	return
68
+    fi
69
+    echo $"Restoring webmail"
70 70
 
71
-	function_check restore_database
72
-	restore_database webmail
71
+    function_check restore_database
72
+    restore_database webmail
73 73
 
74
-	echo $"Restore of webmail complete"
74
+    echo $"Restore of webmail complete"
75 75
 }
76 76
 
77 77
 function backup_remote_webmail {
78
-	echo -n ''
78
+    echo -n ''
79 79
 }
80 80
 
81 81
 function restore_remote_webmail {
82
-	echo -n ''
82
+    echo -n ''
83 83
 }
84 84
 
85 85
 function remove_webmail {
86
-	if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
87
-		return
88
-	fi
89
-	nginx_dissite webmail
90
-	if [ -f /etc/nginx/sites-available/webmail ]; then
91
-		rm /etc/nginx/sites-available/webmail
92
-	fi
93
-	function_check remove_onion_service
94
-	remove_onion_service webmail ${WEBMAIL_ONION_PORT}
95
-	function_check drop_database
96
-	drop_database webmail
97
-	if [ -d $WEB_PATH/webmail ]; then
98
-		rm -rf $WEB_PATH/webmail
99
-	fi
100
-	sed -i '/Webmail /d' $COMPLETION_FILE
101
-	sed -i '/install_webmail/d' $COMPLETION_FILE
86
+    if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
87
+	return
88
+    fi
89
+    nginx_dissite webmail
90
+    if [ -f /etc/nginx/sites-available/webmail ]; then
91
+	rm /etc/nginx/sites-available/webmail
92
+    fi
93
+    function_check remove_onion_service
94
+    remove_onion_service webmail ${WEBMAIL_ONION_PORT}
95
+    function_check drop_database
96
+    drop_database webmail
97
+    if [ -d $WEB_PATH/webmail ]; then
98
+	rm -rf $WEB_PATH/webmail
99
+    fi
100
+    sed -i '/Webmail /d' $COMPLETION_FILE
101
+    sed -i '/install_webmail/d' $COMPLETION_FILE
102 102
 }
103 103
 
104 104
 function install_webmail {
105
-	if grep -Fxq "install_webmail" $COMPLETION_FILE; then
106
-		return
105
+    if grep -Fxq "install_webmail" $COMPLETION_FILE; then
106
+	return
107
+    fi
108
+    if [ -d /etc/apache2 ]; then
109
+	rm -rf /etc/apache2
110
+	echo $'Removed Apache installation after Dokuwiki install'
111
+    fi
112
+
113
+    function_check install_mariadb
114
+    install_mariadb
115
+
116
+    function_check get_mariadb_password
117
+    get_mariadb_password
118
+
119
+    function_check repair_databases_script
120
+    repair_databases_script
121
+
122
+    apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
123
+    apt-get -y install php5-dev imagemagick php5-imagick php5-sqlite php-auth-sasl php-net-smtp php-mime-type
124
+    apt-get -y install php-mail-mime php-mail-mimedecode php-net-ldap3 php5-pspell
125
+    pear install Net_IDNA2
126
+
127
+    if [ ! -f $WEBMAIL_PATH/index.php ]; then
128
+	cd $WEB_PATH
129
+	git_clone $WEBMAIL_REPO webmail
130
+	cd $WEBMAIL_PATH
131
+	git checkout $WEBMAIL_COMMIT -b $WEBMAIL_COMMIT
132
+	if ! grep -q "Webmail commit" $COMPLETION_FILE; then
133
+	    echo "Webmail commit:$WEBMAIL_COMMIT" >> $COMPLETION_FILE
134
+	else
135
+	    sed -i "s/Webmail commit.*/Webmail commit:$WEBMAIL_COMMIT/g" $COMPLETION_FILE
107 136
 	fi
108
-	if [ -d /etc/apache2 ]; then
109
-		rm -rf /etc/apache2
110
-		echo $'Removed Apache installation after Dokuwiki install'
137
+    fi
138
+    if [ ! -f $WEBMAIL_PATH/index.php ]; then
139
+	echo $'Did not clone webmail repo'
140
+	exit 52825
141
+    fi
142
+
143
+    WEBMAIL_ONION_HOSTNAME=$(add_onion_service webmail 80 ${WEBMAIL_ONION_PORT})
144
+    echo "Webmail onion domain:${WEBMAIL_ONION_HOSTNAME}" >> $COMPLETION_FILE
145
+
146
+    function_check get_mariadb_webmail_admin_password
147
+    get_mariadb_webmail_admin_password
148
+    if [ ! $WEBMAIL_ADMIN_PASSWORD ]; then
149
+	if [ -f $IMAGE_PASSWORD_FILE ]; then
150
+	    WEBMAIL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
151
+	else
152
+	    WEBMAIL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
111 153
 	fi
112
-
113
-	function_check install_mariadb
114
-	install_mariadb
115
-
116
-	function_check get_mariadb_password
117
-	get_mariadb_password
118
-
119
-	function_check repair_databases_script
120
-	repair_databases_script
121
-
122
-	apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
123
-	apt-get -y install php5-dev imagemagick php5-imagick php5-sqlite php-auth-sasl php-net-smtp php-mime-type
124
-	apt-get -y install php-mail-mime php-mail-mimedecode php-net-ldap3 php5-pspell
125
-	pear install Net_IDNA2
126
-
127
-	if [ ! -f $WEBMAIL_PATH/index.php ]; then
128
-		cd $WEB_PATH
129
-		git_clone $WEBMAIL_REPO webmail
130
-		cd $WEBMAIL_PATH
131
-		git checkout $WEBMAIL_COMMIT -b $WEBMAIL_COMMIT
132
-		if ! grep -q "Webmail commit" $COMPLETION_FILE; then
133
-			echo "Webmail commit:$WEBMAIL_COMMIT" >> $COMPLETION_FILE
134
-		else
135
-			sed -i "s/Webmail commit.*/Webmail commit:$WEBMAIL_COMMIT/g" $COMPLETION_FILE
136
-		fi
137
-	fi
138
-	if [ ! -f $WEBMAIL_PATH/index.php ]; then
139
-		echo $'Did not clone webmail repo'
140
-		exit 52825
141
-	fi
142
-
143
-	WEBMAIL_ONION_HOSTNAME=$(add_onion_service webmail 80 ${WEBMAIL_ONION_PORT})
144
-	echo "Webmail onion domain:${WEBMAIL_ONION_HOSTNAME}" >> $COMPLETION_FILE
145
-
146
-	function_check get_mariadb_webmail_admin_password
147
-	get_mariadb_webmail_admin_password
148
-	if [ ! $WEBMAIL_ADMIN_PASSWORD ]; then
149
-		if [ -f $IMAGE_PASSWORD_FILE ]; then
150
-			WEBMAIL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
151
-		else
152
-			WEBMAIL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
153
-		fi
154
-	fi
155
-	function_check create_database
156
-	create_database webmail "$WEBMAIL_ADMIN_PASSWORD"
157
-	mysql -u root --password="$MARIADB_PASSWORD" -D webmail < $WEBMAIL_PATH/SQL/mysql.initial.sql
158
-
159
-	if [ ! -d /var/www/$DEFAULT_DOMAIN_NAME/htdocs ]; then
160
-		mkdir -p /var/www/$DEFAULT_DOMAIN_NAME/htdocs
161
-	fi
162
-	ln -s $WEBMAIL_PATH /var/www/$DEFAULT_DOMAIN_NAME/htdocs/webmail
163
-
164
-	if [ ! -f /var/www/webmail/config/config.inc.php ]; then
165
-		# generate the configuration
166
-		echo '<?php' > /var/www/webmail/config/config.inc.php
167
-		echo "\$config['db_dsnw'] = 'mysql://root:${MARIADB_PASSWORD}@localhost/webmail';" >> /var/www/webmail/config/config.inc.php
168
-		echo "\$config['default_host'] = 'localhost';" >> /var/www/webmail/config/config.inc.php
169
-		echo "\$config['support_url'] = '';" >> /var/www/webmail/config/config.inc.php
170
-		WEBMAIL_DES_KEY="$(create_password 25)"
171
-		echo "\$config['des_key'] = '${WEBMAIL_DES_KEY}';" >> /var/www/webmail/config/config.inc.php
172
-		echo "\$config['product_name'] = '${PROJECT_NAME}';" >> /var/www/webmail/config/config.inc.php
173
-		echo "\$config['plugins'] = array('enigma');" >> /var/www/webmail/config/config.inc.php
174
-		echo "\$config['mime_param_folding'] = 0;" >> /var/www/webmail/config/config.inc.php
175
-		echo "\$config['enable_installer'] = false;" >> /var/www/webmail/config/config.inc.php
176
-	fi
177
-
178
-	chown -R www-data:www-data $WEBMAIL_PATH
179
-
180
-	echo 'server {' > /etc/nginx/sites-available/webmail
181
-	echo "  listen 127.0.0.1:$WEBMAIL_ONION_PORT default_server;" >> /etc/nginx/sites-available/webmail
182
-	echo "  server_name $WEBMAIL_ONION_HOSTNAME;" >> /etc/nginx/sites-available/webmail
183
-	echo "  root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
184
-	echo '  index index.php index.html index.htm;' >> /etc/nginx/sites-available/webmail
185
-	echo '  access_log off;' >> /etc/nginx/sites-available/webmail
186
-	echo '  error_log off;' >> /etc/nginx/sites-available/webmail
187
-	echo '  location / {' >> /etc/nginx/sites-available/webmail
188
-	echo '    try_files $uri $uri/ /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/webmail
189
-	echo '  }' >> /etc/nginx/sites-available/webmail
190
-	echo '  error_page 404 /404.html;' >> /etc/nginx/sites-available/webmail
191
-	echo '  error_page 500 502 503 504 /50x.html;' >> /etc/nginx/sites-available/webmail
192
-	echo '  location = /50x.html {' >> /etc/nginx/sites-available/webmail
193
-	echo "    root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
194
-	echo '  }' >> /etc/nginx/sites-available/webmail
195
-	echo '  location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {' >> /etc/nginx/sites-available/webmail
196
-	echo '    deny all;' >> /etc/nginx/sites-available/webmail
197
-	echo '  }' >> /etc/nginx/sites-available/webmail
198
-	echo '  location ~ ^/(config|temp|logs)/ {' >> /etc/nginx/sites-available/webmail
199
-	echo '    deny all;' >> /etc/nginx/sites-available/webmail
200
-	echo '  }' >> /etc/nginx/sites-available/webmail
201
-	echo '  location ~ /\. {' >> /etc/nginx/sites-available/webmail
202
-	echo '    deny all;' >> /etc/nginx/sites-available/webmail
203
-	echo '    access_log off;' >> /etc/nginx/sites-available/webmail
204
-	echo '    log_not_found off;' >> /etc/nginx/sites-available/webmail
205
-	echo '  }' >> /etc/nginx/sites-available/webmail
206
-	echo '  location ~ \.php$ {' >> /etc/nginx/sites-available/webmail
207
-	echo '    try_files $uri =404;' >> /etc/nginx/sites-available/webmail
208
-	echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/webmail
209
-	echo '    fastcgi_index index.php;' >> /etc/nginx/sites-available/webmail
210
-	echo '    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/webmail
211
-	echo '    include fastcgi_params;' >> /etc/nginx/sites-available/webmail
212
-	echo '  }' >> /etc/nginx/sites-available/webmail
213
-	echo '  add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/webmail
214
-	echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/webmail
215
-	echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/webmail
216
-	echo '}' >> /etc/nginx/sites-available/webmail
217
-
218
-	nginx_ensite webmail
219
-	systemctl restart php5-fpm
220
-	systemctl restart nginx
221
-
222
-	if ! grep -q "Webmail" /home/$MY_USERNAME/README; then
223
-		echo '' >> /home/$MY_USERNAME/README
224
-		echo '' >> /home/$MY_USERNAME/README
225
-		echo 'Webmail' >> /home/$MY_USERNAME/README
226
-		echo '=======' >> /home/$MY_USERNAME/README
227
-		if [[ $ONION_ONLY == 'no' ]]; then
228
-			echo $"Open https://$DEFAULT_DOMAIN_NAME/webmail/index.php" >> /home/$MY_USERNAME/README
229
-		else
230
-			echo $"Open http://$WEBMAIL_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
231
-		fi
232
-		echo $"MariaDB webmail admin password: $WEBMAIL_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
233
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
234
-		chmod 600 /home/$MY_USERNAME/README
154
+    fi
155
+    function_check create_database
156
+    create_database webmail "$WEBMAIL_ADMIN_PASSWORD"
157
+    mysql -u root --password="$MARIADB_PASSWORD" -D webmail < $WEBMAIL_PATH/SQL/mysql.initial.sql
158
+
159
+    if [ ! -d /var/www/$DEFAULT_DOMAIN_NAME/htdocs ]; then
160
+	mkdir -p /var/www/$DEFAULT_DOMAIN_NAME/htdocs
161
+    fi
162
+    ln -s $WEBMAIL_PATH /var/www/$DEFAULT_DOMAIN_NAME/htdocs/webmail
163
+
164
+    if [ ! -f /var/www/webmail/config/config.inc.php ]; then
165
+	# generate the configuration
166
+	echo '<?php' > /var/www/webmail/config/config.inc.php
167
+	echo "\$config['db_dsnw'] = 'mysql://root:${MARIADB_PASSWORD}@localhost/webmail';" >> /var/www/webmail/config/config.inc.php
168
+	echo "\$config['default_host'] = 'localhost';" >> /var/www/webmail/config/config.inc.php
169
+	echo "\$config['support_url'] = '';" >> /var/www/webmail/config/config.inc.php
170
+	WEBMAIL_DES_KEY="$(create_password 25)"
171
+	echo "\$config['des_key'] = '${WEBMAIL_DES_KEY}';" >> /var/www/webmail/config/config.inc.php
172
+	echo "\$config['product_name'] = '${PROJECT_NAME}';" >> /var/www/webmail/config/config.inc.php
173
+	echo "\$config['plugins'] = array('enigma');" >> /var/www/webmail/config/config.inc.php
174
+	echo "\$config['mime_param_folding'] = 0;" >> /var/www/webmail/config/config.inc.php
175
+	echo "\$config['enable_installer'] = false;" >> /var/www/webmail/config/config.inc.php
176
+    fi
177
+
178
+    chown -R www-data:www-data $WEBMAIL_PATH
179
+
180
+    echo 'server {' > /etc/nginx/sites-available/webmail
181
+    echo "  listen 127.0.0.1:$WEBMAIL_ONION_PORT default_server;" >> /etc/nginx/sites-available/webmail
182
+    echo "  server_name $WEBMAIL_ONION_HOSTNAME;" >> /etc/nginx/sites-available/webmail
183
+    echo "  root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
184
+    echo '  index index.php index.html index.htm;' >> /etc/nginx/sites-available/webmail
185
+    echo '  access_log off;' >> /etc/nginx/sites-available/webmail
186
+    echo '  error_log off;' >> /etc/nginx/sites-available/webmail
187
+    echo '  location / {' >> /etc/nginx/sites-available/webmail
188
+    echo '    try_files $uri $uri/ /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/webmail
189
+    echo '  }' >> /etc/nginx/sites-available/webmail
190
+    echo '  error_page 404 /404.html;' >> /etc/nginx/sites-available/webmail
191
+    echo '  error_page 500 502 503 504 /50x.html;' >> /etc/nginx/sites-available/webmail
192
+    echo '  location = /50x.html {' >> /etc/nginx/sites-available/webmail
193
+    echo "    root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
194
+    echo '  }' >> /etc/nginx/sites-available/webmail
195
+    echo '  location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {' >> /etc/nginx/sites-available/webmail
196
+    echo '    deny all;' >> /etc/nginx/sites-available/webmail
197
+    echo '  }' >> /etc/nginx/sites-available/webmail
198
+    echo '  location ~ ^/(config|temp|logs)/ {' >> /etc/nginx/sites-available/webmail
199
+    echo '    deny all;' >> /etc/nginx/sites-available/webmail
200
+    echo '  }' >> /etc/nginx/sites-available/webmail
201
+    echo '  location ~ /\. {' >> /etc/nginx/sites-available/webmail
202
+    echo '    deny all;' >> /etc/nginx/sites-available/webmail
203
+    echo '    access_log off;' >> /etc/nginx/sites-available/webmail
204
+    echo '    log_not_found off;' >> /etc/nginx/sites-available/webmail
205
+    echo '  }' >> /etc/nginx/sites-available/webmail
206
+    echo '  location ~ \.php$ {' >> /etc/nginx/sites-available/webmail
207
+    echo '    try_files $uri =404;' >> /etc/nginx/sites-available/webmail
208
+    echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/webmail
209
+    echo '    fastcgi_index index.php;' >> /etc/nginx/sites-available/webmail
210
+    echo '    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/webmail
211
+    echo '    include fastcgi_params;' >> /etc/nginx/sites-available/webmail
212
+    echo '  }' >> /etc/nginx/sites-available/webmail
213
+    echo '  add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/webmail
214
+    echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/webmail
215
+    echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/webmail
216
+    echo '}' >> /etc/nginx/sites-available/webmail
217
+
218
+    nginx_ensite webmail
219
+    systemctl restart php5-fpm
220
+    systemctl restart nginx
221
+
222
+    if ! grep -q "Webmail" /home/$MY_USERNAME/README; then
223
+	echo '' >> /home/$MY_USERNAME/README
224
+	echo '' >> /home/$MY_USERNAME/README
225
+	echo 'Webmail' >> /home/$MY_USERNAME/README
226
+	echo '=======' >> /home/$MY_USERNAME/README
227
+	if [[ $ONION_ONLY == 'no' ]]; then
228
+	    echo $"Open https://$DEFAULT_DOMAIN_NAME/webmail/index.php" >> /home/$MY_USERNAME/README
229
+	else
230
+	    echo $"Open http://$WEBMAIL_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
235 231
 	fi
232
+	echo $"MariaDB webmail admin password: $WEBMAIL_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
233
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
234
+	chmod 600 /home/$MY_USERNAME/README
235
+    fi
236 236
 
237
-	echo 'install_webmail' >> $COMPLETION_FILE
237
+    echo 'install_webmail' >> $COMPLETION_FILE
238 238
 }
239 239
 
240 240
 # NOTE: deliberately no exit 0

+ 389
- 389
src/freedombone-app-wiki Voir le fichier

@@ -37,391 +37,302 @@ WIKI_CODE=
37 37
 WIKI_ONION_PORT=8089
38 38
 
39 39
 function reconfigure_wiki {
40
-	echo -n ''
40
+    echo -n ''
41 41
 }
42 42
 
43 43
 function upgrade_wiki {
44
-	echo -n ''
44
+    echo -n ''
45 45
 }
46 46
 
47 47
 function backup_local_wiki {
48
-	source_directory=/var/lib/dokuwiki
49
-	if [ -d $source_directory ]; then
50
-		dest_directory=wiki
51
-		echo $"Backing up $source_directory to $dest_directory"
48
+    source_directory=/var/lib/dokuwiki
49
+    if [ -d $source_directory ]; then
50
+	dest_directory=wiki
51
+	echo $"Backing up $source_directory to $dest_directory"
52 52
 
53
-		function_check backup_directory_to_usb
54
-		backup_directory_to_usb $source_directory $dest_directory
55
-		backup_directory_to_usb /etc/dokuwiki wiki2
53
+	function_check backup_directory_to_usb
54
+	backup_directory_to_usb $source_directory $dest_directory
55
+	backup_directory_to_usb /etc/dokuwiki wiki2
56 56
 
57
-		echo $"Backup to $dest_directory complete"
58
-	fi
57
+	echo $"Backup to $dest_directory complete"
58
+    fi
59 59
 }
60 60
 
61 61
 function restore_local_wiki {
62
-	if [ -d /var/lib/dokuwiki ]; then
63
-		echo $"Restoring Wiki installation"
64
-		WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
65
-		temp_restore_dir=/root/tempwiki
66
-		function_check restore_directory_from_usb
67
-		restore_directory_from_usb $temp_restore_dir wiki
68
-		cp -r $temp_restore_dir/var/lib/dokuwiki/* /var/lib/dokuwiki/
69
-		if [ ! "$?" = "0" ]; then
70
-			function_check restore_directory_from_usb
71
-			set_user_permissions
72
-			function_check backup_unmount_drive
73
-			backup_unmount_drive
74
-			exit 868
75
-		fi
76
-		restore_directory_from_usb ${temp_restore_dir}2 wiki2
77
-		cp -r ${temp_restore_dir}2/etc/dokuwiki/* /etc/dokuwiki/
78
-		if [ ! "$?" = "0" ]; then
79
-			function_check set_user_permissions
80
-			set_user_permissions
81
-			function_check backup_unmount_drive
82
-			backup_unmount_drive
83
-			exit 869
84
-		fi
85
-		rm -rf $temp_restore_dir
86
-		rm -rf ${temp_restore_dir}2
87
-		chown -R www-data:www-data /var/lib/dokuwiki/*
88
-		# Ensure that the bundled SSL cert is being used
89
-		if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
90
-			sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
91
-		fi
92
-		if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
93
-			ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
94
-			ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
95
-		fi
96
-		echo $"Restore of Wiki complete"
62
+    if [ -d /var/lib/dokuwiki ]; then
63
+	echo $"Restoring Wiki installation"
64
+	WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
65
+	temp_restore_dir=/root/tempwiki
66
+	function_check restore_directory_from_usb
67
+	restore_directory_from_usb $temp_restore_dir wiki
68
+	cp -r $temp_restore_dir/var/lib/dokuwiki/* /var/lib/dokuwiki/
69
+	if [ ! "$?" = "0" ]; then
70
+	    function_check restore_directory_from_usb
71
+	    set_user_permissions
72
+	    function_check backup_unmount_drive
73
+	    backup_unmount_drive
74
+	    exit 868
75
+	fi
76
+	restore_directory_from_usb ${temp_restore_dir}2 wiki2
77
+	cp -r ${temp_restore_dir}2/etc/dokuwiki/* /etc/dokuwiki/
78
+	if [ ! "$?" = "0" ]; then
79
+	    function_check set_user_permissions
80
+	    set_user_permissions
81
+	    function_check backup_unmount_drive
82
+	    backup_unmount_drive
83
+	    exit 869
84
+	fi
85
+	rm -rf $temp_restore_dir
86
+	rm -rf ${temp_restore_dir}2
87
+	chown -R www-data:www-data /var/lib/dokuwiki/*
88
+	# Ensure that the bundled SSL cert is being used
89
+	if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
90
+	    sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
91
+	fi
92
+	if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
93
+	    ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
94
+	    ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
97 95
 	fi
96
+	echo $"Restore of Wiki complete"
97
+    fi
98 98
 }
99 99
 
100 100
 function backup_remote_wiki {
101
-	if [ -d /etc/dokuwiki ]; then
102
-		echo $"Backing up wiki"
103
-		backup_directory_to_friend /var/lib/dokuwiki wiki
104
-		backup_directory_to_friend /etc/dokuwiki wiki2
105
-	fi
101
+    if [ -d /etc/dokuwiki ]; then
102
+	echo $"Backing up wiki"
103
+	backup_directory_to_friend /var/lib/dokuwiki wiki
104
+	backup_directory_to_friend /etc/dokuwiki wiki2
105
+    fi
106 106
 }
107 107
 
108 108
 function restore_remote_wiki {
109
-	if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
110
-		WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
111
-		echo $"Restoring Wiki installation $WIKI_DOMAIN_NAME"
112
-		function_check restore_directory_from_friend
113
-		restore_directory_from_friend /root/tempwiki wiki
114
-		cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
115
-		if [ ! "$?" = "0" ]; then
116
-			exit 868
117
-		fi
118
-		restore_directory_from_friend /root/tempwiki2 wiki2
119
-		cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
120
-		if [ ! "$?" = "0" ]; then
121
-			exit 869
122
-		fi
123
-		rm -rf /root/tempwiki
124
-		rm -rf /root/tempwiki2
125
-		chown -R www-data:www-data /var/lib/dokuwiki/*
126
-		# Ensure that the bundled SSL cert is being used
127
-		if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
128
-			sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
129
-		fi
130
-		if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
131
-			ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
132
-			ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
133
-		fi
134
-		echo $"Restore of Wiki complete"
109
+    if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
110
+	WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
111
+	echo $"Restoring Wiki installation $WIKI_DOMAIN_NAME"
112
+	function_check restore_directory_from_friend
113
+	restore_directory_from_friend /root/tempwiki wiki
114
+	cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
115
+	if [ ! "$?" = "0" ]; then
116
+	    exit 868
135 117
 	fi
136
-}
137
-
138
-function remove_wiki {
139
-	if ! grep -Fxq "install_wiki" $COMPLETION_FILE; then
140
-		return
118
+	restore_directory_from_friend /root/tempwiki2 wiki2
119
+	cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
120
+	if [ ! "$?" = "0" ]; then
121
+	    exit 869
141 122
 	fi
142
-	function_check remove_onion_service
143
-	remove_onion_service wiki ${WIKI_ONION_PORT}
144
-	nginx_dissite $WIKI_DOMAIN_NAME
145
-	if [ -f /etc/nginx/sites-available/$WIKI_DOMAIN_NAME ]; then
146
-		rm /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
123
+	rm -rf /root/tempwiki
124
+	rm -rf /root/tempwiki2
125
+	chown -R www-data:www-data /var/lib/dokuwiki/*
126
+	# Ensure that the bundled SSL cert is being used
127
+	if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
128
+	    sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
147 129
 	fi
148
-	apt-get -y remove --purge dokuwiki
149
-	if [ ! -d /var/www/$WIKI_DOMAIN_NAME ]; then
150
-		rm -rf /var/www/$WIKI_DOMAIN_NAME
130
+	if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
131
+	    ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
132
+	    ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
151 133
 	fi
152
-	if [ -d /var/lib/dokuwiki ]; then
153
-		rm -rf /var/lib/dokuwiki
154
-	fi
155
-	if [ -d /etc/dokuwiki ]; then
156
-		rm -rf /etc/dokuwiki
157
-	fi
158
-	if [ -d /usr/share/dokuwiki ]; then
159
-		rm -rf /usr/share/dokuwiki
160
-	fi
161
-	sed -i '/install_wiki/d' $COMPLETION_FILE
134
+	echo $"Restore of Wiki complete"
135
+    fi
136
+}
137
+
138
+function remove_wiki {
139
+    if ! grep -Fxq "install_wiki" $COMPLETION_FILE; then
140
+	return
141
+    fi
142
+    function_check remove_onion_service
143
+    remove_onion_service wiki ${WIKI_ONION_PORT}
144
+    nginx_dissite $WIKI_DOMAIN_NAME
145
+    if [ -f /etc/nginx/sites-available/$WIKI_DOMAIN_NAME ]; then
146
+	rm /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
147
+    fi
148
+    apt-get -y remove --purge dokuwiki
149
+    if [ ! -d /var/www/$WIKI_DOMAIN_NAME ]; then
150
+	rm -rf /var/www/$WIKI_DOMAIN_NAME
151
+    fi
152
+    if [ -d /var/lib/dokuwiki ]; then
153
+	rm -rf /var/lib/dokuwiki
154
+    fi
155
+    if [ -d /etc/dokuwiki ]; then
156
+	rm -rf /etc/dokuwiki
157
+    fi
158
+    if [ -d /usr/share/dokuwiki ]; then
159
+	rm -rf /usr/share/dokuwiki
160
+    fi
161
+    sed -i '/install_wiki/d' $COMPLETION_FILE
162 162
 }
163 163
 
164 164
 function get_wiki_admin_password {
165
-	if [ -f /home/$MY_USERNAME/README ]; then
166
-		if grep -q "Wiki password" /home/$MY_USERNAME/README; then
167
-			WIKI_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Wiki password:" | awk -F ':' '{print $2}' | sed 's/^ *//')
168
-		fi
165
+    if [ -f /home/$MY_USERNAME/README ]; then
166
+	if grep -q "Wiki password" /home/$MY_USERNAME/README; then
167
+	    WIKI_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Wiki password:" | awk -F ':' '{print $2}' | sed 's/^ *//')
169 168
 	fi
169
+    fi
170 170
 }
171 171
 
172 172
 function install_wiki {
173
-	if grep -Fxq "install_wiki" $COMPLETION_FILE; then
174
-		return
175
-	fi
176
-	if [ ! $WIKI_DOMAIN_NAME ]; then
177
-		return
178
-	fi
179
-	apt-get -y install dokuwiki
180
-	apt-get -y remove --purge apache*
181
-	if [ -d /etc/apache2 ]; then
182
-		rm -rf /etc/apache2
183
-		echo $'Removed Apache installation after Dokuwiki install'
184
-	fi
185
-
186
-	if [ ! -d /var/www/$WIKI_DOMAIN_NAME ]; then
187
-		mkdir /var/www/$WIKI_DOMAIN_NAME
188
-	fi
189
-	if [ -d /var/www/$WIKI_DOMAIN_NAME/htdocs ]; then
190
-		rm -rf /var/www/$WIKI_DOMAIN_NAME/htdocs
191
-	fi
192
-
193
-	ln -s /usr/share/dokuwiki /var/www/$WIKI_DOMAIN_NAME/htdocs
194
-
195
-	mkdir /var/lib/dokuwiki/custom
196
-	cp /etc/dokuwiki/local.php.dist /var/lib/dokuwiki/custom/local.php
197
-	ln -s /var/lib/dokuwiki/custom/local.php /etc/dokuwiki/local.php
198
-
199
-	chown www-data /var/lib/dokuwiki/custom
200
-	chown www-data /var/lib/dokuwiki/custom/local.php
201
-	chown -R www-data /etc/dokuwiki
202
-	chown -R www-data /usr/share/dokuwiki/lib/
203
-	chmod 600 /var/lib/dokuwiki/custom/local.php
204
-	chmod -R 755 /usr/share/dokuwiki/lib
205
-
206
-	sed -i 's|//$conf|$conf|g' /var/lib/dokuwiki/custom/local.php
207
-	sed -i "s|joe|$MY_USERNAME|g" /var/lib/dokuwiki/custom/local.php
208
-
209
-	sed -i "s|Debian DokuWiki|$WIKI_TITLE|g" /etc/dokuwiki/local.php
210
-
211
-	# set the admin user
212
-	sed -i "s/@admin/$MY_USERNAME/g" /etc/dokuwiki/local.php
213
-
214
-	# disallow registration of new users
215
-	if ! grep -q "disableactions" /etc/dokuwiki/local.php; then
216
-		echo "\$conf['disableactions'] = 'register';" >> /etc/dokuwiki/local.php
217
-	fi
218
-	if ! grep -q "disableactions" /var/lib/dokuwiki/custom/local.php; then
219
-		echo "\$conf['disableactions'] = 'register';" >> /var/lib/dokuwiki/custom/local.php
220
-	fi
221
-
222
-	if ! grep -q "authtype" /var/lib/dokuwiki/custom/local.php; then
223
-		echo "\$conf['authtype'] = 'authplain';" >> /var/lib/dokuwiki/custom/local.php
224
-	fi
225
-	if ! grep -q "authtype" /etc/dokuwiki/local.php; then
226
-		echo "\$conf['authtype'] = 'authplain';" >> /etc/dokuwiki/local.php
227
-	fi
228
-
229
-	function_check get_wiki_admin_password
230
-	get_wiki_admin_password
231
-	if [ ! $WIKI_ADMIN_PASSWORD ]; then
232
-		if [ -f $IMAGE_PASSWORD_FILE ]; then
233
-			WIKI_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
234
-		else
235
-			WIKI_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
236
-		fi
237
-	fi
238
-	HASHED_WIKI_PASSWORD=$(echo -n "$WIKI_ADMIN_PASSWORD" | md5sum | awk -F ' ' '{print $1}')
239
-	echo -n "$MY_USERNAME:$HASHED_WIKI_PASSWORD:$MY_NAME:$MY_EMAIL:admin,user,upload" > /var/lib/dokuwiki/acl/users.auth.php
240
-	chmod 640 /var/lib/dokuwiki/acl/users.auth.php
241
-
242
-	if ! grep -q "video/ogg" /etc/dokuwiki/mime.conf; then
243
-		echo 'ogv     video/ogg' >> /etc/dokuwiki/mime.conf
244
-	fi
245
-	if ! grep -q "video/mp4" /etc/dokuwiki/mime.conf; then
246
-		echo 'mp4     video/mp4' >> /etc/dokuwiki/mime.conf
247
-	fi
248
-	if ! grep -q "video/webm" /etc/dokuwiki/mime.conf; then
249
-		echo 'webm    video/webm' >> /etc/dokuwiki/mime.conf
250
-	fi
251
-
252
-	WIKI_ONION_HOSTNAME=$(add_onion_service wiki 80 ${WIKI_ONION_PORT})
253
-
254
-	if [[ $ONION_ONLY == "no" ]]; then
255
-		echo 'server {' > /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
256
-		echo '    listen 80;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
257
-		echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
258
-		echo "    server_name $WIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
259
-		echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
260
-		echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
261
-		echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
262
-		echo '    charset utf-8;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
263
-		echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
264
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
265
-		function_check nginx_disable_sniffing
266
-		nginx_disable_sniffing $WIKI_DOMAIN_NAME
267
-		function_check nginx_limits
268
-		nginx_limits $WIKI_DOMAIN_NAME
269
-		echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
270
-		echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
271
-		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
272
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
273
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
274
-		echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
275
-		echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
276
-		echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
277
-		echo '        allow all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
278
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
279
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
280
-		echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
281
-		echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
282
-		echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
283
-		echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
284
-		echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
285
-		echo '        expires 30d;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
286
-		echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
287
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
288
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
289
-		echo '    # block these file types' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
290
-		echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
291
-		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
292
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
293
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
294
-		echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
295
-		echo '    # or a unix socket' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
296
-		echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
297
-		echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
298
-		echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
299
-		echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
300
-		echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
301
-		echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
302
-		echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
303
-		echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
304
-		echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
305
-		echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
306
-		echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
307
-		echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
308
-		echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
309
-		echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
310
-		echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
311
-		echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
312
-		echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
313
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
314
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
315
-		echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
316
-		echo '    location ~ /\. {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
317
-		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
318
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
319
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
320
-		echo '    #deny access to store' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
321
-		echo '    location ~ /store {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
322
-		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
323
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
324
-		echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
325
-		echo '      deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
326
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
327
-		echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
328
-		echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
329
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
330
-		echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
331
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
332
-		echo 'server {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
333
-		echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
334
-		echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
335
-		echo "    server_name $WIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
336
-		echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
337
-		echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
338
-		echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
339
-		echo '    charset utf-8;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
340
-		echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
341
-		function_check nginx_limits
342
-		nginx_limits $WIKI_DOMAIN_NAME
343
-		function_check nginx_ssl
344
-		nginx_ssl $WIKI_DOMAIN_NAME
345
-		function_check nginx_disable_sniffing
346
-		nginx_disable_sniffing $WIKI_DOMAIN_NAME
347
-		echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
348
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
349
-		echo '    # webmail' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
350
-		echo '    location /webmail {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
351
-		echo '        rewrite ^/(.*) /webmail/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
352
-		echo '        rewrite ^/(.*) /webmail/installer/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
353
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
354
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
355
-		echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
356
-		echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
357
-		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
358
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
359
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
360
-		echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
361
-		echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
362
-		echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
363
-		echo '        allow all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
364
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
365
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
366
-		echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
367
-		echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
368
-		echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
369
-		echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
370
-		echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
371
-		echo '        expires 30d;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
372
-		echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
373
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
374
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
375
-		echo '    # block these file types' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
376
-		echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
377
-		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
378
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
379
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
380
-		echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
381
-		echo '    # or a unix socket' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
382
-		echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
383
-		echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
384
-		echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
385
-		echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
386
-		echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
387
-		echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
388
-		echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
389
-		echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
390
-		echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
391
-		echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
392
-		echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
393
-		echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
394
-		echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
395
-		echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
396
-		echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
397
-		echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
398
-		echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
399
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
400
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
401
-		echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
402
-		echo '    location ~ /\. {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
403
-		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
404
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
405
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
406
-		echo '    #deny access to store' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
407
-		echo '    location ~ /store {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
408
-		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
409
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
410
-		echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
411
-		echo '      deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
412
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
413
-		echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
414
-		echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
415
-		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
416
-		echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
417
-		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
173
+    if grep -Fxq "install_wiki" $COMPLETION_FILE; then
174
+	return
175
+    fi
176
+    if [ ! $WIKI_DOMAIN_NAME ]; then
177
+	return
178
+    fi
179
+    apt-get -y install dokuwiki
180
+    apt-get -y remove --purge apache*
181
+    if [ -d /etc/apache2 ]; then
182
+	rm -rf /etc/apache2
183
+	echo $'Removed Apache installation after Dokuwiki install'
184
+    fi
185
+
186
+    if [ ! -d /var/www/$WIKI_DOMAIN_NAME ]; then
187
+	mkdir /var/www/$WIKI_DOMAIN_NAME
188
+    fi
189
+    if [ -d /var/www/$WIKI_DOMAIN_NAME/htdocs ]; then
190
+	rm -rf /var/www/$WIKI_DOMAIN_NAME/htdocs
191
+    fi
192
+
193
+    ln -s /usr/share/dokuwiki /var/www/$WIKI_DOMAIN_NAME/htdocs
194
+
195
+    mkdir /var/lib/dokuwiki/custom
196
+    cp /etc/dokuwiki/local.php.dist /var/lib/dokuwiki/custom/local.php
197
+    ln -s /var/lib/dokuwiki/custom/local.php /etc/dokuwiki/local.php
198
+
199
+    chown www-data /var/lib/dokuwiki/custom
200
+    chown www-data /var/lib/dokuwiki/custom/local.php
201
+    chown -R www-data /etc/dokuwiki
202
+    chown -R www-data /usr/share/dokuwiki/lib/
203
+    chmod 600 /var/lib/dokuwiki/custom/local.php
204
+    chmod -R 755 /usr/share/dokuwiki/lib
205
+
206
+    sed -i 's|//$conf|$conf|g' /var/lib/dokuwiki/custom/local.php
207
+    sed -i "s|joe|$MY_USERNAME|g" /var/lib/dokuwiki/custom/local.php
208
+
209
+    sed -i "s|Debian DokuWiki|$WIKI_TITLE|g" /etc/dokuwiki/local.php
210
+
211
+    # set the admin user
212
+    sed -i "s/@admin/$MY_USERNAME/g" /etc/dokuwiki/local.php
213
+
214
+    # disallow registration of new users
215
+    if ! grep -q "disableactions" /etc/dokuwiki/local.php; then
216
+	echo "\$conf['disableactions'] = 'register';" >> /etc/dokuwiki/local.php
217
+    fi
218
+    if ! grep -q "disableactions" /var/lib/dokuwiki/custom/local.php; then
219
+	echo "\$conf['disableactions'] = 'register';" >> /var/lib/dokuwiki/custom/local.php
220
+    fi
221
+
222
+    if ! grep -q "authtype" /var/lib/dokuwiki/custom/local.php; then
223
+	echo "\$conf['authtype'] = 'authplain';" >> /var/lib/dokuwiki/custom/local.php
224
+    fi
225
+    if ! grep -q "authtype" /etc/dokuwiki/local.php; then
226
+	echo "\$conf['authtype'] = 'authplain';" >> /etc/dokuwiki/local.php
227
+    fi
228
+
229
+    function_check get_wiki_admin_password
230
+    get_wiki_admin_password
231
+    if [ ! $WIKI_ADMIN_PASSWORD ]; then
232
+	if [ -f $IMAGE_PASSWORD_FILE ]; then
233
+	    WIKI_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
418 234
 	else
419
-		echo -n '' > /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
235
+	    WIKI_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
420 236
 	fi
237
+    fi
238
+    HASHED_WIKI_PASSWORD=$(echo -n "$WIKI_ADMIN_PASSWORD" | md5sum | awk -F ' ' '{print $1}')
239
+    echo -n "$MY_USERNAME:$HASHED_WIKI_PASSWORD:$MY_NAME:$MY_EMAIL:admin,user,upload" > /var/lib/dokuwiki/acl/users.auth.php
240
+    chmod 640 /var/lib/dokuwiki/acl/users.auth.php
241
+
242
+    if ! grep -q "video/ogg" /etc/dokuwiki/mime.conf; then
243
+	echo 'ogv     video/ogg' >> /etc/dokuwiki/mime.conf
244
+    fi
245
+    if ! grep -q "video/mp4" /etc/dokuwiki/mime.conf; then
246
+	echo 'mp4     video/mp4' >> /etc/dokuwiki/mime.conf
247
+    fi
248
+    if ! grep -q "video/webm" /etc/dokuwiki/mime.conf; then
249
+	echo 'webm    video/webm' >> /etc/dokuwiki/mime.conf
250
+    fi
251
+
252
+    WIKI_ONION_HOSTNAME=$(add_onion_service wiki 80 ${WIKI_ONION_PORT})
253
+
254
+    if [[ $ONION_ONLY == "no" ]]; then
255
+	echo 'server {' > /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
256
+	echo '    listen 80;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
257
+	echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
258
+	echo "    server_name $WIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
259
+	echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
260
+	echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
261
+	echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
262
+	echo '    charset utf-8;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
263
+	echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
264
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
265
+	function_check nginx_disable_sniffing
266
+	nginx_disable_sniffing $WIKI_DOMAIN_NAME
267
+	function_check nginx_limits
268
+	nginx_limits $WIKI_DOMAIN_NAME
269
+	echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
270
+	echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
271
+	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
272
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
273
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
274
+	echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
275
+	echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
276
+	echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
277
+	echo '        allow all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
278
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
279
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
280
+	echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
281
+	echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
282
+	echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
283
+	echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
284
+	echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
285
+	echo '        expires 30d;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
286
+	echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
287
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
288
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
289
+	echo '    # block these file types' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
290
+	echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
291
+	echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
292
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
293
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
294
+	echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
295
+	echo '    # or a unix socket' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
296
+	echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
297
+	echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
298
+	echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
299
+	echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
300
+	echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
301
+	echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
302
+	echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
303
+	echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
304
+	echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
305
+	echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
306
+	echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
307
+	echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
308
+	echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
309
+	echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
310
+	echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
311
+	echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
312
+	echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
313
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
314
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
315
+	echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
316
+	echo '    location ~ /\. {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
317
+	echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
318
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
319
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
320
+	echo '    #deny access to store' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
321
+	echo '    location ~ /store {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
322
+	echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
323
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
324
+	echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
325
+	echo '      deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
326
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
327
+	echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
328
+	echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
329
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
330
+	echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
331
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
421 332
 	echo 'server {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
422
-	echo "    listen 127.0.0.1:${WIKI_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
333
+	echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
423 334
 	echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
424
-	echo "    server_name $WIKI_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
335
+	echo "    server_name $WIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
425 336
 	echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
426 337
 	echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
427 338
 	echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
@@ -429,10 +340,18 @@ function install_wiki {
429 340
 	echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
430 341
 	function_check nginx_limits
431 342
 	nginx_limits $WIKI_DOMAIN_NAME
343
+	function_check nginx_ssl
344
+	nginx_ssl $WIKI_DOMAIN_NAME
432 345
 	function_check nginx_disable_sniffing
433 346
 	nginx_disable_sniffing $WIKI_DOMAIN_NAME
434 347
 	echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
435 348
 	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
349
+	echo '    # webmail' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
350
+	echo '    location /webmail {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
351
+	echo '        rewrite ^/(.*) /webmail/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
352
+	echo '        rewrite ^/(.*) /webmail/installer/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
353
+	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
354
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
436 355
 	echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
437 356
 	echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
438 357
 	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
@@ -495,43 +414,124 @@ function install_wiki {
495 414
 	echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
496 415
 	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
497 416
 	echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
498
-
499
-	function_check create_site_certificate
500
-	create_site_certificate $WIKI_DOMAIN_NAME
501
-
502
-	function_check configure_php
503
-	configure_php
504
-
505
-	nginx_ensite $WIKI_DOMAIN_NAME
506
-
507
-	systemctl restart php5-fpm
508
-	systemctl restart nginx
509
-
510
-	echo "Wiki onion domain:${WIKI_ONION_HOSTNAME}" >> $COMPLETION_FILE
511
-
512
-	function_check add_ddns_domain
513
-	add_ddns_domain $WIKI_DOMAIN_NAME
514
-
515
-	# add some post-install instructions
516
-	if ! grep -q $"Wiki password" /home/$MY_USERNAME/README; then
517
-		echo '' >> /home/$MY_USERNAME/README
518
-		echo '' >> /home/$MY_USERNAME/README
519
-		echo $'Wiki' >> /home/$MY_USERNAME/README
520
-		echo '====' >> /home/$MY_USERNAME/README
521
-		echo $"Wiki onion domain: ${WIKI_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
522
-		echo $"Wiki username: $MY_USERNAME" >> /home/$MY_USERNAME/README
523
-		echo $"Wiki password: $WIKI_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
524
-		echo '' >> /home/$MY_USERNAME/README
525
-		echo $'Once you have set up the wiki then remove the install file:' >> /home/$MY_USERNAME/README
526
-		echo '' >> /home/$MY_USERNAME/README
527
-		echo "  rm /var/www/$WIKI_DOMAIN_NAME/htdocs/install.php" >> /home/$MY_USERNAME/README
528
-		echo '' >> /home/$MY_USERNAME/README
529
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
530
-		chmod 600 /home/$MY_USERNAME/README
531
-	fi
532
-
533
-	echo "Wiki domain:$WIKI_DOMAIN_NAME" >> $COMPLETION_FILE
534
-	echo 'install_wiki' >> $COMPLETION_FILE
417
+	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
418
+    else
419
+	echo -n '' > /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
420
+    fi
421
+    echo 'server {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
422
+    echo "    listen 127.0.0.1:${WIKI_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
423
+    echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
424
+    echo "    server_name $WIKI_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
425
+    echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
426
+    echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
427
+    echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
428
+    echo '    charset utf-8;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
429
+    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
430
+    function_check nginx_limits
431
+    nginx_limits $WIKI_DOMAIN_NAME
432
+    function_check nginx_disable_sniffing
433
+    nginx_disable_sniffing $WIKI_DOMAIN_NAME
434
+    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
435
+    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
436
+    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
437
+    echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
438
+    echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
439
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
440
+    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
441
+    echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
442
+    echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
443
+    echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
444
+    echo '        allow all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
445
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
446
+    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
447
+    echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
448
+    echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
449
+    echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
450
+    echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
451
+    echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
452
+    echo '        expires 30d;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
453
+    echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
454
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
455
+    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
456
+    echo '    # block these file types' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
457
+    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
458
+    echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
459
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
460
+    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
461
+    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
462
+    echo '    # or a unix socket' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
463
+    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
464
+    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
465
+    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
466
+    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
467
+    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
468
+    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
469
+    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
470
+    echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
471
+    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
472
+    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
473
+    echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
474
+    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
475
+    echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
476
+    echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
477
+    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
478
+    echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
479
+    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
480
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
481
+    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
482
+    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
483
+    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
484
+    echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
485
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
486
+    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
487
+    echo '    #deny access to store' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
488
+    echo '    location ~ /store {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
489
+    echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
490
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
491
+    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
492
+    echo '      deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
493
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
494
+    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
495
+    echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
496
+    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
497
+    echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
498
+
499
+    function_check create_site_certificate
500
+    create_site_certificate $WIKI_DOMAIN_NAME
501
+
502
+    function_check configure_php
503
+    configure_php
504
+
505
+    nginx_ensite $WIKI_DOMAIN_NAME
506
+
507
+    systemctl restart php5-fpm
508
+    systemctl restart nginx
509
+
510
+    echo "Wiki onion domain:${WIKI_ONION_HOSTNAME}" >> $COMPLETION_FILE
511
+
512
+    function_check add_ddns_domain
513
+    add_ddns_domain $WIKI_DOMAIN_NAME
514
+
515
+    # add some post-install instructions
516
+    if ! grep -q $"Wiki password" /home/$MY_USERNAME/README; then
517
+	echo '' >> /home/$MY_USERNAME/README
518
+	echo '' >> /home/$MY_USERNAME/README
519
+	echo $'Wiki' >> /home/$MY_USERNAME/README
520
+	echo '====' >> /home/$MY_USERNAME/README
521
+	echo $"Wiki onion domain: ${WIKI_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
522
+	echo $"Wiki username: $MY_USERNAME" >> /home/$MY_USERNAME/README
523
+	echo $"Wiki password: $WIKI_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
524
+	echo '' >> /home/$MY_USERNAME/README
525
+	echo $'Once you have set up the wiki then remove the install file:' >> /home/$MY_USERNAME/README
526
+	echo '' >> /home/$MY_USERNAME/README
527
+	echo "  rm /var/www/$WIKI_DOMAIN_NAME/htdocs/install.php" >> /home/$MY_USERNAME/README
528
+	echo '' >> /home/$MY_USERNAME/README
529
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
530
+	chmod 600 /home/$MY_USERNAME/README
531
+    fi
532
+
533
+    echo "Wiki domain:$WIKI_DOMAIN_NAME" >> $COMPLETION_FILE
534
+    echo 'install_wiki' >> $COMPLETION_FILE
535 535
 }
536 536
 
537 537
 # NOTE: deliberately no exit 0

+ 399
- 399
src/freedombone-app-xmpp Voir le fichier

@@ -38,444 +38,444 @@ XMPP_CIPHERS='"EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+
38 38
 XMPP_ECC_CURVE='"secp384r1"'
39 39
 
40 40
 function reconfigure_xmpp {
41
-	echo -n ''
41
+    echo -n ''
42 42
 }
43 43
 
44 44
 function update_prosody_modules {
45
-	if [ ! -d $INSTALL_DIR/prosody-modules ]; then
46
-		return
47
-	fi
48
-	if [ ! -d /usr/lib/prosody ]; then
49
-		return
50
-	fi
51
-
52
-	cd $INSTALL_DIR/prosody-modules
53
-	hg pull
54
-	hg update
55
-
56
-	# support onion addresses
57
-	if [ -f $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua ]; then
58
-		cp $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua /usr/lib/prosody/modules/mod_onions.lua
59
-	fi
60
-
61
-	# XEP-0313 message archive management
62
-	# https://modules.prosody.im/mod_mam.html
63
-	# Allows you to download your previous messages onto a new client
64
-	# This only applies if you are not using forward secret crypto
65
-	# such as OTR or OMEMO (eg. OpenPGP)
66
-	if [ -d $INSTALL_DIR/prosody-modules/mod_mam ]; then
67
-		cp $INSTALL_DIR/prosody-modules/mod_mam/*.lua /usr/lib/prosody/modules
68
-	fi
69
-
70
-	# XEP-0352 Client State Indication
71
-	# Notifies the server if the app is in the background or not
72
-	if [ -d $INSTALL_DIR/prosody-modules/mod_csi ]; then
73
-		cp $INSTALL_DIR/prosody-modules/mod_csi/*.lua /usr/lib/prosody/modules
74
-	fi
75
-
76
-	# XEP-0280 Message Carbons
77
-	# Ensures all messages get delivered to all clients (if you have a mobile and desktop client)
78
-	if [ -d $INSTALL_DIR/prosody-modules/mod_carbons ]; then
79
-		cp $INSTALL_DIR/prosody-modules/mod_carbons/*.lua /usr/lib/prosody/modules
80
-	fi
81
-
82
-	# XEP-0198 Stream management
83
-	# Helps mobile apps recover when a device switches networks.
84
-	if [ -d $INSTALL_DIR/prosody-modules/mod_smacks ]; then
85
-		cp $INSTALL_DIR/prosody-modules/mod_smacks/*.lua /usr/lib/prosody/modules
86
-	fi
87
-	if [ -d $INSTALL_DIR/prosody-modules/mod_smacks_offline ]; then
88
-		cp $INSTALL_DIR/prosody-modules/mod_smacks_offline/*.lua /usr/lib/prosody/modules
89
-	fi
90
-
91
-	# XEP-0191: blocking
92
-	if [ -d $INSTALL_DIR/prosody-modules/mod_blocking ]; then
93
-		cp $INSTALL_DIR/prosody-modules/mod_blocking/*.lua /usr/lib/prosody/modules
94
-	fi
95
-
96
-	# XEP-0016 Privacy lists
97
-	if [ -d $INSTALL_DIR/prosody-modules/mod_privacy_lists ]; then
98
-		cp $INSTALL_DIR/prosody-modules/mod_privacy_lists/*.lua /usr/lib/prosody/modules
99
-	fi
45
+    if [ ! -d $INSTALL_DIR/prosody-modules ]; then
46
+	return
47
+    fi
48
+    if [ ! -d /usr/lib/prosody ]; then
49
+	return
50
+    fi
51
+
52
+    cd $INSTALL_DIR/prosody-modules
53
+    hg pull
54
+    hg update
55
+
56
+    # support onion addresses
57
+    if [ -f $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua ]; then
58
+	cp $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua /usr/lib/prosody/modules/mod_onions.lua
59
+    fi
60
+
61
+    # XEP-0313 message archive management
62
+    # https://modules.prosody.im/mod_mam.html
63
+    # Allows you to download your previous messages onto a new client
64
+    # This only applies if you are not using forward secret crypto
65
+    # such as OTR or OMEMO (eg. OpenPGP)
66
+    if [ -d $INSTALL_DIR/prosody-modules/mod_mam ]; then
67
+	cp $INSTALL_DIR/prosody-modules/mod_mam/*.lua /usr/lib/prosody/modules
68
+    fi
69
+
70
+    # XEP-0352 Client State Indication
71
+    # Notifies the server if the app is in the background or not
72
+    if [ -d $INSTALL_DIR/prosody-modules/mod_csi ]; then
73
+	cp $INSTALL_DIR/prosody-modules/mod_csi/*.lua /usr/lib/prosody/modules
74
+    fi
75
+
76
+    # XEP-0280 Message Carbons
77
+    # Ensures all messages get delivered to all clients (if you have a mobile and desktop client)
78
+    if [ -d $INSTALL_DIR/prosody-modules/mod_carbons ]; then
79
+	cp $INSTALL_DIR/prosody-modules/mod_carbons/*.lua /usr/lib/prosody/modules
80
+    fi
81
+
82
+    # XEP-0198 Stream management
83
+    # Helps mobile apps recover when a device switches networks.
84
+    if [ -d $INSTALL_DIR/prosody-modules/mod_smacks ]; then
85
+	cp $INSTALL_DIR/prosody-modules/mod_smacks/*.lua /usr/lib/prosody/modules
86
+    fi
87
+    if [ -d $INSTALL_DIR/prosody-modules/mod_smacks_offline ]; then
88
+	cp $INSTALL_DIR/prosody-modules/mod_smacks_offline/*.lua /usr/lib/prosody/modules
89
+    fi
90
+
91
+    # XEP-0191: blocking
92
+    if [ -d $INSTALL_DIR/prosody-modules/mod_blocking ]; then
93
+	cp $INSTALL_DIR/prosody-modules/mod_blocking/*.lua /usr/lib/prosody/modules
94
+    fi
95
+
96
+    # XEP-0016 Privacy lists
97
+    if [ -d $INSTALL_DIR/prosody-modules/mod_privacy_lists ]; then
98
+	cp $INSTALL_DIR/prosody-modules/mod_privacy_lists/*.lua /usr/lib/prosody/modules
99
+    fi
100 100
 }
101 101
 
102 102
 function upgrade_xmpp {
103
-	if ! grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
104
-		return
105
-	fi
106
-	function_check update_prosody_modules
107
-	update_prosody_modules
103
+    if ! grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
104
+	return
105
+    fi
106
+    function_check update_prosody_modules
107
+    update_prosody_modules
108 108
 }
109 109
 
110 110
 function backup_local_xmpp {
111
-	source_directory=/var/lib/prosody xmpp
112
-	if [ -d $source_directory ]; then
113
-		dest_directory=xmpp
114
-		echo $"Backing up $source_directory to $dest_directory"
111
+    source_directory=/var/lib/prosody xmpp
112
+    if [ -d $source_directory ]; then
113
+	dest_directory=xmpp
114
+	echo $"Backing up $source_directory to $dest_directory"
115 115
 
116
-		function_check backup_directory_to_usb
117
-		backup_directory_to_usb $source_directory $dest_directory
116
+	function_check backup_directory_to_usb
117
+	backup_directory_to_usb $source_directory $dest_directory
118 118
 
119
-		echo $"Backup to $dest_directory complete"
120
-	fi
119
+	echo $"Backup to $dest_directory complete"
120
+    fi
121 121
 }
122 122
 
123 123
 function restore_local_xmpp {
124
-	if [ -d /var/lib/prosody ]; then
125
-		echo $"Restoring XMPP settings"
126
-		temp_restore_dir=/root/tempxmpp
127
-		function_check restore_directory_from_usb
128
-		restore_directory_from_usb $temp_restore_dir xmpp
129
-		cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
130
-		if [ ! "$?" = "0" ]; then
131
-			function_check set_user_permissions
132
-			set_user_permissions
133
-			function_check backup_unmount_drive
134
-			backup_unmount_drive
135
-			exit 725
136
-		fi
137
-		rm -rf $temp_restore_dir
138
-		service prosody restart
139
-		chown -R prosody:prosody /var/lib/prosody/*
140
-		echo $"Restore of XMPP settings complete"
141
-	fi
124
+    if [ -d /var/lib/prosody ]; then
125
+	echo $"Restoring XMPP settings"
126
+	temp_restore_dir=/root/tempxmpp
127
+	function_check restore_directory_from_usb
128
+	restore_directory_from_usb $temp_restore_dir xmpp
129
+	cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
130
+	if [ ! "$?" = "0" ]; then
131
+	    function_check set_user_permissions
132
+	    set_user_permissions
133
+	    function_check backup_unmount_drive
134
+	    backup_unmount_drive
135
+	    exit 725
136
+	fi
137
+	rm -rf $temp_restore_dir
138
+	service prosody restart
139
+	chown -R prosody:prosody /var/lib/prosody/*
140
+	echo $"Restore of XMPP settings complete"
141
+    fi
142 142
 }
143 143
 
144 144
 function backup_remote_xmpp {
145
-	if [ -d /var/lib/prosody ]; then
146
-		echo $"Backing up the XMPP settings"
147
-		backup_directory_to_friend /var/lib/prosody xmpp
148
-		echo $"Backup of XMPP settings complete"
149
-	fi
145
+    if [ -d /var/lib/prosody ]; then
146
+	echo $"Backing up the XMPP settings"
147
+	backup_directory_to_friend /var/lib/prosody xmpp
148
+	echo $"Backup of XMPP settings complete"
149
+    fi
150 150
 }
151 151
 
152 152
 function restore_remote_xmpp {
153
-	if [ -d /var/lib/prosody ]; then
154
-		echo $"Restoring XMPP settings"
155
-		temp_restore_dir=/root/tempxmpp
156
-		function_check restore_directory_from_friend
157
-		restore_directory_from_friend $temp_restore_dir xmpp
158
-		cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
159
-		if [ ! "$?" = "0" ]; then
160
-			exit 725
161
-		fi
162
-		rm -rf $temp_restore_dir
163
-		service prosody restart
164
-		chown -R prosody:prosody /var/lib/prosody/*
165
-		echo $"Restore of XMPP settings complete"
166
-	fi
153
+    if [ -d /var/lib/prosody ]; then
154
+	echo $"Restoring XMPP settings"
155
+	temp_restore_dir=/root/tempxmpp
156
+	function_check restore_directory_from_friend
157
+	restore_directory_from_friend $temp_restore_dir xmpp
158
+	cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
159
+	if [ ! "$?" = "0" ]; then
160
+	    exit 725
161
+	fi
162
+	rm -rf $temp_restore_dir
163
+	service prosody restart
164
+	chown -R prosody:prosody /var/lib/prosody/*
165
+	echo $"Restore of XMPP settings complete"
166
+    fi
167 167
 }
168 168
 
169 169
 function configure_firewall_for_xmpp {
170
-	if [ ! -d /etc/prosody ]; then
171
-		return
172
-	fi
173
-	if grep -Fxq "configure_firewall_for_xmpp" $COMPLETION_FILE; then
174
-		return
175
-	fi
176
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
177
-		# docker does its own firewalling
178
-		return
179
-	fi
180
-	if [[ $ONION_ONLY != "no" ]]; then
181
-		return
182
-	fi
183
-	iptables -A INPUT -p tcp --dport 5222:5223 -j ACCEPT
184
-	iptables -A INPUT -p tcp --dport 5269 -j ACCEPT
185
-	iptables -A INPUT -p tcp --dport 5280:5281 -j ACCEPT
186
-	function_check save_firewall_settings
187
-	save_firewall_settings
188
-
189
-	OPEN_PORTS+=('XMPP     5222-5223')
190
-	OPEN_PORTS+=('XMPP     5269')
191
-	OPEN_PORTS+=('XMPP     5280-5281')
192
-	echo 'configure_firewall_for_xmpp' >> $COMPLETION_FILE
170
+    if [ ! -d /etc/prosody ]; then
171
+	return
172
+    fi
173
+    if grep -Fxq "configure_firewall_for_xmpp" $COMPLETION_FILE; then
174
+	return
175
+    fi
176
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
177
+	# docker does its own firewalling
178
+	return
179
+    fi
180
+    if [[ $ONION_ONLY != "no" ]]; then
181
+	return
182
+    fi
183
+    iptables -A INPUT -p tcp --dport 5222:5223 -j ACCEPT
184
+    iptables -A INPUT -p tcp --dport 5269 -j ACCEPT
185
+    iptables -A INPUT -p tcp --dport 5280:5281 -j ACCEPT
186
+    function_check save_firewall_settings
187
+    save_firewall_settings
188
+
189
+    OPEN_PORTS+=('XMPP     5222-5223')
190
+    OPEN_PORTS+=('XMPP     5269')
191
+    OPEN_PORTS+=('XMPP     5280-5281')
192
+    echo 'configure_firewall_for_xmpp' >> $COMPLETION_FILE
193 193
 }
194 194
 
195 195
 function remove_xmpp_client {
196
-	if ! grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
197
-		return
198
-	fi
199
-	apt-get -y remove --purge profanity
200
-	sed '/install_xmpp_client/d' $COMPLETION_FILE
196
+    if ! grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
197
+	return
198
+    fi
199
+    apt-get -y remove --purge profanity
200
+    sed '/install_xmpp_client/d' $COMPLETION_FILE
201 201
 }
202 202
 
203 203
 function remove_xmpp {
204
-	remove_xmpp_client
205
-	if ! grep -Fxq "install_xmpp" $COMPLETION_FILE; then
206
-		return
207
-	fi
208
-	iptables -D INPUT -p tcp --dport 5222:5223 -j ACCEPT
209
-	iptables -D INPUT -p tcp --dport 5269 -j ACCEPT
210
-	iptables -D INPUT -p tcp --dport 5280:5281 -j ACCEPT
211
-	function_check save_firewall_settings
212
-	save_firewall_settings
213
-
214
-	function_check remove_onion_service
215
-	remove_onion_service xmpp 5222 5223 5269
216
-
217
-	apt-get -y remove --purge prosody prosody-modules
218
-	if [ -d $INSTALL_DIR/prosody-modules ]; then
219
-		rm -rf $INSTALL_DIR/prosody-modules
220
-	fi
221
-	if [ -d /etc/prosody ]; then
222
-		rm -rf /etc/prosody
223
-	fi
224
-
225
-	sed '/install_xmpp/d' $COMPLETION_FILE
226
-	sed '/XMPP /d' $COMPLETION_FILE
204
+    remove_xmpp_client
205
+    if ! grep -Fxq "install_xmpp" $COMPLETION_FILE; then
206
+	return
207
+    fi
208
+    iptables -D INPUT -p tcp --dport 5222:5223 -j ACCEPT
209
+    iptables -D INPUT -p tcp --dport 5269 -j ACCEPT
210
+    iptables -D INPUT -p tcp --dport 5280:5281 -j ACCEPT
211
+    function_check save_firewall_settings
212
+    save_firewall_settings
213
+
214
+    function_check remove_onion_service
215
+    remove_onion_service xmpp 5222 5223 5269
216
+
217
+    apt-get -y remove --purge prosody prosody-modules
218
+    if [ -d $INSTALL_DIR/prosody-modules ]; then
219
+	rm -rf $INSTALL_DIR/prosody-modules
220
+    fi
221
+    if [ -d /etc/prosody ]; then
222
+	rm -rf /etc/prosody
223
+    fi
224
+
225
+    sed '/install_xmpp/d' $COMPLETION_FILE
226
+    sed '/XMPP /d' $COMPLETION_FILE
227 227
 }
228 228
 
229 229
 function install_xmpp_main {
230
-	update_prosody_modules
231
-
232
-	if grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
233
-		return
234
-	fi
235
-	apt-get -y install lua-sec lua-bitop
236
-	apt-get -y install prosody prosody-modules mercurial
237
-
238
-	if [ ! -d /etc/prosody ]; then
239
-		echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
240
-		exit 52
241
-	fi
242
-
243
-	# obtain the prosody modules
244
-	cd $INSTALL_DIR
245
-	hg clone https://hg.prosody.im/prosody-modules/ prosody-modules
246
-	if [ ! -d $INSTALL_DIR/prosody-modules/mod_onions ]; then
247
-		echo $'mod_onions prosody module could not be found'
248
-		exit 73254
249
-	fi
250
-
251
-	# install the onions module
252
-	update_prosody_modules
253
-	if [ ! -f /usr/lib/prosody/modules/mod_onions.lua ]; then
254
-		echo $'mod_onions.lua could not be copied to the prosody modules directory'
255
-		exit 63952
256
-	fi
257
-
258
-	# create a certificate
259
-	if [ ! -f /etc/ssl/certs/xmpp.dhparam ]; then
260
-		${PROJECT_NAME}-addcert -h xmpp --dhkey $DH_KEYLENGTH
261
-		check_certificates xmpp
262
-	fi
263
-	chown prosody:prosody /etc/ssl/private/xmpp.key
264
-	chown prosody:prosody /etc/ssl/certs/xmpp.*
265
-	cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
266
-
267
-	sed -i 's|/etc/prosody/certs/example.com.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
268
-	sed -i 's|/etc/prosody/certs/example.com.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
269
-	if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
270
-		sed -i '/certificate =/a\        dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
271
-	fi
272
-	if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
273
-		sed -i '/certificate =/a\        options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
274
-	fi
275
-	if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
276
-		sed -i "/certificate =/a\        ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
277
-	fi
278
-	if ! grep -q 'depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
279
-		sed -i '/certificate =/a\        depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua
280
-	fi
281
-	if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
282
-		sed -i "/certificate =/a\        curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
283
-	fi
284
-
285
-	sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
286
-	sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
287
-
288
-	if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
289
-		echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
290
-		echo 'modules_enabled = {' >> /etc/prosody/conf.avail/xmpp.cfg.lua
291
-		echo '  "bosh"; -- Enable mod_bosh' >> /etc/prosody/conf.avail/xmpp.cfg.lua
292
-		echo '  "tls"; -- Enable mod_tls' >> /etc/prosody/conf.avail/xmpp.cfg.lua
293
-		echo '  "saslauth"; -- Enable mod_saslauth' >> /etc/prosody/conf.avail/xmpp.cfg.lua
294
-		echo '  "onions"; -- Enable chat via onion service' >> /etc/prosody/conf.avail/xmpp.cfg.lua
295
-		echo '  "mam"; -- Message archive management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
296
-		echo '  "csi"; -- Client state indication' >> /etc/prosody/conf.avail/xmpp.cfg.lua
297
-		echo '  "carbons"; -- Message carbons' >> /etc/prosody/conf.avail/xmpp.cfg.lua
298
-		echo '  "smacks"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
299
-		echo '  "smacks_offline"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
300
-		echo '  "pep"; -- Personal Eventing Protocol (to support OMEMO)' >> /etc/prosody/conf.avail/xmpp.cfg.lua
301
-		echo '  "privacy"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
302
-		echo '  "privacy_lists"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
303
-		echo '  "blocking"; -- Blocking command' >> /etc/prosody/conf.avail/xmpp.cfg.lua
304
-		echo '  "roster"; -- Roster versioning' >> /etc/prosody/conf.avail/xmpp.cfg.lua
305
-		echo '}' >> /etc/prosody/conf.avail/xmpp.cfg.lua
306
-		echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
307
-		echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
308
-		echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
309
-		echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
310
-	fi
311
-	ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
312
-
313
-	sed -i 's|/etc/prosody/certs/localhost.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/prosody.cfg.lua
314
-	sed -i 's|/etc/prosody/certs/localhost.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/prosody.cfg.lua
315
-	if ! grep -q "xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
316
-		sed -i '/certificate =/a\    dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/prosody.cfg.lua
317
-	fi
318
-	if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/prosody.cfg.lua; then
319
-		sed -i '/certificate =/a\    options = {"no_sslv2", "no_sslv3" };' /etc/prosody/prosody.cfg.lua
320
-	fi
321
-	if ! grep -q 'ciphers =' /etc/prosody/prosody.cfg.lua; then
322
-		sed -i "/certificate =/a\    ciphers = $XMPP_CIPHERS;" /etc/prosody/prosody.cfg.lua
323
-	fi
324
-	if ! grep -q 'depth = "1";' /etc/prosody/prosody.cfg.lua; then
325
-		sed -i '/certificate =/a\    depth = "1";' /etc/prosody/prosody.cfg.lua
326
-	fi
327
-	if ! grep -q 'curve =' /etc/prosody/prosody.cfg.lua; then
328
-		sed -i "/certificate =/a\    curve = $XMPP_ECC_CURVE;" /etc/prosody/prosody.cfg.lua
329
-	fi
330
-	sed -i 's/c2s_require_encryption = false/c2s_require_encryption = true/g' /etc/prosody/prosody.cfg.lua
331
-	if ! grep -q "s2s_require_encryption" /etc/prosody/prosody.cfg.lua; then
332
-		sed -i '/c2s_require_encryption/a\s2s_require_encryption = true' /etc/prosody/prosody.cfg.lua
333
-	fi
334
-	if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/prosody.cfg.lua; then
335
-		echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
336
-	fi
337
-	sed -i 's/--"bosh";/"bosh";/g' /etc/prosody/prosody.cfg.lua
338
-	sed -i 's/authentication = "internal_plain"/authentication = "internal_hashed"/g' /etc/prosody/prosody.cfg.lua
339
-	sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/prosody.cfg.lua
340
-	sed -i 's|key = "/etc/prosody/certs/example.com.key"|key = "/etc/ssl/private/xmpp.key"|g' /etc/prosody/prosody.cfg.lua
341
-	sed -i 's|certificate = "/etc/prosody/certs/example.com.crt"|certificate = "/etc/ssl/certs/xmpp.crt"|g' /etc/prosody/prosody.cfg.lua
342
-	sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/prosody.cfg.lua
343
-
344
-	systemctl restart prosody
345
-	touch /home/$MY_USERNAME/README
346
-
347
-	if [ ! -d /var/lib/tor ]; then
348
-		echo $'No Tor installation found. XMPP onion site cannot be configured.'
349
-		exit 877367
350
-	fi
351
-	if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
352
-		echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/' >> /etc/tor/torrc
353
-		echo "HiddenServicePort 5222 127.0.0.1:5222" >> /etc/tor/torrc
354
-		echo "HiddenServicePort 5269 127.0.0.1:5269" >> /etc/tor/torrc
355
-		echo $'Added onion site for XMPP chat'
356
-	fi
357
-
358
-	systemctl restart tor
359
-	wait_for_onion_service 'xmpp'
360
-
361
-	if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
362
-		echo $'XMPP onion site hostname not found'
363
-		exit 65349
364
-	fi
365
-	XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
366
-	if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
367
-		echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
368
-		echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/conf.avail/xmpp.cfg.lua
369
-		echo '    modules_enabled = { "onions" };' >> /etc/prosody/conf.avail/xmpp.cfg.lua
370
-	fi
371
-	if ! grep -q "XMPP onion domain" $COMPLETION_FILE; then
372
-		echo "XMPP onion domain:${XMPP_ONION_HOSTNAME}" >> $COMPLETION_FILE
373
-	else
374
-		sed -i "s|XMPP onion domain.*|XMPP onion domain:${XMPP_ONION_HOSTNAME}|g" $COMPLETION_FILE
375
-	fi
376
-
377
-	if ! grep -q "Your XMPP password is" /home/$MY_USERNAME/README; then
378
-		if [ ${#XMPP_PASSWORD} -lt 8 ]; then
379
-			if [ -f $IMAGE_PASSWORD_FILE ]; then
380
-				XMPP_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
381
-			else
382
-				XMPP_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
383
-			fi
384
-		fi
385
-		prosodyctl register $MY_USERNAME $DEFAULT_DOMAIN_NAME $XMPP_PASSWORD
386
-		echo '' >> /home/$MY_USERNAME/README
387
-		echo '' >> /home/$MY_USERNAME/README
388
-		echo $'XMPP' >> /home/$MY_USERNAME/README
389
-		echo '====' >> /home/$MY_USERNAME/README
390
-		echo $"XMPP onion domain: ${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
391
-		echo $"Your XMPP password is: $XMPP_PASSWORD" >> /home/$MY_USERNAME/README
392
-		echo $'You can change it with: ' >> /home/$MY_USERNAME/README
393
-		echo '' >> /home/$MY_USERNAME/README
394
-		echo "    prosodyctl passwd $MY_EMAIL_ADDRESS" >> /home/$MY_USERNAME/README
395
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
396
-		chmod 600 /home/$MY_USERNAME/README
397
-	fi
398
-
399
-	function_check configure_firewall_for_xmpp
400
-	configure_firewall_for_xmpp
401
-
402
-	echo 'install_xmpp_main' >> $COMPLETION_FILE
230
+    update_prosody_modules
231
+
232
+    if grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
233
+	return
234
+    fi
235
+    apt-get -y install lua-sec lua-bitop
236
+    apt-get -y install prosody prosody-modules mercurial
237
+
238
+    if [ ! -d /etc/prosody ]; then
239
+	echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
240
+	exit 52
241
+    fi
242
+
243
+    # obtain the prosody modules
244
+    cd $INSTALL_DIR
245
+    hg clone https://hg.prosody.im/prosody-modules/ prosody-modules
246
+    if [ ! -d $INSTALL_DIR/prosody-modules/mod_onions ]; then
247
+	echo $'mod_onions prosody module could not be found'
248
+	exit 73254
249
+    fi
250
+
251
+    # install the onions module
252
+    update_prosody_modules
253
+    if [ ! -f /usr/lib/prosody/modules/mod_onions.lua ]; then
254
+	echo $'mod_onions.lua could not be copied to the prosody modules directory'
255
+	exit 63952
256
+    fi
257
+
258
+    # create a certificate
259
+    if [ ! -f /etc/ssl/certs/xmpp.dhparam ]; then
260
+	${PROJECT_NAME}-addcert -h xmpp --dhkey $DH_KEYLENGTH
261
+	check_certificates xmpp
262
+    fi
263
+    chown prosody:prosody /etc/ssl/private/xmpp.key
264
+    chown prosody:prosody /etc/ssl/certs/xmpp.*
265
+    cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
266
+
267
+    sed -i 's|/etc/prosody/certs/example.com.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
268
+    sed -i 's|/etc/prosody/certs/example.com.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
269
+    if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
270
+	sed -i '/certificate =/a\        dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
271
+    fi
272
+    if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
273
+	sed -i '/certificate =/a\        options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
274
+    fi
275
+    if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
276
+	sed -i "/certificate =/a\        ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
277
+    fi
278
+    if ! grep -q 'depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
279
+	sed -i '/certificate =/a\        depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua
280
+    fi
281
+    if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
282
+	sed -i "/certificate =/a\        curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
283
+    fi
284
+
285
+    sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
286
+    sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
287
+
288
+    if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
289
+	echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
290
+	echo 'modules_enabled = {' >> /etc/prosody/conf.avail/xmpp.cfg.lua
291
+	echo '  "bosh"; -- Enable mod_bosh' >> /etc/prosody/conf.avail/xmpp.cfg.lua
292
+	echo '  "tls"; -- Enable mod_tls' >> /etc/prosody/conf.avail/xmpp.cfg.lua
293
+	echo '  "saslauth"; -- Enable mod_saslauth' >> /etc/prosody/conf.avail/xmpp.cfg.lua
294
+	echo '  "onions"; -- Enable chat via onion service' >> /etc/prosody/conf.avail/xmpp.cfg.lua
295
+	echo '  "mam"; -- Message archive management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
296
+	echo '  "csi"; -- Client state indication' >> /etc/prosody/conf.avail/xmpp.cfg.lua
297
+	echo '  "carbons"; -- Message carbons' >> /etc/prosody/conf.avail/xmpp.cfg.lua
298
+	echo '  "smacks"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
299
+	echo '  "smacks_offline"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
300
+	echo '  "pep"; -- Personal Eventing Protocol (to support OMEMO)' >> /etc/prosody/conf.avail/xmpp.cfg.lua
301
+	echo '  "privacy"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
302
+	echo '  "privacy_lists"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
303
+	echo '  "blocking"; -- Blocking command' >> /etc/prosody/conf.avail/xmpp.cfg.lua
304
+	echo '  "roster"; -- Roster versioning' >> /etc/prosody/conf.avail/xmpp.cfg.lua
305
+	echo '}' >> /etc/prosody/conf.avail/xmpp.cfg.lua
306
+	echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
307
+	echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
308
+	echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
309
+	echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
310
+    fi
311
+    ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
312
+
313
+    sed -i 's|/etc/prosody/certs/localhost.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/prosody.cfg.lua
314
+    sed -i 's|/etc/prosody/certs/localhost.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/prosody.cfg.lua
315
+    if ! grep -q "xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
316
+	sed -i '/certificate =/a\    dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/prosody.cfg.lua
317
+    fi
318
+    if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/prosody.cfg.lua; then
319
+	sed -i '/certificate =/a\    options = {"no_sslv2", "no_sslv3" };' /etc/prosody/prosody.cfg.lua
320
+    fi
321
+    if ! grep -q 'ciphers =' /etc/prosody/prosody.cfg.lua; then
322
+	sed -i "/certificate =/a\    ciphers = $XMPP_CIPHERS;" /etc/prosody/prosody.cfg.lua
323
+    fi
324
+    if ! grep -q 'depth = "1";' /etc/prosody/prosody.cfg.lua; then
325
+	sed -i '/certificate =/a\    depth = "1";' /etc/prosody/prosody.cfg.lua
326
+    fi
327
+    if ! grep -q 'curve =' /etc/prosody/prosody.cfg.lua; then
328
+	sed -i "/certificate =/a\    curve = $XMPP_ECC_CURVE;" /etc/prosody/prosody.cfg.lua
329
+    fi
330
+    sed -i 's/c2s_require_encryption = false/c2s_require_encryption = true/g' /etc/prosody/prosody.cfg.lua
331
+    if ! grep -q "s2s_require_encryption" /etc/prosody/prosody.cfg.lua; then
332
+	sed -i '/c2s_require_encryption/a\s2s_require_encryption = true' /etc/prosody/prosody.cfg.lua
333
+    fi
334
+    if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/prosody.cfg.lua; then
335
+	echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
336
+    fi
337
+    sed -i 's/--"bosh";/"bosh";/g' /etc/prosody/prosody.cfg.lua
338
+    sed -i 's/authentication = "internal_plain"/authentication = "internal_hashed"/g' /etc/prosody/prosody.cfg.lua
339
+    sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/prosody.cfg.lua
340
+    sed -i 's|key = "/etc/prosody/certs/example.com.key"|key = "/etc/ssl/private/xmpp.key"|g' /etc/prosody/prosody.cfg.lua
341
+    sed -i 's|certificate = "/etc/prosody/certs/example.com.crt"|certificate = "/etc/ssl/certs/xmpp.crt"|g' /etc/prosody/prosody.cfg.lua
342
+    sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/prosody.cfg.lua
343
+
344
+    systemctl restart prosody
345
+    touch /home/$MY_USERNAME/README
346
+
347
+    if [ ! -d /var/lib/tor ]; then
348
+	echo $'No Tor installation found. XMPP onion site cannot be configured.'
349
+	exit 877367
350
+    fi
351
+    if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
352
+	echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/' >> /etc/tor/torrc
353
+	echo "HiddenServicePort 5222 127.0.0.1:5222" >> /etc/tor/torrc
354
+	echo "HiddenServicePort 5269 127.0.0.1:5269" >> /etc/tor/torrc
355
+	echo $'Added onion site for XMPP chat'
356
+    fi
357
+
358
+    systemctl restart tor
359
+    wait_for_onion_service 'xmpp'
360
+
361
+    if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
362
+	echo $'XMPP onion site hostname not found'
363
+	exit 65349
364
+    fi
365
+    XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
366
+    if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
367
+	echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
368
+	echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/conf.avail/xmpp.cfg.lua
369
+	echo '    modules_enabled = { "onions" };' >> /etc/prosody/conf.avail/xmpp.cfg.lua
370
+    fi
371
+    if ! grep -q "XMPP onion domain" $COMPLETION_FILE; then
372
+	echo "XMPP onion domain:${XMPP_ONION_HOSTNAME}" >> $COMPLETION_FILE
373
+    else
374
+	sed -i "s|XMPP onion domain.*|XMPP onion domain:${XMPP_ONION_HOSTNAME}|g" $COMPLETION_FILE
375
+    fi
376
+
377
+    if ! grep -q "Your XMPP password is" /home/$MY_USERNAME/README; then
378
+	if [ ${#XMPP_PASSWORD} -lt 8 ]; then
379
+	    if [ -f $IMAGE_PASSWORD_FILE ]; then
380
+		XMPP_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
381
+	    else
382
+		XMPP_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
383
+	    fi
384
+	fi
385
+	prosodyctl register $MY_USERNAME $DEFAULT_DOMAIN_NAME $XMPP_PASSWORD
386
+	echo '' >> /home/$MY_USERNAME/README
387
+	echo '' >> /home/$MY_USERNAME/README
388
+	echo $'XMPP' >> /home/$MY_USERNAME/README
389
+	echo '====' >> /home/$MY_USERNAME/README
390
+	echo $"XMPP onion domain: ${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
391
+	echo $"Your XMPP password is: $XMPP_PASSWORD" >> /home/$MY_USERNAME/README
392
+	echo $'You can change it with: ' >> /home/$MY_USERNAME/README
393
+	echo '' >> /home/$MY_USERNAME/README
394
+	echo "    prosodyctl passwd $MY_EMAIL_ADDRESS" >> /home/$MY_USERNAME/README
395
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
396
+	chmod 600 /home/$MY_USERNAME/README
397
+    fi
398
+
399
+    function_check configure_firewall_for_xmpp
400
+    configure_firewall_for_xmpp
401
+
402
+    echo 'install_xmpp_main' >> $COMPLETION_FILE
403 403
 }
404 404
 
405 405
 function install_xmpp_client {
406
-	if grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
407
-		return
408
-	fi
409
-	apt-get -y install profanity
410
-
411
-	XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
412
-	XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
413
-	if [ ! -d $XMPP_CLIENT_DIR ]; then
414
-		mkdir -p $XMPP_CLIENT_DIR
415
-	fi
416
-
406
+    if grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
407
+	return
408
+    fi
409
+    apt-get -y install profanity
410
+
411
+    XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
412
+    XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
413
+    if [ ! -d $XMPP_CLIENT_DIR ]; then
414
+	mkdir -p $XMPP_CLIENT_DIR
415
+    fi
416
+
417
+    if [[ $ONION_ONLY == 'no' ]]; then
418
+	echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
419
+	echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
420
+	echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
421
+	echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
422
+	echo "muc.service=conference.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
423
+	echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
424
+	echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
425
+	echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
426
+	echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
427
+	echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
428
+	echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
429
+	echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
430
+	echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
431
+	if [ ${#XMPP_PASSWORD} -gt 2 ]; then
432
+	    echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
433
+	fi
434
+    fi
435
+
436
+    if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
437
+	XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
438
+	echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
417 439
 	if [[ $ONION_ONLY == 'no' ]]; then
418
-		echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
419
-		echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
420
-		echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
421
-		echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
422
-		echo "muc.service=conference.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
423
-		echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
424
-		echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
425
-		echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
426
-		echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
427
-		echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
428
-		echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
429
-		echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
430
-		echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
431
-		if [ ${#XMPP_PASSWORD} -gt 2 ]; then
432
-			echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
433
-		fi
434
-	fi
435
-
436
-	if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
437
-		XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
438
-		echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
439
-		if [[ $ONION_ONLY == 'no' ]]; then
440
-			echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
441
-		else
442
-			echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
443
-		fi
444
-		echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
445
-		echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
446
-		echo "muc.service=conference.${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
447
-		echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
448
-		echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
449
-		echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
450
-		echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
451
-		echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
452
-		echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
453
-		echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
454
-		echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
455
-		if [ ${#XMPP_PASSWORD} -gt 2 ]; then
456
-			echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
457
-		fi
458
-	fi
459
-
460
-	if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
461
-		mkdir /home/$MY_USERNAME/.config/profanity
462
-	fi
463
-	echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
464
-	echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
465
-
466
-	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
467
-	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
468
-
469
-	echo 'install_xmpp_client' >> $COMPLETION_FILE
440
+	    echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
441
+	else
442
+	    echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
443
+	fi
444
+	echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
445
+	echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
446
+	echo "muc.service=conference.${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
447
+	echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
448
+	echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
449
+	echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
450
+	echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
451
+	echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
452
+	echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
453
+	echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
454
+	echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
455
+	if [ ${#XMPP_PASSWORD} -gt 2 ]; then
456
+	    echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
457
+	fi
458
+    fi
459
+
460
+    if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
461
+	mkdir /home/$MY_USERNAME/.config/profanity
462
+    fi
463
+    echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
464
+    echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
465
+
466
+    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
467
+    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
468
+
469
+    echo 'install_xmpp_client' >> $COMPLETION_FILE
470 470
 }
471 471
 
472 472
 function install_xmpp {
473
-	if grep -Fxq "install_xmpp" $COMPLETION_FILE; then
474
-		return
475
-	fi
476
-	install_xmpp_main
477
-	install_xmpp_client
478
-	echo 'install_xmpp' >> $COMPLETION_FILE
473
+    if grep -Fxq "install_xmpp" $COMPLETION_FILE; then
474
+	return
475
+    fi
476
+    install_xmpp_main
477
+    install_xmpp_client
478
+    echo 'install_xmpp' >> $COMPLETION_FILE
479 479
 }
480 480
 
481 481
 # NOTE: deliberately no exit 0

+ 555
- 555
src/freedombone-app-zeronet
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 376
- 376
src/freedombone-mesh-install Voir le fichier

@@ -82,434 +82,434 @@ REMOVE='no'
82 82
 source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-git
83 83
 
84 84
 function show_help {
85
-	echo ''
86
-	echo $"${PROJECT_NAME}-mesh-install -f [function] -r [rootdir]"
87
-	echo ''
88
-	echo $'Runs a mesh network install function'
89
-	echo ''
90
-	echo $'  -h --help                   Show help'
91
-	echo $'  -f --function [name]        Name of the function to be run'
92
-	echo $'  -r --rootdir [directory]    Root directory'
93
-	echo $'  -w --wifi [interface]       e.g. wlan0'
94
-	echo ''
95
-	exit 0
85
+    echo ''
86
+    echo $"${PROJECT_NAME}-mesh-install -f [function] -r [rootdir]"
87
+    echo ''
88
+    echo $'Runs a mesh network install function'
89
+    echo ''
90
+    echo $'  -h --help                   Show help'
91
+    echo $'  -f --function [name]        Name of the function to be run'
92
+    echo $'  -r --rootdir [directory]    Root directory'
93
+    echo $'  -w --wifi [interface]       e.g. wlan0'
94
+    echo ''
95
+    exit 0
96 96
 }
97 97
 
98 98
 
99 99
 function install_babel {
100
-	$CHROOT_PREFIX apt-get -y install babeld
101
-
102
-	babel_script=${rootdir}/var/lib/babel
103
-
104
-	echo '#!/bin/bash' > $babel_script
105
-	echo '' >> $babel_script
106
-	echo 'if [[ $1 == "ls" || $1 == "list" ]]; then' >> $babel_script
107
-	echo '    avahi-browse -atl' >> $babel_script
108
-	echo '    exit 0' >> $babel_script
109
-	echo 'fi' >> $babel_script
110
-	echo '' >> $babel_script
111
-	echo 'if [[ $1 == "start" ]]; then' >> $babel_script
112
-	echo '    sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
113
-	echo '    sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
114
-	echo '    sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
115
-	echo '    sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
116
-	echo '    sed -i "s|hosts:.*|hosts:          files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf' >> $babel_script
117
-	echo '    systemctl restart avahi-daemon' >> $babel_script
118
-	echo 'fi' >> $babel_script
119
-	echo '' >> $babel_script
120
-	echo "IFACE=$WIFI_INTERFACE" >> $babel_script
121
-	echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
122
-	echo '    if grep -q "wlan1" /proc/net/dev; then' >> $babel_script
123
-	echo '        IFACE=wlan1' >> $babel_script
124
-	echo '    fi' >> $babel_script
125
-	echo 'fi' >> $babel_script
126
-	echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
127
-	echo '    if grep -q "wlan2" /proc/net/dev; then' >> $babel_script
128
-	echo '        IFACE=wlan2' >> $babel_script
129
-	echo '    fi' >> $babel_script
130
-	echo 'fi' >> $babel_script
131
-	echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
132
-	echo '    if grep -q "wlan3" /proc/net/dev; then' >> $babel_script
133
-	echo '        IFACE=wlan3' >> $babel_script
134
-	echo '    fi' >> $babel_script
135
-	echo 'fi' >> $babel_script
136
-	echo '' >> $babel_script
137
-	echo 'if [[ ! grep -q "$IFACE" /proc/net/dev || $1 == "stop" ]]; then' >> $babel_script
138
-	echo '    if ! grep -q "$IFACE" /proc/net/dev; then' >> $babel_script
139
-	echo '        echo "Interface $IFACE was not found"' >> $babel_script
140
-	echo '    else' >> $babel_script
141
-	echo '        echo "Stopping"' >> $babel_script
142
-	echo '    fi' >> $babel_script
143
-	echo '    ifconfig $IFACE down' >> $babel_script
144
-	echo '    pkill babeld' >> $babel_script
145
-	echo '    systemctl restart network-manager' >> $babel_script
146
-	echo '    exit 1' >> $babel_script
147
-	echo 'fi' >> $babel_script
148
-	echo '' >> $babel_script
149
-	echo 'systemctl stop network-manager' >> $babel_script
150
-	echo 'ifconfig $IFACE down' >> $babel_script
151
-	echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script
152
-	echo "$WIFI_CHANNEL essid \"$WIFI_SSID\"" >> $babel_script
153
-	echo 'ifconfig $IFACE up' >> $babel_script
154
-	echo -n 'ifconfig $IFACE:avahi ' >> $babel_script
155
-	echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script
156
-	echo '255.255.255.0 broadcast 192.168.13.255' >> $babel_script
157
-	echo -n 'babeld -D $IFACE:avahi -p ' >> $babel_script
158
-	echo -n "$BABEL_PORT -d 5 " >> $babel_script
159
-	echo '$IFACE' >> $babel_script
160
-	echo 'exit 0' >> $babel_script
161
-	chmod +x $babel_script
162
-
163
-	echo '[Unit]' > ${rootdir}/etc/systemd/system/babel.service
164
-	echo 'Description=Babel Mesh' >> ${rootdir}/etc/systemd/system/babel.service
165
-	echo '' >> ${rootdir}/etc/systemd/system/babel.service
166
-	echo '[Service]' >> ${rootdir}/etc/systemd/system/babel.service
167
-	echo 'Type=oneshot' >> ${rootdir}/etc/systemd/system/babel.service
168
-	echo "ExecStart=$babel_script start" >> ${rootdir}/etc/systemd/system/babel.service
169
-	echo "ExecStop=$babel_script stop" >> ${rootdir}/etc/systemd/system/babel.service
170
-	echo 'RemainAfterExit=yes' >> ${rootdir}/etc/systemd/system/babel.service
171
-	echo '' >> ${rootdir}/etc/systemd/system/babel.service
172
-	echo '# Allow time for the server to start/stop' >> ${rootdir}/etc/systemd/system/babel.service
173
-	echo 'TimeoutSec=300' >> ${rootdir}/etc/systemd/system/babel.service
174
-	echo '' >> ${rootdir}/etc/systemd/system/babel.service
175
-	echo '[Install]' >> /etc/systemd/system/babel.service
176
-	echo 'WantedBy=multi-user.target' >> ${rootdir}/etc/systemd/system/babel.service
177
-	$CHROOT_PREFIX systemctl enable babel
100
+    $CHROOT_PREFIX apt-get -y install babeld
101
+
102
+    babel_script=${rootdir}/var/lib/babel
103
+
104
+    echo '#!/bin/bash' > $babel_script
105
+    echo '' >> $babel_script
106
+    echo 'if [[ $1 == "ls" || $1 == "list" ]]; then' >> $babel_script
107
+    echo '    avahi-browse -atl' >> $babel_script
108
+    echo '    exit 0' >> $babel_script
109
+    echo 'fi' >> $babel_script
110
+    echo '' >> $babel_script
111
+    echo 'if [[ $1 == "start" ]]; then' >> $babel_script
112
+    echo '    sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
113
+    echo '    sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
114
+    echo '    sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
115
+    echo '    sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
116
+    echo '    sed -i "s|hosts:.*|hosts:          files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf' >> $babel_script
117
+    echo '    systemctl restart avahi-daemon' >> $babel_script
118
+    echo 'fi' >> $babel_script
119
+    echo '' >> $babel_script
120
+    echo "IFACE=$WIFI_INTERFACE" >> $babel_script
121
+    echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
122
+    echo '    if grep -q "wlan1" /proc/net/dev; then' >> $babel_script
123
+    echo '        IFACE=wlan1' >> $babel_script
124
+    echo '    fi' >> $babel_script
125
+    echo 'fi' >> $babel_script
126
+    echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
127
+    echo '    if grep -q "wlan2" /proc/net/dev; then' >> $babel_script
128
+    echo '        IFACE=wlan2' >> $babel_script
129
+    echo '    fi' >> $babel_script
130
+    echo 'fi' >> $babel_script
131
+    echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
132
+    echo '    if grep -q "wlan3" /proc/net/dev; then' >> $babel_script
133
+    echo '        IFACE=wlan3' >> $babel_script
134
+    echo '    fi' >> $babel_script
135
+    echo 'fi' >> $babel_script
136
+    echo '' >> $babel_script
137
+    echo 'if [[ ! grep -q "$IFACE" /proc/net/dev || $1 == "stop" ]]; then' >> $babel_script
138
+    echo '    if ! grep -q "$IFACE" /proc/net/dev; then' >> $babel_script
139
+    echo '        echo "Interface $IFACE was not found"' >> $babel_script
140
+    echo '    else' >> $babel_script
141
+    echo '        echo "Stopping"' >> $babel_script
142
+    echo '    fi' >> $babel_script
143
+    echo '    ifconfig $IFACE down' >> $babel_script
144
+    echo '    pkill babeld' >> $babel_script
145
+    echo '    systemctl restart network-manager' >> $babel_script
146
+    echo '    exit 1' >> $babel_script
147
+    echo 'fi' >> $babel_script
148
+    echo '' >> $babel_script
149
+    echo 'systemctl stop network-manager' >> $babel_script
150
+    echo 'ifconfig $IFACE down' >> $babel_script
151
+    echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script
152
+    echo "$WIFI_CHANNEL essid \"$WIFI_SSID\"" >> $babel_script
153
+    echo 'ifconfig $IFACE up' >> $babel_script
154
+    echo -n 'ifconfig $IFACE:avahi ' >> $babel_script
155
+    echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script
156
+    echo '255.255.255.0 broadcast 192.168.13.255' >> $babel_script
157
+    echo -n 'babeld -D $IFACE:avahi -p ' >> $babel_script
158
+    echo -n "$BABEL_PORT -d 5 " >> $babel_script
159
+    echo '$IFACE' >> $babel_script
160
+    echo 'exit 0' >> $babel_script
161
+    chmod +x $babel_script
162
+
163
+    echo '[Unit]' > ${rootdir}/etc/systemd/system/babel.service
164
+    echo 'Description=Babel Mesh' >> ${rootdir}/etc/systemd/system/babel.service
165
+    echo '' >> ${rootdir}/etc/systemd/system/babel.service
166
+    echo '[Service]' >> ${rootdir}/etc/systemd/system/babel.service
167
+    echo 'Type=oneshot' >> ${rootdir}/etc/systemd/system/babel.service
168
+    echo "ExecStart=$babel_script start" >> ${rootdir}/etc/systemd/system/babel.service
169
+    echo "ExecStop=$babel_script stop" >> ${rootdir}/etc/systemd/system/babel.service
170
+    echo 'RemainAfterExit=yes' >> ${rootdir}/etc/systemd/system/babel.service
171
+    echo '' >> ${rootdir}/etc/systemd/system/babel.service
172
+    echo '# Allow time for the server to start/stop' >> ${rootdir}/etc/systemd/system/babel.service
173
+    echo 'TimeoutSec=300' >> ${rootdir}/etc/systemd/system/babel.service
174
+    echo '' >> ${rootdir}/etc/systemd/system/babel.service
175
+    echo '[Install]' >> /etc/systemd/system/babel.service
176
+    echo 'WantedBy=multi-user.target' >> ${rootdir}/etc/systemd/system/babel.service
177
+    $CHROOT_PREFIX systemctl enable babel
178 178
 }
179 179
 
180 180
 function install_babel_remove {
181
-	$CHROOT_PREFIX systemctl stop babel
182
-	$CHROOT_PREFIX apt-get -y remove --purge babeld
183
-	rm ${rootdir}/var/lib/babel
184
-	rm ${rootdir}/etc/systemd/system/babel.service
181
+    $CHROOT_PREFIX systemctl stop babel
182
+    $CHROOT_PREFIX apt-get -y remove --purge babeld
183
+    rm ${rootdir}/var/lib/babel
184
+    rm ${rootdir}/etc/systemd/system/babel.service
185 185
 }
186 186
 
187 187
 function mesh_avahi {
188
-	$CHROOT_PREFIX apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
189
-
190
-	decarray=( 1 2 3 4 5 6 7 8 9 0 )
191
-	PEER_ID=${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}
192
-	sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf
193
-
194
-	if [ ! -d $rootdir/etc/avahi/services ]; then
195
-		mkdir -p $rootdir/etc/avahi/services
196
-	fi
197
-
198
-	# remove an avahi service which isn't used
199
-	if [ -f $rootdir/etc/avahi/services/udisks.service ]; then
200
-		rm $rootdir/etc/avahi/services/udisks.service
201
-	fi
202
-
203
-	# Add an ssh service
204
-	echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/ssh.service
205
-	echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/ssh.service
206
-	echo '<service-group>' >> $rootdir/etc/avahi/services/ssh.service
207
-	echo '  <name replace-wildcards="yes">%h SSH</name>' >> $rootdir/etc/avahi/services/ssh.service
208
-	echo '  <service>' >> $rootdir/etc/avahi/services/ssh.service
209
-	echo '    <type>_ssh._tcp</type>' >> $rootdir/etc/avahi/services/ssh.service
210
-	echo "    <port>$SSH_PORT</port>" >> $rootdir/etc/avahi/services/ssh.service
211
-	echo '  </service>' >> $rootdir/etc/avahi/services/ssh.service
212
-	echo '</service-group>' >> $rootdir/etc/avahi/services/ssh.service
213
-
214
-	# keep the daemon running
215
-	WATCHDOG_SCRIPT_NAME="keepon"
216
-	echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
217
-	echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
218
-	echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
219
-	echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
220
-	echo '  systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
221
-	echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
222
-	echo '  echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
223
-	echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
224
-	chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
188
+    $CHROOT_PREFIX apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
189
+
190
+    decarray=( 1 2 3 4 5 6 7 8 9 0 )
191
+    PEER_ID=${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}
192
+    sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf
193
+
194
+    if [ ! -d $rootdir/etc/avahi/services ]; then
195
+	mkdir -p $rootdir/etc/avahi/services
196
+    fi
197
+
198
+    # remove an avahi service which isn't used
199
+    if [ -f $rootdir/etc/avahi/services/udisks.service ]; then
200
+	rm $rootdir/etc/avahi/services/udisks.service
201
+    fi
202
+
203
+    # Add an ssh service
204
+    echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/ssh.service
205
+    echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/ssh.service
206
+    echo '<service-group>' >> $rootdir/etc/avahi/services/ssh.service
207
+    echo '  <name replace-wildcards="yes">%h SSH</name>' >> $rootdir/etc/avahi/services/ssh.service
208
+    echo '  <service>' >> $rootdir/etc/avahi/services/ssh.service
209
+    echo '    <type>_ssh._tcp</type>' >> $rootdir/etc/avahi/services/ssh.service
210
+    echo "    <port>$SSH_PORT</port>" >> $rootdir/etc/avahi/services/ssh.service
211
+    echo '  </service>' >> $rootdir/etc/avahi/services/ssh.service
212
+    echo '</service-group>' >> $rootdir/etc/avahi/services/ssh.service
213
+
214
+    # keep the daemon running
215
+    WATCHDOG_SCRIPT_NAME="keepon"
216
+    echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
217
+    echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
218
+    echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
219
+    echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
220
+    echo '  systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
221
+    echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
222
+    echo '  echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
223
+    echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
224
+    chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
225 225
 }
226 226
 
227 227
 function install_babel_client {
228
-	# TODO to be fixed
229
-	TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
230
-
231
-	if [ ! -f ${rootdir}/tmp/meshtype ]; then
232
-		$CHROOT_PREFIX sudo apt-get -y install babeld
233
-		if [ ! -f $TOXIC_FILE ]; then
234
-			$CHROOT_PREFIX sudo apt-get -y install toxic
235
-		fi
236
-
237
-		CURR_DIR=$(pwd)
238
-		if [ ! -f ~/develop/toxid ]; then
239
-			if [ ! -f ~/develop ]; then
240
-				mkdir ~/develop
241
-			fi
242
-			cd ~/develop
243
-			git_clone $TOXID_REPO ~/develop/toxid
244
-		fi
245
-		cd ~/develop/toxid
246
-		sudo make install
247
-		cd $CURR_DIR
228
+    # TODO to be fixed
229
+    TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
230
+
231
+    if [ ! -f ${rootdir}/tmp/meshtype ]; then
232
+	$CHROOT_PREFIX sudo apt-get -y install babeld
233
+	if [ ! -f $TOXIC_FILE ]; then
234
+	    $CHROOT_PREFIX sudo apt-get -y install toxic
248 235
 	fi
249 236
 
250
-	babel_script=${rootdir}/tmp/babel
251
-
252
-	echo '#!/bin/bash' > $babel_script
253
-	echo '' >> $babel_script
254
-	echo 'if [[ $1 == "ls" || $1 == "list" ]]; then' >> $babel_script
255
-	echo '    avahi-browse -atl' >> $babel_script
256
-	echo '    exit 0' >> $babel_script
257
-	echo 'fi' >> $babel_script
258
-	echo '' >> $babel_script
259
-	echo 'if [[ $1 == "start" ]]; then' >> $babel_script
260
-	echo '    if [ -f /tmp/meshtype ] ; then' >> $babel_script
261
-	echo '        echo "Mesh already running"' >> $babel_script
262
-	echo '        return' >> $babel_script
263
-	echo '    fi' >> $batman_script
264
-	echo '    # install avahi' >> $babel_script
265
-	echo '    apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd bittornado' >> $babel_script
266
-	echo '    sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
267
-	echo '    sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
268
-	echo '    if [ -f /bin/systemctl ]; then' >> $babel_script
269
-	echo '        systemctl restart avahi-daemon' >> $babel_script
270
-	echo '    else' >> $babel_script
271
-	echo '        service avahi-daemon restart' >> $babel_script
272
-	echo '    fi' >> $babel_script
273
-	echo '    echo "babel" > /tmp/meshtype' >> $babel_script
274
-	echo 'fi' >> $babel_script
275
-	echo '' >> $babel_script
276
-	echo "IFACE=$WIFI_INTERFACE" >> $babel_script
277
-	echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
278
-	echo '    if grep -q "wlan1" /proc/net/dev; then' >> $babel_script
279
-	echo '        IFACE=wlan1' >> $babel_script
280
-	echo '    fi' >> $babel_script
281
-	echo 'fi' >> $babel_script
282
-	echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
283
-	echo '    if grep -q "wlan2" /proc/net/dev; then' >> $babel_script
284
-	echo '        IFACE=wlan2' >> $babel_script
285
-	echo '    fi' >> $babel_script
286
-	echo 'fi' >> $babel_script
287
-	echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
288
-	echo '    if grep -q "wlan3" /proc/net/dev; then' >> $babel_script
289
-	echo '        IFACE=wlan3' >> $babel_script
290
-	echo '    fi' >> $babel_script
291
-	echo 'fi' >> $babel_script
292
-	echo '' >> $babel_script
293
-	echo 'if [[ ! grep -q "$IFACE" /proc/net/dev || $1 == "stop" ]]; then' >> $babel_script
294
-	echo '    if ! grep -q "$IFACE" /proc/net/dev; then' >> $babel_script
295
-	echo '        echo "Interface $IFACE was not found"' >> $babel_script
296
-	echo '    else' >> $babel_script
297
-	echo '        echo "Stopping"' >> $babel_script
298
-	echo '    fi' >> $babel_script
299
-	echo '    ifconfig $IFACE down' >> $babel_script
300
-	echo '    pkill babeld' >> $babel_script
301
-	echo '    if [ -f /bin/systemctl ]; then' >> $babel_script
302
-	echo '        systemctl restart network-manager' >> $babel_script
303
-	echo '    else' >> $babel_script
304
-	echo '        service network-manager restart' >> $babel_script
305
-	echo '    fi' >> $babel_script
306
-	echo '    exit 1' >> $babel_script
307
-	echo 'fi' >> $babel_script
308
-	echo '' >> $babel_script
309
-	echo 'if [ -f /bin/systemctl ]; then' >> $babel_script
310
-	echo '    systemctl stop network-manager' >> $babel_script
311
-	echo 'else' >> $babel_script
312
-	echo '    service network-manager stop' >> $babel_script
313
-	echo 'fi' >> $babel_script
314
-	echo 'ifconfig $IFACE down' >> $babel_script
315
-	echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script
316
-	echo "$WIFI_CHANNEL essid \"$WIFI_SSID\"" >> $babel_script
317
-	echo 'ifconfig $IFACE up' >> $babel_script
318
-	echo -n 'ifconfig $IFACE:avahi ' >> $babel_script
319
-	echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script
320
-	echo '255.255.255.0 broadcast 192.168.13.255' >> $babel_script
321
-	echo -n 'babeld -D $IFACE:avahi -p ' >> $babel_script
322
-	echo -n "$BABEL_PORT -d 5 " >> $babel_script
323
-	echo '$IFACE' >> $babel_script
324
-	echo 'exit 0' >> $babel_script
325
-	chmod +x $babel_script
326
-	sudo mv $babel_script ${rootdir}/usr/bin/babel
237
+	CURR_DIR=$(pwd)
238
+	if [ ! -f ~/develop/toxid ]; then
239
+	    if [ ! -f ~/develop ]; then
240
+		mkdir ~/develop
241
+	    fi
242
+	    cd ~/develop
243
+	    git_clone $TOXID_REPO ~/develop/toxid
244
+	fi
245
+	cd ~/develop/toxid
246
+	sudo make install
247
+	cd $CURR_DIR
248
+    fi
249
+
250
+    babel_script=${rootdir}/tmp/babel
251
+
252
+    echo '#!/bin/bash' > $babel_script
253
+    echo '' >> $babel_script
254
+    echo 'if [[ $1 == "ls" || $1 == "list" ]]; then' >> $babel_script
255
+    echo '    avahi-browse -atl' >> $babel_script
256
+    echo '    exit 0' >> $babel_script
257
+    echo 'fi' >> $babel_script
258
+    echo '' >> $babel_script
259
+    echo 'if [[ $1 == "start" ]]; then' >> $babel_script
260
+    echo '    if [ -f /tmp/meshtype ] ; then' >> $babel_script
261
+    echo '        echo "Mesh already running"' >> $babel_script
262
+    echo '        return' >> $babel_script
263
+    echo '    fi' >> $batman_script
264
+    echo '    # install avahi' >> $babel_script
265
+    echo '    apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd bittornado' >> $babel_script
266
+    echo '    sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
267
+    echo '    sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
268
+    echo '    if [ -f /bin/systemctl ]; then' >> $babel_script
269
+    echo '        systemctl restart avahi-daemon' >> $babel_script
270
+    echo '    else' >> $babel_script
271
+    echo '        service avahi-daemon restart' >> $babel_script
272
+    echo '    fi' >> $babel_script
273
+    echo '    echo "babel" > /tmp/meshtype' >> $babel_script
274
+    echo 'fi' >> $babel_script
275
+    echo '' >> $babel_script
276
+    echo "IFACE=$WIFI_INTERFACE" >> $babel_script
277
+    echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
278
+    echo '    if grep -q "wlan1" /proc/net/dev; then' >> $babel_script
279
+    echo '        IFACE=wlan1' >> $babel_script
280
+    echo '    fi' >> $babel_script
281
+    echo 'fi' >> $babel_script
282
+    echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
283
+    echo '    if grep -q "wlan2" /proc/net/dev; then' >> $babel_script
284
+    echo '        IFACE=wlan2' >> $babel_script
285
+    echo '    fi' >> $babel_script
286
+    echo 'fi' >> $babel_script
287
+    echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
288
+    echo '    if grep -q "wlan3" /proc/net/dev; then' >> $babel_script
289
+    echo '        IFACE=wlan3' >> $babel_script
290
+    echo '    fi' >> $babel_script
291
+    echo 'fi' >> $babel_script
292
+    echo '' >> $babel_script
293
+    echo 'if [[ ! grep -q "$IFACE" /proc/net/dev || $1 == "stop" ]]; then' >> $babel_script
294
+    echo '    if ! grep -q "$IFACE" /proc/net/dev; then' >> $babel_script
295
+    echo '        echo "Interface $IFACE was not found"' >> $babel_script
296
+    echo '    else' >> $babel_script
297
+    echo '        echo "Stopping"' >> $babel_script
298
+    echo '    fi' >> $babel_script
299
+    echo '    ifconfig $IFACE down' >> $babel_script
300
+    echo '    pkill babeld' >> $babel_script
301
+    echo '    if [ -f /bin/systemctl ]; then' >> $babel_script
302
+    echo '        systemctl restart network-manager' >> $babel_script
303
+    echo '    else' >> $babel_script
304
+    echo '        service network-manager restart' >> $babel_script
305
+    echo '    fi' >> $babel_script
306
+    echo '    exit 1' >> $babel_script
307
+    echo 'fi' >> $babel_script
308
+    echo '' >> $babel_script
309
+    echo 'if [ -f /bin/systemctl ]; then' >> $babel_script
310
+    echo '    systemctl stop network-manager' >> $babel_script
311
+    echo 'else' >> $babel_script
312
+    echo '    service network-manager stop' >> $babel_script
313
+    echo 'fi' >> $babel_script
314
+    echo 'ifconfig $IFACE down' >> $babel_script
315
+    echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script
316
+    echo "$WIFI_CHANNEL essid \"$WIFI_SSID\"" >> $babel_script
317
+    echo 'ifconfig $IFACE up' >> $babel_script
318
+    echo -n 'ifconfig $IFACE:avahi ' >> $babel_script
319
+    echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script
320
+    echo '255.255.255.0 broadcast 192.168.13.255' >> $babel_script
321
+    echo -n 'babeld -D $IFACE:avahi -p ' >> $babel_script
322
+    echo -n "$BABEL_PORT -d 5 " >> $babel_script
323
+    echo '$IFACE' >> $babel_script
324
+    echo 'exit 0' >> $babel_script
325
+    chmod +x $babel_script
326
+    sudo mv $babel_script ${rootdir}/usr/bin/babel
327 327
 }
328 328
 
329 329
 function install_batman_remove {
330
-	systemctl stop batman
331
-	rm $rootdir/var/lib/batman
332
-	rm $rootdir/etc/systemd/system/batman.service
330
+    systemctl stop batman
331
+    rm $rootdir/var/lib/batman
332
+    rm $rootdir/etc/systemd/system/batman.service
333 333
 }
334 334
 
335 335
 function install_batman {
336
-	$CHROOT_PREFIX apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
337
-	$CHROOT_PREFIX apt-get -y install python-dev libevent-dev ebtables python-pip git
338
-	$CHROOT_PREFIX apt-get -y install wireless-tools rfkill
339
-
340
-	if ! grep -q "batman_adv" $rootdir/etc/modules; then
341
-		echo 'batman_adv' >> $rootdir/etc/modules
342
-	fi
343
-
344
-	BATMAN_SCRIPT=$rootdir/var/lib/batman
345
-
346
-	if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
347
-		cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
348
-	else
349
-		cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
350
-	fi
351
-
352
-	BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
353
-	echo '[Unit]' > $BATMAN_DAEMON
354
-	echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
355
-	echo 'After=network.target' >> $BATMAN_DAEMON
356
-	echo '' >> $BATMAN_DAEMON
357
-	echo '[Service]' >> $BATMAN_DAEMON
358
-	echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
359
-	echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
360
-	echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
361
-	echo 'Restart=on-failure' >> $BATMAN_DAEMON
362
-	echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
363
-	echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
364
-	echo '' >> $BATMAN_DAEMON
365
-	echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
366
-	echo 'TimeoutSec=300' >> $BATMAN_DAEMON
367
-	echo '' >> $BATMAN_DAEMON
368
-	echo '[Install]' >> $BATMAN_DAEMON
369
-	echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
370
-	$CHROOT_PREFIX systemctl enable batman
336
+    $CHROOT_PREFIX apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
337
+    $CHROOT_PREFIX apt-get -y install python-dev libevent-dev ebtables python-pip git
338
+    $CHROOT_PREFIX apt-get -y install wireless-tools rfkill
339
+
340
+    if ! grep -q "batman_adv" $rootdir/etc/modules; then
341
+	echo 'batman_adv' >> $rootdir/etc/modules
342
+    fi
343
+
344
+    BATMAN_SCRIPT=$rootdir/var/lib/batman
345
+
346
+    if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
347
+	cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
348
+    else
349
+	cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
350
+    fi
351
+
352
+    BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
353
+    echo '[Unit]' > $BATMAN_DAEMON
354
+    echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
355
+    echo 'After=network.target' >> $BATMAN_DAEMON
356
+    echo '' >> $BATMAN_DAEMON
357
+    echo '[Service]' >> $BATMAN_DAEMON
358
+    echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
359
+    echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
360
+    echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
361
+    echo 'Restart=on-failure' >> $BATMAN_DAEMON
362
+    echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
363
+    echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
364
+    echo '' >> $BATMAN_DAEMON
365
+    echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
366
+    echo 'TimeoutSec=300' >> $BATMAN_DAEMON
367
+    echo '' >> $BATMAN_DAEMON
368
+    echo '[Install]' >> $BATMAN_DAEMON
369
+    echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
370
+    $CHROOT_PREFIX systemctl enable batman
371 371
 }
372 372
 
373 373
 function mesh_firewall {
374
-	FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
375
-	MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall
376
-
377
-	echo '#!/bin/bash' > $MESH_FIREWALL_SCRIPT
378
-	echo 'iptables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
379
-	echo 'ip6tables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
380
-	echo 'iptables -F' >> $MESH_FIREWALL_SCRIPT
381
-	echo 'ip6tables -F' >> $MESH_FIREWALL_SCRIPT
382
-	echo 'iptables -t nat -F' >> $MESH_FIREWALL_SCRIPT
383
-	echo 'ip6tables -t nat -F' >> $MESH_FIREWALL_SCRIPT
384
-	echo 'iptables -X' >> $MESH_FIREWALL_SCRIPT
385
-	echo 'ip6tables -X' >> $MESH_FIREWALL_SCRIPT
386
-	echo 'iptables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
387
-	echo 'ip6tables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
388
-	echo 'iptables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
389
-	echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
390
-	echo '' >> $MESH_FIREWALL_SCRIPT
391
-	echo '# Make sure incoming tcp connections are SYN packets' >> $MESH_FIREWALL_SCRIPT
392
-	echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT
393
-	echo '' >> $MESH_FIREWALL_SCRIPT
394
-	echo '# Drop packets with incoming fragments' >> $MESH_FIREWALL_SCRIPT
395
-	echo 'iptables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT
396
-	echo '' >> $MESH_FIREWALL_SCRIPT
397
-	echo '# Drop bogons' >> $MESH_FIREWALL_SCRIPT
398
-	echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT
399
-	echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
400
-	echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
401
-	echo '' >> $MESH_FIREWALL_SCRIPT
402
-	echo '# Incoming malformed NULL packets:' >> $MESH_FIREWALL_SCRIPT
403
-	echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT
404
-	echo '' >> $MESH_FIREWALL_SCRIPT
405
-	echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
406
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
407
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
408
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
409
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
410
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
411
-	chmod +x $MESH_FIREWALL_SCRIPT
412
-
413
-	echo '[Unit]' > $FIREWALL_FILENAME
414
-	echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME
415
-	echo '' >> $FIREWALL_FILENAME
416
-	echo '[Service]' >> $FIREWALL_FILENAME
417
-	echo 'Type=oneshot' >> $FIREWALL_FILENAME
418
-	echo 'ExecStart=/usr/bin/mesh-firewall' >> $FIREWALL_FILENAME
419
-	echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME
420
-	echo '' >> $FIREWALL_FILENAME
421
-	echo 'TimeoutSec=30' >> $FIREWALL_FILENAME
422
-	echo '' >> $FIREWALL_FILENAME
423
-	echo '[Install]' >> $FIREWALL_FILENAME
424
-	echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
425
-	$CHROOT_PREFIX systemctl enable meshfirewall
374
+    FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
375
+    MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall
376
+
377
+    echo '#!/bin/bash' > $MESH_FIREWALL_SCRIPT
378
+    echo 'iptables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
379
+    echo 'ip6tables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
380
+    echo 'iptables -F' >> $MESH_FIREWALL_SCRIPT
381
+    echo 'ip6tables -F' >> $MESH_FIREWALL_SCRIPT
382
+    echo 'iptables -t nat -F' >> $MESH_FIREWALL_SCRIPT
383
+    echo 'ip6tables -t nat -F' >> $MESH_FIREWALL_SCRIPT
384
+    echo 'iptables -X' >> $MESH_FIREWALL_SCRIPT
385
+    echo 'ip6tables -X' >> $MESH_FIREWALL_SCRIPT
386
+    echo 'iptables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
387
+    echo 'ip6tables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
388
+    echo 'iptables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
389
+    echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
390
+    echo '' >> $MESH_FIREWALL_SCRIPT
391
+    echo '# Make sure incoming tcp connections are SYN packets' >> $MESH_FIREWALL_SCRIPT
392
+    echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT
393
+    echo '' >> $MESH_FIREWALL_SCRIPT
394
+    echo '# Drop packets with incoming fragments' >> $MESH_FIREWALL_SCRIPT
395
+    echo 'iptables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT
396
+    echo '' >> $MESH_FIREWALL_SCRIPT
397
+    echo '# Drop bogons' >> $MESH_FIREWALL_SCRIPT
398
+    echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT
399
+    echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
400
+    echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
401
+    echo '' >> $MESH_FIREWALL_SCRIPT
402
+    echo '# Incoming malformed NULL packets:' >> $MESH_FIREWALL_SCRIPT
403
+    echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT
404
+    echo '' >> $MESH_FIREWALL_SCRIPT
405
+    echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
406
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
407
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
408
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
409
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
410
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
411
+    chmod +x $MESH_FIREWALL_SCRIPT
412
+
413
+    echo '[Unit]' > $FIREWALL_FILENAME
414
+    echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME
415
+    echo '' >> $FIREWALL_FILENAME
416
+    echo '[Service]' >> $FIREWALL_FILENAME
417
+    echo 'Type=oneshot' >> $FIREWALL_FILENAME
418
+    echo 'ExecStart=/usr/bin/mesh-firewall' >> $FIREWALL_FILENAME
419
+    echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME
420
+    echo '' >> $FIREWALL_FILENAME
421
+    echo 'TimeoutSec=30' >> $FIREWALL_FILENAME
422
+    echo '' >> $FIREWALL_FILENAME
423
+    echo '[Install]' >> $FIREWALL_FILENAME
424
+    echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
425
+    $CHROOT_PREFIX systemctl enable meshfirewall
426 426
 }
427 427
 
428 428
 function enable_tox_repo {
429
-	sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > /etc/apt/sources.list.d/tox.list"
430
-	wget http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key
431
-	sudo sh -c "apt-key add - < Release.key"
432
-	sudo apt-get update
433
-	echo "Tox Repository Installed."
429
+    sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > /etc/apt/sources.list.d/tox.list"
430
+    wget http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key
431
+    sudo sh -c "apt-key add - < Release.key"
432
+    sudo apt-get update
433
+    echo "Tox Repository Installed."
434 434
 }
435 435
 
436 436
 function mesh_tox_client_qtox {
437
-	enable_tox_repo
438
-	sudo apt-get -y install qtox
439
-	echo "qTox Installed."
437
+    enable_tox_repo
438
+    sudo apt-get -y install qtox
439
+    echo "qTox Installed."
440 440
 }
441 441
 
442 442
 function mesh_tox_client_toxic_from_repo {
443
-	enable_tox_repo
444
-	sudo apt-get -y install toxic
445
-	echo "Toxic Installed."
443
+    enable_tox_repo
444
+    sudo apt-get -y install toxic
445
+    echo "Toxic Installed."
446 446
 }
447 447
 
448 448
 while [[ $# > 1 ]]
449 449
 do
450
-	key="$1"
451
-
452
-	case $key in
453
-		-h|--help)
454
-			show_help
455
-			;;
456
-		-f|--function)
457
-			shift
458
-			FN="$1"
459
-			;;
460
-		-r|--rootdir)
461
-			shift
462
-			rootdir="$1"
463
-			CHROOT_PREFIX='chroot "${rootdir}"'
464
-			;;
465
-		-w|--wifi|--interface)
466
-			shift
467
-			WIFI_INTERFACE="$1"
468
-			;;
469
-		-m|--mirror)
470
-			shift
471
-			FRIENDS_MIRRORS_SERVER="$1"
472
-			;;
473
-		--remove)
474
-			shift
475
-			REMOVE="$1"
476
-			;;
477
-		*)
478
-			# unknown option
479
-			;;
480
-
481
-	esac
482
-	shift
450
+    key="$1"
451
+
452
+    case $key in
453
+	-h|--help)
454
+	    show_help
455
+	    ;;
456
+	-f|--function)
457
+	    shift
458
+	    FN="$1"
459
+	    ;;
460
+	-r|--rootdir)
461
+	    shift
462
+	    rootdir="$1"
463
+	    CHROOT_PREFIX='chroot "${rootdir}"'
464
+	    ;;
465
+	-w|--wifi|--interface)
466
+	    shift
467
+	    WIFI_INTERFACE="$1"
468
+	    ;;
469
+	-m|--mirror)
470
+	    shift
471
+	    FRIENDS_MIRRORS_SERVER="$1"
472
+	    ;;
473
+	--remove)
474
+	    shift
475
+	    REMOVE="$1"
476
+	    ;;
477
+	*)
478
+	    # unknown option
479
+	    ;;
480
+
481
+    esac
482
+    shift
483 483
 done
484 484
 
485 485
 if [[ $FN == 'babel' ]]; then
486
-	if [[ $REMOVE != 'yes' ]]; then
487
-		install_babel
488
-	else
489
-		install_babel_remove
490
-	fi
486
+    if [[ $REMOVE != 'yes' ]]; then
487
+	install_babel
488
+    else
489
+	install_babel_remove
490
+    fi
491 491
 fi
492 492
 if [[ $FN == 'babel_client' ]]; then
493
-	install_babel_client
493
+    install_babel_client
494 494
 fi
495 495
 if [[ $FN == 'avahi' ]]; then
496
-	mesh_avahi
496
+    mesh_avahi
497 497
 fi
498 498
 if [[ $FN == 'firewall' ]]; then
499
-	mesh_firewall
499
+    mesh_firewall
500 500
 fi
501 501
 if [[ $FN == 'batman' ]]; then
502
-	if [[ $REMOVE != 'yes' ]]; then
503
-		install_batman
504
-	else
505
-		install_batman_remove
506
-	fi
502
+    if [[ $REMOVE != 'yes' ]]; then
503
+	install_batman
504
+    else
505
+	install_batman_remove
506
+    fi
507 507
 fi
508 508
 if [[ $FN == 'qtox' ]]; then
509
-	mesh_tox_client_qtox
509
+    mesh_tox_client_qtox
510 510
 fi
511 511
 if [[ $FN == 'toxic' ]]; then
512
-	mesh_tox_client_toxic_from_repo
512
+    mesh_tox_client_toxic_from_repo
513 513
 fi
514 514
 
515 515
 exit 0