mirror of
https://github.com/YunoHost-Apps/peertube_ynh.git
synced 2024-09-03 19:56:29 +02:00
133 lines
3.9 KiB
Text
133 lines
3.9 KiB
Text
|
#!/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
|
||
|
chmod a+rx _common.sh
|
||
|
fi
|
||
|
source _common.sh
|
||
|
source psql.sh
|
||
|
source ../settings/scripts/psql.sh
|
||
|
source ../settings/scripts/nodejs.sh
|
||
|
source nodejs.sh
|
||
|
source /usr/share/yunohost/helpers
|
||
|
|
||
|
#=================================================
|
||
|
# 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
|
||
|
|
||
|
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_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 "
|
||
|
|
||
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||
|
|
||
|
#=================================================
|
||
|
# FIND AND OPEN A PORT
|
||
|
#=================================================
|
||
|
|
||
|
# Find a free port
|
||
|
ynh_find_port $port
|
||
|
# Open this port
|
||
|
yunohost firewall allow Both $port 2>&1
|
||
|
ynh_app_setting_set $app port $port
|
||
|
|
||
|
|
||
|
#=================================================
|
||
|
# RESTORE THE APP MAIN DIR
|
||
|
#=================================================
|
||
|
|
||
|
ynh_restore_file "$final_path"
|
||
|
ynh_restore_file "/home/yunohost.app/${app}"
|
||
|
|
||
|
#=================================================
|
||
|
# RECREATE THE DEDICATED USER
|
||
|
#=================================================
|
||
|
|
||
|
# Create the dedicated user (if not existing)
|
||
|
ynh_system_user_create $app
|
||
|
|
||
|
|
||
|
# Set right permissions for curl install
|
||
|
datadir="/home/yunohost.app/${app}/storage"
|
||
|
chown -R $app:$app "$final_path" "$datadir"
|
||
|
|
||
|
#=================================================
|
||
|
# 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"
|
||
|
|
||
|
|
||
|
|
||
|
#=================================================
|
||
|
# SPECIFIC RESTORATION
|
||
|
#=================================================
|
||
|
# REINSTALL DEPENDENCIES
|
||
|
#=================================================
|
||
|
|
||
|
# install yarn
|
||
|
wget https://github.com/yarnpkg/yarn/releases/download/v1.5.1/yarn_1.5.1_all.deb
|
||
|
echo "a4770cd8dcb13dc9a9218940dbd24b510ddf5eec78adb4e0da9ef3760b55a76e yarn_1.5.1_all.deb" | sha256sum -c || ynh_die
|
||
|
sudo dpkg -i yarn_1.5.1_all.deb
|
||
|
|
||
|
# add backports (required to install ffmpeg)
|
||
|
echo "deb http://httpredir.debian.org/debian jessie-backports main" | sudo tee /etc/apt/sources.list.d/jessie-backports.list
|
||
|
ynh_package_update
|
||
|
|
||
|
# Define and install dependencies
|
||
|
ynh_install_app_dependencies postgresql-9.4 ffmpeg redis-server redis-tools
|
||
|
|
||
|
# install nodejs
|
||
|
ynh_install_nodejs 8
|
||
|
|
||
|
#=================================================
|
||
|
# RESTORE SYSTEMD
|
||
|
#=================================================
|
||
|
|
||
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
||
|
systemctl enable $app.service
|
||
|
|
||
|
#=================================================
|
||
|
# RESTORE THE LOGROTATE CONFIGURATION
|
||
|
#=================================================
|
||
|
|
||
|
ynh_restore_file "/etc/logrotate.d/$app"
|
||
|
|
||
|
#=================================================
|
||
|
# GENERIC FINALIZATION
|
||
|
#=================================================
|
||
|
(cd $final_path && yarn install --production --pure-lockfile)
|
||
|
systemctl reload nginx
|
||
|
service $app restart
|