From dc9cb69cc6c5e79a85835f29f1e024c1f191618e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 15 Aug 2021 21:31:52 +0200 Subject: [PATCH] Various fixes --- conf/biboumi.cfg | 8 ++++---- conf/biboumi.cfg.lua | 2 +- scripts/backup | 7 +++---- scripts/install | 26 +++++++++++++++----------- scripts/remove | 8 +++++--- scripts/restore | 19 ++++++++++++------- scripts/upgrade | 29 +++++++++++++++++++++-------- 7 files changed, 61 insertions(+), 38 deletions(-) diff --git a/conf/biboumi.cfg b/conf/biboumi.cfg index 6ce9189..950f1af 100644 --- a/conf/biboumi.cfg +++ b/conf/biboumi.cfg @@ -1,15 +1,15 @@ -hostname=biboumi.__DOMAIN__ -password=__SECRET__ +hostname=__APP__.__DOMAIN__ +password=__SHARED_SECRET__ #xmpp_server_ip=127.0.0.1 #port=5347 -db_name=/var/lib/biboumi/biboumi.sqlite +db_name=/var/lib/__APP__/__APP__.sqlite identd_port=__PORT__ admin=__ADMIN_JID__ realname_customization=true realname_from_jid=false log_level=1 -log_file=/var/log/biboumi/biboumi.log +log_file=/var/log/__APP__/__APP__.log #ca_file= #outgoing_bind= diff --git a/conf/biboumi.cfg.lua b/conf/biboumi.cfg.lua index 01c7b9b..fe8f28c 100644 --- a/conf/biboumi.cfg.lua +++ b/conf/biboumi.cfg.lua @@ -1,2 +1,2 @@ -Component "biboumi.__DOMAIN__" +Component "__APP__.__DOMAIN__" component_secret = "__SHARED_SECRET__" diff --git a/scripts/backup b/scripts/backup index 859e7ba..170a5e5 100755 --- a/scripts/backup +++ b/scripts/backup @@ -41,12 +41,11 @@ ynh_backup --src_path="/etc/logrotate.d/$app" # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/biboumi" +ynh_backup --src_path="/etc/$app" -ynh_backup --src_path="/var/lib/biboumi" +ynh_backup --src_path="/var/lib/$app" - -ynh_backup --src_path="/etc/metronome/conf.d/biboumi.cfg.lua" +ynh_backup --src_path="/etc/metronome/conf.d/$app.cfg.lua" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index c3548e6..d91e072 100755 --- a/scripts/install +++ b/scripts/install @@ -70,29 +70,33 @@ ynh_script_progression --message="Adding a configuration file..." # Create a secret password that will be shared by metronome and biboumi. shared_secret="$(ynh_string_random 25)" +ynh_app_setting_set --app=$app --key=shared_secret --value=$shared_secret # Biboumi needs at least one admin JID. -admin_jid="${admin}@biboumi.${domain}" +admin_jid="${admin}@$app.${domain}" +ynh_app_setting_set --app=$app --key=admin_jid --value=$admin_jid -ynh_add_config --template="../conf/biboumi/biboumi.cfg" --destination="/etc/biboumi/biboumi.cfg" +ynh_add_config --template="../conf/biboumi.cfg" --destination="/etc/$app/$app.cfg" -chown _biboumi /etc/biboumi +chown -R _biboumi:_biboumi "/etc/$app/$app.cfg" #================================================= # CONFIGURE METRONOME #================================================= # Add metronome component -ynh_add_config --template="../conf/biboumi.cfg.lua" --destination="/etc/metronome/conf.d/biboumi.cfg.lua" +ynh_add_config --template="../conf/biboumi.cfg.lua" --destination="/etc/metronome/conf.d/$app.cfg.lua" + +chown metronome:metronome "/etc/metronome/conf.d/$app.cfg.lua" #================================================= # CREATE DIRECTORIES #================================================= -mkdir -p /var/lib/biboumi +mkdir -p /var/lib/$app # Set permissions to app files -chown _biboumi /var/lib/biboumi +chown -R _biboumi:_biboumi "/var/lib/$app" #================================================= # GENERIC FINALIZATION @@ -101,17 +105,17 @@ chown _biboumi /var/lib/biboumi #================================================= ynh_script_progression --message="Configuring log rotation..." --weight=1 -mkdir -p /var/log/biboumi -chown _biboumi /var/log/biboumi +mkdir -p /var/log/$app +chown -R _biboumi:_biboumi "/var/log/$app" # Use logrotate to manage application logfile(s) -ynh_use_logrotate /var/log/biboumi/ +ynh_use_logrotate /var/log/$app/ #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="XMPP gateway for the IRC network" --log="/var/log/biboumi/biboumi.log" +yunohost service add $app --description="XMPP gateway for the IRC network" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -119,7 +123,7 @@ yunohost service add $app --description="XMPP gateway for the IRC network" --log ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --action=restart --service_name=metronome -ynh_systemd_action --action=restart --service_name=biboumi +ynh_systemd_action --action=restart --service_name=$app #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 8d027ef..43521c5 100755 --- a/scripts/remove +++ b/scripts/remove @@ -52,9 +52,10 @@ ynh_remove_logrotate #================================================= ynh_script_progression --message="Removing various files..." +ynh_secure_remove --file="/var/lib/$app" + # Remove a directory securely ynh_secure_remove --file="/etc/$app" -ynh_secure_remove --file="/var/lib/$app" # Remove the log files ynh_secure_remove --file="/var/log/$app" @@ -63,10 +64,11 @@ ynh_secure_remove --file="/var/log/$app" # REMOVE METRONOME COMPONENT #================================================= -ynh_secure_remove "/etc/metronome/conf.d/biboumi.cfg.lua" +ynh_secure_remove --file="/etc/metronome/conf.d/$app.cfg.lua" +ynh_systemd_action --action=restart --service_name=metronome #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of Biboumi completed" --last +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 8da63d2..8af5a09 100755 --- a/scripts/restore +++ b/scripts/restore @@ -51,17 +51,21 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Restoring various files..." -ynh_restore_file--origin_path= "/etc/biboumi" -ynh_restore_file --origin_path="/var/lib/biboumi" -ynh_restore_file --origin_path="/etc/metronome/conf.d/biboumi.cfg.lua" -chown _biboumi /var/log/biboumi /var/lib/biboumi /etc/biboumi +ynh_restore_file--origin_path= "/etc/$app" +chown -R _biboumi:_biboumi /etc/$app + +ynh_restore_file --origin_path="/var/lib/$app" +chown -R _biboumi:_biboumi /var/lib/$app + +ynh_restore_file --origin_path="/etc/metronome/conf.d/$app.cfg.lua" +chown metronome:metronome "/etc/metronome/conf.d/$app.cfg.lua" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="XMPP gateway for the IRC network" --log="/var/log/biboumi/biboumi.log" +yunohost service add $app --description="XMPP gateway for the IRC network" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -69,15 +73,16 @@ yunohost service add $app --description="XMPP gateway for the IRC network" --log ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --action=restart --service_name=metronome -ynh_systemd_action --action=restart --service_name=biboumi +ynh_systemd_action --action=restart --service_name=$app #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= ynh_script_progression --message="Restoring the logrotate configuration..." -mkdir -p /var/log/biboumi +mkdir -p /var/log/$app ynh_restore_file --origin_path="/etc/logrotate.d/$app" +chown -R _biboumi:_biboumi /var/log/$app #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 7edc197..ea9ea31 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,6 +19,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) admin=$(ynh_app_setting_get --app=$app --key=admin) port=$(ynh_app_setting_get --app=$app --key=port) +shared_secret=$(ynh_app_setting_get --app=$app --key=shared_secret) +admin_jid=$(ynh_app_setting_get --app=$app --key=admin_jid) #================================================= # CHECK VERSION @@ -30,6 +32,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -50,6 +53,16 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Prevent conflict with other apps on the same domain ynh_app_setting_set --app=$app --key=no_sso --value=1 +if [ -z "$shared_secret" ]; then + shared_secret="$(grep password "/etc/biboumi/biboumi.cfg" | cut -d= -f2)" + ynh_app_setting_set --app=$app --key=shared_secret --value=$shared_secret +fi + +if [ -z "$admin_jid" ]; then + admin_jid="${admin}@$app.${domain}" + ynh_app_setting_set --app=$app --key=admin_jid --value=$admin_jid +fi + #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -64,25 +77,25 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Updating a configuration file..." -ynh_add_config --template="/etc/biboumi/biboumi.cfg" --destination="/etc/biboumi/biboumi.cfg" +ynh_add_config --template="../conf/biboumi.cfg" --destination="/etc/$app/$app.cfg" -chown _biboumi /etc/biboumi +chown _biboumi /etc/$app #================================================= # UPGRADE METRONOME COMPONENT #================================================= # Upgrade metronome component -ynh_add_config --template="../conf/biboumi.cfg.lua" --destination="/etc/metronome/conf.d/biboumi.cfg.lua" +ynh_add_config --template="../conf/biboumi.cfg.lua" --destination="/etc/metronome/conf.d/$app.cfg.lua" #================================================= # CREATE DIRECTORIES #================================================= -mkdir -p /var/lib/biboumi +mkdir -p /var/lib/$app # Set permissions to app files -chown _biboumi /var/lib/biboumi +chown _biboumi /var/lib/$app #================================================= # GENERIC FINALIZATION @@ -91,7 +104,7 @@ chown _biboumi /var/lib/biboumi #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 -chown _biboumi /var/log/biboumi +chown _biboumi /var/log/$app # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append @@ -100,7 +113,7 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="XMPP gateway for the IRC network" --log="/var/log/biboumi/biboumi.log" +yunohost service add $app --description="XMPP gateway for the IRC network" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -108,7 +121,7 @@ yunohost service add $app --description="XMPP gateway for the IRC network" --log ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --action=restart --service_name=metronome -ynh_systemd_action --action=restart --service_name=biboumi +ynh_systemd_action --action=restart --service_name=$app #================================================= # END OF SCRIPT