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/upgrade
ericgaspar a29a3e37ff Fix
2021-06-06 14:33:28 +02:00

285 lines
9.7 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# 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)
no_sso=$(ynh_app_setting_get --app=$app --key=no_sso)
server_password=$(ynh_app_setting_get --app=$app --key=server_password)
su_passwd=$(ynh_app_setting_get --app=$app --key=su_passwd)
welcometext=$(ynh_app_setting_get --app=$app --key=welcometext)
registername=$(ynh_app_setting_get --app=$app --key=registerName)
port=$(ynh_app_setting_get --app=$app --key=port)
port_web=$(ynh_app_setting_get --app=$app --key=port_web)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
instance_id=$(ynh_app_setting_get --app=$app --key=instance_id)
mumbleweb=$(ynh_app_setting_get --app=$app --key=mumbleweb)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set "$app" final_path "$final_path"
fi
# test old time
if [ -z "$server_password" ]; then
old_mumble_conf="/etc/mumble-server.ini"
server_password=$(cat "$old_mumble_conf" \
| grep "serverpassword=" \
| sed "s/serverpassword=//")
welcometext=$(cat "$old_mumble_conf" \
| grep "welcometext=" \
| sed "s/welcometext=//")
registername=$(cat "$old_mumble_conf" \
| grep "registerName=" \
| sed "s/registername=//")
# we don't know what the previous password was, let's regenerate it
su_passwd=$(ynh_string_random)
domain=$(yunohost domain list \
| grep "\- " \
| head -1 \
| sed -r "s/.* (([a-z])*\.([a-z])*).*/\1/g")
ynh_app_setting_set --app=$app --key=server_password --value=$server_password
ynh_app_setting_set --app=$app --key=welcometext --value=$welcometext
ynh_app_setting_set --app=$app --key=registerName --value=$registername
ynh_app_setting_set --app=$app --key=su_passwd --value=$su_passwd
ynh_app_setting_set --app=$app --key=domain --value=$domain
systemctl stop mumble-server
dpkg-reconfigure mumble-server --frontend=Noninteractive
systemctl stop mumble-server
systemctl disable mumble-server --quiet
fi
# Fix SSO issue
# https://github.com/YunoHost-Apps/mumbleserver_ynh/issues/19
if [ -z "$domain" ]; then
domain=$(ynh_app_setting_get "$app" domain_mumble)
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_delete "$app" domain_mumble
fi
# Fix SSO issue
# https://github.com/YunoHost-Apps/mumbleserver_ynh/issues/19
if [ -z "$no_sso" ]; then
ynh_app_setting_set "$app" no_sso "true"
fi
# Fix multi installation
if [ -z "$instance_id" ]; then
instance_id=$YNH_APP_INSTANCE_NUMBER
ynh_app_setting_set "$app" instance_id "$instance_id"
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="stop"
if [ "$mumbleweb" -eq 1 ] ; then
ynh_systemd_action --service_name="mumble-web" --action="stop"
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
if [ "$mumbleweb" -eq 1 ] ; then
# Create a dedicated user (if not existing)
ynh_system_user_create --username="$app" --home_dir="$final_path"
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$mumbleweb" -eq 1 ] ; then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" #--keep="$final_path/mumble-server.ini"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=5
# Create a dedicated nginx config
if [ "$mumbleweb" -eq 1 ] ; then
ynh_add_nginx_config
fi
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=1
# Install Mumble Debian package via apt
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
if [ "$mumbleweb" -eq 1 ] ; then
ynh_install_nodejs --nodejs_version=$nodejs_version
fi
#=================================================
# SPECIFIC UPGRADE
#=================================================
# mumble server conf.ini
#=================================================
#mkdir -p $final_path
ynh_add_config --template="../conf/mumble-server.ini" --destination="$final_path/mumble-server.ini"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
# Create a dedicated systemd config
ynh_add_systemd_config
if [ "$mumbleweb" -eq 1 ] ; then
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/mumble-web.service"
ynh_add_systemd_config --service=mumble-web --template=mumble-web.service
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
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
#=================================================
# Set SuperUser password
#=================================================
# || true temporarily to ignore a bug in murmurd 1.3.0
# https://github.com/mumble-voip/mumble/issues/3911
murmurd -ini "../conf/mumble-server.ini" -supw "$su_passwd" "$instance_id" || true
#=================================================
# Disable default server installed by Debian's package
#=================================================
systemctl stop mumble-server
systemctl disable mumble-server --quiet
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
# 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
#=================================================
# 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
#=================================================
# RELOAD NGINX
#=================================================
if [ "$mumbleweb" -eq 1 ] ; then
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
ynh_systemd_action --service_name=nginx --action=reload
fi
#=================================================
# SEND README TO ADMIN
#=================================================
message="
Mumble server was updated!
Port : $port
Password to join server: $server_password
SuperUser Password : $su_passwd
Welcome text : $welcometext
Root channel (your Mumble server name): $registername
Final path (where to find your files) : $final_path
Mumble configuration file : $final_path/mumble-server.ini
Note about config file: this package will regenerate the config file on upgrade.
If you changed it manually and upgrade mumble, you'll find a backup in $final_path.
Are you facing an issue, want to improve this app or say thank you?
Please open a new issue in this project: https://github.com/YunoHost-Apps/mumbleserver_ynh
"
ynh_send_readme_to_admin "$message"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last