diff --git a/scripts/restore b/scripts/restore index 26451b8..1b22c25 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,20 +1,26 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu - +#================================================= +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= if [ ! -e _common.sh ]; then - # Fetch helpers file if not in current directory - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh + # Get the _common.sh file if it's not in the current directory + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh fi source _common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # LOAD SETTINGS #================================================= @@ -30,62 +36,69 @@ final_path=$(ynh_app_setting_get $app final_path) # CHECK IF THE APP CAN BE RESTORED #================================================= -yunohost app checkurl "${domain}${path_url}" -a "$app" \ +ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die "There is already a directory: $final_path " -CHECK_FINALPATH # Check if destination directory is not already in use - #================================================= -# STANDARD RESTORE STEPS +# STANDARD RESTORATION STEPS #================================================= -# RESTORE NGINX CONFIGURATION +# RESTORE THE NGINX CONFIGURATION #================================================= -sudo cp -a ./nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# RESTORE LOGROTATE CONFIGURATION +# INSTALL NODEJS #================================================= -sudo cp -a ./logrotate /etc/logrotate.d/$app +ynh_install_nodejs $nodejs_version #================================================= -# RESTORE APP MAIN DIR +# RESTORE THE APP MAIN DIR #================================================= -sudo cp -a ./sources/. $final_path +ynh_restore_file "$final_path" #================================================= -# RECREATE OF THE DEDICATED USER +# RECREATE THE DEDICATED USER #================================================= -ynh_system_user_create $app # Recreate the dedicated user, if not existing +# Create the dedicated user (if not existing) +ynh_system_user_create $app #================================================= # RESTORE USER RIGHTS #================================================= -sudo chown -R $app: $final_path +# Restore permissions on app files +chown -R $app:$app $final_path #================================================= -# INSTALL NODEJS +# ADVERTISE SERVICE IN ADMIN PANEL #================================================= -ynh_install_nodejs $NODEJS_VERSION + +yunohost service add $app --log "/var/log/$app/APP.log" #================================================= -# RESTORE SYSTEMD CONFIGURATION +# RESTORE SYSTEMD #================================================= -sudo cp -a ./systemd.service "/etc/systemd/system/$app.service" -sudo systemctl enable $app -sudo systemctl daemon-reload -sudo systemctl start $app - + +ynh_restore_file "/etc/systemd/system/$app.service" +systemctl enable $app.service + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file "/etc/logrotate.d/$app" + #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM #================================================= -sudo systemctl reload nginx +systemctl reload php5-fpm +systemctl reload nginx