Script to restore only hubzilla

This commit is contained in:
Bob Mottram 2015-11-15 11:58:19 +00:00
parent e8c32454e2
commit 74b94e4f45
1 changed files with 225 additions and 62 deletions

View File

@ -153,6 +153,7 @@ HUBZILLA_CODE=
HUBZILLA_REPO="https://github.com/redmatrix/hubzilla.git"
HUBZILLA_ADDONS_REPO="https://github.com/redmatrix/hubzilla-addons.git"
HUBZILLA_ADMIN_PASSWORD=
RESTORE_HUBZILLA_SCRIPT_NAME="restorehubzilla"
# Domain name for git hosting installation
GIT_DOMAIN_NAME=
@ -2595,13 +2596,13 @@ function create_backup_script {
echo -n '$1' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "}')" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'if [ $used_percent -gt 95 ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "Less than 5% of space remaining on backup drive"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "Less than 5% of space remaining on backup drive"' >> /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 6492' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo '' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo '# MariaDB password' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n 'DATABASE_PASSWORD=$(cat ' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "$DATABASE_PASSWORD_FILE)" >> /usr/bin/$BACKUP_SCRIPT_NAME
@ -3003,77 +3004,79 @@ function create_backup_script {
}
function restore_directory_from_usb {
echo 'function restore_directory_from_usb {' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo " BACKUP_CERTIFICATE=$BACKUP_CERTIFICATE" >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ ! -d ${1} ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' mkdir ${1}' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
script_name=$1
echo 'function restore_directory_from_usb {' >> $script_name
echo " BACKUP_CERTIFICATE=$BACKUP_CERTIFICATE" >> $script_name
echo ' if [ ! -d ${1} ]; then' >> $script_name
echo ' mkdir ${1}' >> $script_name
echo ' fi' >> $script_name
if [[ $BACKUP_TYPE == 'obnam' ]]; then
echo ' obnam restore -r $USB_MOUNT/backup/${2} --to ${1}' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' obnam restore -r $USB_MOUNT/backup/${2} --to ${1}' >> $script_name
else
echo ' rsyncrypto -v -d -r $USB_MOUNT/backup/${2} ${1} $USB_MOUNT/backup/${2}.keys $BACKUP_CERTIFICATE' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rsyncrypto -v -d -r $USB_MOUNT/backup/${2} ${1} $USB_MOUNT/backup/${2}.keys $BACKUP_CERTIFICATE' >> $script_name
fi
echo '}' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo '}' >> $script_name
}
function restore_database {
echo 'function restore_database {' >> /usr/bin/$RESTORE_SCRIPT_NAME
script_name=$1
echo 'function restore_database {' >> $script_name
if [[ $BACKUP_TYPE == 'obnam' ]]; then
echo ' RESTORE_SUBDIR="root"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' RESTORE_SUBDIR="root"' >> $script_name
else
echo ' RESTORE_SUBDIR="usb/backup/${1}data"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' RESTORE_SUBDIR="usb/backup/${1}data"' >> $script_name
fi
echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ -d $USB_MOUNT/backup/${1} ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' echo "Restoring ${1} database"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' restore_directory_from_usb "/root/temp${1}data" "${1}data"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' echo "Unable to restore ${1} database"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rm -rf /root/temp${1}data' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' exit 503' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo -n ' mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo '${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' echo "$mysqlsuccess"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' exit 964' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rm -rf /root/temp${1}data' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' echo "Restoring ${1} installation"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ ! -d /root/temp${1} ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' mkdir /root/temp${1}' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' restore_directory_from_usb "/root/temp${1}" "${1}"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo '' >> $script_name
echo ' if [ -d $USB_MOUNT/backup/${1} ]; then' >> $script_name
echo ' echo "Restoring ${1} database"' >> $script_name
echo ' restore_directory_from_usb "/root/temp${1}data" "${1}data"' >> $script_name
echo ' if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then' >> $script_name
echo ' echo "Unable to restore ${1} database"' >> $script_name
echo ' rm -rf /root/temp${1}data' >> $script_name
echo ' umount $USB_MOUNT' >> $script_name
echo ' rm -rf $USB_MOUNT' >> $script_name
echo ' exit 503' >> $script_name
echo ' fi' >> $script_name
echo -n ' mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ' >> $script_name
echo '${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)' >> $script_name
echo ' if [ ! "$?" = "0" ]; then' >> $script_name
echo ' echo "$mysqlsuccess"' >> $script_name
echo ' umount $USB_MOUNT' >> $script_name
echo ' rm -rf $USB_MOUNT' >> $script_name
echo ' exit 964' >> $script_name
echo ' fi' >> $script_name
echo ' shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*' >> $script_name
echo ' rm -rf /root/temp${1}data' >> $script_name
echo ' echo "Restoring ${1} installation"' >> $script_name
echo ' if [ ! -d /root/temp${1} ]; then' >> $script_name
echo ' mkdir /root/temp${1}' >> $script_name
echo ' fi' >> $script_name
echo ' restore_directory_from_usb "/root/temp${1}" "${1}"' >> $script_name
if [[ $BACKUP_TYPE == 'obnam' ]]; then
echo ' RESTORE_SUBDIR="var"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' RESTORE_SUBDIR="var"' >> $script_name
else
echo ' RESTORE_SUBDIR="usb/backup/${1}"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' RESTORE_SUBDIR="usb/backup/${1}"' >> $script_name
fi
echo ' if [ ${2} ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ -d /var/www/${2}/htdocs ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rm -rf /var/www/${2}/htdocs' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ ! "$?" = "0" ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' exit 683' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' # Ensure that the bundled SSL cert is being used' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo '}' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ ${2} ]; then' >> $script_name
echo ' if [ -d /var/www/${2}/htdocs ]; then' >> $script_name
echo ' if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then' >> $script_name
echo ' rm -rf /var/www/${2}/htdocs' >> $script_name
echo ' mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/' >> $script_name
echo ' if [ ! "$?" = "0" ]; then' >> $script_name
echo ' umount $USB_MOUNT' >> $script_name
echo ' rm -rf $USB_MOUNT' >> $script_name
echo ' exit 683' >> $script_name
echo ' fi' >> $script_name
echo ' # Ensure that the bundled SSL cert is being used' >> $script_name
echo ' if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then' >> $script_name
echo ' sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}' >> $script_name
echo ' fi' >> $script_name
echo ' fi' >> $script_name
echo ' fi' >> $script_name
echo ' fi' >> $script_name
echo ' fi' >> $script_name
echo '}' >> $script_name
}
function create_restore_script {
@ -3146,9 +3149,9 @@ function create_restore_script {
echo "$DATABASE_PASSWORD_FILE)" >> /usr/bin/$RESTORE_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME
restore_directory_from_usb
restore_directory_from_usb /usr/bin/$RESTORE_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME
restore_database
restore_database /usr/bin/$RESTORE_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME
if [[ $BACKUP_TYPE != 'obnam' ]]; then
@ -3902,6 +3905,166 @@ function create_restore_script {
echo 'create_restore_script' >> $COMPLETION_FILE
}
function create_restore_hubzilla_script {
if grep -Fxq "create_restore_hubzilla_script" $COMPLETION_FILE; then
return
fi
apt-get -y install rsyncrypto cryptsetup obnam
get_mariadb_password
get_mariadb_hubzilla_admin_password
get_mariadb_git_admin_password
echo '#!/bin/bash' > /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "USB_DRIVE=$USB_DRIVE" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [ $1 ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' USB_DRIVE=/dev/${1}1' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "USB_MOUNT=$USB_MOUNT" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "ADMIN_USERNAME=$MY_USERNAME" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "MY_USERNAME=$MY_USERNAME" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [ $2 ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' MY_USERNAME=$2' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [ ! -b $USB_DRIVE ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' echo "Please attach a USB drive"' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' exit 1' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [ ! -d $USB_MOUNT ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' mkdir $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' if [ -f /dev/mapper/encrypted_usb ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' rm -rf /dev/mapper/encrypted_usb' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' cryptsetup luksClose encrypted_usb' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' cryptsetup luksOpen $USB_DRIVE encrypted_usb' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' if [ "$?" = "0" ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' USB_DRIVE=/dev/mapper/encrypted_usb' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo -n ' mount $USB_DRIVE ' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '$USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [ ! -d $USB_MOUNT/backup ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' echo "No backup directory found on the USB drive."' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' exit 2' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'echo "Checking that user exists"' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [ ! -d /home/$MY_USERNAME ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' echo "Username $MY_USERNAME not found. Reinstall Freedombone with this username."' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' exit 295' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'echo "Copying GPG keys to root"' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'cp -r /home/$MY_USERNAME/.gnupg /root' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '# MariaDB password' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo -n 'DATABASE_PASSWORD=$(cat ' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "$DATABASE_PASSWORD_FILE)" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
restore_directory_from_usb /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
restore_database /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
if [[ $BACKUP_TYPE != 'obnam' ]]; then
echo 'if [ -f $USB_MOUNT/backup/key.gpg ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " if [ -f $BACKUP_CERTIFICATE.new ]; then" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " rm $BACKUP_CERTIFICATE.new" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' cp $USB_MOUNT/backup/key.gpg /root/tempbackupkey.gpg' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " gpg /root/tempbackupkey.gpg" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " if [ -f /root/tempbackupkey ]; then" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' echo "Backup key decrypted"' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " cp /root/tempbackupkey $BACKUP_CERTIFICATE" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " shred -zu /root/tempbackupkey" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " chmod 400 $BACKUP_CERTIFICATE" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' echo "Backup certificate installed"' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' else' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' echo "Unable to decrypt the backup key"' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' exit 735' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "if [ ! -f $BACKUP_CERTIFICATE ]; then" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " echo 'No backup key was found. Copy your backup key to $BACKUP_CERTIFICATE'" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' umount $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' rm -rf $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' exit 563' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
fi
BACKUP_INCLUDES_WEBSITES="no"
if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
BACKUP_INCLUDES_WEBSITES="yes"
echo "restore_database hubzilla $HUBZILLA_DOMAIN_NAME" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [ -d $USB_MOUNT/backup/hubzilla ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/store/[data]/smarty3 ]; then" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " mkdir -p /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/store/[data]/smarty3" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " fi" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " chmod 777 /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/store/[data]/smarty3" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo " chown -R www-data:www-data /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/*" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' if [ -d /root/temphubzilla ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' rm -rf /root/temphubzilla' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
fi
echo 'sync' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "# Unmount the USB drive" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'umount $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'rm -rf $USB_MOUNT' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
if [[ $BACKUP_INCLUDES_WEBSITES == "yes" ]]; then
echo "# Restart the web server" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "service nginx restart" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo "service php5-fpm restart" >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
fi
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'echo "Setting permissions"' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'for d in /home/*/ ; do' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' chown -R $USERNAME:$USERNAME /home/$USERNAME' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'done' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' echo "Unmount encrypted USB"' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' cryptsetup luksClose encrypted_usb' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'if [ -f /dev/mapper/encrypted_usb ]; then' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo ' rm -rf /dev/mapper/encrypted_usb' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'echo "Restore of Hubzilla from USB drive is complete. You can now remove it."' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'exit 0' >> /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
chmod 400 /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
chmod +x /usr/bin/$RESTORE_HUBZILLA_SCRIPT_NAME
echo 'create_restore_hubzilla_script' >> $COMPLETION_FILE
}
function create_freedns_updater {
# currently inadyn doesn't work as expected with freeDNS, so this is a workaround
if grep -Fxq "create_freedns_updater" $COMPLETION_FILE; then