mirror of
https://github.com/YunoHost-Apps/peertube_ynh.git
synced 2024-09-03 19:56:29 +02:00
165 lines
5.1 KiB
Bash
165 lines
5.1 KiB
Bash
#!/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
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
source ynh_add_secure_repos__3
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_print_info "Loading settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
path_url="/"
|
|
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)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
ynh_print_info "Validating restoration parameters..."
|
|
|
|
ynh_webpath_available "$domain" "$path_url" \
|
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
|
test ! -d "$final_path" \
|
|
|| ynh_die "There is already a directory: $final_path "
|
|
|
|
#=================================================
|
|
# STANDARD RESTORATION STEPS
|
|
#=================================================
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
#=================================================
|
|
# RESTORE THE APP MAIN DIR
|
|
#=================================================
|
|
ynh_print_info "Restoring the app main directory..."
|
|
|
|
ynh_restore_file "$final_path"
|
|
|
|
#=================================================
|
|
# RECREATE THE DEDICATED USER
|
|
#=================================================
|
|
ynh_print_info "Recreating the dedicated system user..."
|
|
|
|
# Create the dedicated user (if not existing)
|
|
ynh_system_user_create "$app"
|
|
|
|
#=================================================
|
|
# 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
|
|
#=================================================
|
|
ynh_print_info "Reinstalling dependencies..."
|
|
|
|
# Install nodejs
|
|
ynh_install_nodejs 8
|
|
|
|
# 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
|
|
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
|
|
|
|
# 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"
|
|
|
|
#=================================================
|
|
# RESTORE THE POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_print_info "Restoring the PostgreSQL database..."
|
|
|
|
ynh_psql_test_if_first_run
|
|
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;"
|
|
ynh_psql_execute_file_as_root ./db.sql "$db_name"
|
|
|
|
#=================================================
|
|
# RESTORE SYSTEMD
|
|
#=================================================
|
|
ynh_print_info "Restoring the systemd configuration..."
|
|
|
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
|
systemctl enable "$app.service"
|
|
|
|
#=================================================
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_restore_file "/etc/logrotate.d/$app"
|
|
|
|
#=================================================
|
|
# BUILD YARN DEPENDENCIES
|
|
#=================================================
|
|
|
|
(
|
|
cd "$final_path"
|
|
yarn install --production --pure-lockfile --silent --cache-folder /var/cache/yarn/
|
|
)
|
|
|
|
# Set right permissions
|
|
chown -R "$app":"$app" "$final_path"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# RELOAD NGINX AND PEERTUBE
|
|
#=================================================
|
|
ynh_print_info "Reloading nginx web server and peertube..."
|
|
|
|
systemctl reload nginx
|
|
|
|
#=================================================
|
|
# START SERVICE
|
|
#=================================================
|
|
ynh_print_info "Start service..."
|
|
|
|
systemctl enable "$app"
|
|
systemctl start "$app"
|
|
# App needs time to start
|
|
sleep 30
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_print_info "Restoration completed for $app"
|