Selaa lähdekoodia

Tidying of restore functions

Bob Mottram 8 vuotta sitten
vanhempi
commit
06751dac0f
2 muutettua tiedostoa jossa 20 lisäystä ja 28 poistoa
  1. 15
    18
      src/freedombone-restore-local
  2. 5
    10
      src/freedombone-restore-remote

+ 15
- 18
src/freedombone-restore-local Näytä tiedosto

@@ -30,6 +30,7 @@
30 30
 
31 31
 PROJECT_NAME='freedombone'
32 32
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
33
+CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
33 34
 BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
34 35
 
35 36
 # whether to restore everything or just a specific application
@@ -38,6 +39,13 @@ RESTORE_APP='all'
38 39
 export TEXTDOMAIN=${PROJECT_NAME}-restore-local
39 40
 export TEXTDOMAINDIR="/usr/share/locale"
40 41
 
42
+PROJECT_INSTALL_DIR=/usr/local/bin
43
+if [ -f /usr/bin/${PROJECT_NAME} ]; then
44
+    PROJECT_INSTALL_DIR=/usr/bin
45
+fi
46
+
47
+source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
48
+
41 49
 # include utils which allow function_check, go and drive mount
42 50
 UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
43 51
 for f in $UTILS_FILES
@@ -48,20 +56,11 @@ done
48 56
 USB_DRIVE=/dev/sdb1
49 57
 USB_MOUNT=/mnt/usb
50 58
 
51
-# get default USB from config file
52
-CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
53
-if [ -f $CONFIG_FILE ]; then
54
-    if grep -q "USB_DRIVE=" $CONFIG_FILE; then
55
-        USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
56
-    fi
57
-fi
58
-
59
-# get the version of Go being used
60
-GO_VERSION=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
61
-GVM_HOME=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GVM_HOME=' | head -n 1 | awk -F '=' '{print $2}')
62
-
63 59
 ADMIN_USERNAME=''
64 60
 ADMIN_NAME=
61
+
62
+read_config_param USB_DRIVE
63
+
65 64
 if [ -f $COMPLETION_FILE ]; then
66 65
     ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
67 66
 fi
@@ -113,16 +112,16 @@ function restore_configuration {
113 112
         temp_restore_dir=/root/tempconfig
114 113
         restore_directory_from_usb $temp_restore_dir config
115 114
 
116
-        cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE
115
+        cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIGURATION_FILE
117 116
         if [ ! "$?" = "0" ]; then
118 117
             set_user_permissions
119 118
             backup_unmount_drive
120 119
             rm -rf $temp_restore_dir
121 120
             exit 5294
122 121
         fi
123
-        if [ -f $CONFIG_FILE ]; then
122
+        if [ -f $CONFIGURATION_FILE ]; then
124 123
             # install according to the config file
125
-            freedombone -c $CONFIG_FILE
124
+            freedombone -c $CONFIGURATION_FILE
126 125
         fi
127 126
 
128 127
         cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
@@ -489,9 +488,7 @@ function restore_user_monkeysphere {
489 488
 
490 489
         # The admin user is the identity certifier
491 490
         MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
492
-        if grep -q "MY_EMAIL_ADDRESS" $CONFIG_FILE; then
493
-            MY_EMAIL_ADDRESS=$(grep "MY_EMAIL_ADDRESS" $CONFIG_FILE | awk -F '=' '{print $2}')
494
-        fi
491
+        read_config_param MY_EMAIL_ADDRESS
495 492
         MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
496 493
         fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
497 494
         monkeysphere-authentication add-identity-certifier $fpr

+ 5
- 10
src/freedombone-restore-remote Näytä tiedosto

@@ -30,7 +30,7 @@
30 30
 
31 31
 PROJECT_NAME='freedombone'
32 32
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
33
-CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
33
+CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
34 34
 BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
35 35
 
36 36
 export TEXTDOMAIN=${PROJECT_NAME}-restore-remote
@@ -89,9 +89,6 @@ else
89 89
     echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> /var/log/remotebackups.log
90 90
 fi
91 91
 
92
-# get the version of Go being used
93
-GO_VERSION=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
94
-
95 92
 # MariaDB password
96 93
 DATABASE_PASSWORD=$(cat /root/dbpass)
97 94
 
@@ -118,15 +115,15 @@ function restore_configuration {
118 115
         temp_restore_dir=/root/tempconfig
119 116
         restore_directory_from_friend $temp_restore_dir config
120 117
 
121
-        cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE
118
+        cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIGURATION_FILE
122 119
         if [ ! "$?" = "0" ]; then
123 120
             unmount_drive
124 121
             rm -rf $temp_restore_dir
125 122
             exit 5372
126 123
         fi
127
-        if [ -f $CONFIG_FILE ]; then
124
+        if [ -f $CONFIGURATION_FILE ]; then
128 125
             # install according to the config file
129
-            freedombone -c $CONFIG_FILE
126
+            freedombone -c $CONFIGURATION_FILE
130 127
         fi
131 128
 
132 129
         cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
@@ -450,9 +447,7 @@ function restore_user_monkeysphere {
450 447
 
451 448
         # The admin user is the identity certifier
452 449
         MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
453
-        if grep -q "MY_EMAIL_ADDRESS" $CONFIG_FILE; then
454
-            MY_EMAIL_ADDRESS=$(grep "MY_EMAIL_ADDRESS" $CONFIG_FILE | awk -F '=' '{print $2}')
455
-        fi
450
+        read_config_param MY_EMAIL_ADDRESS
456 451
         MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
457 452
         fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
458 453
         monkeysphere-authentication add-identity-certifier $fpr