Restore from friend command

This commit is contained in:
Bob Mottram 2015-12-08 15:50:34 +00:00
parent 85291853ad
commit 4454206e76
4 changed files with 648 additions and 951 deletions

View File

@ -22,6 +22,7 @@ install:
install -m 755 src/${APP}-backup-local ${DESTDIR}${PREFIX}/bin/backup
install -m 755 src/${APP}-backup-local ${DESTDIR}${PREFIX}/bin/backup2friends
install -m 755 src/${APP}-restore-local ${DESTDIR}${PREFIX}/bin/restore
install -m 755 src/${APP}-restore-local ${DESTDIR}${PREFIX}/bin/restorefromfriend
mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1
install -m 644 man/*.1.gz ${DESTDIR}${PREFIX}/share/man/man1
bash -c "./translate install"
@ -34,6 +35,7 @@ uninstall:
rm -f ${PREFIX}/bin/backup
rm -f ${PREFIX}/bin/backup2friends
rm -f ${PREFIX}/bin/restore
rm -f ${PREFIX}/bin/restorefromfriend
rm -f ${PREFIX}/bin/meshweb
rm -rf /etc/freedombone
bash -c "./translate uninstall"

Binary file not shown.

View File

@ -264,18 +264,6 @@ BACKUP_TYPE='obnam'
# Number of days to keep backups for
BACKUP_MAX_DAYS=30
# Name of a script used to create a backup of the system on usb drive
BACKUP_SCRIPT_NAME="backup"
# Name of a script used to restore the system from usb drive
RESTORE_SCRIPT_NAME="restore"
# name of a script used to backup to friends servers
BACKUP_TO_FRIENDS_SCRIPT_NAME="backup2friends"
# name of a script used to restore backed up data from a friend
RESTORE_FROM_FRIEND_SCRIPT_NAME="restorefromfriend"
# Location of the certificate used to encrypt backups
BACKUP_CERTIFICATE=/etc/ssl/private/backup.key
@ -2734,80 +2722,6 @@ function get_mariadb_owncloud_admin_password {
fi
}
function backup_directory_to_usb {
echo 'function backup_directory_to_usb {' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [ ! -d ${1} ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "WARNING: directory does not exist: ${1}"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' else' >> /usr/bin/$BACKUP_SCRIPT_NAME
if [[ $BACKUP_TYPE == 'obnam' ]]; then
echo ' BACKUP_KEY_EXISTS=$(gpg --list-keys "$MY_NAME (backup key)")' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "Backup key could not be found"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' exit 43382' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n ' MY_BACKUP_KEY_ID=$(gpg --list-keys "$MY_NAME (backup key)" ' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n "| grep 'pub ' | awk -F ' ' '{print " >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n '$2' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n "}' | awk -F '/' '{print " >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n '$2' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "}')" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n " obnam forget --keep=${BACKUP_MAX_DAYS}d " >> /usr/bin/$BACKUP_SCRIPT_NAME
echo '-r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID' >> /usr/bin/$BACKUP_SCRIPT_NAME
else
# For rsyncrypto usage see http://archive09.linux.com/feature/125322
echo " BACKUP_CERTIFICATE=$BACKUP_CERTIFICATE" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rsyncrypto -v -r ${1} $USB_MOUNT/backup/${2} $USB_MOUNT/backup/${2}.keys $BACKUP_CERTIFICATE' >> /usr/bin/$BACKUP_SCRIPT_NAME
fi
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' shred -zu ${1}/*' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rm -rf ${1}' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' exit 853' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' shred -zu ${1}/*' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rm -rf ${1}' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo '}' >> /usr/bin/$BACKUP_SCRIPT_NAME
}
function backup_database {
echo '' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'function backup_database {' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [ ! -d $USB_MOUNT/backup/${1} ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' mkdir -p $USB_MOUNT/backup/${1}' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [ ! -d $USB_MOUNT/backup/${1}data ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' mkdir -p $USB_MOUNT/backup/${1}data' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [ ! -d /root/temp${1}data ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' mkdir -p /root/temp${1}data' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "Obtaining ${1} database backup"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n ' mysqldump --password=$DATABASE_PASSWORD ' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo '${1} > /root/temp${1}data/${1}.sql' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [ ! -s /root/temp${1}data/${1}.sql ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "${1} database could not be saved"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' if [ ! $DATABASE_PASSWORD ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "No MariaDB password was given"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' shred -zu /root/temp${1}data/*' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rm -rf /root/temp${1}data' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' exit 296' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo '}' >> /usr/bin/$BACKUP_SCRIPT_NAME
}
function restore_directory_from_usb {
script_name=$1
echo 'function restore_directory_from_usb {' >> $script_name
@ -3136,870 +3050,6 @@ function backup_to_friends_servers {
echo 'backup_to_friends_servers' >> $COMPLETION_FILE
}
function restore_directory_from_friend {
echo 'function restore_directory_from_friend {' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d ${1} ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' mkdir ${1}' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
if [[ $BACKUP_TYPE == 'obnam' ]]; then
echo -n ' obnam restore -r $SERVER_DIRECTORY/backup/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '${2} --to ${1}' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
else
echo " BACKUP_CERTIFICATE=$BACKUP_CERTIFICATE" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' rsyncrypto -v -d -r $SERVER_DIRECTORY/backup/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '${2} ${1} ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '$SERVER_DIRECTORY/backup/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '${2}.keys $BACKUP_CERTIFICATE' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
fi
echo '}' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
}
function restore_database_from_friend {
echo 'function restore_database_from_friend {' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " DATABASE_PASSWORD=$DATABASE_PASSWORD" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
if [[ $BACKUP_TYPE == 'obnam' ]]; then
echo ' RESTORE_SUBDIR="root"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
else
echo ' RESTORE_SUBDIR="remoterestore/backup/${1}data"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
fi
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/${1} ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring ${1} database"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/temp${1}data ${1}data' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Unable to restore ${1} database"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/temp${1}data' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 503' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "$mysqlsuccess"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 964' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/temp${1}data' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring ${1} installation"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/temp${1} ${1}' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
if [[ $BACKUP_TYPE == 'obnam' ]]; then
echo ' RESTORE_SUBDIR="var"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
else
echo ' RESTORE_SUBDIR="remoterestore/backup/${1}"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
fi
echo ' if [ ${1} ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d /var/www/${2}/htdocs ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /var/www/${2}/htdocs' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 683' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d /etc/letsencrypt/live/${2} ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' else' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' # Ensure that the bundled SSL cert is being used' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '}' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
}
function restore_from_friend {
if grep -Fxq "restore_from_friend" $COMPLETION_FILE; then
return
fi
apt-get -y install rsyncrypto sshpass obnam
get_mariadb_password
get_mariadb_gnusocial_admin_password
get_mariadb_hubzilla_admin_password
get_mariadb_owncloud_admin_password
get_mariadb_git_admin_password
if ! grep -q "restore from a friend's server" /home/$MY_USERNAME/README; then
echo '' >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README
echo 'Restoring from backups to friends servers' >> /home/$MY_USERNAME/README
echo '=========================================' >> /home/$MY_USERNAME/README
echo "To restore from a friend's server use the command:" >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README
echo " $RESTORE_FROM_FRIEND_SCRIPT_NAME [server]" >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
chmod 600 /home/$MY_USERNAME/README
fi
echo '#!/bin/bash' > /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'SERVER_NAME=$1' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "COMPLETION_FILE=$COMPLETION_FILE" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n 'ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n"awk -F ':' '{print " >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n'$2' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "}')" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'MY_USERNAME=$ADMIN_USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '# Temporary location for data to be backed up to other servers' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'SERVER_DIRECTORY=/root/remoterestore' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'if [ ! $SERVER_NAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " echo '$RESTORE_FROM_FRIEND_SCRIPT_NAME [server]'" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 1' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "if [ ! -f $FRIENDS_SERVERS_LIST ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " echo 'No friends list found at $FRIENDS_SERVERS_LIST'" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 2' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n 'if ! grep -q "$SERVER_NAME" ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$FRIENDS_SERVERS_LIST; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Server not found within the friends list"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 3' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n 'REMOTE_SERVER=$(grep -i "$SERVER_NAME" ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n "$FRIENDS_SERVERS_LIST | awk -F ' ' '{print " >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '$1' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "}')" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n 'REMOTE_SSH_PORT=$(grep -i "$SERVER_NAME" ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n "$FRIENDS_SERVERS_LIST | awk -F ' ' '{print " >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '$2' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "}')" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n 'REMOTE_PASSWORD=$(grep -i "$SERVER_NAME" ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n "$FRIENDS_SERVERS_LIST | awk -F ' ' '{print " >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '$3' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "}')" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '# Check that a backup key exists' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "if [ ! -f $BACKUP_CERTIFICATE ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " echo 'No backup key was found in $BACKUP_CERTIFICATE'" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 84' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
# Rsync from the remote server back to this server
echo 'NOW=$(date +"%Y-%m-%d %H:%M:%S")' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n 'echo "$NOW Starting restore from $REMOTE_SERVER" >> ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$REMOTE_BACKUPS_LOG" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n 'rsync -ratlzv --rsh="/usr/bin/sshpass -p $REMOTE_PASSWORD ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$REMOTE_SERVER/backup $SERVER_DIRECTORY' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' echo "$NOW Restore from $REMOTE_SERVER failed" >> ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$REMOTE_BACKUPS_LOG" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' # Send a warning email' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' echo "Restore from $REMOTE_SERVER failed" | mail -s "Freedombone restore from friend" ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$MY_EMAIL_ADDRESS" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 790' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'else' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$REMOTE_BACKUPS_LOG" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '# MariaDB password' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n 'DATABASE_PASSWORD=$(cat ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$DATABASE_PASSWORD_FILE)" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
restore_directory_from_friend
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
restore_database_from_friend
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='root/'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/mariadb/'
fi
echo ' echo "Restoring mysql settings"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempmariadb mariadb' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Get the MariaDB password from the backup"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " if [ ! -f /root/tempmariadb/${RESTORE_SUBDIR}tempmariadb/db ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "MariaDB password file not found"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 495' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' BACKUP_MARIADB_PASSWORD=$(cat /root/tempmariadb/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "${RESTORE_SUBDIR}tempmariadb/db)" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $BACKUP_MARIADB_PASSWORD != $DATABASE_PASSWORD ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restore the MariaDB user table"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD mysql -o < ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "/root/tempmariadb/${RESTORE_SUBDIR}tempmariadb/mysql.sql)" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Try again using the password obtained from backup"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' mysqlsuccess=$(mysql -u root --password=$BACKUP_MARIADB_PASSWORD mysql -o < ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "/root/tempmariadb/${RESTORE_SUBDIR}tempmariadb/mysql.sql)" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "$mysqlsuccess"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 962' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restarting database"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' service mysql restart' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Change the MariaDB password to the backup version"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " shred -zu /root/tempmariadb/${RESTORE_SUBDIR}tempmariadb/db" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempmariadb' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' # Change database password file' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n ' echo "$DATABASE_PASSWORD" > ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$DATABASE_PASSWORD_FILE" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " chmod 600 $DATABASE_PASSWORD_FILE" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home/'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/letsencrypt/'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/letsencrypt ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring Lets Encrypt settings"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend / letsencrypt' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home/'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/mutt/'
fi
echo 'for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring Mutt settings for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempmutt mutt/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " if [ -f /root/tempmutt/${RESTORE_SUBDIR}" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/tempbackup/.muttrc ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -f /root/tempmutt/${RESTORE_SUBDIR}" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " if [ -f /root/tempmutt/${RESTORE_SUBDIR}" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/tempbackup/Muttrc ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -f /root/tempmutt/${RESTORE_SUBDIR}" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/tempbackup/Muttrc /etc/Muttrc' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempmutt' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 276' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempmutt' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/gnupg'
fi
echo 'for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring gnupg settings for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempgnupg gnupg/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -r /root/tempgnupg/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/.gnupg /home/$USERNAME/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempgnupg' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 276' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempgnupg' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ "$USERNAME" == "$MY_USERNAME" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' cp -r /home/$USERNAME/.gnupg /root' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 283' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/procmail'
fi
echo 'for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring procmail settings for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempprocmail procmail/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -f /root/tempprocmail/${RESTORE_SUBDIR}" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempprocmail' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 276' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempprocmail' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/spamassassin'
fi
echo 'for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring spamassassin settings for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempspamassassin spamassassin/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -rf /root/tempspamassassin/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/.spamassassin /home/$USERNAME/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempspamassassin' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 276' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempspamassassin' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/readme'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/readme ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring README"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempreadme readme' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -f /root/tempreadme/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$MY_USERNAME/tempbackup/README /home/$MY_USERNAME/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempreadme' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 276' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempreadme' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/ipfs'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring IPFS"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempipfs ipfs' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -rf /root/tempipfs/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$MY_USERNAME/.ipfs/* /home/$MY_USERNAME/.ipfs' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempipfs' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 276' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempipfs' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/ssh'
fi
echo 'for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring ssh keys for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempssh ssh/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -r /root/tempssh/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/.ssh /home/$USERNAME/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempssh' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 664' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempssh' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/config'
fi
echo 'for d in $SERVER_DIRECTORY/backup/config/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/config/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring config files for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempconfig config/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -r /root/tempconfig/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/.config /home/$USERNAME/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempconfig' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 664' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempconfig' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='etc'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/ssl'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/ssl ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring certificates"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempssl ssl' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -r /root/tempssl/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'ssl/* /etc/ssl' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 276' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempssl' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/projects'
fi
echo 'for d in $SERVER_DIRECTORY/backup/projects/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/projects/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring projects for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempprojects projects/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d /home/$USERNAME/projects ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /home/$USERNAME/projects' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " mv /root/tempprojects/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/projects /home/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 166' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempprojects' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/personal'
fi
echo 'for d in $SERVER_DIRECTORY/backup/personal/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring personal settings for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/temppersonal personal/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d /home/$USERNAME/personal ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /home/$USERNAME/personal' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " mv /root/temppersonal/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/personal /home/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 184' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/temppersonal' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='root'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/mailinglist'
fi
echo "if [ -d $PUBLIC_MAILING_LIST_DIRECTORY ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring public mailing list"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempmailinglist mailinglist' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " cp -r /root/tempmailinglist/${RESTORE_SUBDIR}/spool/mlmmj/* $PUBLIC_MAILING_LIST_DIRECTORY" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 526' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempmailinglist' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='var'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/xmpp'
fi
echo "if [ -d $XMPP_DIRECTORY ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring XMPP settings"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempxmpp xmpp' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " cp -r /root/tempxmpp/${RESTORE_SUBDIR}/lib/prosody/* $XMPP_DIRECTORY" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 725' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempxmpp' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' service prosody restart' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' chown -R prosody:prosody /var/lib/prosody/*' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
BACKUP_INCLUDES_WEBSITES="no"
if grep -Fxq "install_gnu_social" $COMPLETION_FILE; then
BACKUP_INCLUDES_WEBSITES="yes"
echo "restore_database_from_friend gnusocial $MICROBLOG_DOMAIN_NAME" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "if [ -d /root/tempgnusocial ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " rm -rf /root/tempgnusocial" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "fi" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
fi
if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
BACKUP_INCLUDES_WEBSITES="yes"
echo "restore_database_from_friend hubzilla $HUBZILLA_DOMAIN_NAME" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'if [ -d $SERVER_DIRECTORY/backup/hubzilla ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/store/[data]/smarty3 ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " mkdir -p /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/store/[data]/smarty3" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " chmod 777 /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/store/[data]/smarty3" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " chown -R www-data:www-data /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/*" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "if [ -d /root/temphubzilla ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " rm -rf /root/temphubzilla" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "fi" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
fi
if grep -Fxq "install_owncloud" $COMPLETION_FILE; then
BACKUP_INCLUDES_WEBSITES="yes"
echo "restore_database_from_friend owncloud $OWNCLOUD_DOMAIN_NAME" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='var'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/owncloud'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/owncloud ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring Owncloud installation"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " cp -r /root/tempowncloud/${RESTORE_SUBDIR}/lib/owncloud/* /var/lib/owncloud/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 981' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'restore_directory_from_friend /root/tempowncloud2 owncloud2' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='etc'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/owncloud2'
fi
echo " cp -r /root/tempowncloud2/${RESTORE_SUBDIR}/owncloud/* /etc/owncloud/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 982' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempowncloud' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempowncloud2' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' chown -R www-data:www-data /var/lib/owncloud/data' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' chown -R www-data:www-data /var/lib/owncloud/backup' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' chown -R www-data:www-data /var/lib/owncloud/assets' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' for d in /home/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' occ files:scan $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " ln -s /usr/share/owncloud /var/www/$OWNCLOUD_DOMAIN_NAME/htdocs" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
fi
if grep -Fxq "install_gogs" $COMPLETION_FILE; then
BACKUP_INCLUDES_WEBSITES="yes"
echo "restore_database_from_friend gogs $GIT_DOMAIN_NAME" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/gogs'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/gogs ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/git/go/src/github.com/gogits/gogs/custom ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' mkdir -p /home/git/go/src/github.com/gogits/gogs/custom' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " cp -r /root/tempgogs/${RESTORE_SUBDIR}/git/go/src/github.com/gogits/gogs/custom/* /home/git/go/src/github.com/gogits/gogs/custom/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 5885' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring Gogs repos"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempgogsrepos gogsrepos' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/gogsrepos'
fi
echo " cp -r /root/tempgogsrepos/${RESTORE_SUBDIR}/git/gogs-repositories/* /home/git/gogs-repositories/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 7649' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring Gogs authorized_keys"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempgogsssh gogsssh' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/git/.ssh ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' mkdir /home/git/.ssh' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/gogsssh'
fi
echo " cp -r /root/tempgogsssh/${RESTORE_SUBDIR}/git/.ssh/* /home/git/.ssh/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 74239' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempgogs' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempgogsrepos' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempgogsssh' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' chown -R git:git /home/git' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
fi
RESTORE_SUBDIR='var'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/wiki'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/wiki ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring Wiki installation"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempwiki wiki' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " cp -r /root/tempwiki/${RESTORE_SUBDIR}/lib/dokuwiki/* /var/lib/dokuwiki/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 868' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempwiki2 wiki2' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='etc'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/wiki2'
fi
echo " cp -r /root/tempwiki2/${RESTORE_SUBDIR}/dokuwiki/* /etc/dokuwiki/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 869' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempwiki' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempwiki2' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' chown -R www-data:www-data /var/lib/dokuwiki/*' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' # Ensure that the bundled SSL cert is being used' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " if [ -f /etc/ssl/certs/$WIKI_DOMAIN_NAME.bundle.crt ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " sed -i 's|$WIKI_DOMAIN_NAME.crt|$WIKI_DOMAIN_NAME.bundle.crt|g' /etc/nginx/sites-available/$WIKI_DOMAIN_NAME" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='var'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/blog'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/blog ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring blog installation"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' mkdir /root/tempblog' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempblog blog' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " rm -rf /var/www/$FULLBLOG_DOMAIN_NAME/htdocs" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " cp -r /root/tempblog/${RESTORE_SUBDIR}/www/$FULLBLOG_DOMAIN_NAME/htdocs /var/www/$FULLBLOG_DOMAIN_NAME/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 593' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempblog' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " if [ ! -d /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/content ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "No content directory found after restoring blog"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 287' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' # Ensure that the bundled SSL cert is being used' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " if [ -f /etc/ssl/certs/$FULLBLOG_DOMAIN_NAME.bundle.crt ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " sed -i 's|$FULLBLOG_DOMAIN_NAME.crt|$FULLBLOG_DOMAIN_NAME.bundle.crt|g' /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' for d in /home/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " if [ -d /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/content" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '/$USERNAME/blog/uncategorized/post ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " mv /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/content" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '/$USERNAME/blog/*.md ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n "/var/www/$FULLBLOG_DOMAIN_NAME/htdocs/content" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '/$USERNAME/blog/uncategorized/post ' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='etc'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/cjdns'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring cjdns installation"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempcjdns cjdns' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " rm -rf /etc/cjdns" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " cp -r /root/tempcjdns/${RESTORE_SUBDIR}/cjdns /etc/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 7438' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempcjdns' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='home'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/voip'
fi
echo 'if [ -d $SERVER_DIRECTORY/backup/voip ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring VoIP settings"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempvoip voip' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -f /root/tempvoip/${RESTORE_SUBDIR}" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '/$MY_USERNAME/tempbackup/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$VOIP_CONFIG_FILE /etc/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempvoip' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 7823' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -f /root/tempvoip/${RESTORE_SUBDIR}" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '/$MY_USERNAME/tempbackup/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'sipwitch.conf /etc/sipwitch.conf' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempvoip' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 7823' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " cp -f /root/tempvoip/${RESTORE_SUBDIR}/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n '$MY_USERNAME/tempbackup/' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo "$VOIP_DATABASE /var/lib/mumble-server/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempvoip' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 276' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempvoip' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' cp /etc/ssl/certs/mumble* /var/lib/mumble-server' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' cp /etc/ssl/private/mumble* /var/lib/mumble-server' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' chown -R mumble-server:mumble-server /var/lib/mumble-server' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' service sipwitch restart' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' service mumble-server restart' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'if [ -d $SERVER_DIRECTORY/backup/tox ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring Tox node settings"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend / tox' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 93653' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' systemctl restart tox-bootstrapd.service' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' systemctl status tox-bootstrapd.service' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 59369' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='root'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/mail'
fi
echo 'for d in $SERVER_DIRECTORY/backup/mail/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $6}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' freedombone-adduser $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring emails for $USERNAME"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempmail mail/$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! -d /home/$USERNAME/Maildir ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' mkdir /home/$USERNAME/Maildir' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo -n " tar -xzvf /root/tempmail/${RESTORE_SUBDIR}/tempbackupemail/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '$USERNAME/maildir.tar.gz -C /' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 927' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempmail' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
RESTORE_SUBDIR='var'
if [[ $BACKUP_TYPE != 'obnam' ]]; then
RESTORE_SUBDIR='remoterestore/backup/dlna'
fi
echo "if [ -d /var/cache/minidlna ]; then" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ -d $SERVER_DIRECTORY/backup/dlna ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' echo "Restoring DLNA cache"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' restore_directory_from_friend /root/tempdlna dlna' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo " cp -r /root/tempdlna/${RESTORE_SUBDIR}/cache/minidlna/* /var/cache/minidlna/" >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' exit 982' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' rm -rf /root/tempdlna' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
if [[ $ENABLE_SOCIAL_KEY_MANAGEMENT == "yes" ]]; then
echo '' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo 'for d in /home/*/ ; do' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo ' # Retrieve key fragments for $USERNAME' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo -n ' /usr/bin/sshpass -p $REMOTE_PASSWORD ' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo -n "scp -r -P $REMOTE_SSH_PORT $REMOTE_SERVER/.gnupg_fragments_$USERNAME " >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo '/home/$USERNAME/' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' if [ -d /home/$USERNAME/.gnupg_fragments_$USERNAME ]; then' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' if [ -d /home/$USERNAME/.gnupg_fragments ]; then' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' cp /home/$USERNAME/.gnupg_fragments_$USERNAME/* /home/$USERNAME/.gnupg_fragments' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' rm -rf /home/$USERNAME/.gnupg_fragments_$USERNAME' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' else' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' mv /home/$USERNAME/.gnupg_fragments_$USERNAME /home/$USERNAME/.gnupg_fragments' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_FROM_FRIENDS_SCRIPT_NAME
fi
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'echo "*** Remote restore was successful ***"' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'exit 0' >> /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
chmod 400 /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
chmod +x /usr/bin/$RESTORE_FROM_FRIEND_SCRIPT_NAME
echo 'restore_from_friend' >> $COMPLETION_FILE
}
function remove_default_user {
# make sure you don't use the default user account
if [[ $MY_USERNAME == "debian" ]]; then
@ -10147,7 +9197,6 @@ install_mediagoblin
repair_databases_script
create_restore_hubzilla_script
backup_to_friends_servers
restore_from_friend
intrusion_detection
install_final
echo 'Freedombone installation is complete'

646
src/freedombone-restore-remote Executable file
View File

@ -0,0 +1,646 @@
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Restore from a given remote server
# License
# =======
#
# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROJECT_NAME='freedombone'
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
export TEXTDOMAIN=${PROJECT_NAME}-restore-local
export TEXTDOMAINDIR="/usr/share/locale"
SERVER_NAME=$1
ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | -nawk -F ':' '{print $2}')
ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
# Temporary location for data to be backed up to other servers
SERVER_DIRECTORY=/root/remoterestore
if [ ! $SERVER_NAME ]; then
echo $'restorefromfriend [server]'
exit 1
fi
if [ ! -f /home/${ADMIN_USERNAME}/backup.list ]; then
echo $"No friends list found at /home/${ADMIN_USERNAME}/backup.list"
exit 2
fi
if ! grep -q "$SERVER_NAME" /home/${ADMIN_USERNAME}/backup.list; then
echo $"Server not found within the friends list"
exit 3
fi
REMOTE_SERVER=$(grep -i "$SERVER_NAME" /home/${ADMIN_USERNAME}/backup.list | awk -F ' ' '{print $1}')
REMOTE_SSH_PORT=$(grep -i "$SERVER_NAME" /home/${ADMIN_USERNAME}/backup.list | awk -F ' ' '{print $2}')
REMOTE_PASSWORD=$(grep -i "$SERVER_NAME" /home/${ADMIN_USERNAME}/backup.list | awk -F ' ' '{print $3}')
# Check that a backup key exists
if [ ! -f /etc/ssl/private/backup.key ]; then
echo $'No backup key was found in /etc/ssl/private/backup.key'
exit 84
fi
NOW=$(date +"%Y-%m-%d %H:%M:%S")
echo "$NOW Starting restore from $REMOTE_SERVER" >> /var/log/remotebackups.log
rsync -ratlzv --rsh="/usr/bin/sshpass -p $REMOTE_PASSWORD ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" $REMOTE_SERVER/backup $SERVER_DIRECTORY
if [ ! "$?" = "0" ]; then
echo "$NOW Restore from $REMOTE_SERVER failed" >> /var/log/remotebackups.log
# Send a warning email
echo "Restore from $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} restore from friend" $ADMIN_EMAIL_ADDRESS
exit 790
else
echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> /var/log/remotebackups.log
fi
# MariaDB password
DATABASE_PASSWORD=$(cat /root/dbpass)
function restore_directory_from_friend {
if [ ! -d ${1} ]; then
mkdir ${1}
fi
obnam restore -r $SERVER_DIRECTORY/backup/${2} --to ${1}
}
function restore_database_from_friend {
DATABASE_PASSWORD=
RESTORE_SUBDIR="root"
if [ -d $SERVER_DIRECTORY/backup/${1} ]; then
echo $"Restoring ${1} database"
restore_directory_from_friend /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
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"
exit 964
fi
shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
rm -rf /root/temp${1}data
echo $"Restoring ${1} installation"
restore_directory_from_friend /root/temp${1} ${1}
RESTORE_SUBDIR="var"
if [ ${1} ]; then
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
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
}
# Restore MariaDB
if [ -d $SERVER_DIRECTORY/backup/mariadb ]; then
echo $"Restoring MariaDB settings"
restore_directory_from_friend /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"
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
# Change database password file
echo "$DATABASE_PASSWORD" > /root/dbpass
chmod 600 /root/dbpass
fi
# restore Let's Encrypt
if [ -d $SERVER_DIRECTORY/backup/letsencrypt ]; then
echo $"Restoring Lets Encrypt settings"
restore_directory_from_friend / letsencrypt
fi
# restore mutt settings
for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then
if [ -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then
${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
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
exit 276
fi
rm -rf /root/tempmutt
fi
fi
done
# restore user gpg keys
for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then
if [ -d $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then
${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/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempgnupg
exit 276
fi
rm -rf /root/tempgnupg
if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
cp -r /home/$USERNAME/.gnupg /root
if [ ! "$?" = "0" ]; then
exit 283
fi
fi
fi
fi
done
# restore user procmail
for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then
if [ -d $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then
${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/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempprocmail
exit 276
fi
rm -rf /root/tempprocmail
fi
fi
done
# Restore user spam settings
for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then
if [ -d $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then
${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/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempspamassassin
exit 276
fi
rm -rf /root/tempspamassassin
fi
fi
done
# Restore admin user README
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/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempreadme
exit 276
fi
rm -rf /root/tempreadme
fi
# restore IPFS
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
if [ ! "$?" = "0" ]; then
rm -rf /root/tempipfs
exit 276
fi
rm -rf /root/tempipfs
fi
# restore user ssh keys
for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then
if [ -d $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then
${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/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempssh
exit 664
fi
rm -rf /root/tempssh
fi
fi
done
# restore user config files
for d in $SERVER_DIRECTORY/backup/config/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then
if [ -d $SERVER_DIRECTORY/backup/config/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then
${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/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempconfig
exit 664
fi
rm -rf /root/tempconfig
fi
fi
done
# restore certs
if [ -d $SERVER_DIRECTORY/backup/ssl ]; then
echo $"Restoring certificates"
restore_directory_from_friend /root/tempssl ssl
cp -r /root/tempssl/etc/ssl/* /etc/ssl
if [ ! "$?" = "0" ]; then
exit 276
fi
rm -rf /root/tempssl
fi
# restore personal settings
for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then
if [ -d $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME
fi
echo $"Restoring personal settings for $USERNAME"
restore_directory_from_friend /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
exit 184
fi
rm -rf /root/temppersonal
fi
fi
done
# restore mailing list
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
if [ ! "$?" = "0" ]; then
exit 526
fi
rm -rf /root/tempmailinglist
fi
# restore XMPP
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
if [ ! "$?" = "0" ]; then
exit 725
fi
rm -rf /root/tempxmpp
service prosody restart
chown -R prosody:prosody /var/lib/prosody/*
fi
# restore gnu social
if grep -q "GNU Social domain" $COMPLETION_FILE; then
MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
restore_database_from_friend gnusocial ${MICROBLOG_DOMAIN_NAME}
if [ -d /root/tempgnusocial ]; then
rm -rf /root/tempgnusocial
fi
fi
# restore hubzilla
if grep -q "Hubzilla domain" $COMPLETION_FILE; then
HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
restore_database_from_friend hubzilla ${HUBZILLA_DOMAIN_NAME}
if [ -d $SERVER_DIRECTORY/backup/hubzilla ]; then
if [ ! -d /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 ]; then
mkdir -p /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
fi
chmod 777 /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
chown -R www-data:www-data /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/*
fi
if [ -d /root/temphubzilla ]; then
rm -rf /root/temphubzilla
fi
fi
# restore owncloud
if grep -q "Owncloud domain" $COMPLETION_FILE; then
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
restore_database_from_friend owncloud $OWNCLOUD_DOMAIN_NAME
if [ -d $SERVER_DIRECTORY/backup/owncloud ]; then
echo $"Restoring Owncloud installation"
cp -r /root/tempowncloud/var/lib/owncloud/* /var/lib/owncloud/
if [ ! "$?" = "0" ]; then
exit 981
fi
restore_directory_from_friend /root/tempowncloud2 owncloud2
cp -r /root/tempowncloud2/etc/owncloud/* /etc/owncloud/
if [ ! "$?" = "0" ]; then
exit 982
fi
rm -rf /root/tempowncloud
rm -rf /root/tempowncloud2
chown -R www-data:www-data /var/lib/owncloud/data
chown -R www-data:www-data /var/lib/owncloud/backup
chown -R www-data:www-data /var/lib/owncloud/assets
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then
occ files:scan $USERNAME
fi
done
ln -s /usr/share/owncloud /var/www/${OWNCLOUD_DOMAIN_NAME}/htdocs
fi
fi
# restore gogs
if grep -q "Gogs domain" $COMPLETION_FILE; then
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
restore_database_from_friend gogs $GIT_DOMAIN_NAME
if [ -d $SERVER_DIRECTORY/backup/gogs ]; then
if [ ! -d /home/git/go/src/github.com/gogits/gogs/custom ]; then
mkdir -p /home/git/go/src/github.com/gogits/gogs/custom
fi
cp -r /root/tempgogs/home/git/go/src/github.com/gogits/gogs/custom/* /home/git/go/src/github.com/gogits/gogs/custom/
if [ ! "$?" = "0" ]; then
exit 5885
fi
echo $"Restoring Gogs repos"
restore_directory_from_friend /root/tempgogsrepos gogsrepos
cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
if [ ! "$?" = "0" ]; then
exit 7649
fi
echo $"Restoring Gogs authorized_keys"
restore_directory_from_friend /root/tempgogsssh gogsssh
if [ ! -d /home/git/.ssh ]; then
mkdir /home/git/.ssh
fi
cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
if [ ! "$?" = "0" ]; then
exit 74239
fi
rm -rf /root/tempgogs
rm -rf /root/tempgogsrepos
rm -rf /root/tempgogsssh
chown -R git:git /home/git
fi
fi
if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
echo $"Restoring Wiki installation $WIKI_DOMAIN_NAME"
restore_directory_from_friend /root/tempwiki wiki
cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
if [ ! "$?" = "0" ]; then
exit 868
fi
restore_directory_from_friend /root/tempwiki2 wiki2
cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
if [ ! "$?" = "0" ]; then
exit 869
fi
rm -rf /root/tempwiki
rm -rf /root/tempwiki2
chown -R www-data:www-data /var/lib/dokuwiki/*
# Ensure that the bundled SSL cert is being used
if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
fi
if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
fi
fi
# 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
rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
cp -r /root/tempblog/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
if [ ! "$?" = "0" ]; then
exit 593
fi
rm -rf /root/tempblog
if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
echo $"No content directory found after restoring blog"
exit 287
fi
# Ensure that the bundled SSL cert is being used
if [ -f /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.bundle.crt ]; then
sed -i "s|${FULLBLOG_DOMAIN_NAME}.crt|${FULLBLOG_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${FULLBLOG_DOMAIN_NAME}
fi
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then
if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then
mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
fi
done
if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then
ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
fi
fi
# restore cjdns
if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
echo $"Restoring cjdns installation"
restore_directory_from_friend /root/tempcjdns cjdns
rm -rf /etc/cjdns
cp -r /root/tempcjdns/etc/cjdns /etc/
if [ ! "$?" = "0" ]; then
exit 7438
fi
rm -rf /root/tempcjdns
fi
# restore voip
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/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempvoip
exit 7823
fi
cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
if [ ! "$?" = "0" ]; then
rm -rf /root/tempvoip
exit 7823
fi
cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempvoip
exit 276
fi
rm -rf /root/tempvoip
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
service sipwitch restart
service mumble-server restart
fi
# Restore tox
if [ -d $SERVER_DIRECTORY/backup/tox ]; then
echo $"Restoring Tox node settings"
restore_directory_from_friend / tox
if [ ! "$?" = "0" ]; then
exit 93653
fi
cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
systemctl restart tox-bootstrapd.service
if [ ! "$?" = "0" ]; then
systemctl status tox-bootstrapd.service
exit 59369
fi
fi
# restore email
for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" ]]; then
if [ -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then
if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME
fi
echo $"Restoring emails for $USERNAME"
restore_directory_from_friend /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
exit 927
fi
rm -rf /root/tempmail
fi
fi
done
# 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/
if [ ! "$?" = "0" ]; then
exit 982
fi
rm -rf /root/tempdlna
fi
fi
# Social key management
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then
# Retrieve key fragments for $USERNAME
/usr/bin/sshpass -p "$REMOTE_PASSWORD" scp -r -P $REMOTE_SSH_PORT $REMOTE_SERVER/.gnupg_fragments_$USERNAME /home/$USERNAME/
if [ -d /home/$USERNAME/.gnupg_fragments_$USERNAME ]; then
if [ -d /home/$USERNAME/.gnupg_fragments ]; then
cp /home/$USERNAME/.gnupg_fragments_$USERNAME/* /home/$USERNAME/.gnupg_fragments
rm -rf /home/$USERNAME/.gnupg_fragments_$USERNAME
else
mv /home/$USERNAME/.gnupg_fragments_$USERNAME /home/$USERNAME/.gnupg_fragments
fi
fi
fi
done
echo $"*** Remote restore was successful ***"
exit 0