Move local blog restore to app script

This commit is contained in:
Bob Mottram 2016-07-08 16:42:31 +01:00
parent 3910ab6ac6
commit 388c8b300d
2 changed files with 48 additions and 45 deletions

View File

@ -73,8 +73,55 @@ function backup_local_blog {
fi
}
function restore_local_blog {
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
if [ $FULLBLOG_DOMAIN_NAME ]; then
echo $"Restoring blog installation"
temp_restore_dir=/root/tempblog
restore_directory_from_usb $temp_restore_dir blog
rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
if [ ! "$?" = "0" ]; then
set_user_permissions
backup_unmount_drive
exit 593
fi
rm -rf $temp_restore_dir
if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
echo $"No content directory found after restoring blog"
set_user_permissions
backup_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 backup_remote_blog {
echo ''
echo -n ''
}
function restore_remote_blog {
echo -n ''
}
function remove_blog {

View File

@ -1070,49 +1070,6 @@ function restore_wiki {
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
set_user_permissions
backup_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"
set_user_permissions
backup_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_email {
if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'email' ]]; then
@ -1209,7 +1166,6 @@ restore_syncthing
restore_mediagoblin
restore_gogs
restore_wiki
restore_blog
restore_email
restore_apps