1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/peertube_ynh.git synced 2024-09-03 19:56:29 +02:00
peertube_ynh/scripts/restore

160 lines
5.6 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-04-03 03:27:49 +02:00
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_add_extra_apt_repos__3
2018-03-31 12:09:27 +02:00
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2019-04-03 03:21:30 +02:00
ynh_clean_setup () {
ynh_clean_check_starting
}
# 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..."
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)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2019-06-03 22:37:54 +02:00
ynh_print_info --message="Validating restoration parameters..."
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-04-01 00:03:32 +02:00
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
2019-06-03 22:37:54 +02:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2019-06-03 22:37:54 +02:00
ynh_print_info --message="Restoring the app main directory..."
2019-06-03 22:37:54 +02:00
ynh_restore_file --origin_path="$final_path"
2018-04-01 00:03:32 +02:00
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2019-06-03 22:37:54 +02:00
ynh_print_info --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
2019-06-03 22:37:54 +02:00
ynh_system_user_create --username=$app
2018-04-01 00:03:32 +02:00
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Set right permissions
if [ ! -d "/home/yunohost.app/$app" ]; then
mkdir -p "/home/yunohost.app/${app}/storage"
fi
chown -R "$app":"$app" "/home/yunohost.app/${app}/storage"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2019-06-03 22:37:54 +02:00
ynh_print_info --message="Reinstalling dependencies..."
2019-04-03 02:43:43 +02:00
# Install nodejs
2019-10-16 23:12:18 +02:00
ynh_install_nodejs --nodejs_version=10
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
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"
fi
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"
#=================================================
# 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
#=================================================
# RESTORE SYSTEMD
#=================================================
2019-06-03 22:37:54 +02:00
ynh_print_info --message="Restoring the systemd configuration..."
2019-06-03 22:37:54 +02:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service
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"
#=================================================
2019-06-03 22:37:54 +02:00
# START SYSTEMD SERVICE
#=================================================
2019-06-03 22:37:54 +02:00
ynh_print_info --message="Starting a systemd service..."
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-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"