瀏覽代碼

Support for amnesia

Bob Mottram 8 年之前
父節點
當前提交
3f01621a23
共有 2 個文件被更改,包括 47 次插入20 次删除
  1. 2
    2
      src/freedombone-config
  2. 45
    18
      src/freedombone-image-mesh

+ 2
- 2
src/freedombone-config 查看文件

2016
 	echo ''
2016
 	echo ''
2017
 }
2017
 }
2018
 
2018
 
2019
-function read_configuration {
2019
+function read_config {
2020
 	if [ ! $CONFIGURATION_FILE ]; then
2020
 	if [ ! $CONFIGURATION_FILE ]; then
2021
 		CONFIGURATION_FILE='freedombone.cfg'
2021
 		CONFIGURATION_FILE='freedombone.cfg'
2022
 	fi
2022
 	fi
2191
 	fi
2191
 	fi
2192
 }
2192
 }
2193
 
2193
 
2194
-read_configuration
2194
+read_config
2195
 interactive_config
2195
 interactive_config
2196
 show_result
2196
 show_result
2197
 exit 0
2197
 exit 0

+ 45
- 18
src/freedombone-image-mesh 查看文件

75
 	echo "New avahi name for this peer is P$PEER_ID"
75
 	echo "New avahi name for this peer is P$PEER_ID"
76
 	toilet "mesh-$PEER_ID"
76
 	toilet "mesh-$PEER_ID"
77
 	echo $"avahi name changed to P${PEER_ID}.local" >> $INSTALL_LOG
77
 	echo $"avahi name changed to P${PEER_ID}.local" >> $INSTALL_LOG
78
-	if [ -f $MESH_INSTALL_COMPLETED ]; then
79
-		systemctl restart avahi-daemon
80
-	fi
81
 }
78
 }
82
 
79
 
83
 function regenerate_ssh_host_keys {
80
 function regenerate_ssh_host_keys {
89
 	awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
86
 	awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
90
 	mv ~/moduli /etc/ssh/moduli
87
 	mv ~/moduli /etc/ssh/moduli
91
 	echo $'ssh small moduli removed' >> $INSTALL_LOG
88
 	echo $'ssh small moduli removed' >> $INSTALL_LOG
92
-
93
-	if [ -f $MESH_INSTALL_COMPLETED ]; then
94
-		systemctl restart ssh
95
-	fi
96
 }
89
 }
97
 
90
 
98
 function configure_zeronet {
91
 function configure_zeronet {
528
 
521
 
529
 function mesh_amnesic {
522
 function mesh_amnesic {
530
 	if [ ! -f $MESH_AMNESIC ]; then
523
 	if [ ! -f $MESH_AMNESIC ]; then
531
-		if [ -f /etc/systemd/system/amnesic.service ]; then
532
-			systemctl disable amnesic
533
-		fi
534
 		return
524
 		return
535
 	fi
525
 	fi
536
 
526
 
527
+	echo '#!/bin/bash' > /usr/bin/amnesic
528
+	echo '' >> /usr/bin/amnesic
529
+	echo 'MY_USERNAME=$1' >> /usr/bin/amnesic
530
+	echo -n "${PROJECT_NAME}-image-mesh " >> /usr/bin/amnesic
531
+	echo '$MY_USERNAME amnesic' >> /usr/bin/amnesic
532
+	echo '' >> /usr/bin/amnesic
533
+	echo 'exit 0' >> /usr/bin/amnesic
534
+	chmod +x /usr/bin/amnesic
535
+
537
 	if [ ! -f /etc/systemd/system/amnesic.service ]; then
536
 	if [ ! -f /etc/systemd/system/amnesic.service ]; then
538
 		echo '[Unit]' > /etc/systemd/system/amnesic.service
537
 		echo '[Unit]' > /etc/systemd/system/amnesic.service
539
 		echo 'Description=Amnesic Mesh' >> /etc/systemd/system/amnesic.service
538
 		echo 'Description=Amnesic Mesh' >> /etc/systemd/system/amnesic.service
540
 		echo '' >> /etc/systemd/system/amnesic.service
539
 		echo '' >> /etc/systemd/system/amnesic.service
541
 		echo '[Service]' >> /etc/systemd/system/amnesic.service
540
 		echo '[Service]' >> /etc/systemd/system/amnesic.service
541
+		echo 'User=root' >> /etc/systemd/system/amnesic.service
542
+		echo 'Group=root' >> /etc/systemd/system/amnesic.service
542
 		echo 'Type=oneshot' >> /etc/systemd/system/amnesic.service
543
 		echo 'Type=oneshot' >> /etc/systemd/system/amnesic.service
543
 		echo 'RemainAfterExit=true' >> /etc/systemd/system/amnesic.service
544
 		echo 'RemainAfterExit=true' >> /etc/systemd/system/amnesic.service
544
 		echo 'ExecStart=/bin/true' >> /etc/systemd/system/amnesic.service
545
 		echo 'ExecStart=/bin/true' >> /etc/systemd/system/amnesic.service
545
-		echo 'ExecStop=TODO' >> /etc/systemd/system/amnesic.service
546
+		echo 'ExecStop=/usr/bin/amnesic' >> /etc/systemd/system/amnesic.service
546
 		echo '' >> /etc/systemd/system/amnesic.service
547
 		echo '' >> /etc/systemd/system/amnesic.service
547
 		echo '[Install]' >> /etc/systemd/system/amnesic.service
548
 		echo '[Install]' >> /etc/systemd/system/amnesic.service
548
 		echo 'WantedBy=multi-user.target' >> /etc/systemd/system/amnesic.service
549
 		echo 'WantedBy=multi-user.target' >> /etc/systemd/system/amnesic.service
553
 	systemctl start amnesic
554
 	systemctl start amnesic
554
 }
555
 }
555
 
556
 
557
+function mesh_restart_daemons {
558
+	systemctl restart avahi-daemon
559
+	systemctl restart ssh
560
+	systemctl restart tox-bootstrapd
561
+	systemctl restart zeronet
562
+	echo $'Daemons restarted' >> $INSTALL_LOG
563
+}
564
+
556
 # whether to reset the identity
565
 # whether to reset the identity
566
+set_new_identity=
557
 if [ $2 ]; then
567
 if [ $2 ]; then
558
 	if [[ "$2" == $"new"* ]]; then
568
 	if [[ "$2" == $"new"* ]]; then
559
 		if [ ! -f $MESH_INSTALL_SETUP ]; then
569
 		if [ ! -f $MESH_INSTALL_SETUP ]; then
560
 			touch $MESH_INSTALL_SETUP
570
 			touch $MESH_INSTALL_SETUP
561
 		fi
571
 		fi
572
+		set_new_identity=1
573
+	fi
574
+	if [[ "$2" == $"amnesic"* ]]; then
575
+		if [ ! -f $MESH_AMNESIC ]; then
576
+			touch $MESH_AMNESIC
577
+		fi
578
+		if [ ! -f $MESH_INSTALL_SETUP ]; then
579
+			touch $MESH_INSTALL_SETUP
580
+		fi
581
+		set_new_identity=1
562
 	fi
582
 	fi
563
 fi
583
 fi
564
 
584
 
567
 		MY_USERNAME=$1
587
 		MY_USERNAME=$1
568
 	fi
588
 	fi
569
 
589
 
570
-	# sleep in order to allow other daemons to start up
571
-	sleep 15
590
+	if [ ! $set_new_identity ]; then
591
+		# sleep in order to allow other daemons to start up
592
+		sleep 15
593
+	fi
572
 
594
 
573
 	# clear the install log
595
 	# clear the install log
574
 	if [ -f $INSTALL_LOG ]; then
596
 	if [ -f $INSTALL_LOG ]; then
589
 	disable_screen_lock
611
 	disable_screen_lock
590
 	mesh_amnesic
612
 	mesh_amnesic
591
 
613
 
592
-	rm $MESH_INSTALL_SETUP
593
-	systemctl disable mesh-setup.service
594
-	touch $MESH_INSTALL_COMPLETED
595
-	echo $'Mesh node setup complete. Rebooting...' >> $INSTALL_LOG
596
-	reboot
614
+	if [ ! -f $MESH_AMNESIC ]; then
615
+		rm $MESH_INSTALL_SETUP
616
+		systemctl disable mesh-setup.service
617
+	fi
618
+
619
+	mesh_restart_daemons
620
+	if [ ! -f $MESH_INSTALL_COMPLETED ]; then
621
+		echo $'Mesh node setup complete' >> $INSTALL_LOG
622
+		touch $MESH_INSTALL_COMPLETED
623
+	fi
597
 fi
624
 fi
598
 
625
 
599
 exit 0
626
 exit 0