diff --git a/src/freedombone-app-gnusocial b/src/freedombone-app-gnusocial
index 1caf15ca5c914c73a60a570e00c514f097db4edc..1d02e00c38b6145be6b3aae29609308144103a12 100755
--- a/src/freedombone-app-gnusocial
+++ b/src/freedombone-app-gnusocial
@@ -50,651 +50,675 @@ SHARINGS_THEME_REPO="http://git.lasindias.club/manuel/SharingsTheme"
 SHARINGS_THEME_COMMIT='7106c7ef03'
 
 function gnusocial_running_script {
-	if ! grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
-		return
-	fi
-
-	# check that the daemon is running
-	echo '#!/bin/bash' > /etc/cron.hourly/gnusocial-daemons
-	echo 'daemon_lines=$(ps aux | grep "scripts/queuedaemon.php" | grep "/var/www")' >> /etc/cron.hourly/gnusocial-daemons
-	echo 'if [[ $daemon_lines != *"/var/www/"* ]]; then' >> /etc/cron.hourly/gnusocial-daemons
-
-	echo "    ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')" >> /etc/cron.hourly/gnusocial-daemons
-	echo '    MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME' >> /etc/cron.hourly/gnusocial-daemons
-	echo '    echo "Restarting GNU Social daemons" | mail -s "GNU Social daemons not found" $MY_EMAIL_ADDRESS' >> /etc/cron.hourly/gnusocial-daemons
-	echo "    cd /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs" >> /etc/cron.hourly/gnusocial-daemons
-	echo '    scripts/startdaemons.sh' >> /etc/cron.hourly/gnusocial-daemons
-	echo 'fi' >> /etc/cron.hourly/gnusocial-daemons
-	chmod +x /etc/cron.hourly/gnusocial-daemons
+    if ! grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
+        return
+    fi
+
+    # check that the daemon is running
+    echo '#!/bin/bash' > /etc/cron.hourly/gnusocial-daemons
+    echo 'daemon_lines=$(ps aux | grep "scripts/queuedaemon.php" | grep "/var/www")' >> /etc/cron.hourly/gnusocial-daemons
+    echo 'if [[ $daemon_lines != *"/var/www/"* ]]; then' >> /etc/cron.hourly/gnusocial-daemons
+
+    echo "    ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')" >> /etc/cron.hourly/gnusocial-daemons
+    echo '    MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME' >> /etc/cron.hourly/gnusocial-daemons
+    echo '    echo "Restarting GNU Social daemons" | mail -s "GNU Social daemons not found" $MY_EMAIL_ADDRESS' >> /etc/cron.hourly/gnusocial-daemons
+    echo "    cd /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs" >> /etc/cron.hourly/gnusocial-daemons
+    echo '    scripts/startdaemons.sh' >> /etc/cron.hourly/gnusocial-daemons
+    echo 'fi' >> /etc/cron.hourly/gnusocial-daemons
+    chmod +x /etc/cron.hourly/gnusocial-daemons
 }
 
 function upgrade_gnusocial {
-	if ! grep -Fxq "install_gnusocial_main" $COMPLETION_FILE; then
-		return
-	fi
+    if ! grep -Fxq "install_gnusocial_main" $COMPLETION_FILE; then
+        return
+    fi
 
-	# update to the next commit
-	function_check set_repo_commit
-	set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs "GNU Social commit" "$MICROBLOG_COMMIT" $MICROBLOG_REPO
+    # update to the next commit
+    function_check set_repo_commit
+    set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs "GNU Social commit" "$MICROBLOG_COMMIT" $MICROBLOG_REPO
 
-	function_check gnusocial_running_script
-	gnusocial_running_script
+    function_check gnusocial_running_script
+    gnusocial_running_script
 }
 
 
 function backup_local_gnusocial {
-	echo ''
+    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
+
+    source_directory=/var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
+    if [ -d $source_directory ]; then
+        dest_directory=gnusocial
+        echo $"Backing up $source_directory to $dest_directory"
+
+        function_check suspend_site
+        suspend_site ${MICROBLOG_DOMAIN_NAME}
+
+        function_check backup_directory_to_usb
+        backup_directory_to_usb $source_directory $dest_directory
+
+        function_check backup_database_local
+        backup_database_local gnusocial
+        backup_directory_to_usb /root/tempgnusocialdata gnusocialdata
+
+        function_check restart_site
+        restart_site
+
+        echo $"Backup to $dest_directory complete"
+    fi
 }
 
 function backup_remote_gnusocial {
-	echo ''
+    echo -n ''
 }
 
 function remove_gnusocial {
-	if ! grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
-		return
-	fi
-	nginx_dissite $MICROBLOG_DOMAIN_NAME
-	if [ -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
-		rm -rf /var/www/$MICROBLOG_DOMAIN_NAME
-	fi
-	if [ -f /etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME ]; then
-		rm /etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME
-	fi
-	function_check drop_database
-	drop_database gnusocial
-	function_check remove_onion_service
-	remove_onion_service microblog ${MICROBLOG_ONION_PORT}
-	sed -i '/install_gnusocial/d' $COMPLETION_FILE
-	sed -i '/GNU Social /d' $COMPLETION_FILE
+    if ! grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
+        return
+    fi
+    nginx_dissite $MICROBLOG_DOMAIN_NAME
+    if [ -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
+        rm -rf /var/www/$MICROBLOG_DOMAIN_NAME
+    fi
+    if [ -f /etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME ]; then
+        rm /etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME
+    fi
+    function_check drop_database
+    drop_database gnusocial
+    function_check remove_onion_service
+    remove_onion_service microblog ${MICROBLOG_ONION_PORT}
+    sed -i '/install_gnusocial/d' $COMPLETION_FILE
+    sed -i '/GNU Social /d' $COMPLETION_FILE
 }
 
 function install_gnusocial_main {
-	if [ ! $MICROBLOG_DOMAIN_NAME ]; then
-		echo $'No domain name was given for the microblog'
-		exit 7359
-	fi
-
-	if grep -Fxq "install_gnusocial_main" $COMPLETION_FILE; then
-		return
-	fi
-
-	function_check gnusocial_running_script
-	gnusocial_running_script
-
-	function_check install_mariadb
-	install_mariadb
-
-	function_check get_mariadb_password
-	get_mariadb_password
-
-	function_check repair_databases_script
-	repair_databases_script
-
-	apt-get -y install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
-	apt-get -y install php5-memcached
-
-	if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
-		mkdir /var/www/$MICROBLOG_DOMAIN_NAME
-	fi
-	if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
-		function_check git_clone
-		git_clone $MICROBLOG_REPO /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-		if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
-			echo $'Unable to clone gnusocial repo'
-			exit 87525
-		fi
-	fi
-
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-	git checkout $MICROBLOG_COMMIT -b $MICROBLOG_COMMIT
-	if ! grep -q "GNU Social commit" $COMPLETION_FILE; then
-		echo "GNU Social commit:$MICROBLOG_COMMIT" >> $COMPLETION_FILE
-	else
-		sed -i "s/GNU Social commit.*/GNU Social commit:$MICROBLOG_COMMIT/g" $COMPLETION_FILE
-	fi
-
-	chmod a+w /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-	chown www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-	chmod +x /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php
-
-	function_check get_mariadb_gnusocial_admin_password
-	get_mariadb_gnusocial_admin_password
-	if [ ! $MICROBLOG_ADMIN_PASSWORD ]; then
-		if [ -f $IMAGE_PASSWORD_FILE ]; then
-			MICROBLOG_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
-		else
-			MICROBLOG_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
-		fi
-	fi
-
-	function_check create_database
-	create_database gnusocial "$MICROBLOG_ADMIN_PASSWORD" $MY_USERNAME
-
-	if [ ! -f "/etc/aliases" ]; then
-		touch /etc/aliases
-	fi
-	if ! grep -q "www-data: root" /etc/aliases; then
-		echo 'www-data: root' >> /etc/aliases
-	fi
-	if ! grep -q "/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
-		echo "*: /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
-	fi
-
-	function_check add_ddns_domain
-	add_ddns_domain $MICROBLOG_DOMAIN_NAME
-
-	microblog_nginx_site=/etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME
-	if [[ $ONION_ONLY == "no" ]]; then
-		function_check nginx_http_redirect
-		nginx_http_redirect $MICROBLOG_DOMAIN_NAME
-		echo 'server {' >> $microblog_nginx_site
-		echo '  listen 443 ssl;' >> $microblog_nginx_site
-		echo "  server_name $MICROBLOG_DOMAIN_NAME;" >> $microblog_nginx_site
-		echo '' >> $microblog_nginx_site
-		echo '  # Security' >> $microblog_nginx_site
-		function_check nginx_ssl
-		nginx_ssl $MICROBLOG_DOMAIN_NAME
-
-		function_check nginx_disable_sniffing
-		nginx_disable_sniffing $MICROBLOG_DOMAIN_NAME
-
-		function_check nginx_limits
-		nginx_limits $MICROBLOG_DOMAIN_NAME '15m'
-		echo '  add_header Strict-Transport-Security max-age=15768000;' >> $microblog_nginx_site
-		echo '' >> $microblog_nginx_site
-		echo '  # Logs' >> $microblog_nginx_site
-		echo '  access_log off;' >> $microblog_nginx_site
-		echo '  error_log off;' >> $microblog_nginx_site
-		echo '' >> $microblog_nginx_site
-		echo '  # Root' >> $microblog_nginx_site
-		echo "  root /var/www/$MICROBLOG_DOMAIN_NAME/htdocs;" >> $microblog_nginx_site
-		echo '' >> $microblog_nginx_site
-		echo '  # Index' >> $microblog_nginx_site
-		echo '  index index.php;' >> $microblog_nginx_site
-		echo '' >> $microblog_nginx_site
-		echo '  # PHP' >> $microblog_nginx_site
-		echo '  location ~ \.php {' >> $microblog_nginx_site
-		echo '    include snippets/fastcgi-php.conf;' >> $microblog_nginx_site
-		echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $microblog_nginx_site
-		echo '  }' >> $microblog_nginx_site
-		echo '' >> $microblog_nginx_site
-		echo '  # Location' >> $microblog_nginx_site
-		echo '  location / {' >> $microblog_nginx_site
-		echo '    try_files $uri $uri/ @gnusocial;' >> $microblog_nginx_site
-		echo '  }' >> $microblog_nginx_site
-		echo '' >> $microblog_nginx_site
-		echo '  # Fancy URLs' >> $microblog_nginx_site
-		echo '  location @gnusocial {' >> $microblog_nginx_site
-		echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $microblog_nginx_site
-		echo '  }' >> $microblog_nginx_site
-		echo '' >> $microblog_nginx_site
-		echo '  # Restrict access that is unnecessary anyway' >> $microblog_nginx_site
-		echo '  location ~ /\.(ht|git) {' >> $microblog_nginx_site
-		echo '    deny all;' >> $microblog_nginx_site
-		echo '  }' >> $microblog_nginx_site
-		echo '}' >> $microblog_nginx_site
-	else
-		echo -n '' > $microblog_nginx_site
-	fi
-	echo 'server {' >> $microblog_nginx_site
-	echo "    listen 127.0.0.1:$MICROBLOG_ONION_PORT default_server;" >> $microblog_nginx_site
-	echo "    server_name $MICROBLOG_DOMAIN_NAME;" >> $microblog_nginx_site
-	echo '' >> $microblog_nginx_site
-	function_check nginx_disable_sniffing
-	nginx_disable_sniffing $MICROBLOG_DOMAIN_NAME
-	function_check nginx_limits
-	nginx_limits $MICROBLOG_DOMAIN_NAME '15m'
-	echo '' >> $microblog_nginx_site
-	echo '  # Logs' >> $microblog_nginx_site
-	echo '  access_log off;' >> $microblog_nginx_site
-	echo '  error_log off;' >> $microblog_nginx_site
-	echo '' >> $microblog_nginx_site
-	echo '  # Root' >> $microblog_nginx_site
-	echo "  root /var/www/$MICROBLOG_DOMAIN_NAME/htdocs;" >> $microblog_nginx_site
-	echo '' >> $microblog_nginx_site
-	echo '  # Index' >> $microblog_nginx_site
-	echo '  index index.php;' >> $microblog_nginx_site
-	echo '' >> $microblog_nginx_site
-	echo '  # PHP' >> $microblog_nginx_site
-	echo '  location ~ \.php {' >> $microblog_nginx_site
-	echo '    include snippets/fastcgi-php.conf;' >> $microblog_nginx_site
-	echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $microblog_nginx_site
-	echo '  }' >> $microblog_nginx_site
-	echo '' >> $microblog_nginx_site
-	echo '  # Location' >> $microblog_nginx_site
-	echo '  location / {' >> $microblog_nginx_site
-	echo '    try_files $uri $uri/ @gnusocial;' >> $microblog_nginx_site
-	echo '  }' >> $microblog_nginx_site
-	echo '' >> $microblog_nginx_site
-	echo '  # Fancy URLs' >> $microblog_nginx_site
-	echo '  location @gnusocial {' >> $microblog_nginx_site
-	echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $microblog_nginx_site
-	echo '  }' >> $microblog_nginx_site
-	echo '' >> $microblog_nginx_site
-	echo '  # Restrict access that is unnecessary anyway' >> $microblog_nginx_site
-	echo '  location ~ /\.(ht|git) {' >> $microblog_nginx_site
-	echo '    deny all;' >> $microblog_nginx_site
-	echo '  }' >> $microblog_nginx_site
-	echo '}' >> $microblog_nginx_site
-
-	function_check configure_php
-	configure_php
-
-	function_check create_site_certificate
-	create_site_certificate $MICROBLOG_DOMAIN_NAME 'yes'
-
-	# Ensure that the database gets backed up locally, if remote
-	# backups are not being used
-	function_check backup_databases_script_header
-	backup_databases_script_header
-
-	function_check backup_database_local
-	backup_database_local gnusocial
-
-	function_check nginx_ensite
-	nginx_ensite $MICROBLOG_DOMAIN_NAME
-
-	# NOTE: For the typical case always enable SSL and only
-	# disable it if in onion only mode. This is due to complexities
-	# with the way URLs are generated by GNU Social
-	gnusocial_ssl='always'
-	if [[ $ONION_ONLY != 'no' ]]; then
-		gnusocial_ssl='never'
-	fi
-
-	MICROBLOG_ONION_HOSTNAME=$(add_onion_service microblog 80 ${MICROBLOG_ONION_PORT})
-
-	MICROBLOG_SERVER=${MICROBLOG_DOMAIN_NAME}
-	if [[ $ONION_ONLY != 'no' ]]; then
-		MICROBLOG_SERVER=${MICROBLOG_ONION_HOSTNAME}
-	fi
-
-	# Create the configuration
-	gnusocial_installer=/var/www/${MICROBLOG_DOMAIN_NAME}/htdocs/scripts/install_cli.php
-	if [ ! -f $gnusocial_installer ]; then
-		echo $'No GNU Social commandline installer found'
-		exit 53026
-	fi
-	${gnusocial_installer} --server "${MICROBLOG_SERVER}" \
-						   --host="localhost" --database="gnusocial" \
-						   --dbtype=mysql --username="root" -v \
-						   --password="$MARIADB_PASSWORD" \
-						   --sitename=$"GNU Social" --fancy='yes' \
-						   --admin-nick="$MY_USERNAME" \
-						   --admin-pass="$MICROBLOG_ADMIN_PASSWORD" \
-						   --site-profile="community" \
-						   --ssl=${gnusocial_ssl}
-	# There can be a lot of warnings here so the return value check is disabled
-	#if [ ! "$?" = "0" ]; then
-	#    # failed to install
-	#    echo $'Could not install GNU Social'
-	#    exit 72357
-	#fi
-
-	# check microblog has a config file
-	microblog_config_file=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
-	if [ ! -f $microblog_config_file ]; then
-		echo $'Microblog config.php not found'
-		exit 87586
-	fi
-
-	# Some useful settings
-	if ! grep -q "Recommended GNU social settings" $microblog_config_file; then
-		echo "" >> $microblog_config_file
-		echo "// Recommended GNU social settings" >> $microblog_config_file
-		echo "\$config['thumbnail']['maxsize'] = 3000;" >> $microblog_config_file
-		echo "\$config['profile']['delete'] = true;" >> $microblog_config_file
-		echo "\$config['profile']['changenick'] = true;" >> $microblog_config_file
-		echo "\$config['public']['localonly'] = false;" >> $microblog_config_file
-		echo "addPlugin('StoreRemoteMedia');" >> $microblog_config_file
-		echo "\$config['queue']['enabled'] = true;" >> $microblog_config_file
-		echo "\$config['queue']['daemon'] = true;" >> $microblog_config_file
-		echo "\$config['ostatus']['hub_retries'] = 3;" >> $microblog_config_file
-	fi
-
-	# This improves performance
-	sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $microblog_config_file
-
-	systemctl restart php5-fpm
-	systemctl restart nginx
-
-	${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$MICROBLOG_DOMAIN_NAME" -g gnusocial --public no
-
-	# some post-install instructions for the user
-	if ! grep -q $"Microblog administrator" /home/$MY_USERNAME/README; then
-		echo '' >> /home/$MY_USERNAME/README
-		echo '' >> /home/$MY_USERNAME/README
-		echo $'Microblog' >> /home/$MY_USERNAME/README
-		echo '=========' >> /home/$MY_USERNAME/README
-		echo $"Microblog administrator nickname: $MY_USERNAME" >> /home/$MY_USERNAME/README
-		echo $"Microblog administrator password: $MICROBLOG_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
-		chmod 600 /home/$MY_USERNAME/README
-	fi
-
-	if ! grep -q "Microblog onion domain" /home/$MY_USERNAME/README; then
-		echo $"Microblog onion domain: ${MICROBLOG_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
-		echo '' >> /home/$MY_USERNAME/README
-		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
-		chmod 600 /home/$MY_USERNAME/README
-	fi
-	echo "GNU Social onion domain:${MICROBLOG_ONION_HOSTNAME}" >> $COMPLETION_FILE
-
-	echo "GNU Social domain:$MICROBLOG_DOMAIN_NAME" >> $COMPLETION_FILE
-	echo 'install_gnusocial_main' >> $COMPLETION_FILE
+    if [ ! $MICROBLOG_DOMAIN_NAME ]; then
+        echo $'No domain name was given for the microblog'
+        exit 7359
+    fi
+
+    if grep -Fxq "install_gnusocial_main" $COMPLETION_FILE; then
+        return
+    fi
+
+    function_check gnusocial_running_script
+    gnusocial_running_script
+
+    function_check install_mariadb
+    install_mariadb
+
+    function_check get_mariadb_password
+    get_mariadb_password
+
+    function_check repair_databases_script
+    repair_databases_script
+
+    apt-get -y install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
+    apt-get -y install php5-memcached
+
+    if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME ]; then
+        mkdir /var/www/$MICROBLOG_DOMAIN_NAME
+    fi
+    if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
+        function_check git_clone
+        git_clone $MICROBLOG_REPO /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+        if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
+            echo $'Unable to clone gnusocial repo'
+            exit 87525
+        fi
+    fi
+
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+    git checkout $MICROBLOG_COMMIT -b $MICROBLOG_COMMIT
+    if ! grep -q "GNU Social commit" $COMPLETION_FILE; then
+        echo "GNU Social commit:$MICROBLOG_COMMIT" >> $COMPLETION_FILE
+    else
+        sed -i "s/GNU Social commit.*/GNU Social commit:$MICROBLOG_COMMIT/g" $COMPLETION_FILE
+    fi
+
+    chmod a+w /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+    chown www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+    chmod +x /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php
+
+    function_check get_mariadb_gnusocial_admin_password
+    get_mariadb_gnusocial_admin_password
+    if [ ! $MICROBLOG_ADMIN_PASSWORD ]; then
+        if [ -f $IMAGE_PASSWORD_FILE ]; then
+            MICROBLOG_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
+        else
+            MICROBLOG_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
+        fi
+    fi
+
+    function_check create_database
+    create_database gnusocial "$MICROBLOG_ADMIN_PASSWORD" $MY_USERNAME
+
+    if [ ! -f "/etc/aliases" ]; then
+        touch /etc/aliases
+    fi
+    if ! grep -q "www-data: root" /etc/aliases; then
+        echo 'www-data: root' >> /etc/aliases
+    fi
+    if ! grep -q "/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
+        echo "*: /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
+    fi
+
+    function_check add_ddns_domain
+    add_ddns_domain $MICROBLOG_DOMAIN_NAME
+
+    microblog_nginx_site=/etc/nginx/sites-available/$MICROBLOG_DOMAIN_NAME
+    if [[ $ONION_ONLY == "no" ]]; then
+        function_check nginx_http_redirect
+        nginx_http_redirect $MICROBLOG_DOMAIN_NAME
+        echo 'server {' >> $microblog_nginx_site
+        echo '  listen 443 ssl;' >> $microblog_nginx_site
+        echo "  server_name $MICROBLOG_DOMAIN_NAME;" >> $microblog_nginx_site
+        echo '' >> $microblog_nginx_site
+        echo '  # Security' >> $microblog_nginx_site
+        function_check nginx_ssl
+        nginx_ssl $MICROBLOG_DOMAIN_NAME
+
+        function_check nginx_disable_sniffing
+        nginx_disable_sniffing $MICROBLOG_DOMAIN_NAME
+
+        function_check nginx_limits
+        nginx_limits $MICROBLOG_DOMAIN_NAME '15m'
+        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $microblog_nginx_site
+        echo '' >> $microblog_nginx_site
+        echo '  # Logs' >> $microblog_nginx_site
+        echo '  access_log off;' >> $microblog_nginx_site
+        echo '  error_log off;' >> $microblog_nginx_site
+        echo '' >> $microblog_nginx_site
+        echo '  # Root' >> $microblog_nginx_site
+        echo "  root /var/www/$MICROBLOG_DOMAIN_NAME/htdocs;" >> $microblog_nginx_site
+        echo '' >> $microblog_nginx_site
+        echo '  # Index' >> $microblog_nginx_site
+        echo '  index index.php;' >> $microblog_nginx_site
+        echo '' >> $microblog_nginx_site
+        echo '  # PHP' >> $microblog_nginx_site
+        echo '  location ~ \.php {' >> $microblog_nginx_site
+        echo '    include snippets/fastcgi-php.conf;' >> $microblog_nginx_site
+        echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $microblog_nginx_site
+        echo '  }' >> $microblog_nginx_site
+        echo '' >> $microblog_nginx_site
+        echo '  # Location' >> $microblog_nginx_site
+        echo '  location / {' >> $microblog_nginx_site
+        echo '    try_files $uri $uri/ @gnusocial;' >> $microblog_nginx_site
+        echo '  }' >> $microblog_nginx_site
+        echo '' >> $microblog_nginx_site
+        echo '  # Fancy URLs' >> $microblog_nginx_site
+        echo '  location @gnusocial {' >> $microblog_nginx_site
+        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $microblog_nginx_site
+        echo '  }' >> $microblog_nginx_site
+        echo '' >> $microblog_nginx_site
+        echo '  # Restrict access that is unnecessary anyway' >> $microblog_nginx_site
+        echo '  location ~ /\.(ht|git) {' >> $microblog_nginx_site
+        echo '    deny all;' >> $microblog_nginx_site
+        echo '  }' >> $microblog_nginx_site
+        echo '}' >> $microblog_nginx_site
+    else
+        echo -n '' > $microblog_nginx_site
+    fi
+    echo 'server {' >> $microblog_nginx_site
+    echo "    listen 127.0.0.1:$MICROBLOG_ONION_PORT default_server;" >> $microblog_nginx_site
+    echo "    server_name $MICROBLOG_DOMAIN_NAME;" >> $microblog_nginx_site
+    echo '' >> $microblog_nginx_site
+    function_check nginx_disable_sniffing
+    nginx_disable_sniffing $MICROBLOG_DOMAIN_NAME
+    function_check nginx_limits
+    nginx_limits $MICROBLOG_DOMAIN_NAME '15m'
+    echo '' >> $microblog_nginx_site
+    echo '  # Logs' >> $microblog_nginx_site
+    echo '  access_log off;' >> $microblog_nginx_site
+    echo '  error_log off;' >> $microblog_nginx_site
+    echo '' >> $microblog_nginx_site
+    echo '  # Root' >> $microblog_nginx_site
+    echo "  root /var/www/$MICROBLOG_DOMAIN_NAME/htdocs;" >> $microblog_nginx_site
+    echo '' >> $microblog_nginx_site
+    echo '  # Index' >> $microblog_nginx_site
+    echo '  index index.php;' >> $microblog_nginx_site
+    echo '' >> $microblog_nginx_site
+    echo '  # PHP' >> $microblog_nginx_site
+    echo '  location ~ \.php {' >> $microblog_nginx_site
+    echo '    include snippets/fastcgi-php.conf;' >> $microblog_nginx_site
+    echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $microblog_nginx_site
+    echo '  }' >> $microblog_nginx_site
+    echo '' >> $microblog_nginx_site
+    echo '  # Location' >> $microblog_nginx_site
+    echo '  location / {' >> $microblog_nginx_site
+    echo '    try_files $uri $uri/ @gnusocial;' >> $microblog_nginx_site
+    echo '  }' >> $microblog_nginx_site
+    echo '' >> $microblog_nginx_site
+    echo '  # Fancy URLs' >> $microblog_nginx_site
+    echo '  location @gnusocial {' >> $microblog_nginx_site
+    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $microblog_nginx_site
+    echo '  }' >> $microblog_nginx_site
+    echo '' >> $microblog_nginx_site
+    echo '  # Restrict access that is unnecessary anyway' >> $microblog_nginx_site
+    echo '  location ~ /\.(ht|git) {' >> $microblog_nginx_site
+    echo '    deny all;' >> $microblog_nginx_site
+    echo '  }' >> $microblog_nginx_site
+    echo '}' >> $microblog_nginx_site
+
+    function_check configure_php
+    configure_php
+
+    function_check create_site_certificate
+    create_site_certificate $MICROBLOG_DOMAIN_NAME 'yes'
+
+    # Ensure that the database gets backed up locally, if remote
+    # backups are not being used
+    function_check backup_databases_script_header
+    backup_databases_script_header
+
+    function_check backup_database_local
+    backup_database_local gnusocial
+
+    function_check nginx_ensite
+    nginx_ensite $MICROBLOG_DOMAIN_NAME
+
+    # NOTE: For the typical case always enable SSL and only
+    # disable it if in onion only mode. This is due to complexities
+    # with the way URLs are generated by GNU Social
+    gnusocial_ssl='always'
+    if [[ $ONION_ONLY != 'no' ]]; then
+        gnusocial_ssl='never'
+    fi
+
+    MICROBLOG_ONION_HOSTNAME=$(add_onion_service microblog 80 ${MICROBLOG_ONION_PORT})
+
+    MICROBLOG_SERVER=${MICROBLOG_DOMAIN_NAME}
+    if [[ $ONION_ONLY != 'no' ]]; then
+        MICROBLOG_SERVER=${MICROBLOG_ONION_HOSTNAME}
+    fi
+
+    # Create the configuration
+    gnusocial_installer=/var/www/${MICROBLOG_DOMAIN_NAME}/htdocs/scripts/install_cli.php
+    if [ ! -f $gnusocial_installer ]; then
+        echo $'No GNU Social commandline installer found'
+        exit 53026
+    fi
+    ${gnusocial_installer} --server "${MICROBLOG_SERVER}" \
+                           --host="localhost" --database="gnusocial" \
+                           --dbtype=mysql --username="root" -v \
+                           --password="$MARIADB_PASSWORD" \
+                           --sitename=$"GNU Social" --fancy='yes' \
+                           --admin-nick="$MY_USERNAME" \
+                           --admin-pass="$MICROBLOG_ADMIN_PASSWORD" \
+                           --site-profile="community" \
+                           --ssl=${gnusocial_ssl}
+    # There can be a lot of warnings here so the return value check is disabled
+    #if [ ! "$?" = "0" ]; then
+    #    # failed to install
+    #    echo $'Could not install GNU Social'
+    #    exit 72357
+    #fi
+
+    # check microblog has a config file
+    microblog_config_file=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
+    if [ ! -f $microblog_config_file ]; then
+        echo $'Microblog config.php not found'
+        exit 87586
+    fi
+
+    # Some useful settings
+    if ! grep -q "Recommended GNU social settings" $microblog_config_file; then
+        echo "" >> $microblog_config_file
+        echo "// Recommended GNU social settings" >> $microblog_config_file
+        echo "\$config['thumbnail']['maxsize'] = 3000;" >> $microblog_config_file
+        echo "\$config['profile']['delete'] = true;" >> $microblog_config_file
+        echo "\$config['profile']['changenick'] = true;" >> $microblog_config_file
+        echo "\$config['public']['localonly'] = false;" >> $microblog_config_file
+        echo "addPlugin('StoreRemoteMedia');" >> $microblog_config_file
+        echo "\$config['queue']['enabled'] = true;" >> $microblog_config_file
+        echo "\$config['queue']['daemon'] = true;" >> $microblog_config_file
+        echo "\$config['ostatus']['hub_retries'] = 3;" >> $microblog_config_file
+    fi
+
+    # This improves performance
+    sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $microblog_config_file
+
+    systemctl restart php5-fpm
+    systemctl restart nginx
+
+    ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$MICROBLOG_DOMAIN_NAME" -g gnusocial --public no
+
+    # some post-install instructions for the user
+    if ! grep -q $"Microblog administrator" /home/$MY_USERNAME/README; then
+        echo '' >> /home/$MY_USERNAME/README
+        echo '' >> /home/$MY_USERNAME/README
+        echo $'Microblog' >> /home/$MY_USERNAME/README
+        echo '=========' >> /home/$MY_USERNAME/README
+        echo $"Microblog administrator nickname: $MY_USERNAME" >> /home/$MY_USERNAME/README
+        echo $"Microblog administrator password: $MICROBLOG_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
+        chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
+        chmod 600 /home/$MY_USERNAME/README
+    fi
+
+    if ! grep -q "Microblog onion domain" /home/$MY_USERNAME/README; then
+        echo $"Microblog onion domain: ${MICROBLOG_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
+        echo '' >> /home/$MY_USERNAME/README
+        chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
+        chmod 600 /home/$MY_USERNAME/README
+    fi
+    echo "GNU Social onion domain:${MICROBLOG_ONION_HOSTNAME}" >> $COMPLETION_FILE
+
+    echo "GNU Social domain:$MICROBLOG_DOMAIN_NAME" >> $COMPLETION_FILE
+    echo 'install_gnusocial_main' >> $COMPLETION_FILE
 }
 
 function install_gnusocial_plugin_sharings {
-	if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
-		echo $'No local/plugins directory found for the microblog'
-		exit 72945
-	fi
-
-	# update to the next commit
-	function_check set_repo_commit
-	set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins "GNU Social sharings plugin commit" "$SHARINGS_COMMIT" $SHARINGS_REPO
-
-	if grep -Fxq "install_gnusocial_plugin_sharings" $COMPLETION_FILE; then
-		return
-	fi
-
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
-	function_check git_clone
-	git_clone $SHARINGS_REPO Sharings
-	if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings ]; then
-		echo $'Unable to clone microblog sharings plugin'
-		exit 36738
-	fi
-
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings
-	git stash
-	git checkout master
-	git branch -D $SHARINGS_COMMIT
-	git checkout $SHARINGS_COMMIT -b $SHARINGS_COMMIT
-
-	# enable the plugin
-	if ! grep -q "addPlugin('Sharings');" /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php; then
-		echo "addPlugin('Sharings');" >> /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
-	fi
-
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-	php scripts/checkschema.php
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings
-	php scripts/seedsharings.php
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-	php scripts/checkschema.php
-
-	# Languages
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES
-	msgfmt -o Sharings.mo Sharings.po
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES
-	msgfmt -o Sharings.mo Sharings.po
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES
-	msgfmt -o Sharings.mo Sharings.po
-
-	chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-
-	if ! grep -q "GNU Social sharings plugin commit" $COMPLETION_FILE; then
-		echo "GNU Social sharings plugin commit:$SHARINGS_COMMIT" >> $COMPLETION_FILE
-	else
-		sed -i "s|GNU Social sharings plugin commit.*|GNU Social sharings plugin commit:$SHARINGS_COMMIT|g" $COMPLETION_FILE
-	fi
-	echo 'install_gnusocial_plugin_sharings' >> $COMPLETION_FILE
+    if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
+        echo $'No local/plugins directory found for the microblog'
+        exit 72945
+    fi
+
+    # update to the next commit
+    function_check set_repo_commit
+    set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins "GNU Social sharings plugin commit" "$SHARINGS_COMMIT" $SHARINGS_REPO
+
+    if grep -Fxq "install_gnusocial_plugin_sharings" $COMPLETION_FILE; then
+        return
+    fi
+
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
+    function_check git_clone
+    git_clone $SHARINGS_REPO Sharings
+    if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings ]; then
+        echo $'Unable to clone microblog sharings plugin'
+        exit 36738
+    fi
+
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings
+    git stash
+    git checkout master
+    git branch -D $SHARINGS_COMMIT
+    git checkout $SHARINGS_COMMIT -b $SHARINGS_COMMIT
+
+    # enable the plugin
+    if ! grep -q "addPlugin('Sharings');" /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php; then
+        echo "addPlugin('Sharings');" >> /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
+    fi
+
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+    php scripts/checkschema.php
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings
+    php scripts/seedsharings.php
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+    php scripts/checkschema.php
+
+    # Languages
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES
+    msgfmt -o Sharings.mo Sharings.po
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES
+    msgfmt -o Sharings.mo Sharings.po
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES
+    msgfmt -o Sharings.mo Sharings.po
+
+    chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+
+    if ! grep -q "GNU Social sharings plugin commit" $COMPLETION_FILE; then
+        echo "GNU Social sharings plugin commit:$SHARINGS_COMMIT" >> $COMPLETION_FILE
+    else
+        sed -i "s|GNU Social sharings plugin commit.*|GNU Social sharings plugin commit:$SHARINGS_COMMIT|g" $COMPLETION_FILE
+    fi
+    echo 'install_gnusocial_plugin_sharings' >> $COMPLETION_FILE
 }
 
 function install_gnusocial_plugin_sharings_theme {
-	if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
-		echo $'No local/plugins directory found for the microblog'
-		exit 74458
-	fi
-
-	# update to the next commit
-	function_check set_repo_commit
-	set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins "GNU Social sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" $SHARINGS_THEME_REPO
-
-	if grep -Fxq "install_gnusocial_plugin_sharings_theme" $COMPLETION_FILE; then
-		return
-	fi
-
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
-	function_check git_clone
-	git_clone $SHARINGS_THEME_REPO SharingsTheme
-	if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme ]; then
-		echo $'Unable to clone microblog sharings plugin theme'
-		exit 639253
-	fi
-
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme
-	git stash
-	git checkout master
-	git branch -D $SHARINGS_THEME_COMMIT
-	git checkout $SHARINGS_THEME_COMMIT -b $SHARINGS_THEME_COMMIT
-
-	# enable the plugin
-	if ! grep -q "addPlugin('SharingsTheme');" /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php; then
-		echo "addPlugin('SharingsTheme');" >> /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
-	fi
-
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-	php scripts/checkschema.php
-
-	chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-
-	if ! grep -q "GNU Social sharings plugin theme commit" $COMPLETION_FILE; then
-		echo "GNU Social sharings plugin theme commit:$SHARINGS_THEME_COMMIT" >> $COMPLETION_FILE
-	else
-		sed -i "s|GNU Social sharings plugin theme commit.*|GNU Social sharings plugin theme commit:$SHARINGS_THEME_COMMIT|g" $COMPLETION_FILE
-	fi
-	echo 'install_gnusocial_plugin_sharings_theme' >> $COMPLETION_FILE
+    if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
+        echo $'No local/plugins directory found for the microblog'
+        exit 74458
+    fi
+
+    # update to the next commit
+    function_check set_repo_commit
+    set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins "GNU Social sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" $SHARINGS_THEME_REPO
+
+    if grep -Fxq "install_gnusocial_plugin_sharings_theme" $COMPLETION_FILE; then
+        return
+    fi
+
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
+    function_check git_clone
+    git_clone $SHARINGS_THEME_REPO SharingsTheme
+    if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme ]; then
+        echo $'Unable to clone microblog sharings plugin theme'
+        exit 639253
+    fi
+
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/SharingsTheme
+    git stash
+    git checkout master
+    git branch -D $SHARINGS_THEME_COMMIT
+    git checkout $SHARINGS_THEME_COMMIT -b $SHARINGS_THEME_COMMIT
+
+    # enable the plugin
+    if ! grep -q "addPlugin('SharingsTheme');" /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php; then
+        echo "addPlugin('SharingsTheme');" >> /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
+    fi
+
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+    php scripts/checkschema.php
+
+    chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+
+    if ! grep -q "GNU Social sharings plugin theme commit" $COMPLETION_FILE; then
+        echo "GNU Social sharings plugin theme commit:$SHARINGS_THEME_COMMIT" >> $COMPLETION_FILE
+    else
+        sed -i "s|GNU Social sharings plugin theme commit.*|GNU Social sharings plugin theme commit:$SHARINGS_THEME_COMMIT|g" $COMPLETION_FILE
+    fi
+    echo 'install_gnusocial_plugin_sharings_theme' >> $COMPLETION_FILE
 }
 
 function expire_gnusocial_posts {
-	# To prevent the database size from growing endlessly this script expires posts
-	# after a number of months
-	if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
-		return
-	fi
-
-	gnusocial_expire_script=/usr/bin/gnusocial-expire
-
-	echo '<?php' > $gnusocial_expire_script
-	echo '' >> $gnusocial_expire_script
-	echo '// GNU Social post expiry script, based on StatExpire by Tony Baldwin' >> $gnusocial_expire_script
-	echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_script
-	echo '' >> $gnusocial_expire_script
-	echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $gnusocial_expire_script
-	echo '$username="root";' >> $gnusocial_expire_script
-	echo "\$password=trim(file_get_contents(\"$DATABASE_PASSWORD_FILE\"));" >> $gnusocial_expire_script
-	echo '$database="gnusocial";' >> $gnusocial_expire_script
-	echo '' >> $gnusocial_expire_script
-	echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_script
-	echo '    echo "Could not connect to mariadb";' >> $gnusocial_expire_script
-	echo '    exit;' >> $gnusocial_expire_script
-	echo '}' >> $gnusocial_expire_script
-	echo '' >> $gnusocial_expire_script
-	echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_script
-	echo '    echo "Could not select gnusocial database";' >> $gnusocial_expire_script
-	echo '    exit;' >> $gnusocial_expire_script
-	echo '}' >> $gnusocial_expire_script
-	echo '' >> $gnusocial_expire_script
-	echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
-	echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_script
-	echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
-	echo '' >> $gnusocial_expire_script
-	echo 'mysql_query($notice_query);' >> $gnusocial_expire_script
-	echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_script
-	echo 'mysql_query($conversation_query);' >> $gnusocial_expire_script
-	echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_script
-	echo 'mysql_query($reply_query);' >> $gnusocial_expire_script
-	echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_script
-	echo 'mysql_close();' >> $gnusocial_expire_script
-	echo '' >> $gnusocial_expire_script
-	echo 'echo "Expire GNU Social posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_script
-	chmod +x $gnusocial_expire_script
-
-	# Add a cron job
-	if ! grep -q "$gnusocial_expire_script" /etc/crontab; then
-		echo "10 3 5   *   *   root /usr/bin/timeout 500 /usr/bin/php $gnusocial_expire_script" >> /etc/crontab
-	fi
-
-	# remove old expire script
-	if [ -f /etc/cron.weekly/clear-microblog-database ]; then
-		rm /etc/cron.weekly/clear-microblog-database
-	fi
+    # To prevent the database size from growing endlessly this script expires posts
+    # after a number of months
+    if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
+        return
+    fi
+
+    gnusocial_expire_script=/usr/bin/gnusocial-expire
+
+    echo '<?php' > $gnusocial_expire_script
+    echo '' >> $gnusocial_expire_script
+    echo '// GNU Social post expiry script, based on StatExpire by Tony Baldwin' >> $gnusocial_expire_script
+    echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_script
+    echo '' >> $gnusocial_expire_script
+    echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $gnusocial_expire_script
+    echo '$username="root";' >> $gnusocial_expire_script
+    echo "\$password=trim(file_get_contents(\"$DATABASE_PASSWORD_FILE\"));" >> $gnusocial_expire_script
+    echo '$database="gnusocial";' >> $gnusocial_expire_script
+    echo '' >> $gnusocial_expire_script
+    echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_script
+    echo '    echo "Could not connect to mariadb";' >> $gnusocial_expire_script
+    echo '    exit;' >> $gnusocial_expire_script
+    echo '}' >> $gnusocial_expire_script
+    echo '' >> $gnusocial_expire_script
+    echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_script
+    echo '    echo "Could not select gnusocial database";' >> $gnusocial_expire_script
+    echo '    exit;' >> $gnusocial_expire_script
+    echo '}' >> $gnusocial_expire_script
+    echo '' >> $gnusocial_expire_script
+    echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
+    echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_script
+    echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
+    echo '' >> $gnusocial_expire_script
+    echo 'mysql_query($notice_query);' >> $gnusocial_expire_script
+    echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_script
+    echo 'mysql_query($conversation_query);' >> $gnusocial_expire_script
+    echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_script
+    echo 'mysql_query($reply_query);' >> $gnusocial_expire_script
+    echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_script
+    echo 'mysql_close();' >> $gnusocial_expire_script
+    echo '' >> $gnusocial_expire_script
+    echo 'echo "Expire GNU Social posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_script
+    chmod +x $gnusocial_expire_script
+
+    # Add a cron job
+    if ! grep -q "$gnusocial_expire_script" /etc/crontab; then
+        echo "10 3 5   *   *   root /usr/bin/timeout 500 /usr/bin/php $gnusocial_expire_script" >> /etc/crontab
+    fi
+
+    # remove old expire script
+    if [ -f /etc/cron.weekly/clear-microblog-database ]; then
+        rm /etc/cron.weekly/clear-microblog-database
+    fi
 }
 
 function install_gnusocial_theme {
-	# update to the next commit
-	function_check set_repo_commit
-	set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter "GNU Social theme commit" "$MICROBLOG_THEME_COMMIT" $MICROBLOG_THEME_REPO
-
-	# customise with project logo
-	if [ -f /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
-		if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
-			cp ~/freedombone/img/gnusocial_sprite.png /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
-		fi
-	fi
-
-	if grep -Fxq "install_gnusocial_theme" $COMPLETION_FILE; then
-		return
-	fi
-
-	apt-get -y install wget
-
-	if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
-		mkdir -p /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
-	fi
-
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
-	function_check git_clone
-	git_clone $MICROBLOG_THEME_REPO Qvitter
-	cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter
-	git checkout $MICROBLOG_THEME_COMMIT -b $MICROBLOG_THEME_COMMIT
-
-	# download a custom background image
-	MICROBLOG_BACKGROUND_IMAGE_URL_EXT=
-	if [ $MICROBLOG_BACKGROUND_IMAGE_URL ]; then
-		if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".jpeg" || $$MICROBLOG_BACKGROUND_IMAGE_URL == *".jpg" ]]; then
-			MICROBLOG_BACKGROUND_IMAGE_URL_EXT="jpg"
-		fi
-		if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".png" ]]; then
-			MICROBLOG_BACKGROUND_IMAGE_URL_EXT="png"
-		fi
-		if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".gif" ]]; then
-			MICROBLOG_BACKGROUND_IMAGE_URL_EXT="gif"
-		fi
-		if [ $MICROBLOG_BACKGROUND_IMAGE_URL_EXT ]; then
-			wget $MICROBLOG_BACKGROUND_IMAGE_URL -O img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}
-			if [ ! -f img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT} ]; then
-				echo "$MICROBLOG_BACKGROUND_IMAGE_URL"
-				echo $'Custom background image for microblog could not be downloaded'
-				exit 87524
-			fi
-		fi
-	fi
-
-	microblog_config_file=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
-	if ! grep -q "addPlugin('Qvitter')" $microblog_config_file; then
-		MICROBLOG_WELCOME_MESSAGE=$(echo $MICROBLOG_WELCOME_MESSAGE | sed "s|\$MICROBLOG_DOMAIN_NAME|$MICROBLOG_DOMAIN_NAME|g")
-		echo "" >> $microblog_config_file
-		echo "// Qvitter settings" >> $microblog_config_file
-		echo "addPlugin('Qvitter');" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $microblog_config_file
-		if [ $MICROBLOG_BACKGROUND_IMAGE_URL ]; then
-			echo "\$config['site']['qvitter']['sitebackground'] = 'img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}';" >> $microblog_config_file
-		else
-			echo "\$config['site']['qvitter']['sitebackground'] = 'img/vagnsmossen.jpg';" >> $microblog_config_file
-		fi
-		echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['enablewelcometext'] = true;" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['customwelcometext']['en'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['customwelcometext']['de'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['customwelcometext']['fr'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['customwelcometext']['es'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
-		echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $microblog_config_file
-	else
-		if [ $MICROBLOG_BACKGROUND_IMAGE_URL_EXT ]; then
-			if [ -f img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT} ]; then
-				sed -i "s|\$config['site']['qvitter']['sitebackground'].*|\$config['site']['qvitter']['sitebackground'] = 'img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}';|g" $microblog_config_file
-			fi
-		fi
-	fi
-
-	# customise with project logo
-	if [ -f /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
-		if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
-			cp ~/freedombone/img/gnusocial_sprite.png /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
-		fi
-	fi
-
-	if ! grep -q "GNU Social theme commit" $COMPLETION_FILE; then
-		echo "GNU Social theme commit:$MICROBLOG_THEME_COMMIT" >> $COMPLETION_FILE
-	fi
-
-	chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
-
-	echo 'install_gnusocial_theme' >> $COMPLETION_FILE
+    # update to the next commit
+    function_check set_repo_commit
+    set_repo_commit /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter "GNU Social theme commit" "$MICROBLOG_THEME_COMMIT" $MICROBLOG_THEME_REPO
+
+    # customise with project logo
+    if [ -f /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
+        if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
+            cp ~/freedombone/img/gnusocial_sprite.png /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
+        fi
+    fi
+
+    if grep -Fxq "install_gnusocial_theme" $COMPLETION_FILE; then
+        return
+    fi
+
+    apt-get -y install wget
+
+    if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins ]; then
+        mkdir -p /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
+    fi
+
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins
+    function_check git_clone
+    git_clone $MICROBLOG_THEME_REPO Qvitter
+    cd /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter
+    git checkout $MICROBLOG_THEME_COMMIT -b $MICROBLOG_THEME_COMMIT
+
+    # download a custom background image
+    MICROBLOG_BACKGROUND_IMAGE_URL_EXT=
+    if [ $MICROBLOG_BACKGROUND_IMAGE_URL ]; then
+        if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".jpeg" || $$MICROBLOG_BACKGROUND_IMAGE_URL == *".jpg" ]]; then
+            MICROBLOG_BACKGROUND_IMAGE_URL_EXT="jpg"
+        fi
+        if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".png" ]]; then
+            MICROBLOG_BACKGROUND_IMAGE_URL_EXT="png"
+        fi
+        if [[ $$MICROBLOG_BACKGROUND_IMAGE_URL == *".gif" ]]; then
+            MICROBLOG_BACKGROUND_IMAGE_URL_EXT="gif"
+        fi
+        if [ $MICROBLOG_BACKGROUND_IMAGE_URL_EXT ]; then
+            wget $MICROBLOG_BACKGROUND_IMAGE_URL -O img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}
+            if [ ! -f img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT} ]; then
+                echo "$MICROBLOG_BACKGROUND_IMAGE_URL"
+                echo $'Custom background image for microblog could not be downloaded'
+                exit 87524
+            fi
+        fi
+    fi
+
+    microblog_config_file=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs/config.php
+    if ! grep -q "addPlugin('Qvitter')" $microblog_config_file; then
+        MICROBLOG_WELCOME_MESSAGE=$(echo $MICROBLOG_WELCOME_MESSAGE | sed "s|\$MICROBLOG_DOMAIN_NAME|$MICROBLOG_DOMAIN_NAME|g")
+        echo "" >> $microblog_config_file
+        echo "// Qvitter settings" >> $microblog_config_file
+        echo "addPlugin('Qvitter');" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $microblog_config_file
+        if [ $MICROBLOG_BACKGROUND_IMAGE_URL ]; then
+            echo "\$config['site']['qvitter']['sitebackground'] = 'img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}';" >> $microblog_config_file
+        else
+            echo "\$config['site']['qvitter']['sitebackground'] = 'img/vagnsmossen.jpg';" >> $microblog_config_file
+        fi
+        echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['enablewelcometext'] = true;" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['customwelcometext']['en'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['customwelcometext']['de'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['customwelcometext']['fr'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['customwelcometext']['es'] = '$MICROBLOG_WELCOME_MESSAGE';" >> $microblog_config_file
+        echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $microblog_config_file
+    else
+        if [ $MICROBLOG_BACKGROUND_IMAGE_URL_EXT ]; then
+            if [ -f img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT} ]; then
+                sed -i "s|\$config['site']['qvitter']['sitebackground'].*|\$config['site']['qvitter']['sitebackground'] = 'img/custom.${MICROBLOG_BACKGROUND_IMAGE_URL_EXT}';|g" $microblog_config_file
+            fi
+        fi
+    fi
+
+    # customise with project logo
+    if [ -f /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
+        if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
+            cp ~/freedombone/img/gnusocial_sprite.png /var/www/$MICROBLOG_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
+        fi
+    fi
+
+    if ! grep -q "GNU Social theme commit" $COMPLETION_FILE; then
+        echo "GNU Social theme commit:$MICROBLOG_THEME_COMMIT" >> $COMPLETION_FILE
+    fi
+
+    chown -R www-data:www-data /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+
+    echo 'install_gnusocial_theme' >> $COMPLETION_FILE
 }
 
 function install_gnusocial_markdown {
-	MICROBLOG_PATH=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+    MICROBLOG_PATH=/var/www/$MICROBLOG_DOMAIN_NAME/htdocs
 
-	# update to the next commit
-	function_check set_repo_commit
-	set_repo_commit $MICROBLOG_PATH/local/plugins/Markdown "GNU Social Markdown commit" "$MICROBLOG_MARKDOWN_COMMIT" $MICROBLOG_MARKDOWN_REPO
+    # update to the next commit
+    function_check set_repo_commit
+    set_repo_commit $MICROBLOG_PATH/local/plugins/Markdown "GNU Social Markdown commit" "$MICROBLOG_MARKDOWN_COMMIT" $MICROBLOG_MARKDOWN_REPO
 
-	if grep -Fxq "install_gnusocial_markdown" $COMPLETION_FILE; then
-		return
-	fi
+    if grep -Fxq "install_gnusocial_markdown" $COMPLETION_FILE; then
+        return
+    fi
 
-	if [ -d $MICROBLOG_PATH/local/plugins/Markdown ]; then
-		rm -rf $MICROBLOG_PATH/local/plugins/Markdown
-	fi
+    if [ -d $MICROBLOG_PATH/local/plugins/Markdown ]; then
+        rm -rf $MICROBLOG_PATH/local/plugins/Markdown
+    fi
 
-	if [ ! -d $MICROBLOG_PATH/local/plugins ]; then
-		mkdir -p $MICROBLOG_PATH/local/plugins
-	fi
+    if [ ! -d $MICROBLOG_PATH/local/plugins ]; then
+        mkdir -p $MICROBLOG_PATH/local/plugins
+    fi
 
-	cd $MICROBLOG_PATH/local/plugins
-	function_check git_clone
-	git_clone $MICROBLOG_MARKDOWN_REPO Markdown
-	cd $MICROBLOG_PATH/local/plugins/Markdown
-	git checkout $MICROBLOG_MARKDOWN_COMMIT -b $MICROBLOG_MARKDOWN_COMMIT
+    cd $MICROBLOG_PATH/local/plugins
+    function_check git_clone
+    git_clone $MICROBLOG_MARKDOWN_REPO Markdown
+    cd $MICROBLOG_PATH/local/plugins/Markdown
+    git checkout $MICROBLOG_MARKDOWN_COMMIT -b $MICROBLOG_MARKDOWN_COMMIT
 
-	microblog_config_file=$MICROBLOG_PATH/config.php
-	if ! grep -q "addPlugin('Markdown'" $microblog_config_file; then
-		echo "" >> $microblog_config_file
-		echo "// Markdown settings" >> $microblog_config_file
-		echo "addPlugin('Markdown');" >> $microblog_config_file
-	fi
+    microblog_config_file=$MICROBLOG_PATH/config.php
+    if ! grep -q "addPlugin('Markdown'" $microblog_config_file; then
+        echo "" >> $microblog_config_file
+        echo "// Markdown settings" >> $microblog_config_file
+        echo "addPlugin('Markdown');" >> $microblog_config_file
+    fi
 
-	if ! grep -q "GNU Social Markdown commit" $COMPLETION_FILE; then
-		echo "GNU Social Markdown commit:$MICROBLOG_MARKDOWN_COMMIT" >> $COMPLETION_FILE
-	fi
+    if ! grep -q "GNU Social Markdown commit" $COMPLETION_FILE; then
+        echo "GNU Social Markdown commit:$MICROBLOG_MARKDOWN_COMMIT" >> $COMPLETION_FILE
+    fi
 
-	chown -R www-data:www-data $MICROBLOG_PATH
+    chown -R www-data:www-data $MICROBLOG_PATH
 
-	echo 'install_gnusocial_markdown' >> $COMPLETION_FILE
+    echo 'install_gnusocial_markdown' >> $COMPLETION_FILE
 }
 
 function install_gnusocial {
-	if grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
-		return
-	fi
-	install_gnusocial_main
-	expire_gnusocial_posts
-	install_gnusocial_theme
-	install_gnusocial_markdown
-	install_gnusocial_plugin_sharings
-	install_gnusocial_plugin_sharings_theme
-	echo 'install_gnusocial' >> $COMPLETION_FILE
+    if grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
+        return
+    fi
+    install_gnusocial_main
+    expire_gnusocial_posts
+    install_gnusocial_theme
+    install_gnusocial_markdown
+    install_gnusocial_plugin_sharings
+    install_gnusocial_plugin_sharings_theme
+    echo 'install_gnusocial' >> $COMPLETION_FILE
 }
 
 # NOTE: deliberately there is no "exit 0"
diff --git a/src/freedombone-backup-local b/src/freedombone-backup-local
index e084f105701cc09db1d55cb3381f6ae567b15bf4..06b631d12afbd173ca5ab3e6b73c77c63a1e8f36 100755
--- a/src/freedombone-backup-local
+++ b/src/freedombone-backup-local
@@ -97,81 +97,6 @@ function update_domains {
 	fi
 }
 
-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
-}
-
-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_BACKUP_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
@@ -245,6 +170,15 @@ function backup_users {
 				fi
 			fi
 
+			# Backup emacs
+			if [ -d /home/$USERNAME/.emacs.d ]; then
+				echo $"Backing up Emacs config for $USERNAME"
+				if [ -f /home/$USERNAME/.emacs ]; then
+					cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
+				fi
+				backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
+			fi
+
 			# Backup user configs
 			if [ -d /home/$USERNAME/.config ]; then
 				echo $"Backing up config files for $USERNAME"
@@ -369,7 +303,7 @@ function backup_directories {
 		if [[ $required_directory != "none" ]]; then
 			if [ -d $required_directory ]; then
 				if [[ $database_name != "none" ]]; then
-					backup_database $database_name
+					backup_database_local $database_name
 				fi
 			fi
 		fi
diff --git a/src/freedombone-restore-local b/src/freedombone-restore-local
index 972420ea0ef816969c56f705830fddce6cb53635..7a103403bb1961ff4eeeaa9f411771bcf6beebc3 100755
--- a/src/freedombone-restore-local
+++ b/src/freedombone-restore-local
@@ -609,6 +609,34 @@ function restore_user_config {
 	fi
 }
 
+function restore_user_emacs {
+	if [[ $RESTORE_APP != 'all' ]]; then
+		if [[ $RESTORE_APP != 'useremacs' ]]; then
+			return
+		fi
+	fi
+	if [ -d $USB_MOUNT/backup/emacs ]; then
+		for d in $USB_MOUNT/backup/emacs/*/ ; 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 Emacs config for $USERNAME"
+				restore_directory_from_usb /root/tempemacs emacs/$USERNAME
+				cp -r /root/tempemacs/home/$USERNAME/.emacs.d /home/$USERNAME/
+				if [ ! "$?" = "0" ]; then
+					rm -rf /root/tempemacs
+					unmount_drive
+					exit 664
+				fi
+				cp -f /root/tempemacs/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
+				rm -rf /root/tempemacs
+			fi
+		done
+	fi
+}
+
 function gpg_pubkey_from_email {
 	key_owner_username=$1
 	key_email_address=$2
@@ -1264,6 +1292,7 @@ restore_admin_readme
 restore_ipfs
 restore_user_ssh_keys
 restore_user_config
+restore_user_emacs
 restore_user_monkeysphere
 restore_user_fin
 restore_user_local
diff --git a/src/freedombone-utils-backup b/src/freedombone-utils-backup
index a559ab2380f85726029656c199dd3da47a7e9685..4ebb5cd7df78156a6fcefc9fa24974a41c4e839e 100755
--- a/src/freedombone-utils-backup
+++ b/src/freedombone-utils-backup
@@ -28,6 +28,26 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+# whether a given site is being suspended during backup
+SUSPENDED_SITE=
+
+function suspend_site {
+	# suspends a given website
+	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=
+}
+
 function configure_backup_key {
 	if grep -Fxq "configure_backup_key" $COMPLETION_FILE; then
 		return
@@ -162,4 +182,83 @@ function backup_unmount_drive {
 	echo $"Backup to USB drive is complete. You can now unplug it."
 }
 
+function backup_database_local {
+	if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
+		echo $"No MariaDB password was given"
+		function_check restart_site
+		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 6835872
+	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"
+			function_check restart_site
+			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_BACKUP_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
+				function_check restart_site
+				restart_site
+				exit 683252
+			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
+			function_check restart_site
+			restart_site
+			exit 7
+		fi
+		if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
+			shred -zu ${1}/*
+			rm -rf ${1}
+		fi
+	fi
+}
+
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-utils-web b/src/freedombone-utils-web
index 14c90bf2d0f0ab151bf23148feb01b18f05b153e..213eadf0beddb78b03aaac569de2d072b716181d 100755
--- a/src/freedombone-utils-web
+++ b/src/freedombone-utils-web
@@ -53,9 +53,6 @@ MAX_PHP_MEMORY=64
 # logging level for Nginx
 WEBSERVER_LOG_LEVEL='warn'
 
-# whether a given site is being suspended during backup
-SUSPENDED_SITE=
-
 # test a domain name to see if it's valid
 function validate_domain_name {
 	# count the number of dots in the domain name
@@ -551,21 +548,4 @@ function install_command_line_browser {
 	echo 'install_command_line_browser' >> $COMPLETION_FILE
 }
 
-function suspend_site {
-	# suspends a given website
-	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=
-}
-
 # NOTE: deliberately no exit 0