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
|
2018-03-31 12:09:27 +02:00
|
|
|
cp ../settings/scripts/psql.sh ./psql.sh
|
2018-05-08 00:42:53 +02:00
|
|
|
chmod a+rx _common.sh psql.sh
|
2018-03-27 19:32:35 +02:00
|
|
|
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
|
2018-03-27 19:32:35 +02:00
|
|
|
source psql.sh
|
2018-05-08 00:42:53 +02:00
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file "$final_path"
|
2018-04-01 00:03:32 +02:00
|
|
|
|
|
|
|
datadir="/home/yunohost.app/${app}/storage"
|
|
|
|
ynh_restore_file "$datadir"
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2018-04-03 09:12:16 +02:00
|
|
|
# Open this port
|
|
|
|
yunohost firewall allow Both "$port" 2>&1
|
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# 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-05-08 01:20:41 +02:00
|
|
|
# Set right permissions
|
2018-03-27 19:32:35 +02:00
|
|
|
datadir="/home/yunohost.app/${app}/storage"
|
2018-05-21 10:24:05 +02:00
|
|
|
chown -R "$app":"$app" "$datadir"
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# install yarn
|
2018-04-04 08:00:27 +02:00
|
|
|
|
|
|
|
# install nodejs
|
|
|
|
ynh_install_nodejs 8
|
|
|
|
|
2018-05-21 11:51:50 +02:00
|
|
|
wget https://github.com/yarnpkg/yarn/releases/download/v1.6.0/yarn_1.6.0_all.deb
|
|
|
|
echo "96866d835da94a1f01a616f3d637c9100e826f65cb38a65e5d96ccf01ff6d692 yarn_1.6.0_all.deb" | sha256sum -c || ynh_die
|
|
|
|
dpkg -i yarn_1.6.0_all.deb
|
2018-03-27 19:32:35 +02:00
|
|
|
|
|
|
|
# add backports (required to install ffmpeg)
|
2018-03-29 23:53:32 +02:00
|
|
|
echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list
|
2018-03-27 19:32:35 +02:00
|
|
|
ynh_package_update
|
|
|
|
|
|
|
|
# Define and install dependencies
|
2018-05-21 10:55:32 +02:00
|
|
|
ynh_install_app_dependencies postgresql ffmpeg redis-server redis-tools mailutils
|
2018-03-27 19:32:35 +02:00
|
|
|
|
2018-03-31 12:09:27 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE PostgreSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
ynh_psql_setup_db "$app" "$db_name" "$db_pwd"
|
|
|
|
ynh_psql_execute_file_as_root ./db.sql "$db_name"
|
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
#=================================================
|
2018-04-01 00:03:32 +02:00
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
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"
|
|
|
|
yarn install --production --pure-lockfile --cache-folder /var/cache/yarn/
|
|
|
|
)
|
2018-04-01 00:03:32 +02:00
|
|
|
|
2018-05-08 01:20:41 +02:00
|
|
|
# Set right permissions for curl install
|
2018-05-21 10:24:05 +02:00
|
|
|
chown -R "$app":"$app" "$datadir"
|
2018-05-08 01:20:41 +02:00
|
|
|
|
2018-04-01 00:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX AND PeerTube
|
|
|
|
#=================================================
|
|
|
|
|
2018-03-27 19:32:35 +02:00
|
|
|
systemctl reload nginx
|
2018-03-29 23:53:32 +02:00
|
|
|
service "$app" restart
|