2017-07-23 17:46:25 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ ! -e _common.sh ]; then
|
|
|
|
# Fetch helpers file if not in current directory
|
|
|
|
sudo cp ../settings/scripts/_common.sh ./_common.sh
|
|
|
|
sudo chmod a+rx _common.sh
|
|
|
|
fi
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-30 21:33:54 +02:00
|
|
|
yunohost app checkurl "${domain}${path_url}" -a "$app" \
|
|
|
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die "There is already a directory: $final_path "
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
CHECK_FINALPATH # Check if destination directory is not already in use
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORE STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo cp -a ./nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
2017-07-30 21:33:54 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo cp -a ./logrotate /etc/logrotate.d/$app
|
|
|
|
|
2017-07-23 17:46:25 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE APP MAIN DIR
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo cp -a ./sources/. $final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RECREATE OF THE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app # Recreate the dedicated user, if not existing
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo chown -R $app: $final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL NODEJS
|
|
|
|
#=================================================
|
|
|
|
ynh_install_nodejs $NODEJS_VERSION
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
sudo cp -a ./systemd.service "/etc/systemd/system/$app.service"
|
|
|
|
sudo systemctl enable $app
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl start $app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo systemctl reload nginx
|