소스 검색

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

+ 45
- 18
src/freedombone-image-mesh 파일 보기

@@ -75,9 +75,6 @@ function change_avahi_name {
75 75
 	echo "New avahi name for this peer is P$PEER_ID"
76 76
 	toilet "mesh-$PEER_ID"
77 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 80
 function regenerate_ssh_host_keys {
@@ -89,10 +86,6 @@ function regenerate_ssh_host_keys {
89 86
 	awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
90 87
 	mv ~/moduli /etc/ssh/moduli
91 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 91
 function configure_zeronet {
@@ -528,21 +521,29 @@ function enable_batman_daemon {
528 521
 
529 522
 function mesh_amnesic {
530 523
 	if [ ! -f $MESH_AMNESIC ]; then
531
-		if [ -f /etc/systemd/system/amnesic.service ]; then
532
-			systemctl disable amnesic
533
-		fi
534 524
 		return
535 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 536
 	if [ ! -f /etc/systemd/system/amnesic.service ]; then
538 537
 		echo '[Unit]' > /etc/systemd/system/amnesic.service
539 538
 		echo 'Description=Amnesic Mesh' >> /etc/systemd/system/amnesic.service
540 539
 		echo '' >> /etc/systemd/system/amnesic.service
541 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 543
 		echo 'Type=oneshot' >> /etc/systemd/system/amnesic.service
543 544
 		echo 'RemainAfterExit=true' >> /etc/systemd/system/amnesic.service
544 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 547
 		echo '' >> /etc/systemd/system/amnesic.service
547 548
 		echo '[Install]' >> /etc/systemd/system/amnesic.service
548 549
 		echo 'WantedBy=multi-user.target' >> /etc/systemd/system/amnesic.service
@@ -553,12 +554,31 @@ function mesh_amnesic {
553 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 565
 # whether to reset the identity
566
+set_new_identity=
557 567
 if [ $2 ]; then
558 568
 	if [[ "$2" == $"new"* ]]; then
559 569
 		if [ ! -f $MESH_INSTALL_SETUP ]; then
560 570
 			touch $MESH_INSTALL_SETUP
561 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 582
 	fi
563 583
 fi
564 584
 
@@ -567,8 +587,10 @@ if [ -f $MESH_INSTALL_SETUP ]; then
567 587
 		MY_USERNAME=$1
568 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 595
 	# clear the install log
574 596
 	if [ -f $INSTALL_LOG ]; then
@@ -589,11 +611,16 @@ if [ -f $MESH_INSTALL_SETUP ]; then
589 611
 	disable_screen_lock
590 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 624
 fi
598 625
 
599 626
 exit 0