2017-07-23 17:46:25 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-05-04 11:52:10 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
|
|
source ../settings/scripts/_common.sh
|
2017-07-23 17:46:25 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2018-05-04 11:52:10 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
2017-12-29 00:57:38 +01:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
|
|
|
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
2017-07-30 21:33:54 +02:00
|
|
|
test ! -d $final_path \
|
2020-07-18 11:46:45 +02:00
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
2017-07-30 21:33:54 +02:00
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
# STANDARD RESTORATION STEPS
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2017-07-30 21:33:54 +02:00
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
# RESTORE THE APP MAIN DIR
|
2017-07-30 21:33:54 +02:00
|
|
|
#=================================================
|
2020-10-13 13:52:56 +02:00
|
|
|
ynh_script_progression --message="Restoring CryptPad main directory..." --weight=6
|
2017-07-30 21:33:54 +02:00
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2017-07-30 21:33:54 +02:00
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
2018-05-04 11:52:10 +02:00
|
|
|
# RECREATE THE DEDICATED USER
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
# Create the dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
# RESTORE USER RIGHTS
|
2018-05-04 11:52:10 +02:00
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
|
|
|
|
# Restore permissions on app files
|
|
|
|
chown -R $app:$app $final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=7
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
# Install Nodejs
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2018-05-04 11:52:10 +02:00
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
# Install Yarn
|
|
|
|
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
# RESTORE SYSTEMD
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
2020-12-04 11:33:12 +01:00
|
|
|
systemctl enable $app.service --quiet
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
2020-12-04 11:33:12 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2018-05-04 11:52:10 +02:00
|
|
|
|
2020-12-04 11:33:12 +01:00
|
|
|
yunohost service add $app --description="Zero Knowledge realtime collaborative editor" --log="/var/log/$app/$app.log"
|
2017-07-23 17:46:25 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
# START SYSTEMD SERVICE
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2018-05-04 11:52:10 +02:00
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="server available"
|
2018-05-04 11:52:10 +02:00
|
|
|
|
2020-07-18 11:46:45 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-10-13 13:52:56 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2020-07-18 11:46:45 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-07-23 17:46:25 +02:00
|
|
|
|
2020-10-13 13:52:56 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for CryptPad" --last
|