diff --git a/src/freedombone-restore-remote b/src/freedombone-restore-remote index c58a02b0..e0ebc08c 100755 --- a/src/freedombone-restore-remote +++ b/src/freedombone-restore-remote @@ -699,13 +699,14 @@ function restore_owncloud { return fi fi - OWNCLOUD_PATH=/var/www/owncloud + OWNCLOUD_PATH=/var/www/owncloud if grep -q "Owncloud domain" $COMPLETION_FILE; then OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}') restore_database_from_friend owncloud $OWNCLOUD_DOMAIN_NAME if [ -d $SERVER_DIRECTORY/backup/owncloudfiles ]; then echo $"Restoring Owncloud installation" + restore_directory_from_friend /root/tempowncloudfiles owncloudfiles cp -r /root/tempowncloudfiles/* / if [ ! "$?" = "0" ]; then exit 1458 @@ -715,6 +716,7 @@ function restore_owncloud { if [ -d $SERVER_DIRECTORY/backup/owncloudconfig ]; then echo $"Restoring Owncloud installation" + restore_directory_from_friend /root/tempowncloudconfig owncloudconfig cp -r /root/tempowncloudconfig/* / if [ ! "$?" = "0" ]; then exit 2571 @@ -723,16 +725,16 @@ function restore_owncloud { fi chown -R www-data:www-data $OWNCLOUD_PATH - chown root:root $OWNCLOUD_PATH/config/config.php + chown root:root $OWNCLOUD_PATH/config/config.php # re-index files for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then $OWNCLOUD_PATH/occ files:scan $USERNAME - fi - done - fi + fi + done + fi } function restore_mediagoblin { @@ -745,246 +747,246 @@ function restore_mediagoblin { MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then echo $"Restoring Mediagoblin installation" - restore_directory_from_friend /root/tempmediagoblin mediagoblin - cp -r /root/tempmediagoblin/* / - if [ ! "$?" = "0" ]; then - exit 5626 - fi - rm -rf /root/tempmediagoblin + 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 + chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs + fi } function restore_gogs { - 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 /home/git/go/src/github.com/gogits/gogs/custom ]; then - mkdir -p /home/git/go/src/github.com/gogits/gogs/custom - fi - cp -r /root/tempgogs/home/git/go/src/github.com/gogits/gogs/custom/* /home/git/go/src/github.com/gogits/gogs/custom/ - if [ ! "$?" = "0" ]; then - exit 5885 - fi - echo $"Restoring Gogs repos" - restore_directory_from_friend /root/tempgogsrepos gogsrepos - cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/ - if [ ! "$?" = "0" ]; then - exit 7649 - fi - echo $"Restoring Gogs authorized_keys" - restore_directory_from_friend /root/tempgogsssh gogsssh - if [ ! -d /home/git/.ssh ]; then - mkdir /home/git/.ssh - fi - cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/ - if [ ! "$?" = "0" ]; then - exit 74239 - fi - rm -rf /root/tempgogs - rm -rf /root/tempgogsrepos - rm -rf /root/tempgogsssh - chown -R git:git /home/git - fi - fi + if [[ $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 /home/git/go/src/github.com/gogits/gogs/custom ]; then + mkdir -p /home/git/go/src/github.com/gogits/gogs/custom + fi + cp -r /root/tempgogs/home/git/go/src/github.com/gogits/gogs/custom/* /home/git/go/src/github.com/gogits/gogs/custom/ + if [ ! "$?" = "0" ]; then + exit 5885 + fi + echo $"Restoring Gogs repos" + restore_directory_from_friend /root/tempgogsrepos gogsrepos + cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/ + if [ ! "$?" = "0" ]; then + exit 7649 + fi + echo $"Restoring Gogs authorized_keys" + restore_directory_from_friend /root/tempgogsssh gogsssh + if [ ! -d /home/git/.ssh ]; then + mkdir /home/git/.ssh + fi + cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/ + if [ ! "$?" = "0" ]; then + exit 74239 + fi + rm -rf /root/tempgogs + rm -rf /root/tempgogsrepos + rm -rf /root/tempgogsssh + chown -R git:git /home/git + fi + fi } 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" && $USRNAME != "mirrors" ]]; 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" && $USRNAME != "mirrors" ]]; 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" && $USRNAME != "mirrors" ]]; 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" && $USRNAME != "mirrors" ]]; 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