mirror of
https://github.com/YunoHost-Apps/jitsi_ynh.git
synced 2024-09-03 19:35:57 +02:00
195 lines
7.1 KiB
Bash
195 lines
7.1 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
source ../settings/scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
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)
|
|
|
|
focus_user=$(ynh_app_setting_get --app=$app --key=focus_user)
|
|
focus_password=$(ynh_app_setting_get --app=$app --key=focus_password)
|
|
focus_secret=$(ynh_app_setting_get --app=$app --key=focus_secret)
|
|
|
|
videobridge_user=$(ynh_app_setting_get --app=$app --key=videobridge_user)
|
|
videobridge_secret=$(ynh_app_setting_get --app=$app --key=videobridge_secret)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
port_videobridge=$(ynh_app_setting_get --app=$app --key=port_videobridge)
|
|
port_component=$(ynh_app_setting_get --app=$app --key=port_component)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
ynh_script_progression --message="Validating restoration parameters..."
|
|
|
|
test ! -d $final_path \
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
|
|
|
#=================================================
|
|
# STANDARD RESTORATION STEPS
|
|
#=================================================
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
#=================================================
|
|
# RECREATE THE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Recreating the dedicated system user..."
|
|
|
|
# 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..."
|
|
|
|
ynh_restore_file --origin_path="$final_path"
|
|
|
|
chown -R root: $final_path
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORATION
|
|
#=================================================
|
|
# REINSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Reinstalling dependencies..."
|
|
|
|
# Define and install dependencies
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
if ! yunohost app list | grep -q "prosody"
|
|
then
|
|
yunohost tools update
|
|
yunohost app install prosody
|
|
else
|
|
yunohost tools update
|
|
yunohost app upgrade prosody
|
|
fi
|
|
|
|
ynh_app_setting_set --app=$app --key=require_prosody --value="1"
|
|
|
|
#=================================================
|
|
# CONFIGURE FIREWALL
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring firewall..."
|
|
|
|
# Open this port
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp UDP $port_videobridge
|
|
|
|
#=================================================
|
|
# CONFIGURE PROSODY
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring prosody..."
|
|
|
|
ynh_restore_file --origin_path="/etc/prosody/conf.avail/$domain.cfg.lua"
|
|
ln -s "/etc/prosody/conf.avail/$domain.cfg.lua" "/etc/prosody/conf.d/$domain.cfg.lua"
|
|
|
|
ln -sf /var/lib/prosody/$domain.key /etc/prosody/certs/$domain.key
|
|
ln -sf /var/lib/prosody/$domain.crt /etc/prosody/certs/$domain.crt
|
|
|
|
ln -sf "/var/lib/prosody/auth.$domain.key" "/etc/prosody/certs/auth.$domain.key"
|
|
ln -sf "/var/lib/prosody/auth.$domain.crt" "/etc/prosody/certs/auth.$domain.crt"
|
|
ln -sf "/var/lib/prosody/auth.$domain.crt" "/usr/local/share/ca-certificates/auth.$domain.crt"
|
|
|
|
update-ca-certificates -f
|
|
|
|
ynh_systemd_action --service_name="prosody" --action="restart"
|
|
|
|
prosodyctl register "$focus_user" "auth.$domain" "$focus_password"
|
|
|
|
prosodyctl register "$videobridge_user" "auth.$domain" "$videobridge_secret"
|
|
|
|
prosodyctl mod_roster_command subscribe $focus_user.$domain $focus_user@auth.$domain
|
|
|
|
#=================================================
|
|
# RESTORE THE APP CONFIG
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the app config..."
|
|
|
|
ynh_restore_file --origin_path="/etc/$app"
|
|
|
|
#=================================================
|
|
# CREATE LOG DIR
|
|
#=================================================
|
|
ynh_script_progression --message="Creating log dir..."
|
|
|
|
mkdir -p "/var/log/$app"
|
|
chown -R $app: /var/log/$app
|
|
|
|
#=================================================
|
|
# RESTORE SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the systemd configuration..."
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app-videobridge.service"
|
|
systemctl enable $app-videobridge.service
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app-jicofo.service"
|
|
systemctl enable $app-jicofo.service
|
|
|
|
#=================================================
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the logrotate configuration..."
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app-videobridge --log="/var/log/$app/$app-videobridge.log"
|
|
yunohost service add $app-jicofo --log="/var/log/$app/$app-jicofo.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
ynh_systemd_action --service_name=$app-jicofo --action="start" --log_path="/var/log/$app/$app-jicofo.log"
|
|
ynh_systemd_action --service_name=$app-videobridge --action="start" --log_path="/var/log/$app/$app-videobridge.log"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# RELOAD NGINX AND PHP-FPM
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoration completed for $app"
|