Browse Source

Begin combining mesh install functions

Bob Mottram 8 years ago
parent
commit
2a3c1bb429

+ 42
- 0
src/freedombone-app-batman View File

@@ -84,7 +84,49 @@ function remove_batman {
84 84
 	sed -i '/configure_firewall_for_batman/d' $COMPLETION_FILE
85 85
 }
86 86
 
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
123
+}
124
+
87 125
 function install_batman {
126
+	if [ $INSTALLING_MESH ]; then
127
+		mesh_install_batman
128
+		return
129
+	fi
88 130
 	if grep -Fxq "install_batman" $COMPLETION_FILE; then
89 131
 		return
90 132
 	fi

+ 41
- 0
src/freedombone-app-syncthing View File

@@ -255,7 +255,48 @@ function configure_firewall_for_syncthing {
255 255
 	echo 'configure_firewall_for_syncthing' >> $COMPLETION_FILE
256 256
 }
257 257
 
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
+	chroot "$rootdir" echo '[Unit]' > /etc/systemd/system/syncthing.service
268
+	chroot "$rootdir" echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
269
+	chroot "$rootdir" echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
270
+	chroot "$rootdir" echo 'After=network.target' >> /etc/systemd/system/syncthing.service
271
+	chroot "$rootdir" echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
272
+	chroot "$rootdir" echo '' >> /etc/systemd/system/syncthing.service
273
+	chroot "$rootdir" echo '[Service]' >> /etc/systemd/system/syncthing.service
274
+	chroot "$rootdir" echo 'User=root' >> /etc/systemd/system/syncthing.service
275
+	chroot "$rootdir" echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
276
+	chroot "$rootdir" echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
277
+	chroot "$rootdir" echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
278
+	chroot "$rootdir" echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
279
+	chroot "$rootdir" echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
280
+	chroot "$rootdir" echo '' >> /etc/systemd/system/syncthing.service
281
+	chroot "$rootdir" echo '[Install]' >> /etc/systemd/system/syncthing.service
282
+	chroot "$rootdir" echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
283
+	chroot "$rootdir" systemctl enable syncthing
284
+	chroot "$rootdir" systemctl daemon-reload
285
+
286
+	if ! grep -q "syncthing" $rootdir/etc/crontab; then
287
+		chroot "$rootdir" echo "*/1            * *   *   *   root /usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null" >> /etc/crontab
288
+		chroot "$rootdir" systemctl restart cron
289
+	fi
290
+
291
+	echo 'mesh_install_syncthing'
292
+}
293
+
258 294
 function install_syncthing {
295
+	if [ $INSTALLING_MESH ]; then
296
+		mesh_install_syncthing
297
+		return
298
+	fi
299
+
259 300
 	if grep -Fxq "install_syncthing" $COMPLETION_FILE; then
260 301
 		return
261 302
 	fi

+ 240
- 0
src/freedombone-app-tox View File

@@ -246,6 +246,11 @@ function tox_avahi {
246 246
 }
247 247
 
248 248
 function install_tox_node {
249
+	if [ $INSTALLING_MESH ]; then
250
+		mesh_tox_node
251
+		return
252
+	fi
253
+
249 254
 	if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
250 255
 		return
251 256
 	fi
@@ -327,4 +332,239 @@ function install_tox {
327 332
 	echo 'install_tox' >> $COMPLETION_FILE
328 333
 }
329 334
 
335
+function mesh_tox_node {
336
+	# obtain commits from the main file
337
+	TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
338
+	if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
339
+		TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
340
+	fi
341
+	if [ ! $TOXCORE_COMMIT ]; then
342
+		echo $'No Tox commit was specified'
343
+		exit 76325
344
+	fi
345
+
346
+	TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
347
+	if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
348
+		TOX_PORT=$TOX_PORT_MAIN
349
+	fi
350
+	if [ ! $TOX_PORT ]; then
351
+		echo $'No Tox port was specified'
352
+		exit 32856
353
+	fi
354
+
355
+	TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
356
+	if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
357
+		TOXCORE_REPO=$TOXCORE_REPO_MAIN
358
+	fi
359
+	if [ ! $TOXCORE_REPO ]; then
360
+		echo $'No Tox repo was specified'
361
+		exit 16865
362
+	fi
363
+
364
+	chroot "$rootdir" apt-get -y install build-essential libtool autotools-dev
365
+	chroot "$rootdir" apt-get -y install automake checkinstall check git yasm
366
+	chroot "$rootdir" apt-get -y install libsodium13 libsodium-dev libcap2-bin
367
+	chroot "$rootdir" apt-get -y install libconfig9 libconfig-dev
368
+
369
+
370
+	TEMP_SCRIPT_NAME=fbtmp37272.sh
371
+	TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
372
+	echo '#!/bin/bash' > $TEMP_SCRIPT
373
+	echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
374
+	echo "git clone $TOXCORE_REPO $INSTALL_DIR/toxcore" >> $TEMP_SCRIPT
375
+	echo "cd $INSTALL_DIR/toxcore" >> $TEMP_SCRIPT
376
+	echo "git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT" >> $TEMP_SCRIPT
377
+	echo 'autoreconf -i' >> $TEMP_SCRIPT
378
+	echo './configure --enable-daemon --disable-av' >> $TEMP_SCRIPT
379
+	echo 'make' >> $TEMP_SCRIPT
380
+	echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
381
+	echo '    exit 1' >> $TEMP_SCRIPT
382
+	echo 'fi' >> $TEMP_SCRIPT
383
+	echo 'make install' >> $TEMP_SCRIPT
384
+	echo 'cp /usr/local/lib/libtoxcore* /usr/lib/' >> $TEMP_SCRIPT
385
+	echo "cp $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service /etc/systemd/system/" >> $TEMP_SCRIPT
386
+	echo "sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' /etc/systemd/system/tox-bootstrapd.service" >> $TEMP_SCRIPT
387
+	echo 'systemctl enable tox-bootstrapd.service' >> $TEMP_SCRIPT
388
+	echo 'exit 0' >> $TEMP_SCRIPT
389
+	chmod +x $TEMP_SCRIPT
390
+	cp $TEMP_SCRIPT $rootdir/root/
391
+
392
+	SECONDS=0
393
+	chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
394
+	if [ ! "$?" = "0" ]; then
395
+		duration=$SECONDS
396
+		echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
397
+		echo $'Unable to make toxcore'
398
+		rm $TEMP_SCRIPT
399
+		exit 73835
400
+	fi
401
+	duration=$SECONDS
402
+	echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
403
+	rm $TEMP_SCRIPT
404
+
405
+	if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
406
+		echo $"File not found /usr/local/bin/tox-bootstrapd"
407
+		exit 37825
408
+	fi
409
+
410
+	chroot "$rootdir" useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment $"Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
411
+	chroot "$rootdir" chmod 700 /var/lib/tox-bootstrapd
412
+
413
+	# remove Maildir
414
+	if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
415
+		rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
416
+	fi
417
+
418
+	# create configuration file
419
+	TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
420
+	echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
421
+	echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
422
+	echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
423
+	echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
424
+	echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
425
+	echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
426
+	echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
427
+	echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
428
+	echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
429
+	echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
430
+
431
+	if [ $TOX_NODES ]; then
432
+		echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
433
+		toxcount=0
434
+		while [ "x${TOX_NODES[toxcount]}" != "x" ]
435
+		do
436
+			toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
437
+			toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
438
+			toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
439
+			toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
440
+			toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
441
+			echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
442
+			if [[ $toxval_ipv6 != 'NONE' ]]; then
443
+				echo "  address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
444
+			else
445
+				echo "  address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
446
+			fi
447
+			echo "  port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
448
+			echo "  public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
449
+			toxcount=$(( $toxcount + 1 ))
450
+			if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
451
+				echo "}," >> $TOX_BOOTSTRAP_CONFIG
452
+			else
453
+				echo "}" >> $TOX_BOOTSTRAP_CONFIG
454
+			fi
455
+		done
456
+		echo ')' >> $TOX_BOOTSTRAP_CONFIG
457
+	fi
458
+}
459
+
460
+function mesh_tox_avahi {
461
+	if [ ! -d $rootdir/etc/avahi ]; then
462
+		echo $'tox_avahi: avahi is not installed'
463
+		exit 87359
464
+	fi
465
+
466
+	TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
467
+	if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
468
+		TOXID_REPO=$TOXID_REPO_MAIN
469
+	fi
470
+	if [ ! $TOXID_REPO ]; then
471
+		echo $'No ToxID repo was specified'
472
+		exit 78252
473
+	fi
474
+
475
+	TEMP_SCRIPT_NAME=fbtmp5328252.sh
476
+	TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
477
+	echo '#!/bin/bash' > $TEMP_SCRIPT
478
+	echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
479
+	echo "git clone $TOXID_REPO $INSTALL_DIR/toxid" >> $TEMP_SCRIPT
480
+	echo "if [ ! -d $INSTALL_DIR/toxid ]; then" >> $TEMP_SCRIPT
481
+	echo '    exit 1' >> $TEMP_SCRIPT
482
+	echo 'fi' >> $TEMP_SCRIPT
483
+	echo "cd $INSTALL_DIR/toxid" >> $TEMP_SCRIPT
484
+	echo "make" >> $TEMP_SCRIPT
485
+	echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
486
+	echo '    exit 2' >> $TEMP_SCRIPT
487
+	echo 'fi' >> $TEMP_SCRIPT
488
+	echo 'make install' >> $TEMP_SCRIPT
489
+	echo 'if [ ! -f /usr/local/bin/toxavahi ]; then' >> $TEMP_SCRIPT
490
+	echo '  exit 3' >> $TEMP_SCRIPT
491
+	echo 'fi' >> $TEMP_SCRIPT
492
+	echo 'toxavahi' >> $TEMP_SCRIPT
493
+	echo 'echo "* *     * * *   root    /usr/local/bin/toxavahi > /dev/null" >> /etc/crontab' >> $TEMP_SCRIPT
494
+	echo 'systemctl restart avahi-daemon' >> $TEMP_SCRIPT
495
+	echo 'exit 0' >> $TEMP_SCRIPT
496
+	chmod +x $TEMP_SCRIPT
497
+	cp $TEMP_SCRIPT $rootdir/root/
498
+
499
+	chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
500
+	if [ ! "$?" = "0" ]; then
501
+		echo $"Unable to install toxid, returned $?"
502
+		rm $TEMP_SCRIPT
503
+		exit 62835
504
+	fi
505
+	rm $TEMP_SCRIPT
506
+}
507
+
508
+function mesh_tox_client {
509
+	TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
510
+
511
+	# obtain commits from the main file
512
+	TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
513
+	if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
514
+		TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
515
+	fi
516
+
517
+	TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
518
+	if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
519
+		TOXIC_REPO=$TOXIC_REPO_MAIN
520
+	fi
521
+
522
+	chroot "$rootdir" apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
523
+	chroot "$rootdir" apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
524
+
525
+	TEMP_SCRIPT_NAME=fbtmp728353.sh
526
+	TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
527
+	echo '#!/bin/bash' > $TEMP_SCRIPT
528
+	echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
529
+	echo "git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
530
+	echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
531
+	echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
532
+	echo 'make' >> $TEMP_SCRIPT
533
+	echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
534
+	echo '    exit 1' >> $TEMP_SCRIPT
535
+	echo 'fi' >> $TEMP_SCRIPT
536
+	echo 'make install' >> $TEMP_SCRIPT
537
+	echo 'exit 0' >> $TEMP_SCRIPT
538
+	chmod +x $TEMP_SCRIPT
539
+	cp $TEMP_SCRIPT $rootdir/root/
540
+
541
+	TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
542
+
543
+	SECONDS=0
544
+	chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
545
+	if [ ! "$?" = "0" ]; then
546
+		duration=$SECONDS
547
+		echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
548
+		echo $'Unable to make tox client'
549
+		rm $TEMP_SCRIPT
550
+		exit 74872
551
+	fi
552
+	rm $TEMP_SCRIPT
553
+	if [ ! -f $rootdir$TOXIC_FILE ]; then
554
+		echo $"Tox client was not installed to $TOXIC_FILE"
555
+		exit 63278
556
+	fi
557
+	duration=$SECONDS
558
+	echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
559
+}
560
+
561
+function enable_tox_repo {
562
+	echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
563
+
564
+
565
+	chroot "$rootdir" wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key -O- | apt-key add -
566
+	chroot "$rootdir" apt-get update
567
+	echo "Tox Repository Installed."
568
+}
569
+
330 570
 # NOTE: deliberately no exit 0

+ 164
- 1
src/freedombone-app-zeronet View File

@@ -48,7 +48,7 @@ ZERONET_ID_REPO="https://github.com/HelloZeroNet/ZeroID"
48 48
 ZERONET_ID_COMMIT='ccf14fdc96fa9cdb2ddd8a7ab283a8e17a4f234b'
49 49
 
50 50
 function reconfigure_zeronet {
51
-    echo -n ''
51
+	echo -n ''
52 52
 }
53 53
 
54 54
 function upgrade_zeronet {
@@ -454,7 +454,170 @@ function install_zeronet_main {
454 454
 	echo 'install_zeronet_main' >> $COMPLETION_FILE
455 455
 }
456 456
 
457
+function mesh_zeronet {
458
+	# obtain commits from the main file
459
+	ZERONET_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
460
+	if [ ${#ZERONET_COMMIT_MAIN} -gt 10 ]; then
461
+		ZERONET_COMMIT=$ZERONET_COMMIT_MAIN
462
+	fi
463
+	if [ ! $ZERONET_COMMIT ]; then
464
+		echo $'No Tox commit was specified'
465
+		exit 37046
466
+	fi
467
+
468
+	ZERONET_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}')
469
+	if [ ${#ZERONET_REPO_MAIN} -gt 5 ]; then
470
+		ZERONET_REPO=$ZERONET_REPO_MAIN
471
+	fi
472
+	if [ ! $ZERONET_REPO ]; then
473
+		echo $'No Tox commit was specified'
474
+		exit 37046
475
+	fi
476
+
477
+	ZERONET_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_PORT=" | head -n 1 | awk -F '=' '{print $2}')
478
+	if [ ${#ZERONET_PORT_MAIN} -gt 1 ]; then
479
+		ZERONET_PORT=$ZERONET_PORT_MAIN
480
+	fi
481
+	if [ ! $ZERONET_PORT ]; then
482
+		echo $'No zeronet port was specified'
483
+		exit 67433
484
+	fi
485
+
486
+	chroot "$rootdir" apt-get -y install python python-msgpack python-gevent
487
+	chroot "$rootdir" apt-get -y install python-pip bittornado
488
+	chroot "$rootdir" pip install msgpack-python --upgrade
489
+
490
+	chroot "$rootdir" useradd -d $MESH_INSTALL_DIR/zeronet/ -s /bin/false zeronet
491
+	git clone $ZERONET_REPO $rootdir$MESH_INSTALL_DIR/zeronet
492
+	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet ]; then
493
+		echo 'WARNING: Unable to clone zeronet'
494
+		return
495
+	fi
496
+	cd $rootdir$MESH_INSTALL_DIR/zeronet
497
+	git checkout $ZERONET_COMMIT -b $ZERONET_COMMIT
498
+	if ! grep -q "ZeroNet commit" $COMPLETION_FILE; then
499
+		echo "ZeroNet commit:$ZERONET_COMMIT" >> $rootdir$COMPLETION_FILE
500
+	else
501
+		sed -i "s/ZeroNet commit.*/ZeroNet commit:$ZERONET_COMMIT/g" $COMPLETION_FILE
502
+	fi
503
+	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
504
+
505
+	# Hack to ensure that the file access port is opened
506
+	# This is because zeronet normally relies on an internet site
507
+	# to do this, but on a purely local mesh the internet isn't available
508
+	sed -i 's|fileserver_port = 0|fileserver_port = config.fileserver_port\n            sys.modules["main"].file_server.port_opened = True|g' $rootdir$MESH_INSTALL_DIR/zeronet/src/Site/Site.py
509
+
510
+	ZERONET_DAEMON=$rootdir/etc/systemd/system/zeronet.service
511
+	echo '[Unit]' > $ZERONET_DAEMON
512
+	echo 'Description=Zeronet Server' >> $ZERONET_DAEMON
513
+	echo 'After=syslog.target' >> $ZERONET_DAEMON
514
+	echo 'After=network.target' >> $ZERONET_DAEMON
515
+	echo '[Service]' >> $ZERONET_DAEMON
516
+	echo 'Type=simple' >> $ZERONET_DAEMON
517
+	echo 'User=zeronet' >> $ZERONET_DAEMON
518
+	echo 'Group=zeronet' >> $ZERONET_DAEMON
519
+	echo "WorkingDirectory=$MESH_INSTALL_DIR/zeronet" >> $ZERONET_DAEMON
520
+	echo "ExecStart=/usr/bin/python zeronet.py --ip_external replace.local --trackers_file $MESH_INSTALL_DIR/zeronet/bootstrap" >> $ZERONET_DAEMON
521
+	echo '' >> $ZERONET_DAEMON
522
+	echo 'TimeoutSec=300' >> $ZERONET_DAEMON
523
+	echo '' >> $ZERONET_DAEMON
524
+	echo '[Install]' >> $ZERONET_DAEMON
525
+	echo 'WantedBy=multi-user.target' >> $ZERONET_DAEMON
526
+
527
+	TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
528
+	echo '[Unit]' > $TRACKER_DAEMON
529
+	echo 'Description=Torrent Tracker' >> $TRACKER_DAEMON
530
+	echo 'After=syslog.target' >> $TRACKER_DAEMON
531
+	echo 'After=network.target' >> $TRACKER_DAEMON
532
+	echo '[Service]' >> $TRACKER_DAEMON
533
+	echo 'Type=simple' >> $TRACKER_DAEMON
534
+	echo 'User=tracker' >> $TRACKER_DAEMON
535
+	echo 'Group=tracker' >> $TRACKER_DAEMON
536
+	echo "WorkingDirectory=$MESH_INSTALL_DIR/tracker" >> $TRACKER_DAEMON
537
+	echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile $MESH_INSTALL_DIR/tracker/dstate --logfile $MESH_INSTALL_DIR/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0" >> $TRACKER_DAEMON
538
+	echo '' >> $TRACKER_DAEMON
539
+	echo 'TimeoutSec=300' >> $TRACKER_DAEMON
540
+	echo '' >> $TRACKER_DAEMON
541
+	echo '[Install]' >> $TRACKER_DAEMON
542
+	echo 'WantedBy=multi-user.target' >> $TRACKER_DAEMON
543
+
544
+	chroot "$rootdir" useradd -d $MESH_INSTALL_DIR/tracker/ -s /bin/false tracker
545
+	if [ ! -d $rootdir$MESH_INSTALL_DIR/tracker ]; then
546
+		mkdir $rootdir$MESH_INSTALL_DIR/tracker
547
+	fi
548
+	chroot "$rootdir" chown -R tracker:tracker $MESH_INSTALL_DIR/tracker
549
+
550
+	# publish regularly
551
+	echo "* *     * * *   root    zeronetavahi > /dev/null" >> $rootdir/etc/crontab
552
+
553
+	chroot "$rootdir" systemctl enable tracker.service
554
+	chroot "$rootdir" systemctl enable zeronet.service
555
+}
556
+
557
+function mesh_zeronet_blog {
558
+	ZERONET_BLOG_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_BLOG_REPO=" | head -n 1 | awk -F '"' '{print $2}')
559
+	ZERONET_BLOG_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_BLOG_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
560
+
561
+	git clone $ZERONET_BLOG_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog
562
+	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog ]; then
563
+		echo $'ZeroBlog repo could not be cloned'
564
+		exit 6739
565
+	fi
566
+	cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog
567
+	git checkout $ZERONET_BLOG_COMMIT -b $ZERONET_BLOG_COMMIT
568
+	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
569
+}
570
+
571
+function mesh_zeronet_mail {
572
+	ZERONET_MAIL_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_MAIL_REPO=" | head -n 1 | awk -F '"' '{print $2}')
573
+	ZERONET_MAIL_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_MAIL_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
574
+
575
+	git clone $ZERONET_MAIL_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail
576
+	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail ]; then
577
+		echo $'ZeroMail repo could not be cloned'
578
+		exit 78493
579
+	fi
580
+	cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail
581
+	git checkout $ZERONET_MAIL_COMMIT -b $ZERONET_MAIL_COMMIT
582
+	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
583
+}
584
+
585
+function mesh_zeronet_forum {
586
+	ZERONET_FORUM_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_FORUM_REPO=" | head -n 1 | awk -F '"' '{print $2}')
587
+	ZERONET_FORUM_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_FORUM_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
588
+
589
+	git clone $ZERONET_FORUM_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk
590
+	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk ]; then
591
+		echo $'ZeroTalk repo could not be cloned'
592
+		exit 78252
593
+	fi
594
+	cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk
595
+	git checkout $ZERONET_FORUM_COMMIT -b $ZERONET_FORUM_COMMIT
596
+	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
597
+}
598
+
599
+function mesh_zeronet_id {
600
+	ZERONET_ID_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_ID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
601
+	ZERONET_ID_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_ID_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
602
+
603
+	git clone $ZERONET_ID_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID
604
+	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID ]; then
605
+		echo $'ZeroID repo could not be cloned'
606
+		exit 37936
607
+	fi
608
+	cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID
609
+	git checkout $ZERONET_ID_COMMIT -b $ZERONET_ID_COMMIT
610
+	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
611
+}
612
+
457 613
 function install_zeronet {
614
+	if [ $INSTALLING_MESH ]; then
615
+		mesh_zeronet
616
+		mesh_zeronet_blog
617
+		mesh_zeronet_mail
618
+		mesh_zeronet_forum
619
+		return
620
+	fi
458 621
 	if grep -Fxq "install_zeronet" $COMPLETION_FILE; then
459 622
 		return
460 623
 	fi

+ 5
- 582
src/freedombone-image-customise View File

@@ -491,534 +491,7 @@ ZERONET_ID_COMMIT=
491 491
 # Directory where source code is downloaded and compiled
492 492
 INSTALL_DIR=$HOME/build
493 493
 
494
-function mesh_avahi {
495
-	chroot "$rootdir" apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
496
-
497
-	decarray=( 1 2 3 4 5 6 7 8 9 0 )
498
-	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]}
499
-	sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf
500
-
501
-	if [ ! -d $rootdir/etc/avahi/services ]; then
502
-		mkdir -p $rootdir/etc/avahi/services
503
-	fi
504
-
505
-	# remove an avahi service which isn't used
506
-	if [ -f $rootdir/etc/avahi/services/udisks.service ]; then
507
-		rm $rootdir/etc/avahi/services/udisks.service
508
-	fi
509
-
510
-	# Add an ssh service
511
-	echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/ssh.service
512
-	echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/ssh.service
513
-	echo '<service-group>' >> $rootdir/etc/avahi/services/ssh.service
514
-	echo '  <name replace-wildcards="yes">%h SSH</name>' >> $rootdir/etc/avahi/services/ssh.service
515
-	echo '  <service>' >> $rootdir/etc/avahi/services/ssh.service
516
-	echo '    <type>_ssh._tcp</type>' >> $rootdir/etc/avahi/services/ssh.service
517
-	echo "    <port>$SSH_PORT</port>" >> $rootdir/etc/avahi/services/ssh.service
518
-	echo '  </service>' >> $rootdir/etc/avahi/services/ssh.service
519
-	echo '</service-group>' >> $rootdir/etc/avahi/services/ssh.service
520
-
521
-	# keep the daemon running
522
-	WATCHDOG_SCRIPT_NAME="keepon"
523
-	echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
524
-	echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
525
-	echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
526
-	echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
527
-	echo '  systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
528
-	echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
529
-	echo '  echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
530
-	echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
531
-	chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
532
-}
533
-
534
-function install_batman {
535
-	chroot "$rootdir" apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
536
-	chroot "$rootdir" apt-get -y install python-dev libevent-dev ebtables python-pip git
537
-	chroot "$rootdir" apt-get -y install wireless-tools rfkill
538
-
539
-	if ! grep -q "batman_adv" $rootdir/etc/modules; then
540
-		echo 'batman_adv' >> $rootdir/etc/modules
541
-	fi
542
-
543
-	BATMAN_SCRIPT=$rootdir/var/lib/batman
544
-
545
-	if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
546
-		cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
547
-	else
548
-		cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
549
-	fi
550
-
551
-	BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
552
-	echo '[Unit]' > $BATMAN_DAEMON
553
-	echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
554
-	echo 'After=network.target' >> $BATMAN_DAEMON
555
-	echo '' >> $BATMAN_DAEMON
556
-	echo '[Service]' >> $BATMAN_DAEMON
557
-	echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
558
-	echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
559
-	echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
560
-	echo 'Restart=on-failure' >> $BATMAN_DAEMON
561
-	echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
562
-	echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
563
-	echo '' >> $BATMAN_DAEMON
564
-	echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
565
-	echo 'TimeoutSec=300' >> $BATMAN_DAEMON
566
-	echo '' >> $BATMAN_DAEMON
567
-	echo '[Install]' >> $BATMAN_DAEMON
568
-	echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
569
-	chroot "$rootdir" systemctl enable batman
570
-}
571
-
572
-function mesh_firewall {
573
-	FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
574
-	MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall
575
-
576
-	echo '#!/bin/bash' > $MESH_FIREWALL_SCRIPT
577
-	echo 'iptables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
578
-	echo 'ip6tables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
579
-	echo 'iptables -F' >> $MESH_FIREWALL_SCRIPT
580
-	echo 'ip6tables -F' >> $MESH_FIREWALL_SCRIPT
581
-	echo 'iptables -t nat -F' >> $MESH_FIREWALL_SCRIPT
582
-	echo 'ip6tables -t nat -F' >> $MESH_FIREWALL_SCRIPT
583
-	echo 'iptables -X' >> $MESH_FIREWALL_SCRIPT
584
-	echo 'ip6tables -X' >> $MESH_FIREWALL_SCRIPT
585
-	echo 'iptables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
586
-	echo 'ip6tables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
587
-	echo 'iptables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
588
-	echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
589
-	echo '' >> $MESH_FIREWALL_SCRIPT
590
-	echo '# Make sure incoming tcp connections are SYN packets' >> $MESH_FIREWALL_SCRIPT
591
-	echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT
592
-	echo '' >> $MESH_FIREWALL_SCRIPT
593
-	echo '# Drop packets with incoming fragments' >> $MESH_FIREWALL_SCRIPT
594
-	echo 'iptables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT
595
-	echo '' >> $MESH_FIREWALL_SCRIPT
596
-	echo '# Drop bogons' >> $MESH_FIREWALL_SCRIPT
597
-	echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT
598
-	echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
599
-	echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
600
-	echo '' >> $MESH_FIREWALL_SCRIPT
601
-	echo '# Incoming malformed NULL packets:' >> $MESH_FIREWALL_SCRIPT
602
-	echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT
603
-	echo '' >> $MESH_FIREWALL_SCRIPT
604
-	echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
605
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
606
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
607
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
608
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
609
-	echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
610
-	chmod +x $MESH_FIREWALL_SCRIPT
611
-
612
-	echo '[Unit]' > $FIREWALL_FILENAME
613
-	echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME
614
-	echo '' >> $FIREWALL_FILENAME
615
-	echo '[Service]' >> $FIREWALL_FILENAME
616
-	echo 'Type=oneshot' >> $FIREWALL_FILENAME
617
-	echo 'ExecStart=/usr/bin/mesh-firewall' >> $FIREWALL_FILENAME
618
-	echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME
619
-	echo '' >> $FIREWALL_FILENAME
620
-	echo 'TimeoutSec=30' >> $FIREWALL_FILENAME
621
-	echo '' >> $FIREWALL_FILENAME
622
-	echo '[Install]' >> $FIREWALL_FILENAME
623
-	echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
624
-	chroot "$rootdir" systemctl enable meshfirewall
625
-}
626
-
627
-function mesh_tox_node {
628
-	# obtain commits from the main file
629
-	TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
630
-	if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
631
-		TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
632
-	fi
633
-	if [ ! $TOXCORE_COMMIT ]; then
634
-		echo $'No Tox commit was specified'
635
-		exit 76325
636
-	fi
637
-
638
-	TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
639
-	if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
640
-		TOX_PORT=$TOX_PORT_MAIN
641
-	fi
642
-	if [ ! $TOX_PORT ]; then
643
-		echo $'No Tox port was specified'
644
-		exit 32856
645
-	fi
646
-
647
-	TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
648
-	if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
649
-		TOXCORE_REPO=$TOXCORE_REPO_MAIN
650
-	fi
651
-	if [ ! $TOXCORE_REPO ]; then
652
-		echo $'No Tox repo was specified'
653
-		exit 16865
654
-	fi
655
-
656
-	chroot "$rootdir" apt-get -y install build-essential libtool autotools-dev
657
-	chroot "$rootdir" apt-get -y install automake checkinstall check git yasm
658
-	chroot "$rootdir" apt-get -y install libsodium13 libsodium-dev libcap2-bin
659
-	chroot "$rootdir" apt-get -y install libconfig9 libconfig-dev
660
-
661
-
662
-	TEMP_SCRIPT_NAME=fbtmp37272.sh
663
-	TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
664
-	echo '#!/bin/bash' > $TEMP_SCRIPT
665
-	echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
666
-	echo "git clone $TOXCORE_REPO $INSTALL_DIR/toxcore" >> $TEMP_SCRIPT
667
-	echo "cd $INSTALL_DIR/toxcore" >> $TEMP_SCRIPT
668
-	echo "git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT" >> $TEMP_SCRIPT
669
-	echo 'autoreconf -i' >> $TEMP_SCRIPT
670
-	echo './configure --enable-daemon --disable-av' >> $TEMP_SCRIPT
671
-	echo 'make' >> $TEMP_SCRIPT
672
-	echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
673
-	echo '    exit 1' >> $TEMP_SCRIPT
674
-	echo 'fi' >> $TEMP_SCRIPT
675
-	echo 'make install' >> $TEMP_SCRIPT
676
-	echo 'cp /usr/local/lib/libtoxcore* /usr/lib/' >> $TEMP_SCRIPT
677
-	echo "cp $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service /etc/systemd/system/" >> $TEMP_SCRIPT
678
-	echo "sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' /etc/systemd/system/tox-bootstrapd.service" >> $TEMP_SCRIPT
679
-	echo 'systemctl enable tox-bootstrapd.service' >> $TEMP_SCRIPT
680
-	echo 'exit 0' >> $TEMP_SCRIPT
681
-	chmod +x $TEMP_SCRIPT
682
-	cp $TEMP_SCRIPT $rootdir/root/
683
-
684
-	SECONDS=0
685
-	chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
686
-	if [ ! "$?" = "0" ]; then
687
-		duration=$SECONDS
688
-		echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
689
-		echo $'Unable to make toxcore'
690
-		rm $TEMP_SCRIPT
691
-		exit 73835
692
-	fi
693
-	duration=$SECONDS
694
-	echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
695
-	rm $TEMP_SCRIPT
696
-
697
-	if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
698
-		echo $"File not found /usr/local/bin/tox-bootstrapd"
699
-		exit 37825
700
-	fi
701
-
702
-	chroot "$rootdir" useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment $"Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
703
-	chroot "$rootdir" chmod 700 /var/lib/tox-bootstrapd
704
-
705
-	# remove Maildir
706
-	if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
707
-		rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
708
-	fi
709
-
710
-	# create configuration file
711
-	TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
712
-	echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
713
-	echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
714
-	echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
715
-	echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
716
-	echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
717
-	echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
718
-	echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
719
-	echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
720
-	echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
721
-	echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
722
-
723
-	if [ $TOX_NODES ]; then
724
-		echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
725
-		toxcount=0
726
-		while [ "x${TOX_NODES[toxcount]}" != "x" ]
727
-		do
728
-			toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
729
-			toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
730
-			toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
731
-			toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
732
-			toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
733
-			echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
734
-			if [[ $toxval_ipv6 != 'NONE' ]]; then
735
-				echo "  address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
736
-			else
737
-				echo "  address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
738
-			fi
739
-			echo "  port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
740
-			echo "  public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
741
-			toxcount=$(( $toxcount + 1 ))
742
-			if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
743
-				echo "}," >> $TOX_BOOTSTRAP_CONFIG
744
-			else
745
-				echo "}" >> $TOX_BOOTSTRAP_CONFIG
746
-			fi
747
-		done
748
-		echo ')' >> $TOX_BOOTSTRAP_CONFIG
749
-	fi
750
-}
751
-
752
-function mesh_tox_avahi {
753
-	if [ ! -d $rootdir/etc/avahi ]; then
754
-		echo $'tox_avahi: avahi is not installed'
755
-		exit 87359
756
-	fi
757
-
758
-	TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
759
-	if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
760
-		TOXID_REPO=$TOXID_REPO_MAIN
761
-	fi
762
-	if [ ! $TOXID_REPO ]; then
763
-		echo $'No ToxID repo was specified'
764
-		exit 78252
765
-	fi
766
-
767
-	TEMP_SCRIPT_NAME=fbtmp5328252.sh
768
-	TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
769
-	echo '#!/bin/bash' > $TEMP_SCRIPT
770
-	echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
771
-	echo "git clone $TOXID_REPO $INSTALL_DIR/toxid" >> $TEMP_SCRIPT
772
-	echo "if [ ! -d $INSTALL_DIR/toxid ]; then" >> $TEMP_SCRIPT
773
-	echo '    exit 1' >> $TEMP_SCRIPT
774
-	echo 'fi' >> $TEMP_SCRIPT
775
-	echo "cd $INSTALL_DIR/toxid" >> $TEMP_SCRIPT
776
-	echo "make" >> $TEMP_SCRIPT
777
-	echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
778
-	echo '    exit 2' >> $TEMP_SCRIPT
779
-	echo 'fi' >> $TEMP_SCRIPT
780
-	echo 'make install' >> $TEMP_SCRIPT
781
-	echo 'if [ ! -f /usr/local/bin/toxavahi ]; then' >> $TEMP_SCRIPT
782
-	echo '  exit 3' >> $TEMP_SCRIPT
783
-	echo 'fi' >> $TEMP_SCRIPT
784
-	echo 'toxavahi' >> $TEMP_SCRIPT
785
-	echo 'echo "* *     * * *   root    /usr/local/bin/toxavahi > /dev/null" >> /etc/crontab' >> $TEMP_SCRIPT
786
-	echo 'systemctl restart avahi-daemon' >> $TEMP_SCRIPT
787
-	echo 'exit 0' >> $TEMP_SCRIPT
788
-	chmod +x $TEMP_SCRIPT
789
-	cp $TEMP_SCRIPT $rootdir/root/
790
-
791
-	chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
792
-	if [ ! "$?" = "0" ]; then
793
-		echo $"Unable to install toxid, returned $?"
794
-		rm $TEMP_SCRIPT
795
-		exit 62835
796
-	fi
797
-	rm $TEMP_SCRIPT
798
-}
799
-
800
-function mesh_tox_client {
801
-	TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
802
-
803
-	# obtain commits from the main file
804
-	TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
805
-	if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
806
-		TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
807
-	fi
808
-
809
-	TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
810
-	if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
811
-		TOXIC_REPO=$TOXIC_REPO_MAIN
812
-	fi
813
-
814
-	chroot "$rootdir" apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
815
-	chroot "$rootdir" apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
816
-
817
-	TEMP_SCRIPT_NAME=fbtmp728353.sh
818
-	TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
819
-	echo '#!/bin/bash' > $TEMP_SCRIPT
820
-	echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
821
-	echo "git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
822
-	echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
823
-	echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
824
-	echo 'make' >> $TEMP_SCRIPT
825
-	echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
826
-	echo '    exit 1' >> $TEMP_SCRIPT
827
-	echo 'fi' >> $TEMP_SCRIPT
828
-	echo 'make install' >> $TEMP_SCRIPT
829
-	echo 'exit 0' >> $TEMP_SCRIPT
830
-	chmod +x $TEMP_SCRIPT
831
-	cp $TEMP_SCRIPT $rootdir/root/
832
-
833
-	TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
834
-
835
-	SECONDS=0
836
-	chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
837
-	if [ ! "$?" = "0" ]; then
838
-		duration=$SECONDS
839
-		echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
840
-		echo $'Unable to make tox client'
841
-		rm $TEMP_SCRIPT
842
-		exit 74872
843
-	fi
844
-	rm $TEMP_SCRIPT
845
-	if [ ! -f $rootdir$TOXIC_FILE ]; then
846
-		echo $"Tox client was not installed to $TOXIC_FILE"
847
-		exit 63278
848
-	fi
849
-	duration=$SECONDS
850
-	echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
851
-}
852
-
853
-function mesh_zeronet {
854
-	# obtain commits from the main file
855
-	ZERONET_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
856
-	if [ ${#ZERONET_COMMIT_MAIN} -gt 10 ]; then
857
-		ZERONET_COMMIT=$ZERONET_COMMIT_MAIN
858
-	fi
859
-	if [ ! $ZERONET_COMMIT ]; then
860
-		echo $'No Tox commit was specified'
861
-		exit 37046
862
-	fi
863
-	
864
-	ZERONET_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}')
865
-	if [ ${#ZERONET_REPO_MAIN} -gt 5 ]; then
866
-		ZERONET_REPO=$ZERONET_REPO_MAIN
867
-	fi
868
-	if [ ! $ZERONET_REPO ]; then
869
-		echo $'No Tox commit was specified'
870
-		exit 37046
871
-	fi
872
-
873
-	ZERONET_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_PORT=" | head -n 1 | awk -F '=' '{print $2}')
874
-	if [ ${#ZERONET_PORT_MAIN} -gt 1 ]; then
875
-		ZERONET_PORT=$ZERONET_PORT_MAIN
876
-	fi
877
-	if [ ! $ZERONET_PORT ]; then
878
-		echo $'No zeronet port was specified'
879
-		exit 67433
880
-	fi
881
-
882
-	chroot "$rootdir" apt-get -y install python python-msgpack python-gevent
883
-	chroot "$rootdir" apt-get -y install python-pip bittornado
884
-	chroot "$rootdir" pip install msgpack-python --upgrade
885
-
886
-	chroot "$rootdir" useradd -d $MESH_INSTALL_DIR/zeronet/ -s /bin/false zeronet
887
-	git clone $ZERONET_REPO $rootdir$MESH_INSTALL_DIR/zeronet
888
-	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet ]; then
889
-		echo 'WARNING: Unable to clone zeronet'
890
-		return
891
-	fi
892
-	cd $rootdir$MESH_INSTALL_DIR/zeronet
893
-	git checkout $ZERONET_COMMIT -b $ZERONET_COMMIT
894
-	if ! grep -q "ZeroNet commit" $COMPLETION_FILE; then
895
-		echo "ZeroNet commit:$ZERONET_COMMIT" >> $rootdir$COMPLETION_FILE
896
-	else
897
-		sed -i "s/ZeroNet commit.*/ZeroNet commit:$ZERONET_COMMIT/g" $COMPLETION_FILE
898
-	fi
899
-	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
900
-
901
-	# Hack to ensure that the file access port is opened
902
-	# This is because zeronet normally relies on an internet site
903
-	# to do this, but on a purely local mesh the internet isn't available
904
-	sed -i 's|fileserver_port = 0|fileserver_port = config.fileserver_port\n            sys.modules["main"].file_server.port_opened = True|g' $rootdir$MESH_INSTALL_DIR/zeronet/src/Site/Site.py
905
-
906
-	ZERONET_DAEMON=$rootdir/etc/systemd/system/zeronet.service
907
-	echo '[Unit]' > $ZERONET_DAEMON
908
-	echo 'Description=Zeronet Server' >> $ZERONET_DAEMON
909
-	echo 'After=syslog.target' >> $ZERONET_DAEMON
910
-	echo 'After=network.target' >> $ZERONET_DAEMON
911
-	echo '[Service]' >> $ZERONET_DAEMON
912
-	echo 'Type=simple' >> $ZERONET_DAEMON
913
-	echo 'User=zeronet' >> $ZERONET_DAEMON
914
-	echo 'Group=zeronet' >> $ZERONET_DAEMON
915
-	echo "WorkingDirectory=$MESH_INSTALL_DIR/zeronet" >> $ZERONET_DAEMON
916
-	echo "ExecStart=/usr/bin/python zeronet.py --ip_external replace.local --trackers_file $MESH_INSTALL_DIR/zeronet/bootstrap" >> $ZERONET_DAEMON
917
-	echo '' >> $ZERONET_DAEMON
918
-	echo 'TimeoutSec=300' >> $ZERONET_DAEMON
919
-	echo '' >> $ZERONET_DAEMON
920
-	echo '[Install]' >> $ZERONET_DAEMON
921
-	echo 'WantedBy=multi-user.target' >> $ZERONET_DAEMON
922
-
923
-	TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
924
-	echo '[Unit]' > $TRACKER_DAEMON
925
-	echo 'Description=Torrent Tracker' >> $TRACKER_DAEMON
926
-	echo 'After=syslog.target' >> $TRACKER_DAEMON
927
-	echo 'After=network.target' >> $TRACKER_DAEMON
928
-	echo '[Service]' >> $TRACKER_DAEMON
929
-	echo 'Type=simple' >> $TRACKER_DAEMON
930
-	echo 'User=tracker' >> $TRACKER_DAEMON
931
-	echo 'Group=tracker' >> $TRACKER_DAEMON
932
-	echo "WorkingDirectory=$MESH_INSTALL_DIR/tracker" >> $TRACKER_DAEMON
933
-	echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile $MESH_INSTALL_DIR/tracker/dstate --logfile $MESH_INSTALL_DIR/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0" >> $TRACKER_DAEMON
934
-	echo '' >> $TRACKER_DAEMON
935
-	echo 'TimeoutSec=300' >> $TRACKER_DAEMON
936
-	echo '' >> $TRACKER_DAEMON
937
-	echo '[Install]' >> $TRACKER_DAEMON
938
-	echo 'WantedBy=multi-user.target' >> $TRACKER_DAEMON
939
-
940
-	chroot "$rootdir" useradd -d $MESH_INSTALL_DIR/tracker/ -s /bin/false tracker
941
-	if [ ! -d $rootdir$MESH_INSTALL_DIR/tracker ]; then
942
-		mkdir $rootdir$MESH_INSTALL_DIR/tracker
943
-	fi
944
-	chroot "$rootdir" chown -R tracker:tracker $MESH_INSTALL_DIR/tracker
945
-
946
-	# publish regularly
947
-	echo "* *     * * *   root    zeronetavahi > /dev/null" >> $rootdir/etc/crontab
948
-
949
-	chroot "$rootdir" systemctl enable tracker.service
950
-	chroot "$rootdir" systemctl enable zeronet.service
951
-}
952
-
953
-function mesh_zeronet_blog {
954
-	ZERONET_BLOG_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_BLOG_REPO=" | head -n 1 | awk -F '"' '{print $2}')
955
-	ZERONET_BLOG_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_BLOG_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
956
-
957
-	git clone $ZERONET_BLOG_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog
958
-	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog ]; then
959
-		echo $'ZeroBlog repo could not be cloned'
960
-		exit 6739
961
-	fi
962
-	cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog
963
-	git checkout $ZERONET_BLOG_COMMIT -b $ZERONET_BLOG_COMMIT
964
-	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
965
-}
966
-
967
-function mesh_zeronet_mail {
968
-	ZERONET_MAIL_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_MAIL_REPO=" | head -n 1 | awk -F '"' '{print $2}')
969
-	ZERONET_MAIL_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_MAIL_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
970
-
971
-	git clone $ZERONET_MAIL_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail
972
-	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail ]; then
973
-		echo $'ZeroMail repo could not be cloned'
974
-		exit 78493
975
-	fi
976
-	cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail
977
-	git checkout $ZERONET_MAIL_COMMIT -b $ZERONET_MAIL_COMMIT
978
-	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
979
-}
980
-
981
-function mesh_zeronet_forum {
982
-	ZERONET_FORUM_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_FORUM_REPO=" | head -n 1 | awk -F '"' '{print $2}')
983
-	ZERONET_FORUM_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_FORUM_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
984
-
985
-	git clone $ZERONET_FORUM_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk
986
-	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk ]; then
987
-		echo $'ZeroTalk repo could not be cloned'
988
-		exit 78252
989
-	fi
990
-	cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk
991
-	git checkout $ZERONET_FORUM_COMMIT -b $ZERONET_FORUM_COMMIT
992
-	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
993
-}
994
-
995
-function mesh_zeronet_id {
996
-	ZERONET_ID_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_ID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
997
-	ZERONET_ID_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_ID_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
998
-
999
-	git clone $ZERONET_ID_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID
1000
-	if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID ]; then
1001
-		echo $'ZeroID repo could not be cloned'
1002
-		exit 37936
1003
-	fi
1004
-	cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID
1005
-	git checkout $ZERONET_ID_COMMIT -b $ZERONET_ID_COMMIT
1006
-	chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
1007
-}
1008
-
1009
-function mesh_web_server {
1010
-	if [ -d /etc/apache2 ]; then
1011
-		chroot "$rootdir" apt-get -y remove --purge apache2
1012
-		chroot "$rootdir" rm -rf /etc/apache2
1013
-	fi
1014
-
1015
-	chroot "$rootdir" apt-get -y install nginx
1016
-
1017
-	if [ ! -d $rootdir/etc/nginx ]; then
1018
-		echo $'Unable to install web server'
1019
-		exit 346825
1020
-	fi
1021
-}
494
+INSTALLING_MESH=
1022 495
 
1023 496
 initialise_mesh() {
1024 497
 	if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
@@ -1045,17 +518,16 @@ initialise_mesh() {
1045 518
 		chroot "$rootdir" apt-get -y install firmware-iwlwifi
1046 519
 	fi
1047 520
 
521
+	INSTALLING_MESH=1
522
+
1048 523
 	mesh_firewall
1049 524
 	mesh_avahi
1050 525
 	install_batman
1051
-	mesh_tox_node
526
+	install_tox_node
1052 527
 	mesh_tox_avahi
1053 528
 	mesh_tox_client
1054 529
 	mesh_web_server
1055
-	mesh_zeronet
1056
-	mesh_zeronet_blog
1057
-	mesh_zeronet_mail
1058
-	mesh_zeronet_forum
530
+	install_zeronet
1059 531
 
1060 532
 	MESH_SERVICE='mesh-setup.service'
1061 533
 	MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
@@ -1080,55 +552,6 @@ initialise_mesh() {
1080 552
 
1081 553
 # User interface for USB drive installs ######################################
1082 554
 
1083
-function enable_tox_repo {
1084
-	echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
1085
-
1086
-
1087
-	chroot "$rootdir" wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key -O- | apt-key add -
1088
-	chroot "$rootdir" apt-get update
1089
-	echo "Tox Repository Installed."
1090
-}
1091
-
1092
-function install_syncthing {
1093
-	if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_DEVELOPER" ]]; then
1094
-		return
1095
-	fi
1096
-
1097
-	chroot "$rootdir" wget -q https://syncthing.net/release-key.txt -O- | apt-key add -
1098
-
1099
-	echo "deb http://apt.syncthing.net/ syncthing release" | tee $rootdir/etc/apt/sources.list.d/syncthing.list
1100
-	chroot "$rootdir" apt-get update
1101
-	chroot "$rootdir" apt-get -y --force-yes install syncthing
1102
-
1103
-	# This probably does need to run as root so that it can access the Sync directories
1104
-	# in each user's home directory
1105
-	chroot "$rootdir" echo '[Unit]' > /etc/systemd/system/syncthing.service
1106
-	chroot "$rootdir" echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
1107
-	chroot "$rootdir" echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
1108
-	chroot "$rootdir" echo 'After=network.target' >> /etc/systemd/system/syncthing.service
1109
-	chroot "$rootdir" echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
1110
-	chroot "$rootdir" echo '' >> /etc/systemd/system/syncthing.service
1111
-	chroot "$rootdir" echo '[Service]' >> /etc/systemd/system/syncthing.service
1112
-	chroot "$rootdir" echo 'User=root' >> /etc/systemd/system/syncthing.service
1113
-	chroot "$rootdir" echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
1114
-	chroot "$rootdir" echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
1115
-	chroot "$rootdir" echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
1116
-	chroot "$rootdir" echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
1117
-	chroot "$rootdir" echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
1118
-	chroot "$rootdir" echo '' >> /etc/systemd/system/syncthing.service
1119
-	chroot "$rootdir" echo '[Install]' >> /etc/systemd/system/syncthing.service
1120
-	chroot "$rootdir" echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
1121
-	chroot "$rootdir" systemctl enable syncthing
1122
-	chroot "$rootdir" systemctl daemon-reload
1123
-
1124
-	if ! grep -q "syncthing" $rootdir/etc/crontab; then
1125
-		chroot "$rootdir" echo "*/1            * *   *   *   root /usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null" >> /etc/crontab
1126
-		chroot "$rootdir" systemctl restart cron
1127
-	fi
1128
-
1129
-	echo 'install_syncthing'
1130
-}
1131
-
1132 555
 function mesh_client_startup_applications {
1133 556
 	if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
1134 557
 		mkdir -p $rootdir/home/$MY_USERNAME/Desktop

+ 40
- 0
src/freedombone-utils-avahi View File

@@ -54,6 +54,46 @@ function create_avahi_service {
54 54
 	echo '</service-group>' >> /etc/avahi/services/${service_name}.service
55 55
 }
56 56
 
57
+function mesh_avahi {
58
+	chroot "$rootdir" apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
59
+
60
+	decarray=( 1 2 3 4 5 6 7 8 9 0 )
61
+	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]}
62
+	sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf
63
+
64
+	if [ ! -d $rootdir/etc/avahi/services ]; then
65
+		mkdir -p $rootdir/etc/avahi/services
66
+	fi
67
+
68
+	# remove an avahi service which isn't used
69
+	if [ -f $rootdir/etc/avahi/services/udisks.service ]; then
70
+		rm $rootdir/etc/avahi/services/udisks.service
71
+	fi
72
+
73
+	# Add an ssh service
74
+	echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/ssh.service
75
+	echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/ssh.service
76
+	echo '<service-group>' >> $rootdir/etc/avahi/services/ssh.service
77
+	echo '  <name replace-wildcards="yes">%h SSH</name>' >> $rootdir/etc/avahi/services/ssh.service
78
+	echo '  <service>' >> $rootdir/etc/avahi/services/ssh.service
79
+	echo '    <type>_ssh._tcp</type>' >> $rootdir/etc/avahi/services/ssh.service
80
+	echo "    <port>$SSH_PORT</port>" >> $rootdir/etc/avahi/services/ssh.service
81
+	echo '  </service>' >> $rootdir/etc/avahi/services/ssh.service
82
+	echo '</service-group>' >> $rootdir/etc/avahi/services/ssh.service
83
+
84
+	# keep the daemon running
85
+	WATCHDOG_SCRIPT_NAME="keepon"
86
+	echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
87
+	echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
88
+	echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
89
+	echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
90
+	echo '  systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
91
+	echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
92
+	echo '  echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
93
+	echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
94
+	chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
95
+}
96
+
57 97
 function configure_avahi {
58 98
 	if grep -Fxq "configure_avahi" $COMPLETION_FILE; then
59 99
 		return

+ 241
- 186
src/freedombone-utils-firewall View File

@@ -29,220 +29,275 @@
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31 31
 function save_firewall_settings {
32
-	iptables-save > /etc/firewall.conf
33
-	ip6tables-save > /etc/firewall6.conf
34
-	printf '#!/bin/sh\n' > /etc/network/if-up.d/iptables
35
-	printf 'iptables-restore < /etc/firewall.conf\n' >> /etc/network/if-up.d/iptables
36
-	printf 'ip6tables-restore < /etc/firewall6.conf\n' >> /etc/network/if-up.d/iptables
37
-	chmod +x /etc/network/if-up.d/iptables
32
+    iptables-save > /etc/firewall.conf
33
+    ip6tables-save > /etc/firewall6.conf
34
+    printf '#!/bin/sh\n' > /etc/network/if-up.d/iptables
35
+    printf 'iptables-restore < /etc/firewall.conf\n' >> /etc/network/if-up.d/iptables
36
+    printf 'ip6tables-restore < /etc/firewall6.conf\n' >> /etc/network/if-up.d/iptables
37
+    chmod +x /etc/network/if-up.d/iptables
38 38
 }
39 39
 
40 40
 function enable_ipv6 {
41
-	# endure that ipv6 is enabled and can route
42
-	sed -i 's/net.ipv6.conf.all.disable_ipv6.*/net.ipv6.conf.all.disable_ipv6 = 0/g' /etc/sysctl.conf
43
-	#sed -i "s/net.ipv6.conf.all.accept_redirects.*/net.ipv6.conf.all.accept_redirects = 1/g" /etc/sysctl.conf
44
-	#sed -i "s/net.ipv6.conf.all.accept_source_route.*/net.ipv6.conf.all.accept_source_route = 1/g" /etc/sysctl.conf
45
-	sed -i "s/net.ipv6.conf.all.forwarding.*/net.ipv6.conf.all.forwarding=1/g" /etc/sysctl.conf
46
-	echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
41
+    # endure that ipv6 is enabled and can route
42
+    sed -i 's/net.ipv6.conf.all.disable_ipv6.*/net.ipv6.conf.all.disable_ipv6 = 0/g' /etc/sysctl.conf
43
+    #sed -i "s/net.ipv6.conf.all.accept_redirects.*/net.ipv6.conf.all.accept_redirects = 1/g" /etc/sysctl.conf
44
+    #sed -i "s/net.ipv6.conf.all.accept_source_route.*/net.ipv6.conf.all.accept_source_route = 1/g" /etc/sysctl.conf
45
+    sed -i "s/net.ipv6.conf.all.forwarding.*/net.ipv6.conf.all.forwarding=1/g" /etc/sysctl.conf
46
+    echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
47 47
 }
48 48
 
49 49
 function configure_firewall {
50
-	if grep -q "RELATED" /etc/firewall.conf; then
51
-		# recreate the firewall to remove RELATED
52
-		sed -i "/firewall/d" $COMPLETION_FILE
53
-	fi
54
-	if grep -Fxq "configure_firewall" $COMPLETION_FILE; then
55
-		return
56
-	fi
57
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
58
-		# docker does its own firewalling
59
-		return
60
-	fi
61
-	iptables -P INPUT ACCEPT
62
-	ip6tables -P INPUT ACCEPT
63
-	iptables -F
64
-	ip6tables -F
65
-	iptables -t nat -F
66
-	ip6tables -t nat -F
67
-	iptables -X
68
-	ip6tables -X
69
-	iptables -P INPUT DROP
70
-	ip6tables -P INPUT DROP
71
-	iptables -A INPUT -i lo -j ACCEPT
72
-	iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
73
-
74
-	# Make sure incoming tcp connections are SYN packets
75
-	iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
76
-
77
-	# Drop packets with incoming fragments
78
-	iptables -A INPUT -f -j DROP
79
-
80
-	# Drop bogons
81
-	iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
82
-	iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
83
-	iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
84
-
85
-	# Incoming malformed NULL packets:
86
-	iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
87
-
88
-	echo 'configure_firewall' >> $COMPLETION_FILE
50
+    if grep -q "RELATED" /etc/firewall.conf; then
51
+        # recreate the firewall to remove RELATED
52
+        sed -i "/firewall/d" $COMPLETION_FILE
53
+    fi
54
+    if grep -Fxq "configure_firewall" $COMPLETION_FILE; then
55
+        return
56
+    fi
57
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
58
+        # docker does its own firewalling
59
+        return
60
+    fi
61
+    iptables -P INPUT ACCEPT
62
+    ip6tables -P INPUT ACCEPT
63
+    iptables -F
64
+    ip6tables -F
65
+    iptables -t nat -F
66
+    ip6tables -t nat -F
67
+    iptables -X
68
+    ip6tables -X
69
+    iptables -P INPUT DROP
70
+    ip6tables -P INPUT DROP
71
+    iptables -A INPUT -i lo -j ACCEPT
72
+    iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
73
+
74
+    # Make sure incoming tcp connections are SYN packets
75
+    iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
76
+
77
+    # Drop packets with incoming fragments
78
+    iptables -A INPUT -f -j DROP
79
+
80
+    # Drop bogons
81
+    iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
82
+    iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
83
+    iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
84
+
85
+    # Incoming malformed NULL packets:
86
+    iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
87
+
88
+    echo 'configure_firewall' >> $COMPLETION_FILE
89 89
 }
90 90
 
91 91
 function configure_firewall_ping {
92
-	if grep -Fxq "configure_firewall_ping" $COMPLETION_FILE; then
93
-		return
94
-	fi
95
-	# Only allow ping for mesh installs
96
-	if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
97
-		return
98
-	fi
99
-	iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
100
-	iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
101
-	function_check save_firewall_settings
102
-	save_firewall_settings
103
-	echo 'configure_firewall_ping' >> $COMPLETION_FILE
92
+    if grep -Fxq "configure_firewall_ping" $COMPLETION_FILE; then
93
+        return
94
+    fi
95
+    # Only allow ping for mesh installs
96
+    if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
97
+        return
98
+    fi
99
+    iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
100
+    iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
101
+    function_check save_firewall_settings
102
+    save_firewall_settings
103
+    echo 'configure_firewall_ping' >> $COMPLETION_FILE
104 104
 }
105 105
 
106 106
 function configure_firewall_for_avahi {
107
-	if grep -Fxq "configure_firewall_for_avahi" $COMPLETION_FILE; then
108
-		return
109
-	fi
110
-	iptables -A INPUT -p tcp --dport 548 -j ACCEPT
111
-	iptables -A INPUT -p udp --dport 548 -j ACCEPT
112
-	iptables -A INPUT -p tcp --dport 5353 -j ACCEPT
113
-	iptables -A INPUT -p udp --dport 5353 -j ACCEPT
114
-	iptables -A INPUT -p tcp --dport 5354 -j ACCEPT
115
-	iptables -A INPUT -p udp --dport 5354 -j ACCEPT
116
-	function_check save_firewall_settings
117
-	save_firewall_settings
118
-	echo 'configure_firewall_for_avahi' >> $COMPLETION_FILE
107
+    if grep -Fxq "configure_firewall_for_avahi" $COMPLETION_FILE; then
108
+        return
109
+    fi
110
+    iptables -A INPUT -p tcp --dport 548 -j ACCEPT
111
+    iptables -A INPUT -p udp --dport 548 -j ACCEPT
112
+    iptables -A INPUT -p tcp --dport 5353 -j ACCEPT
113
+    iptables -A INPUT -p udp --dport 5353 -j ACCEPT
114
+    iptables -A INPUT -p tcp --dport 5354 -j ACCEPT
115
+    iptables -A INPUT -p udp --dport 5354 -j ACCEPT
116
+    function_check save_firewall_settings
117
+    save_firewall_settings
118
+    echo 'configure_firewall_for_avahi' >> $COMPLETION_FILE
119 119
 }
120 120
 
121 121
 function configure_firewall_for_dns {
122
-	if grep -Fxq "configure_firewall_for_dns" $COMPLETION_FILE; then
123
-		return
124
-	fi
125
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
126
-		# docker does its own firewalling
127
-		return
128
-	fi
129
-	iptables -A INPUT -p udp -m udp --dport 1024:65535 --sport 53 -j ACCEPT
130
-	function_check save_firewall_settings
131
-	save_firewall_settings
132
-	echo 'configure_firewall_for_dns' >> $COMPLETION_FILE
122
+    if grep -Fxq "configure_firewall_for_dns" $COMPLETION_FILE; then
123
+        return
124
+    fi
125
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
126
+        # docker does its own firewalling
127
+        return
128
+    fi
129
+    iptables -A INPUT -p udp -m udp --dport 1024:65535 --sport 53 -j ACCEPT
130
+    function_check save_firewall_settings
131
+    save_firewall_settings
132
+    echo 'configure_firewall_for_dns' >> $COMPLETION_FILE
133 133
 }
134 134
 
135 135
 function configure_firewall_for_web_access {
136
-	if grep -Fxq "configure_firewall_for_web_access" $COMPLETION_FILE; then
137
-		return
138
-	fi
139
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
140
-		# docker does its own firewalling
141
-		return
142
-	fi
143
-	if [[ $ONION_ONLY != "no" ]]; then
144
-		return
145
-	fi
146
-	iptables -A INPUT -p tcp --dport 32768:61000 --sport 80 -j ACCEPT
147
-	iptables -A INPUT -p tcp --dport 32768:61000 --sport 443 -j ACCEPT
148
-	function_check save_firewall_settings
149
-	save_firewall_settings
150
-
151
-	echo 'configure_firewall_for_web_access' >> $COMPLETION_FILE
136
+    if grep -Fxq "configure_firewall_for_web_access" $COMPLETION_FILE; then
137
+        return
138
+    fi
139
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
140
+        # docker does its own firewalling
141
+        return
142
+    fi
143
+    if [[ $ONION_ONLY != "no" ]]; then
144
+        return
145
+    fi
146
+    iptables -A INPUT -p tcp --dport 32768:61000 --sport 80 -j ACCEPT
147
+    iptables -A INPUT -p tcp --dport 32768:61000 --sport 443 -j ACCEPT
148
+    function_check save_firewall_settings
149
+    save_firewall_settings
150
+
151
+    echo 'configure_firewall_for_web_access' >> $COMPLETION_FILE
152 152
 }
153 153
 
154 154
 function configure_firewall_for_web_server {
155
-	if grep -Fxq "configure_firewall_for_web_server" $COMPLETION_FILE; then
156
-		return
157
-	fi
158
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
159
-		# docker does its own firewalling
160
-		return
161
-	fi
162
-	if [[ $ONION_ONLY != "no" ]]; then
163
-		return
164
-	fi
165
-	iptables -A INPUT -p tcp --dport 80 -j ACCEPT
166
-	iptables -A INPUT -p tcp --dport 443 -j ACCEPT
167
-	function_check save_firewall_settings
168
-	save_firewall_settings
169
-
170
-	OPEN_PORTS+=('HTTP     80')
171
-	OPEN_PORTS+=('HTTPS    443')
172
-	echo 'configure_firewall_for_web_server' >> $COMPLETION_FILE
155
+    if grep -Fxq "configure_firewall_for_web_server" $COMPLETION_FILE; then
156
+        return
157
+    fi
158
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
159
+        # docker does its own firewalling
160
+        return
161
+    fi
162
+    if [[ $ONION_ONLY != "no" ]]; then
163
+        return
164
+    fi
165
+    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
166
+    iptables -A INPUT -p tcp --dport 443 -j ACCEPT
167
+    function_check save_firewall_settings
168
+    save_firewall_settings
169
+
170
+    OPEN_PORTS+=('HTTP     80')
171
+    OPEN_PORTS+=('HTTPS    443')
172
+    echo 'configure_firewall_for_web_server' >> $COMPLETION_FILE
173 173
 }
174 174
 
175 175
 function configure_firewall_for_ssh {
176
-	if grep -Fxq "configure_firewall_for_ssh" $COMPLETION_FILE; then
177
-		return
178
-	fi
179
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
180
-		# docker does its own firewalling
181
-		return
182
-	fi
183
-	iptables -A INPUT -p tcp --dport 22 -j ACCEPT
184
-	iptables -A INPUT -p tcp --dport $SSH_PORT -j ACCEPT
185
-	function_check save_firewall_settings
186
-	save_firewall_settings
187
-
188
-	OPEN_PORTS+=("SSH      $SSH_PORT")
189
-	echo 'configure_firewall_for_ssh' >> $COMPLETION_FILE
176
+    if grep -Fxq "configure_firewall_for_ssh" $COMPLETION_FILE; then
177
+        return
178
+    fi
179
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
180
+        # docker does its own firewalling
181
+        return
182
+    fi
183
+    iptables -A INPUT -p tcp --dport 22 -j ACCEPT
184
+    iptables -A INPUT -p tcp --dport $SSH_PORT -j ACCEPT
185
+    function_check save_firewall_settings
186
+    save_firewall_settings
187
+
188
+    OPEN_PORTS+=("SSH      $SSH_PORT")
189
+    echo 'configure_firewall_for_ssh' >> $COMPLETION_FILE
190 190
 }
191 191
 
192 192
 function configure_firewall_for_git {
193
-	if grep -Fxq "configure_firewall_for_git" $COMPLETION_FILE; then
194
-		return
195
-	fi
196
-	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
197
-		# docker does its own firewalling
198
-		return
199
-	fi
200
-	if [[ $ONION_ONLY != "no" ]]; then
201
-		return
202
-	fi
203
-	iptables -A INPUT -p tcp --dport 9418 -j ACCEPT
204
-	function_check save_firewall_settings
205
-	save_firewall_settings
206
-
207
-	OPEN_PORTS+=("Git      9418")
208
-	echo 'configure_firewall_for_git' >> $COMPLETION_FILE
193
+    if grep -Fxq "configure_firewall_for_git" $COMPLETION_FILE; then
194
+        return
195
+    fi
196
+    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
197
+        # docker does its own firewalling
198
+        return
199
+    fi
200
+    if [[ $ONION_ONLY != "no" ]]; then
201
+        return
202
+    fi
203
+    iptables -A INPUT -p tcp --dport 9418 -j ACCEPT
204
+    function_check save_firewall_settings
205
+    save_firewall_settings
206
+
207
+    OPEN_PORTS+=("Git      9418")
208
+    echo 'configure_firewall_for_git' >> $COMPLETION_FILE
209 209
 }
210 210
 
211 211
 function configure_internet_protocol {
212
-	if grep -Fxq "configure_internet_protocol" $COMPLETION_FILE; then
213
-		return
214
-	fi
215
-	if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
216
-		return
217
-	fi
218
-	sed -i "s/#net.ipv4.tcp_syncookies=1/net.ipv4.tcp_syncookies=1/g" /etc/sysctl.conf
219
-	sed -i "s/#net.ipv4.conf.all.accept_redirects = 0/net.ipv4.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
220
-	sed -i "s/#net.ipv6.conf.all.accept_redirects = 0/net.ipv6.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
221
-	sed -i "s/#net.ipv4.conf.all.send_redirects = 0/net.ipv4.conf.all.send_redirects = 0/g" /etc/sysctl.conf
222
-	sed -i "s/#net.ipv4.conf.all.accept_source_route = 0/net.ipv4.conf.all.accept_source_route = 0/g" /etc/sysctl.conf
223
-	sed -i "s/#net.ipv6.conf.all.accept_source_route = 0/net.ipv6.conf.all.accept_source_route = 0/g" /etc/sysctl.conf
224
-	sed -i "s/#net.ipv4.conf.default.rp_filter=1/net.ipv4.conf.default.rp_filter=1/g" /etc/sysctl.conf
225
-	sed -i "s/#net.ipv4.conf.all.rp_filter=1/net.ipv4.conf.all.rp_filter=1/g" /etc/sysctl.conf
226
-	sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=0/g" /etc/sysctl.conf
227
-	sed -i "s/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=0/g" /etc/sysctl.conf
228
-	if ! grep -q "ignore pings" /etc/sysctl.conf; then
229
-		echo '# ignore pings' >> /etc/sysctl.conf
230
-		echo 'net.ipv4.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf
231
-		echo 'net.ipv6.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf
232
-	fi
233
-	if ! grep -q "disable ipv6" /etc/sysctl.conf; then
234
-		echo '# disable ipv6' >> /etc/sysctl.conf
235
-		echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
236
-	fi
237
-	if ! grep -q "net.ipv4.tcp_synack_retries" /etc/sysctl.conf; then
238
-		echo 'net.ipv4.tcp_synack_retries = 2' >> /etc/sysctl.conf
239
-		echo 'net.ipv4.tcp_syn_retries = 1' >> /etc/sysctl.conf
240
-	fi
241
-	if ! grep -q "keepalive" /etc/sysctl.conf; then
242
-		echo '# keepalive' >> /etc/sysctl.conf
243
-		echo 'net.ipv4.tcp_keepalive_probes = 9' >> /etc/sysctl.conf
244
-		echo 'net.ipv4.tcp_keepalive_intvl = 75' >> /etc/sysctl.conf
245
-		echo 'net.ipv4.tcp_keepalive_time = 7200' >> /etc/sysctl.conf
246
-	fi
247
-	echo 'configure_internet_protocol' >> $COMPLETION_FILE
212
+    if grep -Fxq "configure_internet_protocol" $COMPLETION_FILE; then
213
+        return
214
+    fi
215
+    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
216
+        return
217
+    fi
218
+    sed -i "s/#net.ipv4.tcp_syncookies=1/net.ipv4.tcp_syncookies=1/g" /etc/sysctl.conf
219
+    sed -i "s/#net.ipv4.conf.all.accept_redirects = 0/net.ipv4.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
220
+    sed -i "s/#net.ipv6.conf.all.accept_redirects = 0/net.ipv6.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
221
+    sed -i "s/#net.ipv4.conf.all.send_redirects = 0/net.ipv4.conf.all.send_redirects = 0/g" /etc/sysctl.conf
222
+    sed -i "s/#net.ipv4.conf.all.accept_source_route = 0/net.ipv4.conf.all.accept_source_route = 0/g" /etc/sysctl.conf
223
+    sed -i "s/#net.ipv6.conf.all.accept_source_route = 0/net.ipv6.conf.all.accept_source_route = 0/g" /etc/sysctl.conf
224
+    sed -i "s/#net.ipv4.conf.default.rp_filter=1/net.ipv4.conf.default.rp_filter=1/g" /etc/sysctl.conf
225
+    sed -i "s/#net.ipv4.conf.all.rp_filter=1/net.ipv4.conf.all.rp_filter=1/g" /etc/sysctl.conf
226
+    sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=0/g" /etc/sysctl.conf
227
+    sed -i "s/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=0/g" /etc/sysctl.conf
228
+    if ! grep -q "ignore pings" /etc/sysctl.conf; then
229
+        echo '# ignore pings' >> /etc/sysctl.conf
230
+        echo 'net.ipv4.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf
231
+        echo 'net.ipv6.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf
232
+    fi
233
+    if ! grep -q "disable ipv6" /etc/sysctl.conf; then
234
+        echo '# disable ipv6' >> /etc/sysctl.conf
235
+        echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
236
+    fi
237
+    if ! grep -q "net.ipv4.tcp_synack_retries" /etc/sysctl.conf; then
238
+        echo 'net.ipv4.tcp_synack_retries = 2' >> /etc/sysctl.conf
239
+        echo 'net.ipv4.tcp_syn_retries = 1' >> /etc/sysctl.conf
240
+    fi
241
+    if ! grep -q "keepalive" /etc/sysctl.conf; then
242
+        echo '# keepalive' >> /etc/sysctl.conf
243
+        echo 'net.ipv4.tcp_keepalive_probes = 9' >> /etc/sysctl.conf
244
+        echo 'net.ipv4.tcp_keepalive_intvl = 75' >> /etc/sysctl.conf
245
+        echo 'net.ipv4.tcp_keepalive_time = 7200' >> /etc/sysctl.conf
246
+    fi
247
+    echo 'configure_internet_protocol' >> $COMPLETION_FILE
248
+}
249
+
250
+function mesh_firewall {
251
+    FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
252
+    MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall
253
+
254
+    echo '#!/bin/bash' > $MESH_FIREWALL_SCRIPT
255
+    echo 'iptables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
256
+    echo 'ip6tables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
257
+    echo 'iptables -F' >> $MESH_FIREWALL_SCRIPT
258
+    echo 'ip6tables -F' >> $MESH_FIREWALL_SCRIPT
259
+    echo 'iptables -t nat -F' >> $MESH_FIREWALL_SCRIPT
260
+    echo 'ip6tables -t nat -F' >> $MESH_FIREWALL_SCRIPT
261
+    echo 'iptables -X' >> $MESH_FIREWALL_SCRIPT
262
+    echo 'ip6tables -X' >> $MESH_FIREWALL_SCRIPT
263
+    echo 'iptables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
264
+    echo 'ip6tables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
265
+    echo 'iptables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
266
+    echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
267
+    echo '' >> $MESH_FIREWALL_SCRIPT
268
+    echo '# Make sure incoming tcp connections are SYN packets' >> $MESH_FIREWALL_SCRIPT
269
+    echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT
270
+    echo '' >> $MESH_FIREWALL_SCRIPT
271
+    echo '# Drop packets with incoming fragments' >> $MESH_FIREWALL_SCRIPT
272
+    echo 'iptables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT
273
+    echo '' >> $MESH_FIREWALL_SCRIPT
274
+    echo '# Drop bogons' >> $MESH_FIREWALL_SCRIPT
275
+    echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT
276
+    echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
277
+    echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
278
+    echo '' >> $MESH_FIREWALL_SCRIPT
279
+    echo '# Incoming malformed NULL packets:' >> $MESH_FIREWALL_SCRIPT
280
+    echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT
281
+    echo '' >> $MESH_FIREWALL_SCRIPT
282
+    echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
283
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
284
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
285
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
286
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
287
+    echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
288
+    chmod +x $MESH_FIREWALL_SCRIPT
289
+
290
+    echo '[Unit]' > $FIREWALL_FILENAME
291
+    echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME
292
+    echo '' >> $FIREWALL_FILENAME
293
+    echo '[Service]' >> $FIREWALL_FILENAME
294
+    echo 'Type=oneshot' >> $FIREWALL_FILENAME
295
+    echo 'ExecStart=/usr/bin/mesh-firewall' >> $FIREWALL_FILENAME
296
+    echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME
297
+    echo '' >> $FIREWALL_FILENAME
298
+    echo 'TimeoutSec=30' >> $FIREWALL_FILENAME
299
+    echo '' >> $FIREWALL_FILENAME
300
+    echo '[Install]' >> $FIREWALL_FILENAME
301
+    echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
302
+    chroot "$rootdir" systemctl enable meshfirewall
248 303
 }

+ 14
- 0
src/freedombone-utils-web View File

@@ -548,4 +548,18 @@ function install_command_line_browser {
548 548
 	echo 'install_command_line_browser' >> $COMPLETION_FILE
549 549
 }
550 550
 
551
+function mesh_web_server {
552
+	if [ -d /etc/apache2 ]; then
553
+		chroot "$rootdir" apt-get -y remove --purge apache2
554
+		chroot "$rootdir" rm -rf /etc/apache2
555
+	fi
556
+
557
+	chroot "$rootdir" apt-get -y install nginx
558
+
559
+	if [ ! -d $rootdir/etc/nginx ]; then
560
+		echo $'Unable to install web server'
561
+		exit 346825
562
+	fi
563
+}
564
+
551 565
 # NOTE: deliberately no exit 0

+ 3
- 0
src/freedombone-vars View File

@@ -97,4 +97,7 @@ done
97 97
 # optionally specify your name to appear on the blog
98 98
 MY_NAME=$DEFAULT_DOMAIN_NAME
99 99
 
100
+# used to select mesh install functions when creating a mesh image
101
+INSTALLING_MESH=
102
+
100 103
 # NOTE: deliberately there is no "exit 0"