浏览代码

In amnesic mode store mesh qtox settings in a tomb

Bob Mottram 8 年前
父节点
当前提交
45b8c85fd7
共有 1 个文件被更改,包括 46 次插入13 次删除
  1. 46
    13
      src/freedombone-image-mesh

+ 46
- 13
src/freedombone-image-mesh 查看文件

@@ -52,6 +52,9 @@ MESH_INSTALL_COMPLETED=/root/.mesh_setup_completed
52 52
 MESH_INSTALL_SETUP=/root/.initial_mesh_setup
53 53
 MESH_AMNESIC=/root/.amnesic
54 54
 
55
+# size of the tomb used to store qtox settings
56
+TOMB_TOX_SIZE_MB=64
57
+
55 58
 function create_ram_disk {
56 59
 	ramdisk_size_mb=$1
57 60
 	if [ ! -d /mnt/ramdisk ]; then
@@ -465,16 +468,6 @@ function configure_zeronet_id {
465 468
 	echo $'Update of ZeroID completed' >> $INSTALL_LOG
466 469
 }
467 470
 
468
-function amnesic_remove_tox {
469
-	echo $'Clearing qtox client settings' >> $INSTALL_LOG
470
-	if [ -d /home/${MY_USERNAME}/.config/tox ]; then
471
-		shred -zu /home/${MY_USERNAME}/.config/tox/*.tox
472
-		shred -zu /home/${MY_USERNAME}/.config/tox/*.db
473
-		shred -zu /home/${MY_USERNAME}/.config/tox/*.ini
474
-		rm -rf /home/${MY_USERNAME}/.config/tox
475
-	fi
476
-}
477
-
478 471
 function configure_toxcore {
479 472
 	echo $'Configuring toxcore' >> $INSTALL_LOG
480 473
 
@@ -500,9 +493,6 @@ function configure_toxcore {
500 493
 	# save the public key for later reference
501 494
 	echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
502 495
 	echo $'Configured toxcore' >> $INSTALL_LOG
503
-
504
-	amnesic_remove_tox
505
-	echo $'toxic client configured' >> $INSTALL_LOG
506 496
 }
507 497
 
508 498
 function disable_password_logins {
@@ -541,6 +531,16 @@ function mesh_amnesic {
541 531
 
542 532
 	echo '#!/bin/bash' > /usr/bin/amnesic
543 533
 	echo '' >> /usr/bin/amnesic
534
+	echo 'tomb slam all' >> /usr/bin/amnesic
535
+	echo '' >> /usr/bin/amnesic
536
+	echo "if [ -d /home/${MY_USERNAME}/.config/tox ]; then" >> /usr/bin/amnesic
537
+	echo "    rm -rf /home/${MY_USERNAME}/.config/tox" >> /usr/bin/amnesic
538
+	echo 'fi' >> /usr/bin/amnesic
539
+	echo '' >> /usr/bin/amnesic
540
+	echo 'if [ -f /tmp/tox.tomb ]; then' >> /usr/bin/amnesic
541
+	echo '    rm -f /tmp/tox.tomb' >> /usr/bin/amnesic
542
+	echo 'fi' >> /usr/bin/amnesic
543
+	echo '' >> /usr/bin/amnesic
544 544
 	echo "shred -zu /var/log/${PROJECT_NAME}*" >> /usr/bin/amnesic
545 545
 	echo '' >> /usr/bin/amnesic
546 546
 	echo 'MY_USERNAME=$1' >> /usr/bin/amnesic
@@ -579,6 +579,37 @@ function mesh_restart_daemons {
579 579
 	echo $'Daemons restarted' >> $INSTALL_LOG
580 580
 }
581 581
 
582
+function setup_amnesic_tox_data {
583
+	if [ ! -f $MESH_AMNESIC ]; then
584
+		return
585
+	fi
586
+	if [ ! -d /mnt/ramdisk ]; then
587
+		return
588
+	fi
589
+
590
+	TOMB_TOX_PASSWORD="$(openssl rand -base64 32 | cut -c1-30)"
591
+	tomb dig -s $TOMB_TOX_SIZE_MB /tmp/tox.tomb
592
+	tomb forge /mnt/ramdisk/tox.tomb.key --tomb-pwd "${TOMB_TOX_PASSWORD}" --unsafe
593
+	tomb lock /tmp/tox.tomb -k /mnt/ramdisk/tox.tomb.key --tomb-pwd "${TOMB_TOX_PASSWORD}" --unsafe
594
+	tomb open /tmp/tox.tomb -k /mnt/ramdisk/tox.tomb.key --tomb-pwd "${TOMB_TOX_PASSWORD}" --unsafe
595
+	TOMB_TOX_PASSWORD=
596
+	if [ -d /media/tox ]; then
597
+		if [ ! -d /home/$MY_USERNAME/.config ]; then
598
+			mkdir -p /home/$MY_USERNAME/.config
599
+		fi
600
+		if [ -d /home/$MY_USERNAME/.config/tox ]; then
601
+			cp -r /home/$MY_USERNAME/.config/tox/* /media/tox
602
+			rm -rf /home/$MY_USERNAME/.config/tox
603
+			ln -s /media/tox /home/$MY_USERNAME/.config/tox
604
+		fi
605
+		chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
606
+		chown -R $MY_USERNAME:$MY_USERNAME /media/tox
607
+		echo "Tox Tomb created" >> /var/log/${PROJECT_NAME}.log
608
+	else
609
+		echo "WARNING: Tox Tomb not found" >> /var/log/${PROJECT_NAME}.log
610
+	fi
611
+}
612
+
582 613
 # whether to reset the identity
583 614
 set_new_identity=
584 615
 if [ $2 ]; then
@@ -615,6 +646,7 @@ if [ -f $MESH_INSTALL_SETUP ]; then
615 646
 	fi
616 647
 
617 648
 	echo $'Beginning mesh node setup' >> $INSTALL_LOG
649
+	tomb slam all
618 650
 	enable_batman_daemon
619 651
 	create_ram_disk 1
620 652
 	change_avahi_name
@@ -623,6 +655,7 @@ if [ -f $MESH_INSTALL_SETUP ]; then
623 655
 	configure_zeronet_mail
624 656
 	configure_zeronet_forum
625 657
 	configure_zeronet_id
658
+	setup_amnesic_tox_data
626 659
 	configure_toxcore
627 660
 	configure_zeronet
628 661
 	disable_password_logins