2016-10-25 23:34:42 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2017-10-14 15:59:58 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
true
|
|
|
|
}
|
2017-10-14 15:59:58 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=2
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
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 "
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=6
|
2017-10-14 15:59:58 +02:00
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# SPECIFIC RESTORE
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# INSTALL NODEJS
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
# RESTORE SYSTEMD
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --weight=2
|
2017-10-14 15:59:58 +02:00
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
|
|
|
systemctl enable $app.service
|
2017-10-14 15:59:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
# RESTORE VARIOUS FILES
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_restore_file "/home/yunohost.app/$app"
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2020-09-06 18:03:25 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE BINARY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/usr/bin/$app"
|
|
|
|
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# SECURE FILES AND DIRECTORIES
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
chown -R root: $final_path
|
2020-09-06 18:03:25 +02:00
|
|
|
chown -R $app: "$final_path/static"
|
|
|
|
chown -R $app: "/home/yunohost.app/$app"
|
|
|
|
chmod +x /usr/bin/$app
|
2017-11-29 15:42:21 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2017-11-29 15:42:21 +01:00
|
|
|
#=================================================
|
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
yunohost service add $app --description "Haste is an open-source pastebin software" --log "/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2020-07-25 23:14:14 +02:00
|
|
|
# RELOAD NGINX AND PHP-FPM
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
2017-10-14 15:59:58 +02:00
|
|
|
#=================================================
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2020-07-25 23:14:14 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|