diff --git a/src/freedombone b/src/freedombone index b029aec6..af02d0a7 100755 --- a/src/freedombone +++ b/src/freedombone @@ -2647,7 +2647,8 @@ function select_go_version { echo "export GVM_ROOT=$GVM_ROOT" >> ~/.bashrc fi cd $GVM_ROOT/bin - ./gvm use go${GO_VERSION} --default + [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" + gvm use go${GO_VERSION} --default systemctl set-environment GOPATH=$GOPATH if [ ${#GOPATH} -lt 2 ]; then @@ -6321,25 +6322,25 @@ function upgrade_golang { # TODO: this script is all over the place # and contains hardcoded github. See if you can do better ./binscripts/gvm-installer - [[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm" - if [ ! -f $HOME/.gvm/bin/gvm ]; then + export GVM_ROOT=$HOME/.gvm + [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" + if [ ! -f $GVM_ROOT/bin/gvm ]; then echo $'gvm was not installed' fi - export GVM_ROOT=$HOME/.gvm - if ! grep -q "GVM_ROOT=" ~/.bashrc; then - echo 'export GVM_ROOT=$HOME/.gvm' >> ~/.bashrc + if ! grep -q "export GVM_ROOT=" ~/.bashrc; then + echo "export GVM_ROOT=$GVM_ROOT" >> ~/.bashrc fi cd $GVM_ROOT/bin - ./gvm install go1.4 - ./gvm use go1.4 + gvm install go1.4 + gvm use go1.4 export GOROOT_BOOTSTRAP=$GOROOT - ./gvm install go${GO_VERSION} + gvm install go${GO_VERSION} if [ ! "$?" = "0" ]; then echo $'Unable to upgrade golang' exit 529252 fi - ./gvm use go${GO_VERSION} --default + gvm use go${GO_VERSION} --default if ! grep -q "gvm commit" $COMPLETION_FILE; then echo "gvm commit:$GVM_COMMIT" >> $COMPLETION_FILE diff --git a/src/freedombone-backup-local b/src/freedombone-backup-local index fa56f4ce..9d793210 100755 --- a/src/freedombone-backup-local +++ b/src/freedombone-backup-local @@ -42,16 +42,16 @@ USB_MOUNT=/mnt/usb # get default USB from config file CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg if [ -f $CONFIG_FILE ]; then - if grep -q "USB_DRIVE=" $CONFIG_FILE; then - USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}') - fi + if grep -q "USB_DRIVE=" $CONFIG_FILE; then + USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}') + fi fi # get the version of Go being used if [ -f /usr/local/bin/${PROJECT_NAME} ]; then - GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') + GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') else - GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') + GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') fi ADMIN_USERNAME= @@ -63,548 +63,550 @@ SUSPENDED_SITE= DATABASE_PASSWORD='' if [ -f /root/dbpass ]; then - DATABASE_PASSWORD=$(cat /root/dbpass) + DATABASE_PASSWORD=$(cat /root/dbpass) fi function suspend_site { - # suspends a given website - if [[ $ENABLE_VERIFICATION != "yes" ]]; then - return - fi - SUSPENDED_SITE="$1" - nginx_dissite $SUSPENDED_SITE - service nginx reload + # suspends a given website + if [[ $ENABLE_VERIFICATION != "yes" ]]; then + return + fi + SUSPENDED_SITE="$1" + nginx_dissite $SUSPENDED_SITE + service nginx reload } function restart_site { - # restarts a given website - if [ ! $SUSPENDED_SITE ]; then - return - fi - nginx_ensite $SUSPENDED_SITE - service nginx reload - SUSPENDED_SITE= + # restarts a given website + if [ ! $SUSPENDED_SITE ]; then + return + fi + nginx_ensite $SUSPENDED_SITE + service nginx reload + SUSPENDED_SITE= } function update_domains { - RSS_READER_DOMAIN_NAME='ttrss' - if grep -q "RSS reader domain" $COMPLETION_FILE; then - RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') - fi - GIT_DOMAIN_NAME='gogs' - if grep -q "Gogs domain" $COMPLETION_FILE; then - GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') - fi - MICROBLOG_DOMAIN_NAME='microblog' - if grep -q "GNU Social domain" $COMPLETION_FILE; then - MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') - fi - HUBZILLA_DOMAIN_NAME='hubzilla' - if grep -q "Hubzilla domain" $COMPLETION_FILE; then - HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') - fi - FULLBLOG_DOMAIN_NAME='blog' - if grep -q "Blog domain" $COMPLETION_FILE; then - FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') - fi - MEDIAGOBLIN_DOMAIN_NAME='mediagoblin' - if grep -q "Mediagoblin domain" $COMPLETION_FILE; then - MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') - fi + RSS_READER_DOMAIN_NAME='ttrss' + if grep -q "RSS reader domain" $COMPLETION_FILE; then + RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') + fi + GIT_DOMAIN_NAME='gogs' + if grep -q "Gogs domain" $COMPLETION_FILE; then + GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') + fi + MICROBLOG_DOMAIN_NAME='microblog' + if grep -q "GNU Social domain" $COMPLETION_FILE; then + MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') + fi + HUBZILLA_DOMAIN_NAME='hubzilla' + if grep -q "Hubzilla domain" $COMPLETION_FILE; then + HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') + fi + FULLBLOG_DOMAIN_NAME='blog' + if grep -q "Blog domain" $COMPLETION_FILE; then + FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') + fi + MEDIAGOBLIN_DOMAIN_NAME='mediagoblin' + if grep -q "Mediagoblin domain" $COMPLETION_FILE; then + MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') + fi } function mount_drive { - if [ $1 ]; then - USB_DRIVE=/dev/${1}1 - fi + if [ $1 ]; then + USB_DRIVE=/dev/${1}1 + fi - # get the admin user - ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') - if [ $2 ]; then - ADMIN_USERNAME=$2 - fi - ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1) + # get the admin user + ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') + if [ $2 ]; then + ADMIN_USERNAME=$2 + fi + ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1) - # check that the backup destination is available - if [ ! -b $USB_DRIVE ]; then - echo $"Please attach a USB drive" - exit 1 - fi + # check that the backup destination is available + if [ ! -b $USB_DRIVE ]; then + echo $"Please attach a USB drive" + exit 1 + fi - # unmount if already mounted - umount -f $USB_MOUNT - if [ ! -d $USB_MOUNT ]; then - mkdir $USB_MOUNT - fi - if [ -f /dev/mapper/encrypted_usb ]; then - rm -rf /dev/mapper/encrypted_usb - fi - cryptsetup luksClose encrypted_usb + # unmount if already mounted + umount -f $USB_MOUNT + if [ ! -d $USB_MOUNT ]; then + mkdir $USB_MOUNT + fi + if [ -f /dev/mapper/encrypted_usb ]; then + rm -rf /dev/mapper/encrypted_usb + fi + cryptsetup luksClose encrypted_usb - # mount the encrypted backup drive - cryptsetup luksOpen $USB_DRIVE encrypted_usb - if [ "$?" = "0" ]; then - USB_DRIVE=/dev/mapper/encrypted_usb - fi - mount $USB_DRIVE $USB_MOUNT - if [ ! "$?" = "0" ]; then - echo $"There was a problem mounting the USB drive to $USB_MOUNT" - rm -rf $USB_MOUNT - exit 2 - fi + # mount the encrypted backup drive + cryptsetup luksOpen $USB_DRIVE encrypted_usb + if [ "$?" = "0" ]; then + USB_DRIVE=/dev/mapper/encrypted_usb + fi + mount $USB_DRIVE $USB_MOUNT + if [ ! "$?" = "0" ]; then + echo $"There was a problem mounting the USB drive to $USB_MOUNT" + rm -rf $USB_MOUNT + exit 2 + fi } function unmount_drive { - sync - umount $USB_MOUNT - if [ ! "$?" = "0" ]; then - echo $"Unable to unmount the drive. This means that the backup did not work" - rm -rf $USB_MOUNT - exit 9 - fi - rm -rf $USB_MOUNT - if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then - echo $"Unmount encrypted USB" - cryptsetup luksClose encrypted_usb - fi - if [ -f /dev/mapper/encrypted_usb ]; then - rm -rf /dev/mapper/encrypted_usb - fi - echo $"Backup to USB drive is complete. You can now unplug it." + sync + umount $USB_MOUNT + if [ ! "$?" = "0" ]; then + echo $"Unable to unmount the drive. This means that the backup did not work" + rm -rf $USB_MOUNT + exit 9 + fi + rm -rf $USB_MOUNT + if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then + echo $"Unmount encrypted USB" + cryptsetup luksClose encrypted_usb + fi + if [ -f /dev/mapper/encrypted_usb ]; then + rm -rf /dev/mapper/encrypted_usb + fi + echo $"Backup to USB drive is complete. You can now unplug it." } function backup_database { - if [ ${#DATABASE_PASSWORD} -lt 2 ]; then - echo $"No MariaDB password was given" - restart_site - exit 10 - fi - if [ ! -d $USB_MOUNT/backup/${1} ]; then - mkdir -p $USB_MOUNT/backup/${1} - fi - if [ ! -d $USB_MOUNT/backup/${1}data ]; then - mkdir -p $USB_MOUNT/backup/${1}data - fi - if [ ! -d /root/temp${1}data ]; then - mkdir -p /root/temp${1}data - fi - echo $"Obtaining ${1} database backup" - mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql - if [ ! -s /root/temp${1}data/${1}.sql ]; then - echo $"${1} database could not be saved" - shred -zu /root/temp${1}data/* - rm -rf /root/temp${1}data - umount $USB_MOUNT - rm -rf $USB_MOUNT - restart_site - exit 5 - fi + if [ ${#DATABASE_PASSWORD} -lt 2 ]; then + echo $"No MariaDB password was given" + restart_site + exit 10 + fi + if [ ! -d $USB_MOUNT/backup/${1} ]; then + mkdir -p $USB_MOUNT/backup/${1} + fi + if [ ! -d $USB_MOUNT/backup/${1}data ]; then + mkdir -p $USB_MOUNT/backup/${1}data + fi + if [ ! -d /root/temp${1}data ]; then + mkdir -p /root/temp${1}data + fi + echo $"Obtaining ${1} database backup" + mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql + if [ ! -s /root/temp${1}data/${1}.sql ]; then + echo $"${1} database could not be saved" + shred -zu /root/temp${1}data/* + rm -rf /root/temp${1}data + umount $USB_MOUNT + rm -rf $USB_MOUNT + restart_site + exit 5 + fi } function backup_directory_to_usb { - if [ ! -d ${1} ]; then - echo $"WARNING: directory does not exist: ${1}" - else - BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)") - if [ ! "$?" = "0" ]; then - echo $"Backup key could not be found" - restart_site - exit 6 - fi - MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - if [ ! -d $USB_MOUNT/backup/${2} ]; then - mkdir -p $USB_MOUNT/backup/${2} - fi - obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} - obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} - if [[ $ENABLE_VERIFICATION == "yes" ]]; then - obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} - if [ ! "$?" = "0" ]; then - umount $USB_MOUNT - rm -rf $USB_MOUNT - if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then - shred -zu ${1}/* - rm -rf ${1} - fi - restart_site - exit 71 - fi - fi - obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID - if [ ! "$?" = "0" ]; then - umount $USB_MOUNT - rm -rf $USB_MOUNT - if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then - shred -zu ${1}/* - rm -rf ${1} - fi - restart_site - exit 7 - fi - if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then - shred -zu ${1}/* - rm -rf ${1} - fi - fi + if [ ! -d ${1} ]; then + echo $"WARNING: directory does not exist: ${1}" + else + BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)") + if [ ! "$?" = "0" ]; then + echo $"Backup key could not be found" + restart_site + exit 6 + fi + MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + if [ ! -d $USB_MOUNT/backup/${2} ]; then + mkdir -p $USB_MOUNT/backup/${2} + fi + obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} + obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} + if [[ $ENABLE_VERIFICATION == "yes" ]]; then + obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} + if [ ! "$?" = "0" ]; then + umount $USB_MOUNT + rm -rf $USB_MOUNT + if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then + shred -zu ${1}/* + rm -rf ${1} + fi + restart_site + exit 71 + fi + fi + obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID + if [ ! "$?" = "0" ]; then + umount $USB_MOUNT + rm -rf $USB_MOUNT + if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then + shred -zu ${1}/* + rm -rf ${1} + fi + restart_site + exit 7 + fi + if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then + shred -zu ${1}/* + rm -rf ${1} + fi + fi } function make_backup_directory { - # make a backup directory on the drive - if [ ! -d $USB_MOUNT/backup ]; then - mkdir $USB_MOUNT/backup - fi - if [ ! -d $USB_MOUNT/backup ]; then - echo $"There was a problem making the directory $USB_MOUNT/backup." - umount $USB_MOUNT - rm -rf $USB_MOUNT - exit 3 - fi + # make a backup directory on the drive + if [ ! -d $USB_MOUNT/backup ]; then + mkdir $USB_MOUNT/backup + fi + if [ ! -d $USB_MOUNT/backup ]; then + echo $"There was a problem making the directory $USB_MOUNT/backup." + umount $USB_MOUNT + rm -rf $USB_MOUNT + exit 3 + fi } function check_storage_space_remaining { - # Check space remaining on the usb drive - used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}') - if [ $used_percent -gt 95 ]; then - echo $"Less than 5% of space remaining on backup drive" - umount $USB_MOUNT - rm -rf $USB_MOUNT - exit 4 - fi + # Check space remaining on the usb drive + used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}') + if [ $used_percent -gt 95 ]; then + echo $"Less than 5% of space remaining on backup drive" + umount $USB_MOUNT + rm -rf $USB_MOUNT + exit 4 + fi } function backup_users { - # Backup user files - for d in /home/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + # Backup user files + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - # Backup any gpg keys - if [ -d /home/$USERNAME/.gnupg ]; then - echo $"Backing up gpg keys for $USERNAME" - backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME - fi + # Backup any gpg keys + if [ -d /home/$USERNAME/.gnupg ]; then + echo $"Backing up gpg keys for $USERNAME" + backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME + fi - # Backup any personal settings - if [ -d /home/$USERNAME/personal ]; then - echo $"Backing up personal settings for $USERNAME" - backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME - fi + # Backup any personal settings + if [ -d /home/$USERNAME/personal ]; then + echo $"Backing up personal settings for $USERNAME" + backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME + fi - # Backup ssh keys - if [ -d /home/$USERNAME/.ssh ]; then - echo $"Backing up ssh keys for $USERNAME" - backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME - fi + # Backup ssh keys + if [ -d /home/$USERNAME/.ssh ]; then + echo $"Backing up ssh keys for $USERNAME" + backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME + fi - # Backup fin database if it exists - if [ -d /home/$USERNAME/.fin ]; then - echo $"Backing up fin files for $USERNAME" - backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME - fi + # Backup fin database if it exists + if [ -d /home/$USERNAME/.fin ]; then + echo $"Backing up fin files for $USERNAME" + backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME + fi - # Backup syncthing - if [ -d /home/$USERNAME/Sync ]; then - echo $"Backing up syncthing files for $USERNAME" - backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME - # ensure that device IDs will be backed up as part of user config settings - if [ ! -d /home/$USERNAME/.config/syncthing ]; then - mkdir -p /home/$USERNAME/.config/syncthing - chown -R $USERNAME:$USERNAME /home/$USERNAME/.config - fi - if [ -f /home/$USERNAME/.syncthing-server-id ]; then - cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing - chown -R $USERNAME:$USERNAME /home/$USERNAME/.config - fi - if [ -f /home/$USERNAME/.syncthingids ]; then - cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing - chown -R $USERNAME:$USERNAME /home/$USERNAME/.config - fi - fi + # Backup syncthing + if [ -d /home/$USERNAME/Sync ]; then + echo $"Backing up syncthing files for $USERNAME" + backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME + # ensure that device IDs will be backed up as part of user config settings + if [ ! -d /home/$USERNAME/.config/syncthing ]; then + mkdir -p /home/$USERNAME/.config/syncthing + chown -R $USERNAME:$USERNAME /home/$USERNAME/.config + fi + if [ -f /home/$USERNAME/.syncthing-server-id ]; then + cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing + chown -R $USERNAME:$USERNAME /home/$USERNAME/.config + fi + if [ -f /home/$USERNAME/.syncthingids ]; then + cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing + chown -R $USERNAME:$USERNAME /home/$USERNAME/.config + fi + fi - # Backup user configs - if [ -d /home/$USERNAME/.config ]; then - echo $"Backing up config files for $USERNAME" - backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME - fi + # Backup user configs + if [ -d /home/$USERNAME/.config ]; then + echo $"Backing up config files for $USERNAME" + backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME + fi - # Backup user local - if [ -d /home/$USERNAME/.local ]; then - echo $"Backing up local files for $USERNAME" - backup_directory_to_usb /home/$USERNAME/.local local/$USERNAME - fi + # Backup user local + if [ -d /home/$USERNAME/.local ]; then + echo $"Backing up local files for $USERNAME" + backup_directory_to_usb /home/$USERNAME/.local local/$USERNAME + fi - # Backup mutt - if [ -f /home/$USERNAME/.muttrc ]; then - echo $"Backing up Mutt settings for $USERNAME" - if [ ! -d /home/$USERNAME/tempbackup ]; then - mkdir -p /home/$USERNAME/tempbackup - fi - cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup - if [ -f /etc/Muttrc ]; then - cp /etc/Muttrc /home/$USERNAME/tempbackup - fi - backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME - fi + # Backup mutt + if [ -f /home/$USERNAME/.muttrc ]; then + echo $"Backing up Mutt settings for $USERNAME" + if [ ! -d /home/$USERNAME/tempbackup ]; then + mkdir -p /home/$USERNAME/tempbackup + fi + cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup + if [ -f /etc/Muttrc ]; then + cp /etc/Muttrc /home/$USERNAME/tempbackup + fi + backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME + fi - # Backup email - if [ -d /home/$USERNAME/Maildir ]; then - echo $"Creating an email archive for $USERNAME" - if [ ! -d /root/tempbackupemail/$USERNAME ]; then - mkdir -p /root/tempbackupemail/$USERNAME - fi - tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir - echo $"Backing up emails for $USERNAME" - backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME - fi + # Backup email + if [ -d /home/$USERNAME/Maildir ]; then + echo $"Creating an email archive for $USERNAME" + if [ ! -d /root/tempbackupemail/$USERNAME ]; then + mkdir -p /root/tempbackupemail/$USERNAME + fi + tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir + echo $"Backing up emails for $USERNAME" + backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME + fi - # Backup spamassassin - if [ -d /home/$USERNAME/.spamassassin ]; then - echo $"Backing up spamassassin settings for $USERNAME" - backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME - fi + # Backup spamassassin + if [ -d /home/$USERNAME/.spamassassin ]; then + echo $"Backing up spamassassin settings for $USERNAME" + backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME + fi - # Backup procmail - if [ -f /home/$USERNAME/.procmailrc ]; then - echo $"Backing up procmail settings for $USERNAME" - if [ ! -d /home/$USERNAME/tempbackup ]; then - mkdir -p /home/$USERNAME/tempbackup - fi - cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup - backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME - fi - fi - done + # Backup procmail + if [ -f /home/$USERNAME/.procmailrc ]; then + echo $"Backing up procmail settings for $USERNAME" + if [ ! -d /home/$USERNAME/tempbackup ]; then + mkdir -p /home/$USERNAME/tempbackup + fi + cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup + backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME + fi + fi + done } function backup_directories { - export GVM_ROOT=$HOME/.gvm - if [ -d $GVM_ROOT/bin ]; then - cd $GVM_ROOT/bin - ./gvm use go${GO_VERSION} --default - systemctl set-environment GOPATH=$GOPATH - fi + export GVM_ROOT=$HOME/.gvm + if [ -d $GVM_ROOT/bin ]; then + cd $GVM_ROOT/bin + [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" + gvm use go${GO_VERSION} --default + systemctl set-environment GOPATH=$GOPATH + fi - # directories to be backed up (source,dest) - backup_dirs=( - "none, none, /etc/letsencrypt, letsencrypt" - "none, none, /var/lib/dokuwiki, wiki" - "none, none, /etc/dokuwiki, wiki2" - "none, none, /etc/ssl, ssl" - "/etc/share/tt-rss, ttrss, /root/tempttrssdata, ttrss" - "none, none, /var/spool/mlmmj, mailinglist" - "none, none, /var/lib/prosody, xmpp" - "none, none, /etc/nginx/sites-available, web" - "none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs" - "none, none, /var/cache/minidlna, dlna" - "$GOPATH/src/github.com/gogits, gogs, /root/tempgogsdata, gogsdata" - "none, none, $GOPATH/src/github.com/gogits/gogs/custom, gogs" - "none, none, /home/git/gogs-repositories, gogsrepos" - "none, none, /home/git/.ssh, gogsssh" - "none, none, /var/lib/tox-bootstrapd, tox" - "/var/www/${MICROBLOG_DOMAIN_NAME}, gnusocial, /root/tempgnusocialdata, gnusocialdata" - "none, none, /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs, gnusocial" - "none, none, /var/lib/syncthing/SyncShared, syncthingshared" - "none, none, /root/.config/syncthing, syncthingconfig" - "/var/www/${HUBZILLA_DOMAIN_NAME}, hubzilla, /root/temphubzilladata, hubzilladata" - "none, none, /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs, hubzilla" - "none, none, /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs, blog" - "none, none, /var/lib/tor, tor" - "none, none, /var/www/${MEDIAGOBLIN_DOMAIN_NAME}/htdocs, mediagoblin" - ) + # directories to be backed up (source,dest) + backup_dirs=( + "none, none, /etc/letsencrypt, letsencrypt" + "none, none, /var/lib/dokuwiki, wiki" + "none, none, /etc/dokuwiki, wiki2" + "none, none, /etc/ssl, ssl" + "/etc/share/tt-rss, ttrss, /root/tempttrssdata, ttrss" + "none, none, /var/spool/mlmmj, mailinglist" + "none, none, /var/lib/prosody, xmpp" + "none, none, /etc/nginx/sites-available, web" + "none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs" + "none, none, /var/cache/minidlna, dlna" + "$GOPATH/src/github.com/gogits, gogs, /root/tempgogsdata, gogsdata" + "none, none, $GOPATH/src/github.com/gogits/gogs/custom, gogs" + "none, none, /home/git/gogs-repositories, gogsrepos" + "none, none, /home/git/.ssh, gogsssh" + "none, none, /var/lib/tox-bootstrapd, tox" + "/var/www/${MICROBLOG_DOMAIN_NAME}, gnusocial, /root/tempgnusocialdata, gnusocialdata" + "none, none, /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs, gnusocial" + "none, none, /var/lib/syncthing/SyncShared, syncthingshared" + "none, none, /root/.config/syncthing, syncthingconfig" + "/var/www/${HUBZILLA_DOMAIN_NAME}, hubzilla, /root/temphubzilladata, hubzilladata" + "none, none, /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs, hubzilla" + "none, none, /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs, blog" + "none, none, /var/lib/tor, tor" + "none, none, /var/www/${MEDIAGOBLIN_DOMAIN_NAME}/htdocs, mediagoblin" + ) - for dr in "${backup_dirs[@]}" - do - # if this directory exists then backup the given database - required_directory=$(echo $dr | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + for dr in "${backup_dirs[@]}" + do + # if this directory exists then backup the given database + required_directory=$(echo $dr | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - if [[ "$database_name" == *"hubzilla"* ]]; then - suspend_site ${HUBZILLA_DOMAIN_NAME} - fi - if [[ "$database_name" == *"gnusocial"* ]]; then - suspend_site ${MICROBLOG_DOMAIN_NAME} - fi - if [[ "$database_name" == *"gogs"* ]]; then - suspend_site ${GIT_DOMAIN_NAME} - fi - if [[ "$database_name" == *"ttrss"* ]]; then - suspend_site ${RSS_READER_DOMAIN_NAME} - fi + if [[ "$database_name" == *"hubzilla"* ]]; then + suspend_site ${HUBZILLA_DOMAIN_NAME} + fi + if [[ "$database_name" == *"gnusocial"* ]]; then + suspend_site ${MICROBLOG_DOMAIN_NAME} + fi + if [[ "$database_name" == *"gogs"* ]]; then + suspend_site ${GIT_DOMAIN_NAME} + fi + if [[ "$database_name" == *"ttrss"* ]]; then + suspend_site ${RSS_READER_DOMAIN_NAME} + fi - if [[ $required_directory != "none" ]]; then - if [ -d $required_directory ]; then - if [[ $database_name != "none" ]]; then - backup_database $database_name - fi - fi - fi + if [[ $required_directory != "none" ]]; then + if [ -d $required_directory ]; then + if [[ $database_name != "none" ]]; then + backup_database $database_name + fi + fi + fi - # if this directory exists then back it up to the given destination - source_directory=$(echo $dr | awk -F ',' '{print $3}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - if [ -d $source_directory ]; then - dest_directory=$(echo $dr | awk -F ',' '{print $4}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - echo $"Backing up $source_directory to $dest_directory" - backup_directory_to_usb $source_directory $dest_directory - fi + # if this directory exists then back it up to the given destination + source_directory=$(echo $dr | awk -F ',' '{print $3}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + if [ -d $source_directory ]; then + dest_directory=$(echo $dr | awk -F ',' '{print $4}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + echo $"Backing up $source_directory to $dest_directory" + backup_directory_to_usb $source_directory $dest_directory + fi - restart_site - done + restart_site + done } function remove_backup_directory { - if [ $1 ]; then - if [[ $1 == "remove" ]]; then - if [ -d $USB_MOUNT/backup ]; then - rm -rf $USB_MOUNT/backup - echo $'Existing backup directory removed' - unmount_drive - exit 0 - fi - fi - fi + if [ $1 ]; then + if [[ $1 == "remove" ]]; then + if [ -d $USB_MOUNT/backup ]; then + rm -rf $USB_MOUNT/backup + echo $'Existing backup directory removed' + unmount_drive + exit 0 + fi + fi + fi } function prepare_directories { - export GVM_ROOT=$HOME/.gvm - if [ -d $GVM_ROOT/bin ]; then - cd $GVM_ROOT/bin - ./gvm use go${GO_VERSION} --default - systemctl set-environment GOPATH=$GOPATH - fi + export GVM_ROOT=$HOME/.gvm + if [ -d $GVM_ROOT/bin ]; then + cd $GVM_ROOT/bin + [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" + gvm use go${GO_VERSION} --default + systemctl set-environment GOPATH=$GOPATH + fi - # Some miscellaneous preparation for backing up directories - if [ -d $GOPATH/src/github.com/gogits ]; then - mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME - fi - if [ -d /var/lib/tox-bootstrapd ]; then - cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd - if [ -d /var/lib/tox-bootstrapd/Maildir ]; then - rm -rf /var/lib/tox-bootstrapd/Maildir - fi - fi + # Some miscellaneous preparation for backing up directories + if [ -d $GOPATH/src/github.com/gogits ]; then + mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME + fi + if [ -d /var/lib/tox-bootstrapd ]; then + cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd + if [ -d /var/lib/tox-bootstrapd/Maildir ]; then + rm -rf /var/lib/tox-bootstrapd/Maildir + fi + fi } function backup_configuration { - echo $"Backing up ${PROJECT_NAME} configuration files" - if [ ! -d /root/tempbackupconfig ]; then - mkdir -p /root/tempbackupconfig - fi - cp -f $CONFIG_FILE /root/tempbackupconfig - cp -f $COMPLETION_FILE /root/tempbackupconfig - if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then - cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig - fi - # nginx password hashes - if [ -f /etc/nginx/.htpasswd ]; then - cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd - fi - backup_directory_to_usb /root/tempbackupconfig config + echo $"Backing up ${PROJECT_NAME} configuration files" + if [ ! -d /root/tempbackupconfig ]; then + mkdir -p /root/tempbackupconfig + fi + cp -f $CONFIG_FILE /root/tempbackupconfig + cp -f $COMPLETION_FILE /root/tempbackupconfig + if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then + cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig + fi + # nginx password hashes + if [ -f /etc/nginx/.htpasswd ]; then + cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd + fi + backup_directory_to_usb /root/tempbackupconfig config } function backup_admin_readme { - if [ -f /home/$ADMIN_USERNAME/README ]; then - echo $"Backing up README" - if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then - mkdir -p /home/$ADMIN_USERNAME/tempbackup - fi - cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup - backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme - fi + if [ -f /home/$ADMIN_USERNAME/README ]; then + echo $"Backing up README" + if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then + mkdir -p /home/$ADMIN_USERNAME/tempbackup + fi + cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup + backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme + fi } function backup_voip { - if [ -f /etc/mumble-server.ini ]; then - echo $"Backing up VoIP settings" - if [ ! -d /root/tempvoipbackup ]; then - mkdir -p /root/tempvoipbackup - fi - cp -f /etc/mumble-server.ini /root/tempvoipbackup - cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup - cp -f /etc/sipwitch.conf /root/tempvoipbackup - backup_directory_to_usb /root/tempvoipbackup voip - fi + if [ -f /etc/mumble-server.ini ]; then + echo $"Backing up VoIP settings" + if [ ! -d /root/tempvoipbackup ]; then + mkdir -p /root/tempvoipbackup + fi + cp -f /etc/mumble-server.ini /root/tempvoipbackup + cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup + cp -f /etc/sipwitch.conf /root/tempvoipbackup + backup_directory_to_usb /root/tempvoipbackup voip + fi } function backup_mariadb { - if [ ${#DATABASE_PASSWORD} -gt 1 ]; then - if [ ! -d /root/tempmariadb ]; then - mkdir /root/tempmariadb - fi - mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql - if [ ! -s /root/tempmariadb/mysql.sql ]; then - echo $"Unable to backup mysql settings" - rm -rf /root/tempmariadb - umount $USB_MOUNT - rm -rf $USB_MOUNT - exit 8 - fi - echo "$DATABASE_PASSWORD" > /root/tempmariadb/db - chmod 400 /root/tempmariadb/db - backup_directory_to_usb /root/tempmariadb mariadb - fi + if [ ${#DATABASE_PASSWORD} -gt 1 ]; then + if [ ! -d /root/tempmariadb ]; then + mkdir /root/tempmariadb + fi + mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql + if [ ! -s /root/tempmariadb/mysql.sql ]; then + echo $"Unable to backup mysql settings" + rm -rf /root/tempmariadb + umount $USB_MOUNT + rm -rf $USB_MOUNT + exit 8 + fi + echo "$DATABASE_PASSWORD" > /root/tempmariadb/db + chmod 400 /root/tempmariadb/db + backup_directory_to_usb /root/tempmariadb mariadb + fi } function valid_backup_destination { - destination_dir="$1" - is_valid="yes" + destination_dir="$1" + is_valid="yes" - if [[ "$destination_dir" == "hubzilla" || \ - "$destination_dir" == "hubzilladata" || \ - "$destination_dir" == "gogs" || \ - "$destination_dir" == "gogsrepos" || \ - "$destination_dir" == "gogsssh" || \ - "$destination_dir" == "gnusocial" || \ - "$destination_dir" == "gnusocialdata" || \ - "$destination_dir" == "mariadb" || \ - "$destination_dir" == "config" || \ - "$destination_dir" == "letsencrypt" || \ - "$destination_dir" == "wiki" || \ - "$destination_dir" == "wiki2" || \ - "$destination_dir" == "xmpp" || \ - "$destination_dir" == "ipfs" || \ - "$destination_dir" == "dlna" || \ - "$destination_dir" == "tox" || \ - "$destination_dir" == "ssl" || \ - "$destination_dir" == "ttrss" || \ - "$destination_dir" == "blog" || \ - "$destination_dir" == "syncthingconfig" || \ - "$destination_dir" == "syncthingshared" || \ - "$destination_dir" == "syncthing" || \ - "$destination_dir" == "mediagoblin" || \ - "$destination_dir" == "mailinglist" ]]; then - is_valid="no" - fi + if [[ "$destination_dir" == "hubzilla" || \ + "$destination_dir" == "hubzilladata" || \ + "$destination_dir" == "gogs" || \ + "$destination_dir" == "gogsrepos" || \ + "$destination_dir" == "gogsssh" || \ + "$destination_dir" == "gnusocial" || \ + "$destination_dir" == "gnusocialdata" || \ + "$destination_dir" == "mariadb" || \ + "$destination_dir" == "config" || \ + "$destination_dir" == "letsencrypt" || \ + "$destination_dir" == "wiki" || \ + "$destination_dir" == "wiki2" || \ + "$destination_dir" == "xmpp" || \ + "$destination_dir" == "ipfs" || \ + "$destination_dir" == "dlna" || \ + "$destination_dir" == "tox" || \ + "$destination_dir" == "ssl" || \ + "$destination_dir" == "ttrss" || \ + "$destination_dir" == "blog" || \ + "$destination_dir" == "syncthingconfig" || \ + "$destination_dir" == "syncthingshared" || \ + "$destination_dir" == "syncthing" || \ + "$destination_dir" == "mediagoblin" || \ + "$destination_dir" == "mailinglist" ]]; then + is_valid="no" + fi - echo $is_valid + echo $is_valid } function backup_extra_directories { - if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then - return - fi + if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then + return + fi - echo $"Backing up some additional directories" - while read backup_line - do - backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - if [ -d "$backup_dir" ]; then - destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then - backup_directory_to_usb "$backup_dir" "$destination_dir" - else - echo $"WARNING: The backup directory $destination_dir is already used." - echo $"Choose a different destination name for backing up $backup_dir" - fi - else - echo $"WARNING: Directory $backup_dir does not exist" - fi - done <$BACKUP_EXTRA_DIRECTORIES + echo $"Backing up some additional directories" + while read backup_line + do + backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + if [ -d "$backup_dir" ]; then + destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then + backup_directory_to_usb "$backup_dir" "$destination_dir" + else + echo $"WARNING: The backup directory $destination_dir is already used." + echo $"Choose a different destination name for backing up $backup_dir" + fi + else + echo $"WARNING: Directory $backup_dir does not exist" + fi + done <$BACKUP_EXTRA_DIRECTORIES } # has the remove option been set ? remove_option=$2 if [[ $1 == "remove" ]]; then - remove_option=$1 + remove_option=$1 fi mount_drive $1 $2 diff --git a/src/freedombone-backup-remote b/src/freedombone-backup-remote index 26807935..cc92414e 100755 --- a/src/freedombone-backup-remote +++ b/src/freedombone-backup-remote @@ -42,36 +42,36 @@ SERVER_DIRECTORY=/root/remotebackup # get the version of Go being used if [ -f /usr/local/bin/${PROJECT_NAME} ]; then - GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') + GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') else - GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') + GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') fi ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1) ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME} if [ ! -f /etc/ssl/private/backup.key ]; then - echo $"Creating backup key" - ${PROJECT_NAME}-addcert -h backup --dhkey 2048 + echo $"Creating backup key" + ${PROJECT_NAME}-addcert -h backup --dhkey 2048 fi if [ ! -f /home/${ADMIN_USERNAME}/backup.list ]; then - exit 1 + exit 1 fi # MariaDB password DATABASE_PASSWORD='' if [ -f /root/dbpass ]; then - DATABASE_PASSWORD=$(cat /root/dbpass) + DATABASE_PASSWORD=$(cat /root/dbpass) fi # local directory where the backup will be made if [ ! -d $SERVER_DIRECTORY ]; then - mkdir $SERVER_DIRECTORY + mkdir $SERVER_DIRECTORY fi if [ ! -d $SERVER_DIRECTORY/backup ]; then - mkdir -p $SERVER_DIRECTORY/backup + mkdir -p $SERVER_DIRECTORY/backup fi # The name of a currently suspended site @@ -79,623 +79,624 @@ fi SUSPENDED_SITE= function suspend_site { - # suspends a given website - if [[ $ENABLE_VERIFICATION != "yes" ]]; then - return - fi - SUSPENDED_SITE="$1" - nginx_dissite $SUSPENDED_SITE - service nginx reload + # suspends a given website + if [[ $ENABLE_VERIFICATION != "yes" ]]; then + return + fi + SUSPENDED_SITE="$1" + nginx_dissite $SUSPENDED_SITE + service nginx reload } function restart_site { - # restarts a given website - if [ ! $SUSPENDED_SITE ]; then - return - fi - nginx_ensite $SUSPENDED_SITE - service nginx reload - SUSPENDED_SITE= + # restarts a given website + if [ ! $SUSPENDED_SITE ]; then + return + fi + nginx_ensite $SUSPENDED_SITE + service nginx reload + SUSPENDED_SITE= } function backup_directory_to_friend { - BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)") - if [ ! "$?" = "0" ]; then - echo $"Backup key could not be found" - restart_site - exit 43382 - fi - ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then - mkdir -p $SERVER_DIRECTORY/backup/${2} - fi - obnam force-lock -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1} - obnam backup -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1} - if [[ $ENABLE_VERIFICATION == "yes" ]]; then - obnam verify -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1} - if [ ! "$?" = "0" ]; then - if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then - shred -zu /root/temp${2}/* - rm -rf /root/temp${2} - fi - # Send a warning email - echo "Unable to verify ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS} - restart_site - exit 953 - fi - fi - obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} - if [ ! "$?" = "0" ]; then - if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then - shred -zu /root/temp${2}/* - rm -rf /root/temp${2} - fi - # Send a warning email - echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS} - restart_site - exit 853 - fi - if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then - shred -zu /root/temp${2}/* - rm -rf /root/temp${2} - fi + BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)") + if [ ! "$?" = "0" ]; then + echo $"Backup key could not be found" + restart_site + exit 43382 + fi + ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then + mkdir -p $SERVER_DIRECTORY/backup/${2} + fi + obnam force-lock -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1} + obnam backup -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1} + if [[ $ENABLE_VERIFICATION == "yes" ]]; then + obnam verify -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1} + if [ ! "$?" = "0" ]; then + if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then + shred -zu /root/temp${2}/* + rm -rf /root/temp${2} + fi + # Send a warning email + echo "Unable to verify ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS} + restart_site + exit 953 + fi + fi + obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} + if [ ! "$?" = "0" ]; then + if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then + shred -zu /root/temp${2}/* + rm -rf /root/temp${2} + fi + # Send a warning email + echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS} + restart_site + exit 853 + fi + if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then + shred -zu /root/temp${2}/* + rm -rf /root/temp${2} + fi } function backup_database_to_friend { - if [ ${#DATABASE_PASSWORD} -lt 2 ]; then - echo $"No MariaDB password was given" - restart_site - exit 5783 - fi - if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then - mkdir -p $SERVER_DIRECTORY/backup/${1} - fi - if [ ! -d $SERVER_DIRECTORY/backup/${1}data ]; then - mkdir -p $SERVER_DIRECTORY/backup/${1}data - fi - if [ ! -d /root/temp${1}data ]; then - mkdir -p /root/temp${1}data - fi - echo "Obtaining ${1} database backup" - mysqldump --password=$DATABASE_PASSWORD ${1} > /root/temp${1}data/${1}.sql - if [ ! -s /root/temp${1}data/${1}.sql ]; then - echo $"${1} database could not be saved" - shred -zu /root/temp${1}data/* - rm -rf /root/temp${1}data - # Send a warning email - echo $"Unable to export ${1} database" | mail -s $"${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS - restart_site - exit 5738 - fi + if [ ${#DATABASE_PASSWORD} -lt 2 ]; then + echo $"No MariaDB password was given" + restart_site + exit 5783 + fi + if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then + mkdir -p $SERVER_DIRECTORY/backup/${1} + fi + if [ ! -d $SERVER_DIRECTORY/backup/${1}data ]; then + mkdir -p $SERVER_DIRECTORY/backup/${1}data + fi + if [ ! -d /root/temp${1}data ]; then + mkdir -p /root/temp${1}data + fi + echo "Obtaining ${1} database backup" + mysqldump --password=$DATABASE_PASSWORD ${1} > /root/temp${1}data/${1}.sql + if [ ! -s /root/temp${1}data/${1}.sql ]; then + echo $"${1} database could not be saved" + shred -zu /root/temp${1}data/* + rm -rf /root/temp${1}data + # Send a warning email + echo $"Unable to export ${1} database" | mail -s $"${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS + restart_site + exit 5738 + fi } function backup_configuration { - echo $"Backing up ${PROJECT_NAME} configuration files" - if [ ! -d /root/tempbackupconfig ]; then - mkdir -p /root/tempbackupconfig - fi - cp -f $CONFIG_FILE /root/tempbackupconfig - cp -f $COMPLETION_FILE /root/tempbackupconfig - if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then - cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig - fi - # nginx password hashes - if [ -f /etc/nginx/.htpasswd ]; then - cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd - fi - backup_directory_to_friend /root/tempbackupconfig config + echo $"Backing up ${PROJECT_NAME} configuration files" + if [ ! -d /root/tempbackupconfig ]; then + mkdir -p /root/tempbackupconfig + fi + cp -f $CONFIG_FILE /root/tempbackupconfig + cp -f $COMPLETION_FILE /root/tempbackupconfig + if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then + cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig + fi + # nginx password hashes + if [ -f /etc/nginx/.htpasswd ]; then + cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd + fi + backup_directory_to_friend /root/tempbackupconfig config } function backup_users { - for d in /home/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - # personal settings - if [ -d /home/$USERNAME/personal ]; then - echo $"Backing up personal settings for $USERNAME" - backup_directory_to_friend /home/$USERNAME/personal personal/$USERNAME - fi + # personal settings + if [ -d /home/$USERNAME/personal ]; then + echo $"Backing up personal settings for $USERNAME" + backup_directory_to_friend /home/$USERNAME/personal personal/$USERNAME + fi - # gpg keys - if [ -d /home/$USERNAME/.gnupg ]; then - echo $"Backing up gpg keys for $USERNAME" - backup_directory_to_friend /home/$USERNAME/.gnupg gnupg/$USERNAME - fi + # gpg keys + if [ -d /home/$USERNAME/.gnupg ]; then + echo $"Backing up gpg keys for $USERNAME" + backup_directory_to_friend /home/$USERNAME/.gnupg gnupg/$USERNAME + fi - # ssh keys - if [ -d /home/$USERNAME/.ssh ]; then - echo $"Backing up ssh keys for $USERNAME" - backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME - fi + # ssh keys + if [ -d /home/$USERNAME/.ssh ]; then + echo $"Backing up ssh keys for $USERNAME" + backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME + fi - # syncthing files - if [ -d /home/$USERNAME/Sync ]; then - echo $"Backing up syncthing files for $USERNAME" - backup_directory_to_friend /home/$USERNAME/Sync syncthing/$USERNAME - # ensure that device IDs will be backed up as part of user config settings - if [ ! -d /home/$USERNAME/.config/syncthing ]; then - mkdir -p /home/$USERNAME/.config/syncthing - chown -R $USERNAME:$USERNAME /home/$USERNAME/.config - fi - if [ -f /home/$USERNAME/.syncthing-server-id ]; then - cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing - chown -R $USERNAME:$USERNAME /home/$USERNAME/.config - fi - if [ -f /home/$USERNAME/.syncthingids ]; then - cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing - chown -R $USERNAME:$USERNAME /home/$USERNAME/.config - fi - fi + # syncthing files + if [ -d /home/$USERNAME/Sync ]; then + echo $"Backing up syncthing files for $USERNAME" + backup_directory_to_friend /home/$USERNAME/Sync syncthing/$USERNAME + # ensure that device IDs will be backed up as part of user config settings + if [ ! -d /home/$USERNAME/.config/syncthing ]; then + mkdir -p /home/$USERNAME/.config/syncthing + chown -R $USERNAME:$USERNAME /home/$USERNAME/.config + fi + if [ -f /home/$USERNAME/.syncthing-server-id ]; then + cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing + chown -R $USERNAME:$USERNAME /home/$USERNAME/.config + fi + if [ -f /home/$USERNAME/.syncthingids ]; then + cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing + chown -R $USERNAME:$USERNAME /home/$USERNAME/.config + fi + fi - # config files - if [ -d /home/$USERNAME/.config ]; then - echo $"Backing up config files for $USERNAME" - backup_directory_to_friend /home/$USERNAME/.config config/$USERNAME - fi + # config files + if [ -d /home/$USERNAME/.config ]; then + echo $"Backing up config files for $USERNAME" + backup_directory_to_friend /home/$USERNAME/.config config/$USERNAME + fi - # fin files - if [ -d /home/$USERNAME/.fin ]; then - echo $"Backing up fin files for $USERNAME" - backup_directory_to_friend /home/$USERNAME/.fin fin/$USERNAME - fi + # fin files + if [ -d /home/$USERNAME/.fin ]; then + echo $"Backing up fin files for $USERNAME" + backup_directory_to_friend /home/$USERNAME/.fin fin/$USERNAME + fi - # local files - if [ -d /home/$USERNAME/.local ]; then - echo $"Backing up local files for $USERNAME" - backup_directory_to_friend /home/$USERNAME/.local local/$USERNAME - fi + # local files + if [ -d /home/$USERNAME/.local ]; then + echo $"Backing up local files for $USERNAME" + backup_directory_to_friend /home/$USERNAME/.local local/$USERNAME + fi - # mutt settings - if [ -f /home/$USERNAME/.muttrc ]; then - echo $"Backing up Mutt settings for $USERNAME" - if [ ! -d /home/$USERNAME/tempbackup ]; then - mkdir -p /home/$USERNAME/tempbackup - fi - cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup - if [ -f /etc/Muttrc ]; then - cp /etc/Muttrc /home/$USERNAME/tempbackup - fi - backup_directory_to_friend /home/$USERNAME/tempbackup mutt/$USERNAME - fi + # mutt settings + if [ -f /home/$USERNAME/.muttrc ]; then + echo $"Backing up Mutt settings for $USERNAME" + if [ ! -d /home/$USERNAME/tempbackup ]; then + mkdir -p /home/$USERNAME/tempbackup + fi + cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup + if [ -f /etc/Muttrc ]; then + cp /etc/Muttrc /home/$USERNAME/tempbackup + fi + backup_directory_to_friend /home/$USERNAME/tempbackup mutt/$USERNAME + fi - # procmail settings - if [ -f /home/$USERNAME/.procmailrc ]; then - echo $"Backing up procmail settings for $USERNAME" - if [ ! -d /home/$USERNAME/tempbackup ]; then - mkdir -p /home/$USERNAME/tempbackup - fi - cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup - backup_directory_to_friend /home/$USERNAME/tempbackup procmail/$USERNAME - fi + # procmail settings + if [ -f /home/$USERNAME/.procmailrc ]; then + echo $"Backing up procmail settings for $USERNAME" + if [ ! -d /home/$USERNAME/tempbackup ]; then + mkdir -p /home/$USERNAME/tempbackup + fi + cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup + backup_directory_to_friend /home/$USERNAME/tempbackup procmail/$USERNAME + fi - # spamassassin settings - if [ -d /home/$USERNAME/.spamassassin ]; then - echo $"Backing up spamassassin settings for $USERNAME" - backup_directory_to_friend /home/$USERNAME/.spamassassin spamassassin/$USERNAME - fi + # spamassassin settings + if [ -d /home/$USERNAME/.spamassassin ]; then + echo $"Backing up spamassassin settings for $USERNAME" + backup_directory_to_friend /home/$USERNAME/.spamassassin spamassassin/$USERNAME + fi - # email - if [ -d /home/$USERNAME/Maildir ]; then - echo $"Creating an email archive" - if [ ! -d /root/backupemail/$USERNAME ]; then - mkdir -p /root/backupemail/$USERNAME - fi - tar -czvf /root/backupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir - echo $"Backing up emails for $USERNAME" - backup_directory_to_friend /root/backupemail/$USERNAME mail/$USERNAME - fi - fi - done + # email + if [ -d /home/$USERNAME/Maildir ]; then + echo $"Creating an email archive" + if [ ! -d /root/backupemail/$USERNAME ]; then + mkdir -p /root/backupemail/$USERNAME + fi + tar -czvf /root/backupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir + echo $"Backing up emails for $USERNAME" + backup_directory_to_friend /root/backupemail/$USERNAME mail/$USERNAME + fi + fi + done } function backup_letsencrypt { - if [ -d /etc/letsencrypt ]; then - echo $"Backing up Lets Encrypt settings" - backup_directory_to_friend /etc/letsencrypt letsencrypt - fi + if [ -d /etc/letsencrypt ]; then + echo $"Backing up Lets Encrypt settings" + backup_directory_to_friend /etc/letsencrypt letsencrypt + fi } function backup_tor { - if [ -d /etc/letsencrypt ]; then - echo $"Backing up Tor settings" - backup_directory_to_friend /var/lib/tor tor - fi + if [ -d /etc/letsencrypt ]; then + echo $"Backing up Tor settings" + backup_directory_to_friend /var/lib/tor tor + fi } function backup_rss_reader { - if grep -q "RSS reader domain" $COMPLETION_FILE; then - RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}') - if [ -d /etc/share/tt-rss ]; then - suspend_site ${RSS_READER_DOMAIN_NAME} - backup_database_to_friend ttrss - backup_directory_to_friend /root/tempttrssdata ttrssdata - echo $"Backing up RSS reader installation" - backup_directory_to_friend /etc/share/tt-rss ttrss - restart_site - else - echo $"RSS reader domain specified but not found in /etc/share/ttrss}" - fi - fi + if grep -q "RSS reader domain" $COMPLETION_FILE; then + RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}') + if [ -d /etc/share/tt-rss ]; then + suspend_site ${RSS_READER_DOMAIN_NAME} + backup_database_to_friend ttrss + backup_directory_to_friend /root/tempttrssdata ttrssdata + echo $"Backing up RSS reader installation" + backup_directory_to_friend /etc/share/tt-rss ttrss + restart_site + else + echo $"RSS reader domain specified but not found in /etc/share/ttrss}" + fi + fi } function backup_gnusocial { - if grep -q "GNU Social domain" $COMPLETION_FILE; then - MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') - if [ -d /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs ]; then - suspend_site ${MICROBLOG_DOMAIN_NAME} - backup_database_to_friend gnusocial - backup_directory_to_friend /root/tempgnusocialdata gnusocialdata - echo $"Backing up GNU social installation" - backup_directory_to_friend /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs gnusocial - restart_site - else - echo $"GNU Social domain specified but not found in /var/www/${MICROBLOG_DOMAIN_NAME}" - fi - fi + if grep -q "GNU Social domain" $COMPLETION_FILE; then + MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') + if [ -d /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs ]; then + suspend_site ${MICROBLOG_DOMAIN_NAME} + backup_database_to_friend gnusocial + backup_directory_to_friend /root/tempgnusocialdata gnusocialdata + echo $"Backing up GNU social installation" + backup_directory_to_friend /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs gnusocial + restart_site + else + echo $"GNU Social domain specified but not found in /var/www/${MICROBLOG_DOMAIN_NAME}" + fi + fi } function backup_hubzilla { - if grep -q "Hubzilla domain" $COMPLETION_FILE; then - HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') - if [ -d /var/www/${HUBZILLA_DOMAIN_NAME} ]; then - suspend_site ${HUBZILLA_DOMAIN_NAME} - backup_database_to_friend hubzilla - backup_directory_to_friend /root/temphubzilladata hubzilladata - echo "Backing up Hubzilla installation" - backup_directory_to_friend /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs hubzilla - restart_site - else - echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}" - exit 2578 - fi - fi + if grep -q "Hubzilla domain" $COMPLETION_FILE; then + HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') + if [ -d /var/www/${HUBZILLA_DOMAIN_NAME} ]; then + suspend_site ${HUBZILLA_DOMAIN_NAME} + backup_database_to_friend hubzilla + backup_directory_to_friend /root/temphubzilladata hubzilladata + echo "Backing up Hubzilla installation" + backup_directory_to_friend /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs hubzilla + restart_site + else + echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}" + exit 2578 + fi + fi } function backup_syncthing { - if [ -d /root/.config/syncthing ]; then - echo $"Backing up syncthing configuration" - backup_directory_to_friend /root/.config/syncthing syncthingconfig - fi - if [ -d /var/lib/syncthing/SyncShared ]; then - echo $"Backing up syncthing shared files" - backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared - fi + if [ -d /root/.config/syncthing ]; then + echo $"Backing up syncthing configuration" + backup_directory_to_friend /root/.config/syncthing syncthingconfig + fi + if [ -d /var/lib/syncthing/SyncShared ]; then + echo $"Backing up syncthing shared files" + backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared + fi } function backup_mediagoblin { - if grep -q "Mediagoblin domain" $COMPLETION_FILE; then - MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') - suspend_site ${MEDIAGOBLIN_DOMAIN_NAME} - echo $"Backing up Mediagoblin" - backup_directory_to_friend /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs mediagoblin - restart_site - fi + if grep -q "Mediagoblin domain" $COMPLETION_FILE; then + MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') + suspend_site ${MEDIAGOBLIN_DOMAIN_NAME} + echo $"Backing up Mediagoblin" + backup_directory_to_friend /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs mediagoblin + restart_site + fi } function backup_gogs { - export GVM_ROOT=$HOME/.gvm - if [ -d $GVM_ROOT/bin ]; then - cd $GVM_ROOT/bin - ./gvm use go${GO_VERSION} --default - systemctl set-environment GOPATH=$GOPATH - fi + export GVM_ROOT=$HOME/.gvm + if [ -d $GVM_ROOT/bin ]; then + cd $GVM_ROOT/bin + [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" + gvm use go${GO_VERSION} --default + systemctl set-environment GOPATH=$GOPATH + fi - if [ -d $GOPATH/src/github.com/gogits ]; then - GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') - suspend_site ${GIT_DOMAIN_NAME} - backup_database_to_friend gogs - backup_directory_to_friend /root/tempgogsdata gogsdata - echo $"Obtaining Gogs settings backup" - backup_directory_to_friend $GOPATH/src/github.com/gogits/gogs/custom gogs - echo $"Obtaining Gogs repos backup" - mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/bob - backup_directory_to_friend /home/git/gogs-repositories gogsrepos - echo $"Obtaining Gogs authorized_keys backup" - backup_directory_to_friend /home/git/.ssh gogsssh - restart_site - fi + if [ -d $GOPATH/src/github.com/gogits ]; then + GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') + suspend_site ${GIT_DOMAIN_NAME} + backup_database_to_friend gogs + backup_directory_to_friend /root/tempgogsdata gogsdata + echo $"Obtaining Gogs settings backup" + backup_directory_to_friend $GOPATH/src/github.com/gogits/gogs/custom gogs + echo $"Obtaining Gogs repos backup" + mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/bob + backup_directory_to_friend /home/git/gogs-repositories gogsrepos + echo $"Obtaining Gogs authorized_keys backup" + backup_directory_to_friend /home/git/.ssh gogsssh + restart_site + fi } function backup_wiki { - if [ -d /etc/dokuwiki ]; then - echo $"Backing up wiki" - backup_directory_to_friend /var/lib/dokuwiki wiki - backup_directory_to_friend /etc/dokuwiki wiki2 - fi + if [ -d /etc/dokuwiki ]; then + echo $"Backing up wiki" + backup_directory_to_friend /var/lib/dokuwiki wiki + backup_directory_to_friend /etc/dokuwiki wiki2 + fi } function backup_blog { - if grep -q "Blog domain" $COMPLETION_FILE; then - FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') - if [ -d /var/www/${FULLBLOG_DOMAIN_NAME} ]; then - echo $"Backing up blog" - backup_directory_to_friend /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs blog - else - echo $"Blog domain specified but not found in /var/www/${FULLBLOG_DOMAIN_NAME}" - exit 2578 - fi - fi + if grep -q "Blog domain" $COMPLETION_FILE; then + FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') + if [ -d /var/www/${FULLBLOG_DOMAIN_NAME} ]; then + echo $"Backing up blog" + backup_directory_to_friend /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs blog + else + echo $"Blog domain specified but not found in /var/www/${FULLBLOG_DOMAIN_NAME}" + exit 2578 + fi + fi } function backup_certs { - if [ -d /etc/ssl ]; then - echo $"Backing up certificates" - backup_directory_to_friend /etc/ssl ssl - fi + if [ -d /etc/ssl ]; then + echo $"Backing up certificates" + backup_directory_to_friend /etc/ssl ssl + fi } function backup_mailing_list { - if [ -d /var/spool/mlmmj ]; then - echo $"Backing up the public mailing list" - backup_directory_to_friend /var/spool/mlmmj mailinglist - fi + if [ -d /var/spool/mlmmj ]; then + echo $"Backing up the public mailing list" + backup_directory_to_friend /var/spool/mlmmj mailinglist + fi } function backup_xmpp { - if [ -d /var/lib/prosody ]; then - echo $"Backing up the XMPP settings" - backup_directory_to_friend /var/lib/prosody xmpp - fi + if [ -d /var/lib/prosody ]; then + echo $"Backing up the XMPP settings" + backup_directory_to_friend /var/lib/prosody xmpp + fi } function backup_web_server { - if [ -d /etc/nginx ]; then - echo $"Backing up web settings" - backup_directory_to_friend /etc/nginx/sites-available web - fi + if [ -d /etc/nginx ]; then + echo $"Backing up web settings" + backup_directory_to_friend /etc/nginx/sites-available web + fi } function backup_admin_readme { - if [ -f /home/$ADMIN_USERNAME/README ]; then - echo $"Backing up README" - if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then - mkdir -p /home/$ADMIN_USERNAME/tempbackup - fi - cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup - backup_directory_to_friend /home/$ADMIN_USERNAME/tempbackup readme - fi + if [ -f /home/$ADMIN_USERNAME/README ]; then + echo $"Backing up README" + if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then + mkdir -p /home/$ADMIN_USERNAME/tempbackup + fi + cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup + backup_directory_to_friend /home/$ADMIN_USERNAME/tempbackup readme + fi } function backup_ipfs { - if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then - echo $"Backing up IPFS" - backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs - fi + if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then + echo $"Backing up IPFS" + backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs + fi } function backup_dlna { - if [ -d /var/cache/minidlna ]; then - echo $"Backing up DLNA cache" - backup_directory_to_friend /var/cache/minidlna dlna - fi + if [ -d /var/cache/minidlna ]; then + echo $"Backing up DLNA cache" + backup_directory_to_friend /var/cache/minidlna dlna + fi } function backup_voip { - if [ -f /etc/mumble-server.ini ]; then - echo $"Backing up VoIP settings" - if [ ! -d /root/tempvoipbackup ]; then - mkdir -p /root/tempvoipbackup - fi - cp -f /etc/mumble-server.ini /root/tempvoipbackup - cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup - cp -f /etc/sipwitch.conf /root/tempvoipbackup - backup_directory_to_friend /root/tempvoipbackup voip - fi + if [ -f /etc/mumble-server.ini ]; then + echo $"Backing up VoIP settings" + if [ ! -d /root/tempvoipbackup ]; then + mkdir -p /root/tempvoipbackup + fi + cp -f /etc/mumble-server.ini /root/tempvoipbackup + cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup + cp -f /etc/sipwitch.conf /root/tempvoipbackup + backup_directory_to_friend /root/tempvoipbackup voip + fi } function backup_tox { - if [ -d /var/lib/tox-bootstrapd ]; then - echo "Backing up Tox node settings" - if [ -d /var/lib/tox-bootstrapd/Maildir ]; then - rm -rf /var/lib/tox-bootstrapd/Maildir - fi - cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd - backup_directory_to_friend /var/lib/tox-bootstrapd tox - fi + if [ -d /var/lib/tox-bootstrapd ]; then + echo "Backing up Tox node settings" + if [ -d /var/lib/tox-bootstrapd/Maildir ]; then + rm -rf /var/lib/tox-bootstrapd/Maildir + fi + cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd + backup_directory_to_friend /var/lib/tox-bootstrapd tox + fi } function backup_mariadb { - if [ ${#DATABASE_PASSWORD} -gt 1 ]; then - if [ ! -d /root/tempmariadb ]; then - mkdir /root/tempmariadb - fi - mysqldump --password=$DATABASE_PASSWORD mysql user > /root/tempmariadb/mysql.sql - if [ ! -s /root/tempmariadb/mysql.sql ]; then - echo $"Unable to backup MariaDB settings" - rm -rf /root/tempmariadb - # Send a warning email - echo $"Unable to export database settings" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS - exit 653 - fi - echo "$DATABASE_PASSWORD" > /root/tempmariadb/db - chmod 400 /root/tempmariadb/db - backup_directory_to_friend /root/tempmariadb mariadb - fi + if [ ${#DATABASE_PASSWORD} -gt 1 ]; then + if [ ! -d /root/tempmariadb ]; then + mkdir /root/tempmariadb + fi + mysqldump --password=$DATABASE_PASSWORD mysql user > /root/tempmariadb/mysql.sql + if [ ! -s /root/tempmariadb/mysql.sql ]; then + echo $"Unable to backup MariaDB settings" + rm -rf /root/tempmariadb + # Send a warning email + echo $"Unable to export database settings" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS + exit 653 + fi + echo "$DATABASE_PASSWORD" > /root/tempmariadb/db + chmod 400 /root/tempmariadb/db + backup_directory_to_friend /root/tempmariadb mariadb + fi } # Returns the filename of a key share function get_key_share { - no_of_shares=$1 - USERNAME="$2" - REMOTE_DOMAIN="$3" + no_of_shares=$1 + USERNAME="$2" + REMOTE_DOMAIN="$3" - # Get a share index based on the supplied domain name - # This ensures that the same share is always given to the same domain - sharenumstr=$(md5sum <<< "$REMOTE_DOMAIN") - share_index=$(echo $((0x${sharenumstr%% *} % ${no_of_shares})) | tr -d -) + # Get a share index based on the supplied domain name + # This ensures that the same share is always given to the same domain + sharenumstr=$(md5sum <<< "$REMOTE_DOMAIN") + share_index=$(echo $((0x${sharenumstr%% *} % ${no_of_shares})) | tr -d -) - # get the filename - share_files=(/home/$USERNAME/.gnupg_fragments/keyshare.asc.*) - share_filename=${share_files[share_index]} + # get the filename + share_files=(/home/$USERNAME/.gnupg_fragments/keyshare.asc.*) + share_filename=${share_files[share_index]} - echo "$share_filename" + echo "$share_filename" } function disperse_key_shares { - USERNAME=$1 - REMOTE_DOMAIN=$2 - REMOTE_SSH_PORT=$3 - REMOTE_PASSWORD=$4 - REMOTE_SERVER=$5 + USERNAME=$1 + REMOTE_DOMAIN=$2 + REMOTE_SSH_PORT=$3 + REMOTE_PASSWORD=$4 + REMOTE_SERVER=$5 - if [ -d /home/$USERNAME/.gnupg_fragments ]; then - if [ $REMOTE_DOMAIN ]; then - cd /home/$USERNAME/.gnupg_fragments - no_of_shares=$(ls -afq keyshare.asc.* | wc -l) - if (( no_of_shares > 1 )); then - share_filename=$(get_key_share $no_of_shares "$USERNAME" "$REMOTE_DOMAIN") + if [ -d /home/$USERNAME/.gnupg_fragments ]; then + if [ $REMOTE_DOMAIN ]; then + cd /home/$USERNAME/.gnupg_fragments + no_of_shares=$(ls -afq keyshare.asc.* | wc -l) + if (( no_of_shares > 1 )); then + share_filename=$(get_key_share $no_of_shares "$USERNAME" "$REMOTE_DOMAIN") - # create a temp directory containing the share - temp_key_share_dir=/home/$USERNAME/tempkey - temp_key_share_fragments=$temp_key_share_dir/.gnupg_fragments_${USERNAME} - mkdir -p $temp_key_share_fragments - cp $share_filename $temp_key_share_fragments/ + # create a temp directory containing the share + temp_key_share_dir=/home/$USERNAME/tempkey + temp_key_share_fragments=$temp_key_share_dir/.gnupg_fragments_${USERNAME} + mkdir -p $temp_key_share_fragments + cp $share_filename $temp_key_share_fragments/ - # copy the fragments directory to the remote server - /usr/bin/sshpass -p "$REMOTE_PASSWORD" \ - scp -r -P $REMOTE_SSH_PORT $temp_key_share_fragments $REMOTE_SERVER - if [ ! "$?" = "0" ]; then - # Send a warning email - echo "Key share to $REMOTE_SERVER failed" | \ - mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS - else - # Send a confirmation email - echo "Key ${share_filename} shared to $REMOTE_SERVER" | \ - mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS - fi + # copy the fragments directory to the remote server + /usr/bin/sshpass -p "$REMOTE_PASSWORD" \ + scp -r -P $REMOTE_SSH_PORT $temp_key_share_fragments $REMOTE_SERVER + if [ ! "$?" = "0" ]; then + # Send a warning email + echo "Key share to $REMOTE_SERVER failed" | \ + mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS + else + # Send a confirmation email + echo "Key ${share_filename} shared to $REMOTE_SERVER" | \ + mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS + fi - # remove the temp file/directory - shred -zu $temp_key_share_fragments/* - rm -rf $temp_key_share_dir - fi - fi - fi + # remove the temp file/directory + shred -zu $temp_key_share_fragments/* + rm -rf $temp_key_share_dir + fi + fi + fi } function valid_backup_destination { - destination_dir="$1" - is_valid="yes" + destination_dir="$1" + is_valid="yes" - if [[ "$destination_dir" == "hubzilla" || \ - "$destination_dir" == "hubzilladata" || \ - "$destination_dir" == "gogs" || \ - "$destination_dir" == "gogsrepos" || \ - "$destination_dir" == "gogsssh" || \ - "$destination_dir" == "gnusocial" || \ - "$destination_dir" == "gnusocialdata" || \ - "$destination_dir" == "mariadb" || \ - "$destination_dir" == "config" || \ - "$destination_dir" == "letsencrypt" || \ - "$destination_dir" == "wiki" || \ - "$destination_dir" == "wiki2" || \ - "$destination_dir" == "xmpp" || \ - "$destination_dir" == "ipfs" || \ - "$destination_dir" == "dlna" || \ - "$destination_dir" == "tox" || \ - "$destination_dir" == "ssl" || \ - "$destination_dir" == "blog" || \ - "$destination_dir" == "syncthing" || \ - "$destination_dir" == "syncthingconfig" || \ - "$destination_dir" == "syncthingshared" || \ - "$destination_dir" == "mailinglist" ]]; then - is_valid="no" - fi + if [[ "$destination_dir" == "hubzilla" || \ + "$destination_dir" == "hubzilladata" || \ + "$destination_dir" == "gogs" || \ + "$destination_dir" == "gogsrepos" || \ + "$destination_dir" == "gogsssh" || \ + "$destination_dir" == "gnusocial" || \ + "$destination_dir" == "gnusocialdata" || \ + "$destination_dir" == "mariadb" || \ + "$destination_dir" == "config" || \ + "$destination_dir" == "letsencrypt" || \ + "$destination_dir" == "wiki" || \ + "$destination_dir" == "wiki2" || \ + "$destination_dir" == "xmpp" || \ + "$destination_dir" == "ipfs" || \ + "$destination_dir" == "dlna" || \ + "$destination_dir" == "tox" || \ + "$destination_dir" == "ssl" || \ + "$destination_dir" == "blog" || \ + "$destination_dir" == "syncthing" || \ + "$destination_dir" == "syncthingconfig" || \ + "$destination_dir" == "syncthingshared" || \ + "$destination_dir" == "mailinglist" ]]; then + is_valid="no" + fi - echo $is_valid + echo $is_valid } function backup_extra_directories { - if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then - return - fi + if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then + return + fi - echo $"Backing up some additional directories" - while read backup_line - do - backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - if [ -d "$backup_dir" ]; then - destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then - backup_directory_to_friend "$backup_dir" "$destination_dir" - else - echo $"WARNING: The backup directory $destination_dir is already used." - echo $"Choose a different destination name for backing up $backup_dir" - fi - else - echo $"WARNING: Directory $backup_dir does not exist" - fi - done <$BACKUP_EXTRA_DIRECTORIES + echo $"Backing up some additional directories" + while read backup_line + do + backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + if [ -d "$backup_dir" ]; then + destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then + backup_directory_to_friend "$backup_dir" "$destination_dir" + else + echo $"WARNING: The backup directory $destination_dir is already used." + echo $"Choose a different destination name for backing up $backup_dir" + fi + else + echo $"WARNING: Directory $backup_dir does not exist" + fi + done <$BACKUP_EXTRA_DIRECTORIES } TEST_MODE="no" if [[ "$1" == "test" ]]; then - TEST_MODE="yes" + TEST_MODE="yes" fi backup_configuration if [[ $TEST_MODE == "no" ]]; then - backup_users - backup_letsencrypt - backup_tor - backup_gnusocial - backup_rss_reader - backup_hubzilla - backup_syncthing - backup_mediagoblin - backup_gogs - backup_wiki - backup_blog - backup_certs - backup_mailing_list - backup_xmpp - backup_web_server - backup_admin_readme - backup_ipfs - backup_dlna - backup_voip - backup_tox - backup_mariadb - backup_extra_directories + backup_users + backup_letsencrypt + backup_tor + backup_gnusocial + backup_rss_reader + backup_hubzilla + backup_syncthing + backup_mediagoblin + backup_gogs + backup_wiki + backup_blog + backup_certs + backup_mailing_list + backup_xmpp + backup_web_server + backup_admin_readme + backup_ipfs + backup_dlna + backup_voip + backup_tox + backup_mariadb + backup_extra_directories fi # For each remote server while read remote_server do - # Get the server and its password - # Format is: - # username@domain /home/username - REMOTE_SERVER=$(echo "${remote_server}" | awk -F ' ' '{print $1}') - if [ $REMOTE_SERVER ]; then - REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}') - REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}') - REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}') - REMOTE_PASSWORD=$(echo "${remote_server}" | awk -F ' ' '{print $4}') - NOW=$(date +"%Y-%m-%d %H:%M:%S") - REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY + # Get the server and its password + # Format is: + # username@domain /home/username + REMOTE_SERVER=$(echo "${remote_server}" | awk -F ' ' '{print $1}') + if [ $REMOTE_SERVER ]; then + REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}') + REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}') + REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}') + REMOTE_PASSWORD=$(echo "${remote_server}" | awk -F ' ' '{print $4}') + NOW=$(date +"%Y-%m-%d %H:%M:%S") + REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY - echo "$NOW Starting backup to $REMOTE_SERVER" >> /var/log/remotebackups.log + echo "$NOW Starting backup to $REMOTE_SERVER" >> /var/log/remotebackups.log - # Social key management - for d in /home/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - disperse_key_shares $USERNAME $REMOTE_DOMAIN $REMOTE_SSH_PORT "$REMOTE_PASSWORD" $REMOTE_SERVER - fi - done + # Social key management + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + disperse_key_shares $USERNAME $REMOTE_DOMAIN $REMOTE_SSH_PORT "$REMOTE_PASSWORD" $REMOTE_SERVER + fi + done - if [[ $TEST_MODE == "yes" ]]; then - echo "rsync -ratlzv --rsh=\"/usr/bin/sshpass -p '$REMOTE_PASSWORD' ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no\" $SERVER_DIRECTORY/backup $REMOTE_SERVER" - fi - rsync -ratlzv --rsh="/usr/bin/sshpass -p \"$REMOTE_PASSWORD\" ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" $SERVER_DIRECTORY/backup $REMOTE_SERVER - if [ ! "$?" = "0" ]; then - echo "$NOW Backup to $REMOTE_SERVER failed" >> /var/log/remotebackups.log - # Send a warning email - echo "Backup to $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS - else - echo "$NOW Backed up to $REMOTE_SERVER" >> /var/log/remotebackups.log - fi - fi + if [[ $TEST_MODE == "yes" ]]; then + echo "rsync -ratlzv --rsh=\"/usr/bin/sshpass -p '$REMOTE_PASSWORD' ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no\" $SERVER_DIRECTORY/backup $REMOTE_SERVER" + fi + rsync -ratlzv --rsh="/usr/bin/sshpass -p \"$REMOTE_PASSWORD\" ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" $SERVER_DIRECTORY/backup $REMOTE_SERVER + if [ ! "$?" = "0" ]; then + echo "$NOW Backup to $REMOTE_SERVER failed" >> /var/log/remotebackups.log + # Send a warning email + echo "Backup to $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS + else + echo "$NOW Backed up to $REMOTE_SERVER" >> /var/log/remotebackups.log + fi + fi done < /home/${ADMIN_USERNAME}/backup.list diff --git a/src/freedombone-restore-local b/src/freedombone-restore-local index 5ac455fb..64fdabc1 100755 --- a/src/freedombone-restore-local +++ b/src/freedombone-restore-local @@ -44,16 +44,16 @@ USB_MOUNT=/mnt/usb # get default USB from config file CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg if [ -f $CONFIG_FILE ]; then - if grep -q "USB_DRIVE=" $CONFIG_FILE; then - USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}') - fi + if grep -q "USB_DRIVE=" $CONFIG_FILE; then + USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}') + fi fi # get the version of Go being used if [ -f /usr/local/bin/${PROJECT_NAME} ]; then - GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') + GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') else - GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') + GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') fi ADMIN_USERNAME= @@ -70,1124 +70,1125 @@ WIKI_DOMAIN_NAME= FULLBLOG_DOMAIN_NAME= function mount_drive { - if [ $1 ]; then - USB_DRIVE=/dev/${1}1 - fi + if [ $1 ]; then + USB_DRIVE=/dev/${1}1 + fi - if [ $2 ]; then - RESTORE_APP=$2 - fi + if [ $2 ]; then + RESTORE_APP=$2 + fi - # get the admin user - ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') - if [ $3 ]; then - ADMIN_USERNAME=$3 - fi - ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1) + # get the admin user + ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') + if [ $3 ]; then + ADMIN_USERNAME=$3 + fi + ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1) - # check that the backup destination is available - if [ ! -b $USB_DRIVE ]; then - echo $"Please attach a USB drive" - exit 1 - fi + # check that the backup destination is available + if [ ! -b $USB_DRIVE ]; then + echo $"Please attach a USB drive" + exit 1 + fi - # unmount if already mounted - umount -f $USB_MOUNT - if [ ! -d $USB_MOUNT ]; then - mkdir $USB_MOUNT - fi - if [ -f /dev/mapper/encrypted_usb ]; then - rm -rf /dev/mapper/encrypted_usb - fi - cryptsetup luksClose encrypted_usb + # unmount if already mounted + umount -f $USB_MOUNT + if [ ! -d $USB_MOUNT ]; then + mkdir $USB_MOUNT + fi + if [ -f /dev/mapper/encrypted_usb ]; then + rm -rf /dev/mapper/encrypted_usb + fi + cryptsetup luksClose encrypted_usb - # mount the encrypted backup drive - cryptsetup luksOpen $USB_DRIVE encrypted_usb - if [ "$?" = "0" ]; then - USB_DRIVE=/dev/mapper/encrypted_usb - fi - mount $USB_DRIVE $USB_MOUNT - if [ ! "$?" = "0" ]; then - echo $"There was a problem mounting the USB drive to $USB_MOUNT" - rm -rf $USB_MOUNT - exit 2 - fi + # mount the encrypted backup drive + cryptsetup luksOpen $USB_DRIVE encrypted_usb + if [ "$?" = "0" ]; then + USB_DRIVE=/dev/mapper/encrypted_usb + fi + mount $USB_DRIVE $USB_MOUNT + if [ ! "$?" = "0" ]; then + echo $"There was a problem mounting the USB drive to $USB_MOUNT" + rm -rf $USB_MOUNT + exit 2 + fi } function unmount_drive { - sync - umount $USB_MOUNT - if [ ! "$?" = "0" ]; then - echo $"Unable to unmount the drive. This means that the backup did not work" - rm -rf $USB_MOUNT - exit 9 - fi - rm -rf $USB_MOUNT + sync + umount $USB_MOUNT + if [ ! "$?" = "0" ]; then + echo $"Unable to unmount the drive. This means that the backup did not work" + rm -rf $USB_MOUNT + exit 9 + fi + rm -rf $USB_MOUNT - echo $"Setting permissions" - for d in /home/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $3}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - chown -R $USERNAME:$USERNAME /home/$USERNAME - fi - done + echo $"Setting permissions" + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + chown -R $USERNAME:$USERNAME /home/$USERNAME + fi + done - if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then - echo $"Unmount encrypted USB" - cryptsetup luksClose encrypted_usb - fi - if [ -f /dev/mapper/encrypted_usb ]; then - rm -rf /dev/mapper/encrypted_usb - fi + if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then + echo $"Unmount encrypted USB" + cryptsetup luksClose encrypted_usb + fi + if [ -f /dev/mapper/encrypted_usb ]; then + rm -rf /dev/mapper/encrypted_usb + fi } function check_backup_exists { - if [ ! -d $USB_MOUNT/backup ]; then - echo $"No backup directory found on the USB drive." - unmount_drive - exit 2 - fi + if [ ! -d $USB_MOUNT/backup ]; then + echo $"No backup directory found on the USB drive." + unmount_drive + exit 2 + fi } function check_admin_user { - echo $"Checking that admin user exists" - if [ ! -d /home/$ADMIN_USERNAME ]; then - echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username." - unmount_drive - exit 295 - fi + echo $"Checking that admin user exists" + if [ ! -d /home/$ADMIN_USERNAME ]; then + echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username." + unmount_drive + exit 295 + fi } function copy_gpg_keys { - echo $"Copying GPG keys from admin user to root" - cp -r /home/$ADMIN_USERNAME/.gnupg /root + echo $"Copying GPG keys from admin user to root" + cp -r /home/$ADMIN_USERNAME/.gnupg /root } function restore_directory_from_usb { - if [ ! -d ${1} ]; then - mkdir ${1} - fi - obnam restore -r $USB_MOUNT/backup/${2} --to ${1} + if [ ! -d ${1} ]; then + mkdir ${1} + fi + obnam restore -r $USB_MOUNT/backup/${2} --to ${1} } function restore_database { - RESTORE_SUBDIR="root" + RESTORE_SUBDIR="root" - if [ -d $USB_MOUNT/backup/${1} ]; then - echo $"Restoring ${1} database" - restore_directory_from_usb "/root/temp${1}data" "${1}data" - if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then - echo $"Unable to restore ${1} database" - rm -rf /root/temp${1}data - unmount_drive - exit 503 - fi - mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql) - if [ ! "$?" = "0" ]; then - echo "$mysqlsuccess" - unmount_drive - exit 964 - fi - shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/* - rm -rf /root/temp${1}data - echo $"Restoring ${1} installation" - if [ ! -d /root/temp${1} ]; then - mkdir /root/temp${1} - fi - restore_directory_from_usb "/root/temp${1}" "${1}" - RESTORE_SUBDIR="var" - if [ ${2} ]; then - # special handline of ttrss - if [[ ${2} == "ttrss" ]]; then - if [ -d /etc/share/tt-rss ]; then - if [ -d /root/temp${1}/etc/share/tt-rss ]; then - rm -rf /etc/share/tt-rss - mv /root/temp${1}/etc/share/tt-rss /etc/share/ - if [ ! "$?" = "0" ]; then - unmount_drive - exit 528 - fi - if [ -d /etc/letsencrypt/live/${2} ]; then - ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key - ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem - else - # Ensure that the bundled SSL cert is being used - if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then - sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2} - fi - fi - fi - fi - fi + if [ -d $USB_MOUNT/backup/${1} ]; then + echo $"Restoring ${1} database" + restore_directory_from_usb "/root/temp${1}data" "${1}data" + if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then + echo $"Unable to restore ${1} database" + rm -rf /root/temp${1}data + unmount_drive + exit 503 + fi + mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql) + if [ ! "$?" = "0" ]; then + echo "$mysqlsuccess" + unmount_drive + exit 964 + fi + shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/* + rm -rf /root/temp${1}data + echo $"Restoring ${1} installation" + if [ ! -d /root/temp${1} ]; then + mkdir /root/temp${1} + fi + restore_directory_from_usb "/root/temp${1}" "${1}" + RESTORE_SUBDIR="var" + if [ ${2} ]; then + # special handline of ttrss + if [[ ${2} == "ttrss" ]]; then + if [ -d /etc/share/tt-rss ]; then + if [ -d /root/temp${1}/etc/share/tt-rss ]; then + rm -rf /etc/share/tt-rss + mv /root/temp${1}/etc/share/tt-rss /etc/share/ + if [ ! "$?" = "0" ]; then + unmount_drive + exit 528 + fi + if [ -d /etc/letsencrypt/live/${2} ]; then + ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key + ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem + else + # Ensure that the bundled SSL cert is being used + if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then + sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2} + fi + fi + fi + fi + fi - if [ -d /var/www/${2}/htdocs ]; then - if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then - rm -rf /var/www/${2}/htdocs - mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/ - if [ ! "$?" = "0" ]; then - unmount_drive - exit 683 - fi - if [ -d /etc/letsencrypt/live/${2} ]; then - ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key - ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem - else - # Ensure that the bundled SSL cert is being used - if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then - sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2} - fi - fi - fi - fi - fi - fi + if [ -d /var/www/${2}/htdocs ]; then + if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then + rm -rf /var/www/${2}/htdocs + mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/ + if [ ! "$?" = "0" ]; then + unmount_drive + exit 683 + fi + if [ -d /etc/letsencrypt/live/${2} ]; then + ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key + ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem + else + # Ensure that the bundled SSL cert is being used + if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then + sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2} + fi + fi + fi + fi + fi + fi } function update_domains { - if grep -q "RSS reader domain" $COMPLETION_FILE; then - RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}') - fi - if grep -q "GNU Social domain" $COMPLETION_FILE; then - MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') - fi - if grep -q "Hubzilla domain" $COMPLETION_FILE; then - HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') - fi - if grep -q "Mediagoblin domain" $COMPLETION_FILE; then - MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') - fi - if grep -q "Gogs domain" $COMPLETION_FILE; then - GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') - fi - if [ -d $USB_MOUNT/backup/wiki ]; then - WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}') - fi - if [ -d $USB_MOUNT/backup/blog ]; then - FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') - fi + if grep -q "RSS reader domain" $COMPLETION_FILE; then + RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}') + fi + if grep -q "GNU Social domain" $COMPLETION_FILE; then + MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') + fi + if grep -q "Hubzilla domain" $COMPLETION_FILE; then + HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') + fi + if grep -q "Mediagoblin domain" $COMPLETION_FILE; then + MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') + fi + if grep -q "Gogs domain" $COMPLETION_FILE; then + GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') + fi + if [ -d $USB_MOUNT/backup/wiki ]; then + WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}') + fi + if [ -d $USB_MOUNT/backup/blog ]; then + FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') + fi } function restore_configuration { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'configuration' ]]; then - return - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'configuration' ]]; then + return + fi + fi - # this restores *.cfg and COMPLETION_FILE - if [ -d $USB_MOUNT/backup/config ]; then - echo $"Restoring configuration files" - restore_directory_from_usb /root/tempconfig config + # this restores *.cfg and COMPLETION_FILE + if [ -d $USB_MOUNT/backup/config ]; then + echo $"Restoring configuration files" + restore_directory_from_usb /root/tempconfig config - cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE - if [ ! "$?" = "0" ]; then - unmount_drive - rm -rf /root/tempconfig - exit 5294 - fi - if [ -f $CONFIG_FILE ]; then - # install according to the config file - freedombone -c $CONFIG_FILE - fi + cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE + if [ ! "$?" = "0" ]; then + unmount_drive + rm -rf /root/tempconfig + exit 5294 + fi + if [ -f $CONFIG_FILE ]; then + # install according to the config file + freedombone -c $CONFIG_FILE + fi - cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE - if [ ! "$?" = "0" ]; then - unmount_drive - rm -rf /root/tempconfig - exit 6382 - fi + cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE + if [ ! "$?" = "0" ]; then + unmount_drive + rm -rf /root/tempconfig + exit 6382 + fi - if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then - cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} - if [ ! "$?" = "0" ]; then - unmount_drive - rm -rf /root/tempconfig - exit 62121 - fi - fi + if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then + cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} + if [ ! "$?" = "0" ]; then + unmount_drive + rm -rf /root/tempconfig + exit 62121 + fi + fi - # restore nginx password hashes - if [ -f /root/tempconfig/root/htpasswd ]; then - cp -f /root/tempconfig/root/htpasswd /etc/nginx/.htpasswd - fi + # restore nginx password hashes + if [ -f /root/tempconfig/root/htpasswd ]; then + cp -f /root/tempconfig/root/htpasswd /etc/nginx/.htpasswd + fi - rm -rf /root/tempconfig - fi + rm -rf /root/tempconfig + fi } function same_admin_user { - PREV_ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') - if [[ "$PREV_ADMIN_USERNAME" != "$ADMIN_USERNAME" ]]; then - echo $"The admin username has changed from $PREV_ADMIN_USERNAME to $ADMIN_USERNAME. To restore you will first need to install a new ${PROJECT_NAME} system with an initial admin user named $PREV_ADMIN_USERNAME" - unmount_drive - exit 73265 - fi + PREV_ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') + if [[ "$PREV_ADMIN_USERNAME" != "$ADMIN_USERNAME" ]]; then + echo $"The admin username has changed from $PREV_ADMIN_USERNAME to $ADMIN_USERNAME. To restore you will first need to install a new ${PROJECT_NAME} system with an initial admin user named $PREV_ADMIN_USERNAME" + unmount_drive + exit 73265 + fi } function restore_mariadb { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mariadb' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/mariadb ]; then - echo $"Restoring mysql settings" - restore_directory_from_usb /root/tempmariadb mariadb - echo $"Get the MariaDB password from the backup" - if [ ! -f /root/tempmariadb/root/tempmariadb/db ]; then - echo $"MariaDB password file not found" - exit 495 - fi - BACKUP_MARIADB_PASSWORD=$(cat /root/tempmariadb/root/tempmariadb/db) - if [[ $BACKUP_MARIADB_PASSWORD != $DATABASE_PASSWORD ]]; then - echo $"Restore the MariaDB user table" - mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) - if [ ! "$?" = "0" ]; then - echo $"Try again using the password obtained from backup" - mysqlsuccess=$(mysql -u root --password=$BACKUP_MARIADB_PASSWORD mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) - fi - if [ ! "$?" = "0" ]; then - echo "$mysqlsuccess" - unmount_drive - exit 962 - fi - echo $"Restarting database" - service mysql restart - echo $"Change the MariaDB password to the backup version" - DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD - fi - shred -zu /root/tempmariadb/root/tempmariadb/db - rm -rf /root/tempmariadb + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mariadb' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/mariadb ]; then + echo $"Restoring mysql settings" + restore_directory_from_usb /root/tempmariadb mariadb + echo $"Get the MariaDB password from the backup" + if [ ! -f /root/tempmariadb/root/tempmariadb/db ]; then + echo $"MariaDB password file not found" + exit 495 + fi + BACKUP_MARIADB_PASSWORD=$(cat /root/tempmariadb/root/tempmariadb/db) + if [[ $BACKUP_MARIADB_PASSWORD != $DATABASE_PASSWORD ]]; then + echo $"Restore the MariaDB user table" + mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) + if [ ! "$?" = "0" ]; then + echo $"Try again using the password obtained from backup" + mysqlsuccess=$(mysql -u root --password=$BACKUP_MARIADB_PASSWORD mysql -o < /root/tempmariadb/root/tempmariadb/mysql.sql) + fi + if [ ! "$?" = "0" ]; then + echo "$mysqlsuccess" + unmount_drive + exit 962 + fi + echo $"Restarting database" + service mysql restart + echo $"Change the MariaDB password to the backup version" + DATABASE_PASSWORD=$BACKUP_MARIADB_PASSWORD + fi + shred -zu /root/tempmariadb/root/tempmariadb/db + rm -rf /root/tempmariadb - # Change database password file - echo "$DATABASE_PASSWORD" > /root/dbpass - chmod 600 /root/dbpass - fi + # Change database password file + echo "$DATABASE_PASSWORD" > /root/dbpass + chmod 600 /root/dbpass + fi } function restore_letsencrypt { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'letsencrypt' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/letsencrypt ]; then - echo $"Restoring Lets Encrypt settings" - restore_directory_from_usb / letsencrypt - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'letsencrypt' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/letsencrypt ]; then + echo $"Restoring Lets Encrypt settings" + restore_directory_from_usb / letsencrypt + fi } function restore_tor { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'tor' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/tor ]; then - echo $"Restoring Tor settings" - restore_directory_from_usb / tor - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'tor' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/tor ]; then + echo $"Restoring Tor settings" + restore_directory_from_usb / tor + fi } function restore_mutt_settings { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mutt' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/mutt ]; then - for d in $USB_MOUNT/backup/mutt/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring Mutt settings for $USERNAME" - restore_directory_from_usb /root/tempmutt mutt/$USERNAME - if [ -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc ]; then - cp -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc - fi - if [ -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc ]; then - cp -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc - fi - if [ ! "$?" = "0" ]; then - rm -rf /root/tempmutt - unmount_drive - exit 276 - fi - rm -rf /root/tempmutt - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mutt' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/mutt ]; then + for d in $USB_MOUNT/backup/mutt/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring Mutt settings for $USERNAME" + restore_directory_from_usb /root/tempmutt mutt/$USERNAME + if [ -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc ]; then + cp -f /root/tempmutt/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc + fi + if [ -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc ]; then + cp -f /root/tempmutt/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc + fi + if [ ! "$?" = "0" ]; then + rm -rf /root/tempmutt + unmount_drive + exit 276 + fi + rm -rf /root/tempmutt + fi + done + fi } function restore_gpg { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'gpg' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/gnupg ]; then - for d in $USB_MOUNT/backup/gnupg/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring gnupg settings for $USERNAME" - restore_directory_from_usb /root/tempgnupg gnupg/$USERNAME - cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempgnupg - unmount_drive - exit 276 - fi - rm -rf /root/tempgnupg - if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then - cp -r /home/$USERNAME/.gnupg /root - if [ ! "$?" = "0" ]; then - unmount_drive - exit 283 - fi - fi - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'gpg' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/gnupg ]; then + for d in $USB_MOUNT/backup/gnupg/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring gnupg settings for $USERNAME" + restore_directory_from_usb /root/tempgnupg gnupg/$USERNAME + cp -r /root/tempgnupg/home/$USERNAME/.gnupg /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempgnupg + unmount_drive + exit 276 + fi + rm -rf /root/tempgnupg + if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then + cp -r /home/$USERNAME/.gnupg /root + if [ ! "$?" = "0" ]; then + unmount_drive + exit 283 + fi + fi + fi + done + fi } function restore_procmail { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'procmail' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/procmail ]; then - for d in $USB_MOUNT/backup/procmail/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring procmail settings for $USERNAME" - restore_directory_from_usb /root/tempprocmail procmail/$USERNAME - cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempprocmail - unmount_drive - exit 276 - fi - rm -rf /root/tempprocmail - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'procmail' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/procmail ]; then + for d in $USB_MOUNT/backup/procmail/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring procmail settings for $USERNAME" + restore_directory_from_usb /root/tempprocmail procmail/$USERNAME + cp -f /root/tempprocmail/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempprocmail + unmount_drive + exit 276 + fi + rm -rf /root/tempprocmail + fi + done + fi } function restore_spamassassin { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'spamassassin' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/spamassassin ]; then - for d in $USB_MOUNT/backup/spamassassin/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ -d $USB_MOUNT/backup/spamassassin/$USERNAME ]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring spamassassin settings for $USERNAME" - restore_directory_from_usb /root/tempspamassassin spamassassin/$USERNAME - cp -rf /root/tempspamassassin/home/$USERNAME/.spamassassin /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempspamassassin - unmount_drive - exit 276 - fi - rm -rf /root/tempspamassassin - fi - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'spamassassin' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/spamassassin ]; then + for d in $USB_MOUNT/backup/spamassassin/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ -d $USB_MOUNT/backup/spamassassin/$USERNAME ]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring spamassassin settings for $USERNAME" + restore_directory_from_usb /root/tempspamassassin spamassassin/$USERNAME + cp -rf /root/tempspamassassin/home/$USERNAME/.spamassassin /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempspamassassin + unmount_drive + exit 276 + fi + rm -rf /root/tempspamassassin + fi + fi + done + fi } function restore_admin_readme { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'readme' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/readme ]; then - echo $"Restoring admin user README" + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'readme' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/readme ]; then + echo $"Restoring admin user README" - # Make a backup of the original README file - # incase old passwords need to be used - if [ -f /home/$ADMIN_USERNAME/README ]; then - if [ ! -f /home/$ADMIN_USERNAME/README_original ]; then - cp /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/README_original - fi - fi + # Make a backup of the original README file + # incase old passwords need to be used + if [ -f /home/$ADMIN_USERNAME/README ]; then + if [ ! -f /home/$ADMIN_USERNAME/README_original ]; then + cp /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/README_original + fi + fi - restore_directory_from_usb /root/tempreadme readme - cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempreadme - unmount_drive - exit 276 - fi - rm -rf /root/tempreadme - fi + restore_directory_from_usb /root/tempreadme readme + cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempreadme + unmount_drive + exit 276 + fi + rm -rf /root/tempreadme + fi } function restore_ipfs { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'ipfs' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/ipfs ]; then - echo $"Restoring IPFS" - restore_directory_from_usb /root/tempipfs ipfs - cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs - if [ ! "$?" = "0" ]; then - rm -rf /root/tempipfs - unmount_drive - exit 276 - fi - rm -rf /root/tempipfs - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'ipfs' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/ipfs ]; then + echo $"Restoring IPFS" + restore_directory_from_usb /root/tempipfs ipfs + cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs + if [ ! "$?" = "0" ]; then + rm -rf /root/tempipfs + unmount_drive + exit 276 + fi + rm -rf /root/tempipfs + fi } function restore_user_ssh_keys { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'ssh' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/ssh ]; then - for d in $USB_MOUNT/backup/ssh/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring ssh keys for $USERNAME" - restore_directory_from_usb /root/tempssh ssh/$USERNAME - cp -r /root/tempssh/home/$USERNAME/.ssh /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempssh - unmount_drive - exit 664 - fi - rm -rf /root/tempssh - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'ssh' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/ssh ]; then + for d in $USB_MOUNT/backup/ssh/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring ssh keys for $USERNAME" + restore_directory_from_usb /root/tempssh ssh/$USERNAME + cp -r /root/tempssh/home/$USERNAME/.ssh /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempssh + unmount_drive + exit 664 + fi + rm -rf /root/tempssh + fi + done + fi } function restore_user_config { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userconfig' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/config ]; then - for d in $USB_MOUNT/backup/config/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring config files for $USERNAME" - restore_directory_from_usb /root/tempconfig config/$USERNAME - cp -r /root/tempconfig/home/$USERNAME/.config /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempconfig - unmount_drive - exit 664 - fi - rm -rf /root/tempconfig - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userconfig' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/config ]; then + for d in $USB_MOUNT/backup/config/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring config files for $USERNAME" + restore_directory_from_usb /root/tempconfig config/$USERNAME + cp -r /root/tempconfig/home/$USERNAME/.config /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempconfig + unmount_drive + exit 664 + fi + rm -rf /root/tempconfig + fi + done + fi } function restore_user_fin { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userfin' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/fin ]; then - for d in $USB_MOUNT/backup/fin/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring fin files for $USERNAME" - restore_directory_from_usb /root/tempfin fin/$USERNAME - cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempfin - unmount_drive - exit 664 - fi - rm -rf /root/tempfin - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userfin' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/fin ]; then + for d in $USB_MOUNT/backup/fin/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring fin files for $USERNAME" + restore_directory_from_usb /root/tempfin fin/$USERNAME + cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempfin + unmount_drive + exit 664 + fi + rm -rf /root/tempfin + fi + done + fi } function restore_user_local { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userlocal' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/local ]; then - for d in $USB_MOUNT/backup/local/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring local files for $USERNAME" - restore_directory_from_usb /root/templocal local/$USERNAME - cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/templocal - unmount_drive - exit 664 - fi - rm -rf /root/templocal - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userlocal' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/local ]; then + for d in $USB_MOUNT/backup/local/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring local files for $USERNAME" + restore_directory_from_usb /root/templocal local/$USERNAME + cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/templocal + unmount_drive + exit 664 + fi + rm -rf /root/templocal + fi + done + fi } function restore_certs { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'certs' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/ssl ]; then - echo $"Restoring certificates" - mkdir /root/tempssl - restore_directory_from_usb /root/tempssl ssl - cp -r /root/tempssl/etc/ssl/* /etc/ssl - if [ ! "$?" = "0" ]; then - unmount_drive - exit 276 - fi - rm -rf /root/tempssl + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'certs' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/ssl ]; then + echo $"Restoring certificates" + mkdir /root/tempssl + restore_directory_from_usb /root/tempssl ssl + cp -r /root/tempssl/etc/ssl/* /etc/ssl + if [ ! "$?" = "0" ]; then + unmount_drive + exit 276 + fi + rm -rf /root/tempssl - # restore ownership - if [ -f /etc/ssl/private/xmpp.key ]; then - chown prosody:prosody /etc/ssl/private/xmpp.key - chown prosody:prosody /etc/ssl/certs/xmpp.* - fi - if [ -d /etc/dovecot ]; then - chown root:dovecot /etc/ssl/private/dovecot.* - chown root:dovecot /etc/ssl/certs/dovecot.* - fi - if [ -f /etc/ssl/private/exim.key ]; then - cp /etc/ssl/private/exim.key /etc/exim4 - cp /etc/ssl/certs/exim.crt /etc/exim4 - cp /etc/ssl/certs/exim.dhparam /etc/exim4 - chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam - chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam - fi - if [ -f /etc/ssl/private/mumble.key ]; then - if [ -d /var/lib/mumble-server ]; then - cp /etc/ssl/certs/mumble.* /var/lib/mumble-server - cp /etc/ssl/private/mumble.key /var/lib/mumble-server - chown -R mumble-server:mumble-server /var/lib/mumble-server - fi - fi - fi + # restore ownership + if [ -f /etc/ssl/private/xmpp.key ]; then + chown prosody:prosody /etc/ssl/private/xmpp.key + chown prosody:prosody /etc/ssl/certs/xmpp.* + fi + if [ -d /etc/dovecot ]; then + chown root:dovecot /etc/ssl/private/dovecot.* + chown root:dovecot /etc/ssl/certs/dovecot.* + fi + if [ -f /etc/ssl/private/exim.key ]; then + cp /etc/ssl/private/exim.key /etc/exim4 + cp /etc/ssl/certs/exim.crt /etc/exim4 + cp /etc/ssl/certs/exim.dhparam /etc/exim4 + chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam + chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam + fi + if [ -f /etc/ssl/private/mumble.key ]; then + if [ -d /var/lib/mumble-server ]; then + cp /etc/ssl/certs/mumble.* /var/lib/mumble-server + cp /etc/ssl/private/mumble.key /var/lib/mumble-server + chown -R mumble-server:mumble-server /var/lib/mumble-server + fi + fi + fi } function restore_personal_settings { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'personal' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/personal ]; then - for d in $USB_MOUNT/backup/personal/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ -d $USB_MOUNT/backup/personal/$USERNAME ]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring personal settings for $USERNAME" - restore_directory_from_usb /root/temppersonal personal/$USERNAME - if [ -d /home/$USERNAME/personal ]; then - rm -rf /home/$USERNAME/personal - fi - mv /root/temppersonal/home/$USERNAME/personal /home/$USERNAME - if [ ! "$?" = "0" ]; then - unmount_drive - exit 184 - fi - rm -rf /root/temppersonal - fi - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'personal' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/personal ]; then + for d in $USB_MOUNT/backup/personal/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ -d $USB_MOUNT/backup/personal/$USERNAME ]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring personal settings for $USERNAME" + restore_directory_from_usb /root/temppersonal personal/$USERNAME + if [ -d /home/$USERNAME/personal ]; then + rm -rf /home/$USERNAME/personal + fi + mv /root/temppersonal/home/$USERNAME/personal /home/$USERNAME + if [ ! "$?" = "0" ]; then + unmount_drive + exit 184 + fi + rm -rf /root/temppersonal + fi + fi + done + fi } function restore_mailing_list { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mailinglist' ]]; then - return - fi - fi - if [ -d /var/spool/mlmmj ]; then - echo $"Restoring public mailing list" - restore_directory_from_usb /root/tempmailinglist mailinglist - cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj - if [ ! "$?" = "0" ]; then - unmount_drive - exit 526 - fi - rm -rf /root/tempmailinglist - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mailinglist' ]]; then + return + fi + fi + if [ -d /var/spool/mlmmj ]; then + echo $"Restoring public mailing list" + restore_directory_from_usb /root/tempmailinglist mailinglist + cp -r /root/tempmailinglist/root/spool/mlmmj/* /var/spool/mlmmj + if [ ! "$?" = "0" ]; then + unmount_drive + exit 526 + fi + rm -rf /root/tempmailinglist + fi } function restore_xmpp { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'xmpp' ]]; then - return - fi - fi - if [ -d /var/lib/prosody ]; then - echo $"Restoring XMPP settings" - restore_directory_from_usb /root/tempxmpp xmpp - cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody - if [ ! "$?" = "0" ]; then - unmount_drive - exit 725 - fi - rm -rf /root/tempxmpp - service prosody restart - chown -R prosody:prosody /var/lib/prosody/* - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'xmpp' ]]; then + return + fi + fi + if [ -d /var/lib/prosody ]; then + echo $"Restoring XMPP settings" + restore_directory_from_usb /root/tempxmpp xmpp + cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody + if [ ! "$?" = "0" ]; then + unmount_drive + exit 725 + fi + rm -rf /root/tempxmpp + service prosody restart + chown -R prosody:prosody /var/lib/prosody/* + fi } function restore_gnu_social { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'gnusocial' ]]; then - return - fi - fi - if [ $MICROBLOG_DOMAIN_NAME ]; then - restore_database gnusocial ${MICROBLOG_DOMAIN_NAME} - if [ -d /root/tempgnusocial ]; then - rm -rf /root/tempgnusocial - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'gnusocial' ]]; then + return + fi + fi + if [ $MICROBLOG_DOMAIN_NAME ]; then + restore_database gnusocial ${MICROBLOG_DOMAIN_NAME} + if [ -d /root/tempgnusocial ]; then + rm -rf /root/tempgnusocial + fi + fi } function restore_rss_reader { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'ttrss' ]]; then - return - fi - fi - if [ $RSS_READER_DOMAIN_NAME ]; then - restore_database ttrss ${RSS_READER_DOMAIN_NAME} - if [ -d $USB_MOUNT/backup/ttrss ]; then - chown -R www-data:www-data /etc/share/tt-rss - if [ -d /root/tempttrss ]; then - rm -rf /root/tempttrss - fi - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'ttrss' ]]; then + return + fi + fi + if [ $RSS_READER_DOMAIN_NAME ]; then + restore_database ttrss ${RSS_READER_DOMAIN_NAME} + if [ -d $USB_MOUNT/backup/ttrss ]; then + chown -R www-data:www-data /etc/share/tt-rss + if [ -d /root/tempttrss ]; then + rm -rf /root/tempttrss + fi + fi + fi } function restore_hubzilla { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'hubzilla' ]]; then - return - fi - fi - if [ $HUBZILLA_DOMAIN_NAME ]; then - restore_database hubzilla ${HUBZILLA_DOMAIN_NAME} - if [ -d $USB_MOUNT/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/* - if [ -d /root/temphubzilla ]; then - rm -rf /root/temphubzilla - fi - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'hubzilla' ]]; then + return + fi + fi + if [ $HUBZILLA_DOMAIN_NAME ]; then + restore_database hubzilla ${HUBZILLA_DOMAIN_NAME} + if [ -d $USB_MOUNT/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/* + if [ -d /root/temphubzilla ]; then + rm -rf /root/temphubzilla + fi + fi + fi } function restore_syncthing { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'syncthing' ]]; then - return - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'syncthing' ]]; then + return + fi + fi - if [ -f /etc/systemd/system/syncthing.service ]; then - systemctl stop syncthing - systemctl stop cron - fi + if [ -f /etc/systemd/system/syncthing.service ]; then + systemctl stop syncthing + systemctl stop cron + fi - if [ -d $USB_MOUNT/backup/syncthingconfig ]; then - echo $"Restoring syncthing configuration" - restore_directory_from_usb /root/tempsyncthingconfig syncthingconfig - cp -r /root/tempsyncthingconfig/* / - if [ ! "$?" = "0" ]; then - unmount_drive - systemctl start syncthing - systemctl start cron - exit 6833 - fi - rm -rf /root/tempsyncthingconfig - fi + if [ -d $USB_MOUNT/backup/syncthingconfig ]; then + echo $"Restoring syncthing configuration" + restore_directory_from_usb /root/tempsyncthingconfig syncthingconfig + cp -r /root/tempsyncthingconfig/* / + if [ ! "$?" = "0" ]; then + unmount_drive + systemctl start syncthing + systemctl start cron + exit 6833 + fi + rm -rf /root/tempsyncthingconfig + fi - if [ -d $USB_MOUNT/backup/syncthingshared ]; then - echo $"Restoring syncthing shared files" - restore_directory_from_usb /root/tempsyncthingshared syncthingshared - cp -r /root/tempsyncthingshared/* / - if [ ! "$?" = "0" ]; then - unmount_drive - systemctl start syncthing - systemctl start cron - exit 37904 - fi - rm -rf /root/tempsyncthingshared - fi + if [ -d $USB_MOUNT/backup/syncthingshared ]; then + echo $"Restoring syncthing shared files" + restore_directory_from_usb /root/tempsyncthingshared syncthingshared + cp -r /root/tempsyncthingshared/* / + if [ ! "$?" = "0" ]; then + unmount_drive + systemctl start syncthing + systemctl start cron + exit 37904 + fi + rm -rf /root/tempsyncthingshared + fi - if [ -d $USB_MOUNT/backup/syncthing ]; then - for d in $USB_MOUNT/backup/syncthing/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring syncthing files for $USERNAME" - restore_directory_from_usb /root/tempsyncthing syncthing/$USERNAME - cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempsyncthing - unmount_drive - systemctl start syncthing - systemctl start cron - exit 68438 - fi - rm -rf /root/tempsyncthing + if [ -d $USB_MOUNT/backup/syncthing ]; then + for d in $USB_MOUNT/backup/syncthing/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring syncthing files for $USERNAME" + restore_directory_from_usb /root/tempsyncthing syncthing/$USERNAME + cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempsyncthing + unmount_drive + systemctl start syncthing + systemctl start cron + exit 68438 + fi + rm -rf /root/tempsyncthing - # restore device IDs from config settings - if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then - cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id - chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id - fi - if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then - cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids - chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids - fi - fi - done - fi + # restore device IDs from config settings + if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then + cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id + chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id + fi + if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then + cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids + chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids + fi + fi + done + fi - if [ -f /etc/systemd/system/syncthing.service ]; then - systemctl start syncthing - systemctl start cron - fi + if [ -f /etc/systemd/system/syncthing.service ]; then + systemctl start syncthing + systemctl start cron + fi } function restore_mediagoblin { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mediagoblin' ]]; then - return - fi - fi - if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then - return - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mediagoblin' ]]; then + return + fi + fi + if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then + return + fi - if [ -d $USB_MOUNT/backup/mediagoblin ]; then - restore_directory_from_usb /root/tempmediagoblin mediagoblin - cp -r /root/tempmediagoblin/* / - if [ ! "$?" = "0" ]; then - unmount_drive - exit 67843 - fi - rm -rf /root/tempmediagoblin - chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs - fi + if [ -d $USB_MOUNT/backup/mediagoblin ]; then + restore_directory_from_usb /root/tempmediagoblin mediagoblin + cp -r /root/tempmediagoblin/* / + if [ ! "$?" = "0" ]; then + unmount_drive + exit 67843 + fi + rm -rf /root/tempmediagoblin + chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs + fi } function restore_gogs { - export GVM_ROOT=$HOME/.gvm - if [ -d $GVM_ROOT/bin ]; then - cd $GVM_ROOT/bin - ./gvm use go${GO_VERSION} --default - systemctl set-environment GOPATH=$GOPATH - fi + export GVM_ROOT=$HOME/.gvm + if [ -d $GVM_ROOT/bin ]; then + cd $GVM_ROOT/bin + [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" + gvm use go${GO_VERSION} --default + systemctl set-environment GOPATH=$GOPATH + fi - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'gogs' ]]; then - return - fi - fi - if [ $GIT_DOMAIN_NAME ]; then - restore_database gogs ${GIT_DOMAIN_NAME} - if [ -d $USB_MOUNT/backup/gogs ]; then - echo $"Restoring Gogs settings" - if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then - mkdir -p $GOPATH/src/github.com/gogits/gogs/custom - fi - cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom - if [ ! "$?" = "0" ]; then - unmount_drive - exit 981 - fi - echo $"Restoring Gogs repos" - restore_directory_from_usb /root/tempgogsrepos gogsrepos - cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/ - if [ ! "$?" = "0" ]; then - unmount_drive - exit 67574 - fi - echo $"Restoring Gogs authorized_keys" - restore_directory_from_usb /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 - unmount_drive - exit 8463 - fi - rm -rf /root/tempgogs - rm -rf /root/tempgogsrepos - rm -rf /root/tempgogsssh - chown -R git:git /home/git - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'gogs' ]]; then + return + fi + fi + if [ $GIT_DOMAIN_NAME ]; then + restore_database gogs ${GIT_DOMAIN_NAME} + if [ -d $USB_MOUNT/backup/gogs ]; then + echo $"Restoring Gogs settings" + if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then + mkdir -p $GOPATH/src/github.com/gogits/gogs/custom + fi + cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom + if [ ! "$?" = "0" ]; then + unmount_drive + exit 981 + fi + echo $"Restoring Gogs repos" + restore_directory_from_usb /root/tempgogsrepos gogsrepos + cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/ + if [ ! "$?" = "0" ]; then + unmount_drive + exit 67574 + fi + echo $"Restoring Gogs authorized_keys" + restore_directory_from_usb /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 + unmount_drive + exit 8463 + fi + rm -rf /root/tempgogs + rm -rf /root/tempgogsrepos + rm -rf /root/tempgogsssh + chown -R git:git /home/git + fi + fi } function restore_wiki { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'wiki' ]]; then - return - fi - fi - if [ $WIKI_DOMAIN_NAME ]; then - echo $"Restoring Wiki installation ${WIKI_DOMAIN_NAME}" - restore_directory_from_usb /root/tempwiki wiki - cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/ - if [ ! "$?" = "0" ]; then - unmount_drive - exit 868 - fi - restore_directory_from_usb /root/tempwiki2 wiki2 - cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/ - if [ ! "$?" = "0" ]; then - unmount_drive - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'wiki' ]]; then + return + fi + fi + if [ $WIKI_DOMAIN_NAME ]; then + echo $"Restoring Wiki installation ${WIKI_DOMAIN_NAME}" + restore_directory_from_usb /root/tempwiki wiki + cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/ + if [ ! "$?" = "0" ]; then + unmount_drive + exit 868 + fi + restore_directory_from_usb /root/tempwiki2 wiki2 + cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/ + if [ ! "$?" = "0" ]; then + unmount_drive + 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 } function restore_blog { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'blog' ]]; then - return - fi - fi - if [ $FULLBLOG_DOMAIN_NAME ]; then - echo $"Restoring blog installation" - restore_directory_from_usb /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 - unmount_drive - 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" - unmount_drive - exit 287 - fi - chown -R www-data:www-data /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs - # 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" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'blog' ]]; then + return + fi + fi + if [ $FULLBLOG_DOMAIN_NAME ]; then + echo $"Restoring blog installation" + restore_directory_from_usb /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 + unmount_drive + 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" + unmount_drive + exit 287 + fi + chown -R www-data:www-data /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs + # 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" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + 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 } function restore_cjdns { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'cjdns' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/cjdns ]; then - echo $"Restoring cjdns installation" - restore_directory_from_usb /root/tempcjdns cjdns - rm -rf /etc/cjdns - cp -r /root/tempcjdns/etc/cjdns /etc/ - if [ ! "$?" = "0" ]; then - unmount_drive - exit 8472 - fi - rm -rf /root/tempcjdns - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'cjdns' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/cjdns ]; then + echo $"Restoring cjdns installation" + restore_directory_from_usb /root/tempcjdns cjdns + rm -rf /etc/cjdns + cp -r /root/tempcjdns/etc/cjdns /etc/ + if [ ! "$?" = "0" ]; then + unmount_drive + exit 8472 + fi + rm -rf /root/tempcjdns + fi } function restore_email { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'email' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/mail ]; then - for d in $USB_MOUNT/backup/mail/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring emails for $USERNAME" - restore_directory_from_usb /root/tempmail mail/$USERNAME - if [ ! -d /home/$USERNAME/Maildir ]; then - mkdir /home/$USERNAME/Maildir - fi - tar -xzvf /root/tempmail/root/tempbackupemail/$USERNAME/maildir.tar.gz -C / - if [ ! "$?" = "0" ]; then - unmount_drive - exit 927 - fi - rm -rf /root/tempmail - fi - done - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'email' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/mail ]; then + for d in $USB_MOUNT/backup/mail/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring emails for $USERNAME" + restore_directory_from_usb /root/tempmail mail/$USERNAME + if [ ! -d /home/$USERNAME/Maildir ]; then + mkdir /home/$USERNAME/Maildir + fi + tar -xzvf /root/tempmail/root/tempbackupemail/$USERNAME/maildir.tar.gz -C / + if [ ! "$?" = "0" ]; then + unmount_drive + exit 927 + fi + rm -rf /root/tempmail + fi + done + fi } function restore_dlna { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'dlna' ]]; then - return - fi - fi - if [ -d /var/cache/minidlna ]; then - if [ -d $USB_MOUNT/backup/dlna ]; then - echo $"Restoring DLNA cache" - restore_directory_from_usb /root/tempdlna dlna - cp -r /root/tempdlna/var/cache/minidlna/* /var/cache/minidlna/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempdlna - unmount_drive - exit 982 - fi - rm -rf /root/tempdlna - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'dlna' ]]; then + return + fi + fi + if [ -d /var/cache/minidlna ]; then + if [ -d $USB_MOUNT/backup/dlna ]; then + echo $"Restoring DLNA cache" + restore_directory_from_usb /root/tempdlna dlna + cp -r /root/tempdlna/var/cache/minidlna/* /var/cache/minidlna/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempdlna + unmount_drive + exit 982 + fi + rm -rf /root/tempdlna + fi + fi } function restore_voip { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'voip' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/voip ]; then - echo $"Restoring VoIP settings" - restore_directory_from_usb /root/tempvoip voip - cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempvoip - unmount_drive - exit 3679 - fi - cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf - if [ ! "$?" = "0" ]; then - rm -rf /root/tempvoip - unmount_drive - exit 3679 - fi - cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempvoip - unmount_drive - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'voip' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/voip ]; then + echo $"Restoring VoIP settings" + restore_directory_from_usb /root/tempvoip voip + cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempvoip + unmount_drive + exit 3679 + fi + cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf + if [ ! "$?" = "0" ]; then + rm -rf /root/tempvoip + unmount_drive + exit 3679 + fi + cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempvoip + unmount_drive + 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 } function restore_tox { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'tox' ]]; then - return - fi - fi - if [ -d $USB_MOUNT/backup/tox ]; then - echo $"Restoring Tox node settings" - restore_directory_from_usb / tox - if [ ! "$?" = "0" ]; then - unmount_drive - exit 6393 - 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 - unmount_drive - exit 59369 - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'tox' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/tox ]; then + echo $"Restoring Tox node settings" + restore_directory_from_usb / tox + if [ ! "$?" = "0" ]; then + unmount_drive + exit 6393 + 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 + unmount_drive + exit 59369 + fi + fi } function get_restore_app { - if [ ${1} ]; then - if [ ! -d /home/${1} ]; then - RESTORE_APP=${1} - echo $"Restore $RESTORE_APP" - fi - fi + if [ ${1} ]; then + if [ ! -d /home/${1} ]; then + RESTORE_APP=${1} + echo $"Restore $RESTORE_APP" + fi + fi } get_restore_app ${2} diff --git a/src/freedombone-restore-remote b/src/freedombone-restore-remote index 0ac2baad..084a5b76 100755 --- a/src/freedombone-restore-remote +++ b/src/freedombone-restore-remote @@ -42,7 +42,7 @@ SERVER_NAME=$1 RESTORE_APP='all' if [ ${2} ]; then - RESTORE_APP=${2} + RESTORE_APP=${2} fi ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | -nawk -F ':' '{print $2}') @@ -54,18 +54,18 @@ SERVER_DIRECTORY=/root/remoterestore BACKUP_LIST=/home/${ADMIN_USERNAME}/backup.list if [ ! $SERVER_NAME ]; then - echo $'restorefromfriend [server]' - exit 1 + echo $'restorefromfriend [server]' + exit 1 fi if [ ! -f $BACKUP_LIST ]; then - echo $"No friends list found at $BACKUP_LIST" - exit 2 + echo $"No friends list found at $BACKUP_LIST" + exit 2 fi if ! grep -q "$SERVER_NAME" $BACKUP_LIST; then - echo $"Server not found within the friends list" - exit 3 + echo $"Server not found within the friends list" + exit 3 fi REMOTE_SERVER=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $1}') @@ -79,960 +79,961 @@ 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 + 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 + echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> /var/log/remotebackups.log fi # get the version of Go being used if [ -f /usr/local/bin/${PROJECT_NAME} ]; then - GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') + GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') else - GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') + GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}') 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} + if [ ! -d ${1} ]; then + mkdir ${1} + fi + obnam restore -r $SERVER_DIRECTORY/backup/${2} --to ${1} } function copy_gpg_keys { - echo $"Copying GPG keys from admin user to root" - cp -r /home/$ADMIN_USERNAME/.gnupg /root + echo $"Copying GPG keys from admin user to root" + cp -r /home/$ADMIN_USERNAME/.gnupg /root } function restore_database_from_friend { - DATABASE_PASSWORD= - RESTORE_SUBDIR="root" + 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 $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 - # special handling of ttrss - if [[ ${2} == "ttrss" ]]; then - if [ -d /etc/share/tt-rss ]; then - rm -rf /etc/share/tt-rss - mv /root/temp${1}/etc/share/tt-rss /etc/share/ - if [ ! "$?" = "0" ]; then - exit 639 - 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 + # special handling of ttrss + if [[ ${2} == "ttrss" ]]; then + if [ -d /etc/share/tt-rss ]; then + rm -rf /etc/share/tt-rss + mv /root/temp${1}/etc/share/tt-rss /etc/share/ + if [ ! "$?" = "0" ]; then + exit 639 + 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 - 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 + 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 } function restore_configuration { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'configuration' ]]; then - return - fi - fi - if [ -d $SERVER_DIRECTORY/backup/config ]; then - echo $"Restoring configuration files" - restore_directory_from_friend /root/tempconfig config + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'configuration' ]]; then + return + fi + fi + if [ -d $SERVER_DIRECTORY/backup/config ]; then + echo $"Restoring configuration files" + restore_directory_from_friend /root/tempconfig config - cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE - if [ ! "$?" = "0" ]; then - unmount_drive - rm -rf /root/tempconfig - exit 5372 - fi - if [ -f $CONFIG_FILE ]; then - # install according to the config file - freedombone -c $CONFIG_FILE - fi + cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE + if [ ! "$?" = "0" ]; then + unmount_drive + rm -rf /root/tempconfig + exit 5372 + fi + if [ -f $CONFIG_FILE ]; then + # install according to the config file + freedombone -c $CONFIG_FILE + fi - cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE - if [ ! "$?" = "0" ]; then - unmount_drive - rm -rf /root/tempconfig - exit 7252 - fi + cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE + if [ ! "$?" = "0" ]; then + unmount_drive + rm -rf /root/tempconfig + exit 7252 + fi - if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then - cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} - if [ ! "$?" = "0" ]; then - unmount_drive - rm -rf /root/tempconfig - exit 62121 - fi - fi + if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then + cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} + if [ ! "$?" = "0" ]; then + unmount_drive + rm -rf /root/tempconfig + exit 62121 + fi + fi - # restore nginx password hashes - if [ -f /root/tempconfig/root/htpasswd ]; then - cp -f /root/tempconfig/root/htpasswd /etc/nginx/.htpasswd - fi + # restore nginx password hashes + if [ -f /root/tempconfig/root/htpasswd ]; then + cp -f /root/tempconfig/root/htpasswd /etc/nginx/.htpasswd + fi - rm -rf /root/tempconfig - fi + rm -rf /root/tempconfig + fi } function restore_mariadb { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mariadb' ]]; then - return - fi - fi - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mariadb' ]]; then + return + fi + fi + 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 + # Change database password file + echo "$DATABASE_PASSWORD" > /root/dbpass + chmod 600 /root/dbpass + fi } function restore_letsencrypt { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'letsencrypt' ]]; then - return - fi - fi - if [ -d $SERVER_DIRECTORY/backup/letsencrypt ]; then - echo $"Restoring Lets Encrypt settings" - restore_directory_from_friend / letsencrypt - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'letsencrypt' ]]; then + return + fi + fi + if [ -d $SERVER_DIRECTORY/backup/letsencrypt ]; then + echo $"Restoring Lets Encrypt settings" + restore_directory_from_friend / letsencrypt + fi } function restore_tor { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'tor' ]]; then - return - fi - fi - if [ -d $SERVER_DIRECTORY/backup/tor ]; then - echo $"Restoring Tor settings" - restore_directory_from_friend / tor - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'tor' ]]; then + return + fi + fi + if [ -d $SERVER_DIRECTORY/backup/tor ]; then + echo $"Restoring Tor settings" + restore_directory_from_friend / tor + fi } function restore_mutt_settings { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mutt' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mutt' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/mutt/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_gpg { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'gpg' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'gpg' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_procmail { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'procmail' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'procmail' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_spamassassin { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'spamassassin' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'spamassassin' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_admin_readme { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'readme' ]]; then - return - fi - fi - if [ -d $SERVER_DIRECTORY/backup/readme ]; then - echo $"Restoring README" - restore_directory_from_friend /root/tempreadme readme - cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempreadme - exit 276 - fi - rm -rf /root/tempreadme - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'readme' ]]; then + return + fi + fi + if [ -d $SERVER_DIRECTORY/backup/readme ]; then + echo $"Restoring README" + restore_directory_from_friend /root/tempreadme readme + cp -f /root/tempreadme/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempreadme + exit 276 + fi + rm -rf /root/tempreadme + fi } function restore_ipfs { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'ipfs' ]]; then - return - fi - fi - if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then - echo $"Restoring IPFS" - restore_directory_from_friend /root/tempipfs ipfs - cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs - if [ ! "$?" = "0" ]; then - rm -rf /root/tempipfs - exit 276 - fi - rm -rf /root/tempipfs - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'ipfs' ]]; then + return + fi + fi + if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then + echo $"Restoring IPFS" + restore_directory_from_friend /root/tempipfs ipfs + cp -rf /root/tempipfs/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs + if [ ! "$?" = "0" ]; then + rm -rf /root/tempipfs + exit 276 + fi + rm -rf /root/tempipfs + fi } function restore_ssh_keys { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'ssh' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'ssh' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_user_config { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userconfig' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/config/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userconfig' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/config/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_user_fin { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userfin' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/fin/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ -d $SERVER_DIRECTORY/backup/fin/$USERNAME ]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring fin files for $USERNAME" - restore_directory_from_friend /root/tempfin fin/$USERNAME - cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempfin - exit 664 - fi - rm -rf /root/tempfin - fi - fi - done + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userfin' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/fin/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ -d $SERVER_DIRECTORY/backup/fin/$USERNAME ]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring fin files for $USERNAME" + restore_directory_from_friend /root/tempfin fin/$USERNAME + cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempfin + exit 664 + fi + rm -rf /root/tempfin + fi + fi + done } function restore_user_local { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'userlocal' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/local/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ -d $SERVER_DIRECTORY/backup/local/$USERNAME ]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring local files for $USERNAME" - restore_directory_from_friend /root/templocal local/$USERNAME - cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/templocal - exit 664 - fi - rm -rf /root/templocal - fi - fi - done + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userlocal' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/local/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ -d $SERVER_DIRECTORY/backup/local/$USERNAME ]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring local files for $USERNAME" + restore_directory_from_friend /root/templocal local/$USERNAME + cp -r /root/templocal/home/$USERNAME/.local /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/templocal + exit 664 + fi + rm -rf /root/templocal + fi + fi + done } function restore_certs { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'certs' ]]; then - return - fi - fi - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'certs' ]]; then + return + fi + fi + 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 - # restore ownership - if [ -f /etc/ssl/private/xmpp.key ]; then - chown prosody:prosody /etc/ssl/private/xmpp.key - chown prosody:prosody /etc/ssl/certs/xmpp.* - fi - if [ -d /etc/dovecot ]; then - chown root:dovecot /etc/ssl/private/dovecot.* - chown root:dovecot /etc/ssl/certs/dovecot.* - fi - if [ -f /etc/ssl/private/exim.key ]; then - cp /etc/ssl/private/exim.key /etc/exim4 - cp /etc/ssl/certs/exim.crt /etc/exim4 - cp /etc/ssl/certs/exim.dhparam /etc/exim4 - chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam - chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam - fi - if [ -f /etc/ssl/private/mumble.key ]; then - if [ -d /var/lib/mumble-server ]; then - cp /etc/ssl/certs/mumble.* /var/lib/mumble-server - cp /etc/ssl/private/mumble.key /var/lib/mumble-server - chown -R mumble-server:mumble-server /var/lib/mumble-server - fi - fi - fi + # restore ownership + if [ -f /etc/ssl/private/xmpp.key ]; then + chown prosody:prosody /etc/ssl/private/xmpp.key + chown prosody:prosody /etc/ssl/certs/xmpp.* + fi + if [ -d /etc/dovecot ]; then + chown root:dovecot /etc/ssl/private/dovecot.* + chown root:dovecot /etc/ssl/certs/dovecot.* + fi + if [ -f /etc/ssl/private/exim.key ]; then + cp /etc/ssl/private/exim.key /etc/exim4 + cp /etc/ssl/certs/exim.crt /etc/exim4 + cp /etc/ssl/certs/exim.dhparam /etc/exim4 + chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam + chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam + fi + if [ -f /etc/ssl/private/mumble.key ]; then + if [ -d /var/lib/mumble-server ]; then + cp /etc/ssl/certs/mumble.* /var/lib/mumble-server + cp /etc/ssl/private/mumble.key /var/lib/mumble-server + chown -R mumble-server:mumble-server /var/lib/mumble-server + fi + fi + fi } function restore_personal_settings { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'personal' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/personal/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'personal' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/personal/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_mailing_list { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mailinglist' ]]; then - return - fi - fi - if [ -d /var/spool/mlmmj ]; then - echo $"Restoring public mailing list" - restore_directory_from_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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mailinglist' ]]; then + return + fi + fi + if [ -d /var/spool/mlmmj ]; then + echo $"Restoring public mailing list" + restore_directory_from_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 } function restore_xmpp { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'xmpp' ]]; then - return - fi - fi - if [ -d /var/lib/prosody ]; then - echo $"Restoring XMPP settings" - restore_directory_from_friend /root/tempxmpp xmpp - cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody - if [ ! "$?" = "0" ]; then - exit 725 - fi - rm -rf /root/tempxmpp - service prosody restart - chown -R prosody:prosody /var/lib/prosody/* - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'xmpp' ]]; then + return + fi + fi + if [ -d /var/lib/prosody ]; then + echo $"Restoring XMPP settings" + restore_directory_from_friend /root/tempxmpp xmpp + cp -r /root/tempxmpp/var/lib/prosody/* /var/lib/prosody + if [ ! "$?" = "0" ]; then + exit 725 + fi + rm -rf /root/tempxmpp + service prosody restart + chown -R prosody:prosody /var/lib/prosody/* + fi } function restore_gnu_social { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'gnusocial' ]]; then - return - fi - fi - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'gnusocial' ]]; then + return + fi + fi + 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 } function restore_rss_reader { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'ttrss' ]]; then - return - fi - fi - if grep -q "RSS reader domain" $COMPLETION_FILE; then - RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}') - restore_database_from_friend ttrss ${RSS_READER_DOMAIN_NAME} - if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then - chown -R www-data:www-data /etc/share/tt-rss - fi - if [ -d /root/tempttrss ]; then - rm -rf /root/tempttrss - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'ttrss' ]]; then + return + fi + fi + if grep -q "RSS reader domain" $COMPLETION_FILE; then + RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "RSS reader domain" | awk -F ':' '{print $2}') + restore_database_from_friend ttrss ${RSS_READER_DOMAIN_NAME} + if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then + chown -R www-data:www-data /etc/share/tt-rss + fi + if [ -d /root/tempttrss ]; then + rm -rf /root/tempttrss + fi + fi } function restore_hubzilla { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'hubzilla' ]]; then - return - fi - fi - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'hubzilla' ]]; then + return + fi + fi + 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 } function restore_syncthing { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'syncthing' ]]; then - return - fi - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'syncthing' ]]; then + return + fi + fi - if [ -f /etc/systemd/system/syncthing.service ]; then - systemctl stop syncthing - systemctl stop cron - fi + if [ -f /etc/systemd/system/syncthing.service ]; then + systemctl stop syncthing + systemctl stop cron + fi - if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then - echo $"Restoring syncthing configuration" - restore_directory_from_friend /root/tempsyncthingconfig syncthingconfig - cp -r /root/tempsyncthingconfig/* / - if [ ! "$?" = "0" ]; then - unmount_drive - systemctl start syncthing - systemctl start cron - exit 6833 - fi - rm -rf /root/tempsyncthingconfig - fi + if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then + echo $"Restoring syncthing configuration" + restore_directory_from_friend /root/tempsyncthingconfig syncthingconfig + cp -r /root/tempsyncthingconfig/* / + if [ ! "$?" = "0" ]; then + unmount_drive + systemctl start syncthing + systemctl start cron + exit 6833 + fi + rm -rf /root/tempsyncthingconfig + fi - if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then - echo $"Restoring syncthing shared files" - restore_directory_from_friend /root/tempsyncthingshared syncthingshared - cp -r /root/tempsyncthingshared/* / - if [ ! "$?" = "0" ]; then - unmount_drive - systemctl start syncthing - systemctl start cron - exit 37904 - fi - rm -rf /root/tempsyncthingshared - fi + if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then + echo $"Restoring syncthing shared files" + restore_directory_from_friend /root/tempsyncthingshared syncthingshared + cp -r /root/tempsyncthingshared/* / + if [ ! "$?" = "0" ]; then + unmount_drive + systemctl start syncthing + systemctl start cron + exit 37904 + fi + rm -rf /root/tempsyncthingshared + fi - if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then - for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then - if [ ! -d /home/$USERNAME ]; then - ${PROJECT_NAME}-adduser $USERNAME - fi - echo $"Restoring syncthing files for $USERNAME" - restore_directory_from_friend /root/tempsyncthing syncthing/$USERNAME - cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/ - if [ ! "$?" = "0" ]; then - rm -rf /root/tempsyncthing - unmount_drive - systemctl start syncthing - systemctl start cron - exit 68438 - fi - rm -rf /root/tempsyncthing + if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then + for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring syncthing files for $USERNAME" + restore_directory_from_friend /root/tempsyncthing syncthing/$USERNAME + cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempsyncthing + unmount_drive + systemctl start syncthing + systemctl start cron + exit 68438 + fi + rm -rf /root/tempsyncthing - # restore device IDs from config settings - if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then - cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id - chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id - fi - if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then - cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids - chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids - fi - fi - done - fi + # restore device IDs from config settings + if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then + cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id + chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id + fi + if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then + cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids + chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids + fi + fi + done + fi - if [ -f /etc/systemd/system/syncthing.service ]; then - systemctl start syncthing - systemctl start cron - fi + if [ -f /etc/systemd/system/syncthing.service ]; then + systemctl start syncthing + systemctl start cron + fi } function restore_mediagoblin { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'mediagoblin' ]]; then - return - fi - fi - if grep -q "Mediagoblin domain" $COMPLETION_FILE; then - MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') - if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then - echo $"Restoring Mediagoblin installation" - restore_directory_from_friend /root/tempmediagoblin mediagoblin - cp -r /root/tempmediagoblin/* / - if [ ! "$?" = "0" ]; then - exit 5626 - fi - rm -rf /root/tempmediagoblin - fi - chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs - fi + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'mediagoblin' ]]; then + return + fi + fi + if grep -q "Mediagoblin domain" $COMPLETION_FILE; then + MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') + if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then + echo $"Restoring Mediagoblin installation" + restore_directory_from_friend /root/tempmediagoblin mediagoblin + cp -r /root/tempmediagoblin/* / + if [ ! "$?" = "0" ]; then + exit 5626 + fi + rm -rf /root/tempmediagoblin + fi + chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs + fi } function restore_gogs { - export GVM_ROOT=$HOME/.gvm - if [ -d $GVM_ROOT/bin ]; then - cd $GVM_ROOT/bin - ./gvm use go${GO_VERSION} --default - systemctl set-environment GOPATH=$GOPATH - fi + export GVM_ROOT=$HOME/.gvm + if [ -d $GVM_ROOT/bin ]; then + cd $GVM_ROOT/bin + [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" + gvm use go${GO_VERSION} --default + systemctl set-environment GOPATH=$GOPATH + fi - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'gogs' ]]; then - return - fi - fi - 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 $GOPATH/src/github.com/gogits/gogs/custom ]; then - mkdir -p $GOPATH/src/github.com/gogits/gogs/custom - fi - cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/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 [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'gogs' ]]; then + return + fi + fi + 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 $GOPATH/src/github.com/gogits/gogs/custom ]; then + mkdir -p $GOPATH/src/github.com/gogits/gogs/custom + fi + cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/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 } function restore_wiki { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'wiki' ]]; then - return - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'wiki' ]]; then + return + 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 } function restore_blog { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'blog' ]]; then - return - fi - fi - 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" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'blog' ]]; then + return + fi + fi + 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" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_cjdns { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'cjdns' ]]; then - return - fi - fi - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'cjdns' ]]; then + return + fi + fi + 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 } function restore_voip { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'voip' ]]; then - return - fi - fi - if [ -d $SERVER_DIRECTORY/backup/voip ]; then - echo $"Restoring VoIP settings" - restore_directory_from_friend /root/tempvoip voip - cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/ - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'voip' ]]; then + return + fi + fi + if [ -d $SERVER_DIRECTORY/backup/voip ]; then + echo $"Restoring VoIP settings" + restore_directory_from_friend /root/tempvoip voip + cp -f /root/tempvoip/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/ + 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 } function restore_tox { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'tox' ]]; then - return - fi - fi - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'tox' ]]; then + return + fi + fi + 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 } function restore_email { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'email' ]]; then - return - fi - fi - for d in $SERVER_DIRECTORY/backup/mail/*/ ; do - USERNAME=$(echo "$d" | awk -F '/' '{print $6}') - if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'email' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/mail/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; 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 } function restore_dlna { - if [[ $RESTORE_APP != 'all' ]]; then - if [[ $RESTORE_APP != 'dlna' ]]; then - return - fi - fi - 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 + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'dlna' ]]; then + return + fi + fi + 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