From f11a4f20809e0f08acc26b4d245ca0e6716f20e2 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 10 Jul 2016 11:04:40 +0100 Subject: [PATCH] Tidying --- src/freedombone-backup-local | 41 +- src/freedombone-restore-local | 1287 ++++++++++++++++---------------- src/freedombone-restore-remote | 241 +++--- 3 files changed, 804 insertions(+), 765 deletions(-) diff --git a/src/freedombone-backup-local b/src/freedombone-backup-local index 3aae2cd1..bd5ba005 100755 --- a/src/freedombone-backup-local +++ b/src/freedombone-backup-local @@ -285,48 +285,51 @@ function prepare_directories { function backup_configuration { echo $"Backing up ${PROJECT_NAME} configuration files" - if [ ! -d /root/tempbackupconfig ]; then - mkdir -p /root/tempbackupconfig + temp_backup_dir=/root/tempbackupconfig + if [ ! -d $temp_backup_dir ]; then + mkdir -p $temp_backup_dir fi - cp -f $CONFIG_FILE /root/tempbackupconfig - cp -f $COMPLETION_FILE /root/tempbackupconfig + cp -f $CONFIG_FILE $temp_backup_dir + cp -f $COMPLETION_FILE $temp_backup_dir if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then - cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig + cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir fi # nginx password hashes if [ -f /etc/nginx/.htpasswd ]; then - cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd + cp -f /etc/nginx/.htpasswd $temp_backup_dir/htpasswd fi - backup_directory_to_usb /root/tempbackupconfig config + backup_directory_to_usb $temp_backup_dir config } function backup_admin_readme { if [ -f /home/$ADMIN_USERNAME/README ]; then echo $"Backing up README" - if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then - mkdir -p /home/$ADMIN_USERNAME/tempbackup + temp_backup_dir=/home/$ADMIN_USERNAME/tempbackup + if [ ! -d $temp_backup_dir ]; then + mkdir -p $temp_backup_dir fi - cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup - backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme + cp -f /home/$ADMIN_USERNAME/README $temp_backup_dir + backup_directory_to_usb $temp_backup_dir readme fi } function backup_mariadb { if [ ${#DATABASE_PASSWORD} -gt 1 ]; then - if [ ! -d /root/tempmariadb ]; then - mkdir /root/tempmariadb + temp_backup_dir=/root/tempmariadb + if [ ! -d $temp_backup_dir ]; then + mkdir $temp_backup_dir fi - mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql - if [ ! -s /root/tempmariadb/mysql.sql ]; then + mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > $temp_backup_dir/mysql.sql + if [ ! -s $temp_backup_dir/mysql.sql ]; then echo $"Unable to backup mysql settings" - rm -rf /root/tempmariadb + rm -rf $temp_backup_dir umount $USB_MOUNT rm -rf $USB_MOUNT exit 8 fi - echo "$DATABASE_PASSWORD" > /root/tempmariadb/db - chmod 400 /root/tempmariadb/db - backup_directory_to_usb /root/tempmariadb mariadb + echo "$DATABASE_PASSWORD" > $temp_backup_dir/db + chmod 400 $temp_backup_dir/db + backup_directory_to_usb $temp_backup_dir mariadb fi } diff --git a/src/freedombone-restore-local b/src/freedombone-restore-local index cecb9ee5..4ea35d73 100755 --- a/src/freedombone-restore-local +++ b/src/freedombone-restore-local @@ -51,9 +51,9 @@ 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 + 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 @@ -63,7 +63,7 @@ GVM_HOME=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep ADMIN_USERNAME='' ADMIN_NAME= if [ -f $COMPLETION_FILE ]; then - ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') + ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') fi # MariaDB password @@ -77,736 +77,747 @@ WIKI_DOMAIN_NAME= FULLBLOG_DOMAIN_NAME= function check_backup_exists { - if [ ! -d $USB_MOUNT/backup ]; then - echo $"No backup directory found on the USB drive." - set_user_permissions - backup_unmount_drive - exit 2 - fi + if [ ! -d $USB_MOUNT/backup ]; then + echo $"No backup directory found on the USB drive." + set_user_permissions + backup_unmount_drive + exit 2 + fi } function check_admin_user { - echo $"Checking that admin user exists" - if [ ! -d /home/$ADMIN_USERNAME ]; then - echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username." - set_user_permissions - backup_unmount_drive - exit 295 - fi + echo $"Checking that admin user exists" + if [ ! -d /home/$ADMIN_USERNAME ]; then + echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username." + set_user_permissions + backup_unmount_drive + exit 295 + fi } function copy_gpg_keys { - echo $"Copying GPG keys from admin user to root" - cp -r /home/$ADMIN_USERNAME/.gnupg /root + echo $"Copying GPG keys from admin user to root" + cp -r /home/$ADMIN_USERNAME/.gnupg /root } function restore_directory_from_usb { - if [ ! -d ${1} ]; then - mkdir ${1} - fi - obnam restore -r $USB_MOUNT/backup/${2} --to ${1} + if [ ! -d ${1} ]; then + mkdir ${1} + fi + obnam restore -r $USB_MOUNT/backup/${2} --to ${1} } function restore_database { - RESTORE_SUBDIR="root" + RESTORE_SUBDIR="root" - if [ -d $USB_MOUNT/backup/${1} ]; then - echo $"Restoring ${1} database" - restore_directory_from_usb "/root/temp${1}data" "${1}data" - if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then - echo $"Unable to restore ${1} database" - rm -rf /root/temp${1}data - set_user_permissions - backup_unmount_drive - exit 503 - fi - mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql) - if [ ! "$?" = "0" ]; then - echo "$mysqlsuccess" - set_user_permissions - backup_unmount_drive - exit 964 - fi - shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/* - rm -rf /root/temp${1}data - echo $"Restoring ${1} installation" - if [ ! -d /root/temp${1} ]; then - mkdir /root/temp${1} - fi - restore_directory_from_usb "/root/temp${1}" "${1}" - RESTORE_SUBDIR="var" - if [ ${2} ]; then - # special handline of ttrss - if [[ ${2} == "ttrss" ]]; then - if [ -d /etc/share/tt-rss ]; then - if [ -d /root/temp${1}/etc/share/tt-rss ]; then - rm -rf /etc/share/tt-rss - mv /root/temp${1}/etc/share/tt-rss /etc/share/ - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - exit 528 - fi - if [ -d /etc/letsencrypt/live/${2} ]; then - ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key - ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem - else - # Ensure that the bundled SSL cert is being used - if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then - sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2} - fi - fi - fi - fi - fi + if [ -d $USB_MOUNT/backup/${1} ]; then + echo $"Restoring ${1} database" + restore_directory_from_usb "/root/temp${1}data" "${1}data" + if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then + echo $"Unable to restore ${1} database" + rm -rf /root/temp${1}data + set_user_permissions + backup_unmount_drive + exit 503 + fi + mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql) + if [ ! "$?" = "0" ]; then + echo "$mysqlsuccess" + set_user_permissions + backup_unmount_drive + exit 964 + fi + shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/* + rm -rf /root/temp${1}data + echo $"Restoring ${1} installation" + if [ ! -d /root/temp${1} ]; then + mkdir /root/temp${1} + fi + restore_directory_from_usb "/root/temp${1}" "${1}" + RESTORE_SUBDIR="var" + if [ ${2} ]; then + # special handline of ttrss + if [[ ${2} == "ttrss" ]]; then + if [ -d /etc/share/tt-rss ]; then + if [ -d /root/temp${1}/etc/share/tt-rss ]; then + rm -rf /etc/share/tt-rss + mv /root/temp${1}/etc/share/tt-rss /etc/share/ + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + exit 528 + fi + if [ -d /etc/letsencrypt/live/${2} ]; then + ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key + ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem + else + # Ensure that the bundled SSL cert is being used + if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then + sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2} + fi + fi + fi + fi + fi - if [ -d /var/www/${2}/htdocs ]; then - if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then - rm -rf /var/www/${2}/htdocs - mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/ - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - exit 683 - fi - if [ -d /etc/letsencrypt/live/${2} ]; then - ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key - ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem - else - # Ensure that the bundled SSL cert is being used - if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then - sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2} - fi - fi - fi - fi - fi - fi + if [ -d /var/www/${2}/htdocs ]; then + if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then + rm -rf /var/www/${2}/htdocs + mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/ + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + exit 683 + fi + if [ -d /etc/letsencrypt/live/${2} ]; then + ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key + ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem + else + # Ensure that the bundled SSL cert is being used + if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then + sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2} + fi + fi + fi + fi + fi + fi } function update_domains { - if grep -q "RSS reader domain" $COMPLETION_FILE; then - RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}') - fi - if grep -q "GNU Social domain" $COMPLETION_FILE; then - MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') - fi - if grep -q "Hubzilla domain" $COMPLETION_FILE; then - HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') - fi - if grep -q "Mediagoblin domain" $COMPLETION_FILE; then - MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') - fi - if grep -q "Gogs domain" $COMPLETION_FILE; then - GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') - fi - if [ -d $USB_MOUNT/backup/wiki ]; then - WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}') - fi - if [ -d $USB_MOUNT/backup/blog ]; then - FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') - fi + if grep -q "RSS reader domain" $COMPLETION_FILE; then + RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}') + fi + if grep -q "GNU Social domain" $COMPLETION_FILE; then + MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') + fi + if grep -q "Hubzilla domain" $COMPLETION_FILE; then + HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') + fi + if grep -q "Mediagoblin domain" $COMPLETION_FILE; then + MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') + fi + if grep -q "Gogs domain" $COMPLETION_FILE; then + GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') + fi + if [ -d $USB_MOUNT/backup/wiki ]; then + WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}') + fi + if [ -d $USB_MOUNT/backup/blog ]; then + FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') + fi } function restore_configuration { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'configuration' ]]; then - return - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'configuration' ]]; then + return + fi + fi - # this restores *.cfg and COMPLETION_FILE - if [ -d $USB_MOUNT/backup/config ]; then - echo $"Restoring configuration files" - restore_directory_from_usb /root/tempconfig config + # this restores *.cfg and COMPLETION_FILE + if [ -d $USB_MOUNT/backup/config ]; then + echo $"Restoring configuration files" + temp_restore_dir=/root/tempconfig + restore_directory_from_usb $temp_restore_dir config - cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - rm -rf /root/tempconfig - exit 5294 - fi - if [ -f $CONFIG_FILE ]; then - # install according to the config file - freedombone -c $CONFIG_FILE - fi + cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + rm -rf $temp_restore_dir + exit 5294 + fi + if [ -f $CONFIG_FILE ]; then + # install according to the config file + freedombone -c $CONFIG_FILE + fi - cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - rm -rf /root/tempconfig - exit 6382 - fi + cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + rm -rf $temp_restore_dir + exit 6382 + fi - if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then - cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - rm -rf /root/tempconfig - exit 62121 - fi - fi + if [ -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ]; then + cp -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + rm -rf $temp_restore_dir + exit 62121 + fi + fi - # restore nginx password hashes - if [ -f /root/tempconfig/root/htpasswd ]; then - cp -f /root/tempconfig/root/htpasswd /etc/nginx/.htpasswd - fi + # restore nginx password hashes + if [ -f $temp_restore_dir/root/htpasswd ]; then + cp -f $temp_restore_dir/root/htpasswd /etc/nginx/.htpasswd + fi - rm -rf /root/tempconfig - fi + rm -rf $temp_restore_dir + fi } function same_admin_user { - PREV_ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') - if [[ "$PREV_ADMIN_USERNAME" != "$ADMIN_USERNAME" ]]; then - echo $"The admin username has changed from $PREV_ADMIN_USERNAME to $ADMIN_USERNAME. To restore you will first need to install a new ${PROJECT_NAME} system with an initial admin user named $PREV_ADMIN_USERNAME" - set_user_permissions - backup_unmount_drive - exit 73265 - fi + PREV_ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') + if [[ "$PREV_ADMIN_USERNAME" != "$ADMIN_USERNAME" ]]; then + echo $"The admin username has changed from $PREV_ADMIN_USERNAME to $ADMIN_USERNAME. To restore you will first need to install a new ${PROJECT_NAME} system with an initial admin user named $PREV_ADMIN_USERNAME" + set_user_permissions + backup_unmount_drive + exit 73265 + fi } function restore_mariadb { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mariadb' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/mariadb ]; then - echo $"Restoring mysql settings" - restore_directory_from_usb /root/tempmariadb mariadb - echo $"Get the MariaDB password from the backup" - if [ ! -f /root/tempmariadb/root/tempmariadb/db ]; then - echo $"MariaDB password file not found" - exit 495 - fi - BACKUP_MARIADB_PASSWORD=$(cat /root/tempmariadb/root/tempmariadb/db) - if [[ $BACKUP_MARIADB_PASSWORD != $DATABASE_PASSWORD ]]; then - echo $"Restore the MariaDB user table" - mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) - if [ ! "$?" = "0" ]; then - echo $"Try again using the password obtained from backup" - mysqlsuccess=$(mysql -u root --password=$BACKUP_MARIADB_PASSWORD mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) - fi - if [ ! "$?" = "0" ]; then - echo "$mysqlsuccess" - set_user_permissions - backup_unmount_drive - exit 962 - fi - echo $"Restarting database" - service mysql restart - echo $"Change the MariaDB password to the backup version" - DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD - fi - shred -zu /root/tempmariadb/root/tempmariadb/db - rm -rf /root/tempmariadb + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mariadb' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/mariadb ]; then + echo $"Restoring mysql settings" + temp_restore_dir=/root/tempmariadb + restore_directory_from_usb $temp_restore_dir mariadb + echo $"Get the MariaDB password from the backup" + if [ ! -f ${temp_restore_dir}${temp_restore_dir}/db ]; then + echo $"MariaDB password file not found" + exit 495 + fi + BACKUP_MARIADB_PASSWORD=$(cat ${temp_restore_dir}${temp_restore_dir}/db) + if [[ $BACKUP_MARIADB_PASSWORD != $DATABASE_PASSWORD ]]; then + echo $"Restore the MariaDB user table" + mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql) + if [ ! "$?" = "0" ]; then + echo $"Try again using the password obtained from backup" + mysqlsuccess=$(mysql -u root --password=$BACKUP_MARIADB_PASSWORD mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql) + fi + if [ ! "$?" = "0" ]; then + echo "$mysqlsuccess" + set_user_permissions + backup_unmount_drive + exit 962 + fi + echo $"Restarting database" + service mysql restart + echo $"Change the MariaDB password to the backup version" + DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD + fi + shred -zu ${temp_restore_dir}${temp_restore_dir}/db + rm -rf $temp_restore_dir - # Change database password file - echo "$DATABASE_PASSWORD" > /root/dbpass - chmod 600 /root/dbpass - fi + # Change database password file + echo "$DATABASE_PASSWORD" > /root/dbpass + chmod 600 /root/dbpass + fi } function restore_letsencrypt { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'letsencrypt' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/letsencrypt ]; then - echo $"Restoring Lets Encrypt settings" - restore_directory_from_usb / letsencrypt - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'letsencrypt' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/letsencrypt ]; then + echo $"Restoring Lets Encrypt settings" + restore_directory_from_usb / letsencrypt + fi } function restore_tor { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'tor' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/tor ]; then - echo $"Restoring Tor settings" - restore_directory_from_usb / tor - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'tor' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/tor ]; then + echo $"Restoring Tor settings" + restore_directory_from_usb / tor + fi } function restore_mutt_settings { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mutt' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/mutt ]; then - for d in $USB_MOUNT/backup/mutt/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring Mutt settings for $USERNAME" - restore_directory_from_usb /root/tempmutt mutt/$USERNAME - if [ -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc ]; then - cp -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc - fi - if [ -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc ]; then - cp -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc - fi - if [ ! "$?" = "0" ]; then - rm -rf /root/tempmutt - set_user_permissions - backup_unmount_drive - exit 276 - fi - rm -rf /root/tempmutt - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mutt' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/mutt ]; then + for d in $USB_MOUNT/backup/mutt/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring Mutt settings for $USERNAME" + restore_directory_from_usb /root/tempmutt mutt/$USERNAME + if [ -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc ]; then + cp -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc + fi + if [ -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc ]; then + cp -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc + fi + if [ ! "$?" = "0" ]; then + rm -rf /root/tempmutt + set_user_permissions + backup_unmount_drive + exit 276 + fi + rm -rf /root/tempmutt + fi + done + fi } function restore_gpg { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'gpg' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/gnupg ]; then - for d in $USB_MOUNT/backup/gnupg/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring gnupg settings for $USERNAME" - restore_directory_from_usb /root/tempgnupg gnupg/$USERNAME - cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempgnupg - set_user_permissions - backup_unmount_drive - exit 276 - fi - rm -rf /root/tempgnupg - if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then - cp -r /home/$USERNAME/.gnupg /root - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - exit 283 - fi - fi - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'gpg' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/gnupg ]; then + for d in $USB_MOUNT/backup/gnupg/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring gnupg settings for $USERNAME" + restore_directory_from_usb /root/tempgnupg gnupg/$USERNAME + cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempgnupg + set_user_permissions + backup_unmount_drive + exit 276 + fi + rm -rf /root/tempgnupg + if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then + cp -r /home/$USERNAME/.gnupg /root + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + exit 283 + fi + fi + fi + done + fi } function restore_procmail { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'procmail' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/procmail ]; then - for d in $USB_MOUNT/backup/procmail/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring procmail settings for $USERNAME" - restore_directory_from_usb /root/tempprocmail procmail/$USERNAME - cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempprocmail - set_user_permissions - backup_unmount_drive - exit 276 - fi - rm -rf /root/tempprocmail - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'procmail' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/procmail ]; then + for d in $USB_MOUNT/backup/procmail/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring procmail settings for $USERNAME" + restore_directory_from_usb /root/tempprocmail procmail/$USERNAME + cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempprocmail + set_user_permissions + backup_unmount_drive + exit 276 + fi + rm -rf /root/tempprocmail + fi + done + fi } function restore_spamassassin { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'spamassassin' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/spamassassin ]; then - for d in $USB_MOUNT/backup/spamassassin/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ -d $USB_MOUNT/backup/spamassassin/$USERNAME ]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring spamassassin settings for $USERNAME" - restore_directory_from_usb /root/tempspamassassin spamassassin/$USERNAME - cp -rf /root/tempspamassassin/home/$USERNAME/.spamassassin /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempspamassassin - set_user_permissions - backup_unmount_drive - exit 276 - fi - rm -rf /root/tempspamassassin - fi - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'spamassassin' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/spamassassin ]; then + for d in $USB_MOUNT/backup/spamassassin/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ -d $USB_MOUNT/backup/spamassassin/$USERNAME ]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring spamassassin settings for $USERNAME" + temp_restore_dir=/root/tempspamassassin + restore_directory_from_usb $temp_restore_dir spamassassin/$USERNAME + cp -rf $temp_restore_dir/home/$USERNAME/.spamassassin /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf $temp_restore_dir + set_user_permissions + backup_unmount_drive + exit 276 + fi + rm -rf $temp_restore_dir + fi + fi + done + fi } function restore_admin_readme { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'readme' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/readme ]; then - echo $"Restoring admin user README" + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'readme' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/readme ]; then + echo $"Restoring admin user README" - # Make a backup of the original README file - # incase old passwords need to be used - if [ -f /home/$ADMIN_USERNAME/README ]; then - if [ ! -f /home/$ADMIN_USERNAME/README_original ]; then - cp /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/README_original - fi - fi + # Make a backup of the original README file + # incase old passwords need to be used + if [ -f /home/$ADMIN_USERNAME/README ]; then + if [ ! -f /home/$ADMIN_USERNAME/README_original ]; then + cp /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/README_original + fi + fi - restore_directory_from_usb /root/tempreadme readme - cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempreadme - set_user_permissions - backup_unmount_drive - exit 276 - fi - rm -rf /root/tempreadme - fi + temp_restore_dir=/root/tempreadme + restore_directory_from_usb $temp_restore_dir readme + cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf $temp_restore_dir + set_user_permissions + backup_unmount_drive + exit 276 + fi + rm -rf $temp_restore_dir + fi } function restore_user_ssh_keys { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'ssh' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/ssh ]; then - for d in $USB_MOUNT/backup/ssh/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring ssh keys for $USERNAME" - restore_directory_from_usb /root/tempssh ssh/$USERNAME - cp -r /root/tempssh/home/$USERNAME/.ssh /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempssh - set_user_permissions - backup_unmount_drive - exit 664 - fi - rm -rf /root/tempssh - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'ssh' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/ssh ]; then + for d in $USB_MOUNT/backup/ssh/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring ssh keys for $USERNAME" + temp_restore_dir=/root/tempssh + restore_directory_from_usb $temp_restore_dir ssh/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.ssh /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf $temp_restore_dir + set_user_permissions + backup_unmount_drive + exit 664 + fi + rm -rf $temp_restore_dir + fi + done + fi } function restore_user_config { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userconfig' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/config ]; then - for d in $USB_MOUNT/backup/config/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring config files for $USERNAME" - restore_directory_from_usb /root/tempconfig config/$USERNAME - cp -r /root/tempconfig/home/$USERNAME/.config /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempconfig - set_user_permissions - backup_unmount_drive - exit 664 - fi - rm -rf /root/tempconfig - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userconfig' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/config ]; then + for d in $USB_MOUNT/backup/config/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring config files for $USERNAME" + temp_restore_dir=/root/tempconfig + restore_directory_from_usb $temp_restore_dir config/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.config /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf $temp_restore_dir + set_user_permissions + backup_unmount_drive + exit 664 + fi + rm -rf $temp_restore_dir + fi + done + fi } function gpg_pubkey_from_email { - key_owner_username=$1 - key_email_address=$2 - key_id= - if [[ $key_owner_username != "root" ]]; then - key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - else - key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - fi - echo $key_id + key_owner_username=$1 + key_email_address=$2 + key_id= + if [[ $key_owner_username != "root" ]]; then + key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + else + key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + fi + echo $key_id } function restore_user_monkeysphere { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'usermonkeysphere' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/monkeysphere ]; then - for d in $USB_MOUNT/backup/monkeysphere/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring monkeysphere ids for $USERNAME" - restore_directory_from_usb /root/tempmonkeysphere monkeysphere/$USERNAME - cp -r /root/tempmonkeysphere/home/$USERNAME/.monkeysphere /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempmonkeysphere - set_user_permissions - backup_unmount_drive - exit 664 - fi - rm -rf /root/tempmonkeysphere - fi - done + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'usermonkeysphere' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/monkeysphere ]; then + for d in $USB_MOUNT/backup/monkeysphere/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring monkeysphere ids for $USERNAME" + temp_restore_dir=/root/tempmonkeysphere + restore_directory_from_usb $temp_restore_dir monkeysphere/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.monkeysphere /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf $temp_restore_dir + set_user_permissions + backup_unmount_drive + exit 664 + fi + rm -rf $temp_restore_dir + fi + done - # 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 - 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 - monkeysphere-authentication update-users - fi + # 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 + 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 + monkeysphere-authentication update-users + fi } function restore_user_fin { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userfin' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/fin ]; then - for d in $USB_MOUNT/backup/fin/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring fin files for $USERNAME" - restore_directory_from_usb /root/tempfin fin/$USERNAME - cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempfin - set_user_permissions - backup_unmount_drive - exit 664 - fi - rm -rf /root/tempfin - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userfin' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/fin ]; then + for d in $USB_MOUNT/backup/fin/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring fin files for $USERNAME" + temp_restore_dir=/root/tempfin + restore_directory_from_usb $temp_restore_dir fin/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.fin /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf $temp_restore_dir + set_user_permissions + backup_unmount_drive + exit 664 + fi + rm -rf $temp_restore_dir + fi + done + fi } function restore_user_local { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userlocal' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/local ]; then - for d in $USB_MOUNT/backup/local/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring local files for $USERNAME" - restore_directory_from_usb /root/templocal local/$USERNAME - cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/templocal - set_user_permissions - backup_unmount_drive - exit 664 - fi - rm -rf /root/templocal - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userlocal' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/local ]; then + for d in $USB_MOUNT/backup/local/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring local files for $USERNAME" + temp_restore_dir=/root/templocal + restore_directory_from_usb $temp_restore_dir local/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.local /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf $temp_restore_dir + set_user_permissions + backup_unmount_drive + exit 664 + fi + rm -rf $temp_restore_dir + fi + done + fi } function restore_certs { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'certs' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/ssl ]; then - echo $"Restoring certificates" - mkdir /root/tempssl - restore_directory_from_usb /root/tempssl ssl - cp -r /root/tempssl/etc/ssl/* /etc/ssl - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - exit 276 - fi - rm -rf /root/tempssl + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'certs' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/ssl ]; then + echo $"Restoring certificates" + mkdir /root/tempssl + restore_directory_from_usb /root/tempssl ssl + cp -r /root/tempssl/etc/ssl/* /etc/ssl + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + exit 276 + fi + rm -rf /root/tempssl - # restore ownership - if [ -f /etc/ssl/private/xmpp.key ]; then - chown prosody:prosody /etc/ssl/private/xmpp.key - chown prosody:prosody /etc/ssl/certs/xmpp.* - fi - if [ -d /etc/dovecot ]; then - chown root:dovecot /etc/ssl/private/dovecot.* - chown root:dovecot /etc/ssl/certs/dovecot.* - fi - if [ -f /etc/ssl/private/exim.key ]; then - cp /etc/ssl/private/exim.key /etc/exim4 - cp /etc/ssl/certs/exim.crt /etc/exim4 - cp /etc/ssl/certs/exim.dhparam /etc/exim4 - chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam - chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam - fi - if [ -f /etc/ssl/private/mumble.key ]; then - if [ -d /var/lib/mumble-server ]; then - cp /etc/ssl/certs/mumble.* /var/lib/mumble-server - cp /etc/ssl/private/mumble.key /var/lib/mumble-server - chown -R mumble-server:mumble-server /var/lib/mumble-server - fi - fi - fi + # restore ownership + if [ -f /etc/ssl/private/xmpp.key ]; then + chown prosody:prosody /etc/ssl/private/xmpp.key + chown prosody:prosody /etc/ssl/certs/xmpp.* + fi + if [ -d /etc/dovecot ]; then + chown root:dovecot /etc/ssl/private/dovecot.* + chown root:dovecot /etc/ssl/certs/dovecot.* + fi + if [ -f /etc/ssl/private/exim.key ]; then + cp /etc/ssl/private/exim.key /etc/exim4 + cp /etc/ssl/certs/exim.crt /etc/exim4 + cp /etc/ssl/certs/exim.dhparam /etc/exim4 + chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam + chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam + fi + if [ -f /etc/ssl/private/mumble.key ]; then + if [ -d /var/lib/mumble-server ]; then + cp /etc/ssl/certs/mumble.* /var/lib/mumble-server + cp /etc/ssl/private/mumble.key /var/lib/mumble-server + chown -R mumble-server:mumble-server /var/lib/mumble-server + fi + fi + fi } function restore_personal_settings { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'personal' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/personal ]; then - for d in $USB_MOUNT/backup/personal/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ -d $USB_MOUNT/backup/personal/$USERNAME ]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring personal settings for $USERNAME" - restore_directory_from_usb /root/temppersonal personal/$USERNAME - if [ -d /home/$USERNAME/personal ]; then - rm -rf /home/$USERNAME/personal - fi - mv /root/temppersonal/home/$USERNAME/personal /home/$USERNAME - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - exit 184 - fi - rm -rf /root/temppersonal - fi - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'personal' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/personal ]; then + for d in $USB_MOUNT/backup/personal/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ -d $USB_MOUNT/backup/personal/$USERNAME ]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring personal settings for $USERNAME" + temp_restore_dir=/root/temppersonal + restore_directory_from_usb $temp_restore_dir personal/$USERNAME + if [ -d /home/$USERNAME/personal ]; then + rm -rf /home/$USERNAME/personal + fi + mv $temp_restore_dir/home/$USERNAME/personal /home/$USERNAME + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + exit 184 + fi + rm -rf $temp_restore_dir + fi + fi + done + fi } function restore_mailing_list { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mailinglist' ]]; then - return - fi - fi - if [ -d /var/spool/mlmmj ]; then - echo $"Restoring public mailing list" - restore_directory_from_usb /root/tempmailinglist mailinglist - cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - exit 526 - fi - rm -rf /root/tempmailinglist - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mailinglist' ]]; then + return + fi + fi + if [ -d /var/spool/mlmmj ]; then + echo $"Restoring public mailing list" + restore_directory_from_usb /root/tempmailinglist mailinglist + cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + exit 526 + fi + rm -rf /root/tempmailinglist + fi } function restore_email { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'email' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/mail ]; then - for d in $USB_MOUNT/backup/mail/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring emails for $USERNAME" - restore_directory_from_usb /root/tempmail mail/$USERNAME - if [ ! -d /home/$USERNAME/Maildir ]; then - mkdir /home/$USERNAME/Maildir - fi - tar -xzvf /root/tempmail/root/tempbackupemail/$USERNAME/maildir.tar.gz -C / - if [ ! "$?" = "0" ]; then - set_user_permissions - backup_unmount_drive - exit 927 - fi - rm -rf /root/tempmail - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'email' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/mail ]; then + for d in $USB_MOUNT/backup/mail/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring emails for $USERNAME" + temp_restore_dir=/root/tempmail + restore_directory_from_usb $temp_restore_dir mail/$USERNAME + if [ ! -d /home/$USERNAME/Maildir ]; then + mkdir /home/$USERNAME/Maildir + fi + tar -xzvf $temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz -C / + if [ ! "$?" = "0" ]; then + set_user_permissions + backup_unmount_drive + exit 927 + fi + rm -rf $temp_restore_dir + fi + done + fi } function get_restore_app { - if [ ${1} ]; then - if [ ! -d /home/${1} ]; then - RESTORE_APP=${1} - echo $"Restore $RESTORE_APP" - fi - fi + if [ ${1} ]; then + if [ ! -d /home/${1} ]; then + RESTORE_APP=${1} + echo $"Restore $RESTORE_APP" + fi + fi } function restore_apps { - FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-* + FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-* - APPS_COMPLETED=() + APPS_COMPLETED=() - # for all the app scripts - for filename in $FILES - do - app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $RESTORE_APP == 'all' || $RESTORE_APP == "${app_name}" ]]; then - if [[ $(item_in_array ${app_name} ${APPS_COMPLETED[@]}) != 0 ]]; then - function_check app_is_installed - if [[ "$(app_is_installed $a)" == "1" ]]; then - APPS_COMPLETED+=("${app_name}") - function_check restore_local_${app_name} - restore_local_${app_name} - fi - fi - fi - done + # for all the app scripts + for filename in $FILES + do + app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') + if [[ $RESTORE_APP == 'all' || $RESTORE_APP == "${app_name}" ]]; then + if [[ $(item_in_array ${app_name} ${APPS_COMPLETED[@]}) != 0 ]]; then + function_check app_is_installed + if [[ "$(app_is_installed $a)" == "1" ]]; then + APPS_COMPLETED+=("${app_name}") + function_check restore_local_${app_name} + restore_local_${app_name} + fi + fi + fi + done } get_restore_app ${2} diff --git a/src/freedombone-restore-remote b/src/freedombone-restore-remote index 2050d2fc..5d1129d4 100755 --- a/src/freedombone-restore-remote +++ b/src/freedombone-restore-remote @@ -179,12 +179,13 @@ function restore_configuration { fi if [ -d $SERVER_DIRECTORY/backup/config ]; then echo $"Restoring configuration files" - restore_directory_from_friend /root/tempconfig config + temp_restore_dir=/root/tempconfig + restore_directory_from_friend $temp_restore_dir config - cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE + cp -f $temp_restore_dir/root/${PROJECT_NAME}.cfg $CONFIG_FILE if [ ! "$?" = "0" ]; then unmount_drive - rm -rf /root/tempconfig + rm -rf $temp_restore_dir exit 5372 fi if [ -f $CONFIG_FILE ]; then @@ -192,28 +193,28 @@ function restore_configuration { freedombone -c $CONFIG_FILE fi - cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE + cp -f $temp_restore_dir/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE if [ ! "$?" = "0" ]; then unmount_drive - rm -rf /root/tempconfig + rm -rf $temp_restore_dir exit 7252 fi - if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then - cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} + if [ -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ]; then + cp -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} if [ ! "$?" = "0" ]; then unmount_drive - rm -rf /root/tempconfig + rm -rf $temp_restore_dir exit 62121 fi fi # restore nginx password hashes - if [ -f /root/tempconfig/root/htpasswd ]; then - cp -f /root/tempconfig/root/htpasswd /etc/nginx/.htpasswd + if [ -f $temp_restore_dir/root/htpasswd ]; then + cp -f $temp_restore_dir/root/htpasswd /etc/nginx/.htpasswd fi - rm -rf /root/tempconfig + rm -rf $temp_restore_dir fi } @@ -225,19 +226,20 @@ function restore_mariadb { fi if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then echo $"Restoring MariaDB settings" - restore_directory_from_friend /root/tempmariadb mariadb + temp_restore_dir=/root/tempmariadb + restore_directory_from_friend $temp_restore_dir mariadb echo $"Get the MariaDB password from the backup" - if [ ! -f /root/tempmariadb/root/tempmariadb/db ]; then + if [ ! -f ${temp_restore_dir}${temp_restore_dir}/db ]; then echo $"MariaDB password file not found" exit 495 fi - BACKUP_MARIADB_PASSWORD=$(cat /root/tempmariadb/root/tempmariadb/db) + BACKUP_MARIADB_PASSWORD=$(cat ${temp_restore_dir}${temp_restore_dir}/db) if [[ "$BACKUP_MARIADB_PASSWORD" != "$DATABASE_PASSWORD" ]]; then echo $"Restore the MariaDB user table" - mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) + mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql) if [ ! "$?" = "0" ]; then echo $"Try again using the password obtained from backup" - mysqlsuccess=$(mysql -u root --password="$BACKUP_MARIADB_PASSWORD" mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) + mysqlsuccess=$(mysql -u root --password="$BACKUP_MARIADB_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql) fi if [ ! "$?" = "0" ]; then echo "$mysqlsuccess" @@ -248,8 +250,8 @@ function restore_mariadb { echo $"Change the MariaDB password to the backup version" DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD fi - shred -zu /root/tempmariadb/root/tempmariadb/db - rm -rf /root/tempmariadb + shred -zu ${temp_restore_dir}${temp_restore_dir}/db + rm -rf ${temp_restore_dir} # Change database password file echo "$DATABASE_PASSWORD" > /root/dbpass @@ -295,18 +297,19 @@ function restore_mutt_settings { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring Mutt settings for $USERNAME" - restore_directory_from_friend /root/tempmutt mutt/$USERNAME - if [ -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc ]; then - cp -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc + temp_restore_dir=/root/tempmutt + restore_directory_from_friend ${temp_restore_dir} mutt/$USERNAME + if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc ]; then + cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc fi - if [ -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc ]; then - cp -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc + if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc ]; then + cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc fi if [ ! "$?" = "0" ]; then - rm -rf /root/tempmutt + rm -rf ${temp_restore_dir} exit 276 fi - rm -rf /root/tempmutt + rm -rf ${temp_restore_dir} fi fi done @@ -326,13 +329,14 @@ function restore_gpg { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring gnupg settings for $USERNAME" - restore_directory_from_friend /root/tempgnupg gnupg/$USERNAME - cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/ + temp_restore_dir=/root/tempgnupg + restore_directory_from_friend ${temp_restore_dir} gnupg/$USERNAME + cp -r ${temp_restore_dir}/home/$USERNAME/.gnupg /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempgnupg + rm -rf ${temp_restore_dir} exit 276 fi - rm -rf /root/tempgnupg + rm -rf ${temp_restore_dir} if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then cp -r /home/$USERNAME/.gnupg /root if [ ! "$?" = "0" ]; then @@ -358,13 +362,14 @@ function restore_procmail { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring procmail settings for $USERNAME" - restore_directory_from_friend /root/tempprocmail procmail/$USERNAME - cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/ + temp_restore_dir=/root/tempprocmail + restore_directory_from_friend ${temp_restore_dir} procmail/$USERNAME + cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempprocmail + rm -rf ${temp_restore_dir} exit 276 fi - rm -rf /root/tempprocmail + rm -rf ${temp_restore_dir} fi fi done @@ -384,13 +389,14 @@ function restore_spamassassin { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring spamassassin settings for $USERNAME" - restore_directory_from_friend /root/tempspamassassin spamassassin/$USERNAME - cp -rf /root/tempspamassassin/home/$USERNAME/.spamassassin /home/$USERNAME/ + temp_restore_dir=/root/tempspamassassin + restore_directory_from_friend $temp_restore_dir spamassassin/$USERNAME + cp -rf $temp_restore_dir/home/$USERNAME/.spamassassin /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempspamassassin + rm -rf $temp_restore_dir exit 276 fi - rm -rf /root/tempspamassassin + rm -rf $temp_restore_dir fi fi done @@ -404,13 +410,14 @@ function restore_admin_readme { fi if [ -d $SERVER_DIRECTORY/backup/readme ]; then echo $"Restoring README" - restore_directory_from_friend /root/tempreadme readme - cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ + temp_restore_dir=/root/tempreadme + restore_directory_from_friend $temp_restore_dir readme + cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempreadme + rm -rf $temp_restore_dir exit 276 fi - rm -rf /root/tempreadme + rm -rf $temp_restore_dir fi } @@ -422,13 +429,14 @@ function restore_ipfs { fi if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then echo $"Restoring IPFS" - restore_directory_from_friend /root/tempipfs ipfs - cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs + temp_restore_dir=/root/tempipfs + restore_directory_from_friend $temp_restore_dir ipfs + cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs if [ ! "$?" = "0" ]; then - rm -rf /root/tempipfs + rm -rf $temp_restore_dir exit 276 fi - rm -rf /root/tempipfs + rm -rf $temp_restore_dir fi } @@ -446,13 +454,14 @@ function restore_ssh_keys { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring ssh keys for $USERNAME" - restore_directory_from_friend /root/tempssh ssh/$USERNAME - cp -r /root/tempssh/home/$USERNAME/.ssh /home/$USERNAME/ + temp_restore_dir=/root/tempssh + restore_directory_from_friend $temp_restore_dir ssh/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.ssh /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempssh + rm -rf $temp_restore_dir exit 664 fi - rm -rf /root/tempssh + rm -rf $temp_restore_dir fi fi done @@ -472,13 +481,14 @@ function restore_user_config { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring config files for $USERNAME" - restore_directory_from_friend /root/tempconfig config/$USERNAME - cp -r /root/tempconfig/home/$USERNAME/.config /home/$USERNAME/ + temp_restore_dir=/root/tempconfig + restore_directory_from_friend $temp_restore_dir config/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.config /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempconfig + rm -rf $temp_restore_dir exit 664 fi - rm -rf /root/tempconfig + rm -rf $temp_restore_dir fi fi done @@ -510,13 +520,14 @@ function restore_user_monkeysphere { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring monkeysphere ids for $USERNAME" - restore_directory_from_friend /root/tempmonkeysphere monkeysphere/$USERNAME - cp -r /root/tempmonkeysphere/home/$USERNAME/.monkeysphere /home/$USERNAME/ + temp_restore_dir=/root/tempmonkeysphere + restore_directory_from_friend $temp_restore_dir monkeysphere/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.monkeysphere /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempmonkeysphere + rm -rf $temp_restore_dir exit 664 fi - rm -rf /root/tempmonkeysphere + rm -rf $temp_restore_dir fi fi @@ -546,13 +557,14 @@ function restore_user_fin { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring fin files for $USERNAME" - restore_directory_from_friend /root/tempfin fin/$USERNAME - cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ + temp_restore_dir=/root/tempfin + restore_directory_from_friend $temp_restore_dir fin/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.fin /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempfin + rm -rf $temp_restore_dir exit 664 fi - rm -rf /root/tempfin + rm -rf $temp_restore_dir fi fi done @@ -572,13 +584,14 @@ function restore_user_local { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring local files for $USERNAME" - restore_directory_from_friend /root/templocal local/$USERNAME - cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/ + temp_restore_dir=/root/templocal + restore_directory_from_friend $temp_restore_dir local/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/.local /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/templocal + rm -rf $temp_restore_dir exit 664 fi - rm -rf /root/templocal + rm -rf $temp_restore_dir fi fi done @@ -639,15 +652,16 @@ function restore_personal_settings { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring personal settings for $USERNAME" - restore_directory_from_friend /root/temppersonal personal/$USERNAME + temp_restore_dir=/root/temppersonal + restore_directory_from_friend $temp_restore_dir personal/$USERNAME if [ -d /home/$USERNAME/personal ]; then rm -rf /home/$USERNAME/personal fi - mv /root/temppersonal/home/$USERNAME/personal /home/$USERNAME + mv $temp_restore_dir/home/$USERNAME/personal /home/$USERNAME if [ ! "$?" = "0" ]; then exit 184 fi - rm -rf /root/temppersonal + rm -rf $temp_restore_dir fi fi done @@ -661,12 +675,13 @@ function restore_mailing_list { fi if [ -d /var/spool/mlmmj ]; then echo $"Restoring public mailing list" - restore_directory_from_friend /root/tempmailinglist mailinglist - cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj + temp_restore_dir=/root/tempmailinglist + restore_directory_from_friend $temp_restore_dir mailinglist + cp -r $temp_restore_dir/root/spool/mlmmj/* /var/spool/mlmmj if [ ! "$?" = "0" ]; then exit 526 fi - rm -rf /root/tempmailinglist + rm -rf $temp_restore_dir fi } @@ -678,12 +693,13 @@ function restore_xmpp { fi if [ -d /var/lib/prosody ]; then echo $"Restoring XMPP settings" - restore_directory_from_friend /root/tempxmpp xmpp - cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody + temp_restore_dir=/root/tempxmpp + restore_directory_from_friend $temp_restore_dir xmpp + cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody if [ ! "$?" = "0" ]; then exit 725 fi - rm -rf /root/tempxmpp + rm -rf $temp_restore_dir service prosody restart chown -R prosody:prosody /var/lib/prosody/* fi @@ -767,28 +783,30 @@ function restore_syncthing { if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then echo $"Restoring syncthing configuration" - restore_directory_from_friend /root/tempsyncthingconfig syncthingconfig - cp -r /root/tempsyncthingconfig/* / + temp_restore_dir=/root/tempsyncthingconfig + restore_directory_from_friend $temp_restore_dir syncthingconfig + cp -r $temp_restore_dir/* / if [ ! "$?" = "0" ]; then unmount_drive systemctl start syncthing systemctl start cron exit 6833 fi - rm -rf /root/tempsyncthingconfig + rm -rf $temp_restore_dir fi if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then echo $"Restoring syncthing shared files" - restore_directory_from_friend /root/tempsyncthingshared syncthingshared - cp -r /root/tempsyncthingshared/* / + temp_restore_dir=/root/tempsyncthingshared + restore_directory_from_friend $temp_restore_dir syncthingshared + cp -r $temp_restore_dir/* / if [ ! "$?" = "0" ]; then unmount_drive systemctl start syncthing systemctl start cron exit 37904 fi - rm -rf /root/tempsyncthingshared + rm -rf $temp_restore_dir fi if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then @@ -799,16 +817,17 @@ function restore_syncthing { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring syncthing files for $USERNAME" - restore_directory_from_friend /root/tempsyncthing syncthing/$USERNAME - cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/ + temp_restore_dir=/root/tempsyncthing + restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME + cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempsyncthing + rm -rf $temp_restore_dir unmount_drive systemctl start syncthing systemctl start cron exit 68438 fi - rm -rf /root/tempsyncthing + rm -rf $temp_restore_dir # restore device IDs from config settings if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then @@ -839,12 +858,13 @@ function restore_mediagoblin { MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then echo $"Restoring Mediagoblin installation" - restore_directory_from_friend /root/tempmediagoblin mediagoblin - cp -r /root/tempmediagoblin/* / + temp_restore_dir=/root/tempmediagoblin + restore_directory_from_friend $temp_restore_dir mediagoblin + cp -r $temp_restore_dir/* / if [ ! "$?" = "0" ]; then exit 5626 fi - rm -rf /root/tempmediagoblin + rm -rf $temp_restore_dir fi chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs fi @@ -940,14 +960,15 @@ function restore_blog { if [ -d $SERVER_DIRECTORY/backup/blog ]; then FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME" - mkdir /root/tempblog - restore_directory_from_friend /root/tempblog blog + temp_restore_dir=/root/tempblog + mkdir $temp_restore_dir + restore_directory_from_friend $temp_restore_dir blog rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs - cp -r /root/tempblog/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/ + cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/ if [ ! "$?" = "0" ]; then exit 593 fi - rm -rf /root/tempblog + rm -rf $temp_restore_dir if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then echo $"No content directory found after restoring blog" exit 287 @@ -978,13 +999,14 @@ function restore_cjdns { fi if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then echo $"Restoring cjdns installation" - restore_directory_from_friend /root/tempcjdns cjdns + temp_restore_dir=/root/tempcjdns + restore_directory_from_friend $temp_restore_dir cjdns rm -rf /etc/cjdns - cp -r /root/tempcjdns/etc/cjdns /etc/ + cp -r $temp_restore_dir/etc/cjdns /etc/ if [ ! "$?" = "0" ]; then exit 7438 fi - rm -rf /root/tempcjdns + rm -rf $temp_restore_dir fi } @@ -996,23 +1018,24 @@ function restore_voip { fi if [ -d $SERVER_DIRECTORY/backup/voip ]; then echo $"Restoring VoIP settings" - restore_directory_from_friend /root/tempvoip voip - cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/ + temp_restore_dir=/root/tempvoip + restore_directory_from_friend $temp_restore_dir voip + cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempvoip + rm -rf $temp_restore_dir exit 7823 fi - cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf + cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf if [ ! "$?" = "0" ]; then - rm -rf /root/tempvoip + rm -rf $temp_restore_dir exit 7823 fi - cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/ + cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/ if [ ! "$?" = "0" ]; then - rm -rf /root/tempvoip + rm -rf $temp_restore_dir exit 276 fi - rm -rf /root/tempvoip + rm -rf $temp_restore_dir cp /etc/ssl/certs/mumble* /var/lib/mumble-server cp /etc/ssl/private/mumble* /var/lib/mumble-server chown -R mumble-server:mumble-server /var/lib/mumble-server @@ -1056,15 +1079,16 @@ function restore_email { ${PROJECT_NAME}-adduser $USERNAME fi echo $"Restoring emails for $USERNAME" - restore_directory_from_friend /root/tempmail mail/$USERNAME + temp_restore_dir=/root/tempmail + restore_directory_from_friend $temp_restore_dir mail/$USERNAME if [ ! -d /home/$USERNAME/Maildir ]; then mkdir /home/$USERNAME/Maildir fi - tar -xzvf /root/tempmail/root/tempbackupemail/$USERNAME/maildir.tar.gz -C / + tar -xzvf $temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz -C / if [ ! "$?" = "0" ]; then exit 927 fi - rm -rf /root/tempmail + rm -rf $temp_restore_dir fi fi done @@ -1079,12 +1103,13 @@ function restore_dlna { if [ -d /var/cache/minidlna ]; then if [ -d $SERVER_DIRECTORY/backup/dlna ]; then echo $"Restoring DLNA cache" - restore_directory_from_friend /root/tempdlna dlna - cp -r /root/tempdlna/var/cache/minidlna/* /var/cache/minidlna/ + temp_restore_dir=/root/tempdlna + restore_directory_from_friend $temp_restore_dir dlna + cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/ if [ ! "$?" = "0" ]; then exit 982 fi - rm -rf /root/tempdlna + rm -rf $temp_restore_dir fi fi }