2018-03-27 19:32:35 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ ! -e _common.sh ]; then
|
|
|
|
# Get the _common.sh file if it's not in the current directory
|
|
|
|
cp ../settings/scripts/_common.sh ./_common.sh
|
|
|
|
fi
|
2018-03-31 12:09:27 +02:00
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
source _common.sh
|
2018-03-31 12:09:27 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2019-04-03 02:43:43 +02:00
|
|
|
source ynh_add_secure_repos__3
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-04-03 01:12:03 +02:00
|
|
|
ynh_print_info "Loading settings..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2018-03-29 23:53:32 +02:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
2018-03-27 19:32:35 +02:00
|
|
|
path_url="/"
|
2018-03-29 23:53:32 +02:00
|
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
|
|
port=$(ynh_app_setting_get "$app" port)
|
|
|
|
db_name=$(ynh_app_setting_get "$app" psql_db)
|
|
|
|
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2019-04-03 01:12:03 +02:00
|
|
|
ynh_print_info "Validating restoration parameters..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_webpath_available "$domain" "$path_url" \
|
2018-03-27 19:32:35 +02:00
|
|
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
2018-03-29 23:53:32 +02:00
|
|
|
test ! -d "$final_path" \
|
2018-03-27 19:32:35 +02:00
|
|
|
|| ynh_die "There is already a directory: $final_path "
|
|
|
|
|
|
|
|
#=================================================
|
2018-04-01 00:03:32 +02:00
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-04-01 00:03:32 +02:00
|
|
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
2019-04-03 01:12:03 +02:00
|
|
|
ynh_print_info "Restoring the app main directory..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
ynh_restore_file "$final_path"
|
2018-04-01 00:03:32 +02:00
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2019-04-03 01:12:03 +02:00
|
|
|
ynh_print_info "Recreating the dedicated system user..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_system_user_create "$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-04-03 01:12:03 +02:00
|
|
|
ynh_print_info "Reinstalling dependencies..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install nodejs
|
2018-04-04 08:00:27 +02:00
|
|
|
ynh_install_nodejs 8
|
|
|
|
|
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
|
|
|
|
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-04-03 01:12:03 +02:00
|
|
|
ynh_print_info "Restoring the PostgreSQL database..."
|
2018-03-31 12:09:27 +02:00
|
|
|
|
|
|
|
ynh_psql_test_if_first_run
|
2018-06-01 19:00:13 +02:00
|
|
|
ynh_psql_create_user "$app" "$db_pwd"
|
|
|
|
ynh_psql_execute_as_root \
|
|
|
|
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
|
2018-03-31 12:09:27 +02:00
|
|
|
ynh_psql_execute_file_as_root ./db.sql "$db_name"
|
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
2019-04-03 01:12:03 +02:00
|
|
|
ynh_print_info "Restoring the systemd configuration..."
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
2018-03-29 23:53:32 +02:00
|
|
|
systemctl enable "$app.service"
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file "/etc/logrotate.d/$app"
|
|
|
|
|
|
|
|
#=================================================
|
2019-04-03 02:23:06 +02:00
|
|
|
# BUILD YARN DEPENDENCIES
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
2018-03-31 12:09:27 +02:00
|
|
|
|
2018-05-21 12:10:41 +02:00
|
|
|
(
|
|
|
|
cd "$final_path"
|
2018-05-21 13:44:19 +02:00
|
|
|
yarn install --production --pure-lockfile --silent --cache-folder /var/cache/yarn/
|
2018-05-21 12:10:41 +02:00
|
|
|
)
|
2018-04-01 00:03:32 +02:00
|
|
|
|
2018-07-29 17:44:16 +02:00
|
|
|
# Set right permissions
|
|
|
|
chown -R "$app":"$app" "$final_path"
|
2018-05-08 01:20:41 +02:00
|
|
|
|
2018-04-01 00:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2019-04-03 01:12:03 +02:00
|
|
|
# RELOAD NGINX AND PEERTUBE
|
2018-04-01 00:03:32 +02:00
|
|
|
#=================================================
|
2019-04-03 01:12:03 +02:00
|
|
|
ynh_print_info "Reloading nginx web server and peertube..."
|
2018-04-01 00:03:32 +02:00
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
systemctl reload nginx
|
2019-04-03 02:23:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Start service..."
|
|
|
|
|
2018-05-31 00:33:14 +02:00
|
|
|
systemctl enable "$app"
|
|
|
|
systemctl start "$app"
|
|
|
|
# App needs time to start
|
2018-06-01 16:19:54 +02:00
|
|
|
sleep 30
|
2019-04-03 01:12:03 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_print_info "Restoration completed for $app"
|