#!/bin/bash source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers # reinstall couchdb ynh_script_progression "Reinstalling couchdb..." flohmarkt_ynh_up_inst_couchdb # add couchdb configuration if ! [[ -e /opt/couchdb/etc/local.d/05-flohmarkt.ini ]]; then ynh_script_progression "Adding $app's configuration..." flohmarkt_ynh_stop_couchdb ynh_restore "/opt/couchdb/etc/local.d/05-flohmarkt.ini" chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini ynh_script_progression "Starting couchdb..." flohmarkt_ynh_start_couchdb else ynh_script_progression "CouchDB configuration file already exists." fi # if exists rename existing couchdb ynh_script_progression "Check if old database exists..." if flohmarkt_ynh_exists_couchdb_db; then flohmarkt_ynh_backup_old_couchdb fi # restore couchdb from json ynh_script_progression "Importing couchdb from json backup..." flohmarkt_ynh_restore_couchdb # RESTORE THE APP MAIN DIR ynh_script_progression "Restoring the app main directory..." ynh_restore "$flohmarkt_install" # RESTORE THE DATA DIRECTORY ynh_script_progression "Restoring the data directory..." ynh_restore "$flohmarkt_data_dir" || true mkdir -p $data_dir # restore logfiles # independent of the question whether one wants the logfiles in a backup (as you can # see I decided I wanted them for the time being) it is important to create the log # directory and file so that the systemd.service can redirect STDOUT to the file. # If the logfile(or maybe just -directory?) is missing the service will not start # on a fresh install, because directory and/or file do not exist. ynh_script_progression "Restoring log directory and logfiles..." ynh_restore "$flohmarkt_log_dir" || true mkdir -p -m755 "$flohmarkt_log_dir" touch "$flohmarkt_logfile" # logfile contains possibly the secret setup URL chmod 640 "$flohmarkt_logfile" # RESTORE FAIL2BAN CONFIGURATION ynh_script_progression "Restoring the Fail2Ban configuration..." ynh_restore "/etc/fail2ban/jail.d/$app.conf" ynh_restore "/etc/fail2ban/filter.d/$app.conf" ynh_systemctl --action=restart --service=fail2ban # RESTORE THE NGINX CONFIGURATION ynh_script_progression "Restoring the NGINX web server configuration..." ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" # RESTORE THE LOGROTATE CONFIGURATION ynh_script_progression "Restoring the logrotate configuration..." ynh_restore "/etc/logrotate.d/$app" # restore flohmarkt systemd service and integrate service into yunohost ynh_script_progression "Restoring flohmarkt.service and integrating service into YunoHost..." ynh_restore "/etc/systemd/system/$flohmarkt_filename.service" ynh_systemctl --action=enable --service=$flohmarkt_filename yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile" flohmarkt_ynh_start_service # RELOAD NGINX ynh_script_progression "Reloading NGINX web server..." ynh_systemctl --service=nginx --action=reload # create symlinks ynh_script_progression "Creating symlinks..." flohmarkt_ynh_create_symlinks # restore cronjob file for urlwatch ynh_script_progression "Restoring cronjob for urlwatch..." ynh_restore "${flohmarkt_cron_job}" ynh_script_progression "Restoration completed for $app"