Tidying of restore functions

This commit is contained in:
Bob Mottram 2016-10-13 11:24:07 +01:00
parent cfa5f4832e
commit 06751dac0f
2 changed files with 20 additions and 28 deletions

View File

@ -30,6 +30,7 @@
PROJECT_NAME='freedombone'
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
# whether to restore everything or just a specific application
@ -38,6 +39,13 @@ RESTORE_APP='all'
export TEXTDOMAIN=${PROJECT_NAME}-restore-local
export TEXTDOMAINDIR="/usr/share/locale"
PROJECT_INSTALL_DIR=/usr/local/bin
if [ -f /usr/bin/${PROJECT_NAME} ]; then
PROJECT_INSTALL_DIR=/usr/bin
fi
source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
# include utils which allow function_check, go and drive mount
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
for f in $UTILS_FILES
@ -48,20 +56,11 @@ done
USB_DRIVE=/dev/sdb1
USB_MOUNT=/mnt/usb
# get default USB from config file
CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
if [ -f $CONFIG_FILE ]; then
if grep -q "USB_DRIVE=" $CONFIG_FILE; then
USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
fi
fi
# get the version of Go being used
GO_VERSION=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
GVM_HOME=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GVM_HOME=' | head -n 1 | awk -F '=' '{print $2}')
ADMIN_USERNAME=''
ADMIN_NAME=
read_config_param USB_DRIVE
if [ -f $COMPLETION_FILE ]; then
ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
fi
@ -113,16 +112,16 @@ function restore_configuration {
temp_restore_dir=/root/tempconfig
restore_directory_from_usb $temp_restore_dir config
cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE
cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIGURATION_FILE
if [ ! "$?" = "0" ]; then
set_user_permissions
backup_unmount_drive
rm -rf $temp_restore_dir
exit 5294
fi
if [ -f $CONFIG_FILE ]; then
if [ -f $CONFIGURATION_FILE ]; then
# install according to the config file
freedombone -c $CONFIG_FILE
freedombone -c $CONFIGURATION_FILE
fi
cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
@ -489,9 +488,7 @@ function restore_user_monkeysphere {
# The admin user is the identity certifier
MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
if grep -q "MY_EMAIL_ADDRESS" $CONFIG_FILE; then
MY_EMAIL_ADDRESS=$(grep "MY_EMAIL_ADDRESS" $CONFIG_FILE | awk -F '=' '{print $2}')
fi
read_config_param MY_EMAIL_ADDRESS
MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
monkeysphere-authentication add-identity-certifier $fpr

View File

@ -30,7 +30,7 @@
PROJECT_NAME='freedombone'
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
export TEXTDOMAIN=${PROJECT_NAME}-restore-remote
@ -89,9 +89,6 @@ else
echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> /var/log/remotebackups.log
fi
# get the version of Go being used
GO_VERSION=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
# MariaDB password
DATABASE_PASSWORD=$(cat /root/dbpass)
@ -118,15 +115,15 @@ function restore_configuration {
temp_restore_dir=/root/tempconfig
restore_directory_from_friend $temp_restore_dir config
cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE
cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIGURATION_FILE
if [ ! "$?" = "0" ]; then
unmount_drive
rm -rf $temp_restore_dir
exit 5372
fi
if [ -f $CONFIG_FILE ]; then
if [ -f $CONFIGURATION_FILE ]; then
# install according to the config file
freedombone -c $CONFIG_FILE
freedombone -c $CONFIGURATION_FILE
fi
cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
@ -450,9 +447,7 @@ function restore_user_monkeysphere {
# The admin user is the identity certifier
MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
if grep -q "MY_EMAIL_ADDRESS" $CONFIG_FILE; then
MY_EMAIL_ADDRESS=$(grep "MY_EMAIL_ADDRESS" $CONFIG_FILE | awk -F '=' '{print $2}')
fi
read_config_param MY_EMAIL_ADDRESS
MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
monkeysphere-authentication add-identity-certifier $fpr