From e2a9c9f196577a8a260b63ac984184801055c7e2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sat, 7 Apr 2018 15:32:27 +0200 Subject: [PATCH] Add upgrade process --- check_process | 6 +- manifest.json | 4 +- scripts/install | 12 ++-- scripts/upgrade | 163 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 172 insertions(+), 13 deletions(-) diff --git a/check_process b/check_process index ed6a303..f1c9e87 100644 --- a/check_process +++ b/check_process @@ -13,12 +13,14 @@ setup_nourl=1 setup_private=0 setup_public=0 - upgrade=0 + upgrade=1 + # latest published in community.json + upgrade=1 from_commit=c3f4863564b17be1cb8193f6962668bcc0d92072 backup_restore=0 multi_instance=1 wrong_user=0 wrong_path=0 - incorrect_path=1 + incorrect_path=0 port_already_use=0 ;;; Levels Level 1=auto diff --git a/manifest.json b/manifest.json index 5928468..e075202 100644 --- a/manifest.json +++ b/manifest.json @@ -13,9 +13,9 @@ "email": "moul@moul.re" }, "requirements": { - "yunohost": ">> 2.7.0" + "yunohost": ">= 2.7.10" }, - "version": "1.2.8-1", + "version": "1.2.8-2", "multi_instance": true, "services": [ ], diff --git a/scripts/install b/scripts/install index 890bc6b..15c25b0 100644 --- a/scripts/install +++ b/scripts/install @@ -70,7 +70,7 @@ yunohost firewall allow Both "$port" #================================================= # Install Mumble Debian package via apt -ynh_install_app_dependencies mumble-server +ynh_install_app_dependencies mumble-server mailutils #================================================= # SPECIFIC SETUP @@ -94,6 +94,8 @@ ynh_replace_string "__SRV_PWD__" "$server_password" "$mumble_conf" ynh_replace_string "__REGISTER__" "$registerName" "$mumble_conf" ynh_replace_string "__DOMAIN__" "$domain" "$mumble_conf" +ynh_store_file_checksum "$mumble_conf" + #================================================= # SETUP SYSTEMD #================================================= @@ -101,12 +103,6 @@ ynh_replace_string "__DOMAIN__" "$domain" "$mumble_conf" # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# STORE THE CHECKSUM OF THE CONFIG FILE -#================================================= - -ynh_store_file_checksum "$mumble_conf" - #================================================= # Start services #================================================= @@ -129,7 +125,7 @@ mumble configuration file : $mumble_conf 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 " -send_readme_to_admin "$message" +ynh_send_readme_to_admin "$message" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 27b6b28..c349cd5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,6 +8,167 @@ source _common.sh source /usr/share/yunohost/helpers +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get "$app" domain) +server_password=$(ynh_app_setting_get "$app" server_password) +su_passwd=$(ynh_app_setting_get "$app" su_passwd) +welcometext=$(ynh_app_setting_get "$app" welcometext) +registerName=$(ynh_app_setting_get "$app" registerName) +port=$(ynh_app_setting_get "$app" port) +final_path=$(ynh_app_setting_get "$app" final_path) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +# 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=//") + + ynh_app_setting_set "$app" server_password "$server_password" + ynh_app_setting_set "$app" welcometext "$welcometext" + ynh_app_setting_set "$app" registerName "$registerName" + + systemctl stop mumble-server + dpkg-reconfigure mumble-server --frontend=Noninteractiv + systemctl stop mumble-server + systemctl disable mumble-server +fi + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# 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 -ynh_die "There is no upgrade yet" +#================================================= +# STANDARD UPGRADE STEPS +#================================================= + +# source and user are provided by debian's package, no web interface + +#================================================= +# INSTALL DEPENDENCIES +#================================================= + +# Install Mumble Debian package via apt +ynh_install_app_dependencies mumble-server mailutils + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# mumble server conf.ini +#================================================= + +mkdir -p $final_path + +# Configuring with given settings +mumble_conf="$final_path/mumble-server.ini" + +cp ../conf/mumble-server.ini "$mumble_conf" + +ynh_replace_string "__FINALPATH__" "$final_path" "$mumble_conf" +ynh_replace_string "__APP__" "$app" "$mumble_conf" +ynh_replace_string "__WELCOME__" "$welcometext" "$mumble_conf" +ynh_replace_string "__PORT__" "$port" "$mumble_conf" +ynh_replace_string "__SRV_PWD__" "$server_password" "$mumble_conf" +ynh_replace_string "__REGISTER__" "$registerName" "$mumble_conf" +ynh_replace_string "__DOMAIN__" "$domain" "$mumble_conf" + +ynh_store_file_checksum "$mumble_conf" + +#================================================= +# SETUP SYSTEMD +#================================================= + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# Start services +#================================================= + +mkdir -p /var/run/mumble-server/ +murmurd -ini "$mumble_conf" -supw "$su_passwd" + +#================================================= +# Start services +#================================================= + +message=" +Mumbleserver 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 : $mumble_conf + +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" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +chmod -R 770 "$final_path" +chown -R :mumble-server "$final_path" + +#================================================= +# Add user to ssl-cert so it can read certificates +#================================================= + +usermod --append --groups ssl-cert mumble-server + +#================================================= +# Disable default server installed by Debian's package +#================================================= + +systemctl stop mumble-server +systemctl disable mumble-server + +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +# Add Mumble as a YunoHost service +yunohost service add "$app" -l "/var/log/mumble-server/$app.log" + +systemctl restart "$app"