2018-03-27 19:32:35 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2019-04-03 03:27:49 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2019-05-22 17:49:24 +02:00
|
|
|
source ../settings/scripts/ynh_add_extra_apt_repos__3
|
2018-03-31 12:09:27 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2019-04-03 03:21:30 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2018-03-27 19:32:35 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Loading settings..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2019-06-03 22:37:54 +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)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=psql_db)
|
|
|
|
db_user=$app
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Validating restoration parameters..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
|
|
|
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-04-01 00:03:32 +02:00
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Restoring the app main directory..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2018-04-01 00:03:32 +02:00
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Recreating the dedicated system user..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2018-04-01 00:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2018-06-14 16:11:29 +02:00
|
|
|
# Set right permissions
|
2018-11-21 21:22:42 +01:00
|
|
|
if [ ! -d "/home/yunohost.app/$app" ]; then
|
|
|
|
mkdir -p "/home/yunohost.app/${app}/storage"
|
|
|
|
fi
|
2018-06-27 09:55:37 +02:00
|
|
|
chown -R "$app":"$app" "/home/yunohost.app/${app}/storage"
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Reinstalling dependencies..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install nodejs
|
2019-10-11 23:20:15 +02:00
|
|
|
ynh_install_nodejs --nodejs_version=10
|
2018-04-04 08:00:27 +02:00
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install dependencies
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
# Install ffmpeg from backports for Debian Jessie and from main for others
|
2018-05-31 00:33:14 +02:00
|
|
|
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
|
2019-04-03 02:43:43 +02:00
|
|
|
ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg"
|
|
|
|
else
|
|
|
|
ynh_add_app_dependencies --package="ffmpeg"
|
2018-05-31 00:33:14 +02:00
|
|
|
fi
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-04-03 02:43:43 +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"
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-06-06 23:16:31 +02:00
|
|
|
#=================================================
|
|
|
|
# FIX NGINX DOMAIN CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_replace_string --match_string="X-Frame-Options : SAMEORIGIN" --replace_string="X-Frame-Options : ALLOWALL" --target_file="/etc/nginx/conf.d/$domain.conf"
|
|
|
|
|
2018-03-31 12:09:27 +02:00
|
|
|
#=================================================
|
2019-04-03 01:12:03 +02:00
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
2018-03-31 12:09:27 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Restoring the PostgreSQL database..."
|
2018-03-31 12:09:27 +02:00
|
|
|
|
|
|
|
ynh_psql_test_if_first_run
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
|
|
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
|
2018-03-31 12:09:27 +02:00
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Restoring the systemd configuration..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
|
|
|
systemctl enable $app.service
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-04-03 03:06:16 +02:00
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log"
|
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
# START SYSTEMD SERVICE
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Starting a systemd service..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2018-04-01 00:03:32 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
2018-04-01 00:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
2019-04-03 02:23:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
2019-04-03 02:23:06 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Reloading nginx web server..."
|
2019-04-03 02:23:06 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-04-03 01:12:03 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_print_info --message="Restoration completed for $app"
|