1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mumbleserver_ynh.git synced 2024-09-03 19:46:03 +02:00
mumbleserver_ynh/scripts/restore
ericgaspar 63df56b4de
Fix
2021-06-05 11:44:15 +02:00

156 lines
5.3 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
mumbleweb=$(ynh_app_setting_get --app=$app --key=mumbleweb)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
if [ "$mumbleweb" -eq 1 ] ; then
ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
fi
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
if [ "$mumbleweb" -eq 1 ] ; then
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
fi
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username="$app" --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=2
ynh_restore_file --origin_path="$final_path"
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=4
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
if [ "$mumbleweb" -eq 1 ] ; then
ynh_install_nodejs --nodejs_version=$nodejs_version
fi
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chmod -R 770 "$final_path"
chown -R :mumble-server "$final_path"
#=================================================
# ADD USER TO SSL-CERT
#=================================================
# Add user to ssl-cert so it can read certificates
usermod --append --groups ssl-cert mumble-server
#=================================================
# DISABLE DEFAULT SERVER
#=================================================
# Disable default server installed by Debian's package
systemctl stop mumble-server
systemctl disable mumble-server --quiet
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
# Add Mumble as a YunoHost service
yunohost service add $app --description="Mumble server" --log="/var/log/$app/$app.log" --needs_exposed_ports=$port
# Add Mumble as a YunoHost service
if [ "$mumbleweb" -eq 1 ] ; then
yunohost service add mumble-web --description="Mumble web interface" --log="/var/log/$app/mumble-web.log"
fi
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable "$app.service" --quiet
if [ "$mumbleweb" -eq 1 ] ; then
ynh_restore_file --origin_path="/etc/systemd/system/mumble-web.service"
systemctl enable "mumble-web.service" --quiet
fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
if [ "$mumbleweb" -eq 1 ] ; then
ynh_systemd_action --service_name="mumble-web" --action="start" --log_path="/var/log/$app/mumble-web.log"
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
if [ "$mumbleweb" -eq 1 ] ; then
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last