1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/biboumi_ynh.git synced 2024-09-03 18:15:58 +02:00

Apply last example_ynh (#14)

* Apply last example_ynh

* Fix $biboumi_config_file

* Update LICENSE

* fix install

* Various fixes

* Cleanup

* Fix variables not initialized

* fix variable... again

* Fix install
This commit is contained in:
yalh76 2021-08-17 10:02:31 +02:00 committed by GitHub
parent 8eefa0a5ae
commit 8a619ba379
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 190 additions and 175 deletions

View file

@ -1,4 +1,7 @@
File containing the license of your package.
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
More information here:
https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-13---indiquer-la-licence-associ%C3%A9e-au-paquet---brouillon--auto--working-
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

View file

@ -10,6 +10,8 @@
setup_private=0
setup_public=0
upgrade=1
# 8.3~ynh1
upgrade=1 from_commit=6596c7e12e17a2b9149b20739e916184e71fdfbd
backup_restore=1
multi_instance=0
port_already_use=1 (113)
@ -17,3 +19,6 @@
;;; Options
Email=pitchum@gramaton.org
Notification=none
;;; Upgrade options
; commit=6596c7e12e17a2b9149b20739e916184e71fdfbd
name=8.3~ynh1.

View file

@ -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=

View file

@ -1,2 +1,2 @@
Component "biboumi.__DOMAIN__"
component_secret = "__SECRET__"
Component "__APP__.__DOMAIN__"
component_secret = "__SHARED_SECRET__"

View file

@ -17,4 +17,4 @@ pkg_dependencies="biboumi"
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
#=================================================

View file

@ -6,6 +6,7 @@
# 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
@ -30,27 +31,24 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "/etc/biboumi"
ynh_backup "/var/lib/biboumi"
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP METRONOME CONFIG
# BACKUP VARIOUS FILES
#=================================================
ynh_backup "/etc/metronome/conf.d/biboumi.cfg.lua"
ynh_backup --src_path="/etc/$app"
ynh_backup --src_path="/var/lib/$app"
ynh_backup --src_path="/etc/metronome/conf.d/$app.cfg.lua"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for Biboumi. (YunoHost will then actually copy those files to the archive)."
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -25,9 +25,13 @@ admin=$YNH_APP_ARG_ADMIN
app=$YNH_APP_INSTANCE_NAME
shared_secret="$(ynh_string_random 25)"
admin_jid="${admin}@$app.${domain}"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
if dpkg --compare-versions "$(uname -r)" "<=" "4.0"
then
@ -37,101 +41,103 @@ fi
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=shared_secret --value=$shared_secret
ynh_app_setting_set --app=$app --key=admin_jid --value=$admin_jid
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=2
ynh_script_progression --message="Finding an available port..."
# Find a free port
# Find an available port
port=$(ynh_find_port --port=113)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=9
ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE BIBOUMI
#=================================================
# Create a secret password that will be shared by metronome and biboumi.
shared_secret="$(ynh_string_random 25)"
# Biboumi needs at least one admin JID.
admin_jid="${admin}@biboumi.${domain}"
biboumi_config_file="/etc/biboumi/biboumi.cfg"
# Create the biboumi config file.
cp ../conf/biboumi.cfg "$biboumi_config_file"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="${domain}" --target_file="$biboumi_config_file"
ynh_replace_string --match_string="__SECRET__" --replace_string="${shared_secret}" --target_file="$biboumi_config_file"
ynh_replace_string --match_string="__PORT__" --replace_string="${port}" --target_file="$biboumi_config_file"
ynh_replace_string --match_string="__ADMIN_JID__" --replace_string="${admin_jid}" --target_file="$biboumi_config_file"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$biboumi_config_file"
#=================================================
# CONFIGURE METRONOME
#=================================================
ynh_script_progression --message="Configuring Metronome..."
# Add metronome component
cp ../conf/biboumi.cfg.lua /etc/metronome/conf.d/
ynh_replace_string --match_string="__DOMAIN__" --replace_string="${domain}" --target_file="/etc/metronome/conf.d/biboumi.cfg.lua"
ynh_replace_string --match_string="__SECRET__" --replace_string="${shared_secret}" --target_file="/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"
ynh_systemd_action --service_name=metronome --action="restart"
#=================================================
# CREATE DIRECTORIES
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..."
mkdir -p /var/log/biboumi /var/lib/biboumi
mkdir -p /var/lib/$app
# Set permissions to app files
chown _biboumi /var/log/biboumi /var/lib/biboumi /etc/biboumi
chown -R _biboumi:_biboumi "/var/lib/$app"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="../conf/biboumi.cfg" --destination="/etc/$app/$app.cfg"
chown -R _biboumi:_biboumi "/etc/$app/$app.cfg"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
ynh_script_progression --message="Configuring log rotation..."
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
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add biboumi --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"
#=================================================
# SET THE APP AS NOT USING THE SSO
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
sleep 5
ynh_systemd_action --service_name=$app --action="restart"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
# Prevent conflict with other apps on the same domain
ynh_app_setting_set --app=$app --key=no_sso --value=1
#=================================================
# RELOAD SERVICES
#=================================================
ynh_systemd_action --action=restart --service_name=metronome
ynh_systemd_action --action=restart --service_name=biboumi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of Biboumi completed" --last
ynh_script_progression --message="Installation of $app completed"

View file

@ -12,64 +12,61 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status | grep -q $app
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app
fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=4
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing Biboumi directory..." --weight=2
# Remove the app directory securely
ynh_secure_remove "/etc/biboumi"
ynh_secure_remove "/var/lib/biboumi"
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
ynh_script_progression --message="Removing logrotate configuration..."
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE LOGS
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
ynh_secure_remove "/var/log/biboumi"
# Remove data directory
ynh_secure_remove --file="/var/lib/$app"
#=================================================
# REMOVE METRONOME COMPONENT
#=================================================
# Remove a directory securely
ynh_secure_remove --file="/etc/$app"
ynh_secure_remove "/etc/metronome/conf.d/biboumi.cfg.lua"
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
# Remove Metronome component
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"

View file

@ -6,6 +6,7 @@
# 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
@ -19,7 +20,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@ -28,7 +29,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_script_progression --message="Validating restoration parameters..."
if dpkg --compare-versions "$(uname -r)" "<=" "4.0"
then
@ -40,55 +41,52 @@ fi
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=9
ynh_script_progression --message="Reinstalling dependencies..."
# Make sure that stretch-backports is enabled
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE APP MAIN DIR
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_restore_file "/etc/biboumi"
ynh_restore_file "/var/lib/biboumi"
ynh_restore_file --origin_path="/etc/$app"
chown -R _biboumi:_biboumi /etc/$app
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
ynh_restore_file --origin_path="/var/lib/$app"
chown -R _biboumi:_biboumi /var/lib/$app
yunohost service add biboumi --description="XMPP gateway for the IRC network" --log="/var/log/biboumi/biboumi.log"
ynh_restore_file --origin_path="/etc/metronome/conf.d/$app.cfg.lua"
chown metronome:metronome "/etc/metronome/conf.d/$app.cfg.lua"
ynh_systemd_action --service_name=metronome --action="restart"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
mkdir -p /var/log/biboumi
ynh_restore_file "/etc/logrotate.d/$app"
mkdir -p /var/log/$app
chown -R _biboumi:_biboumi "/var/log/$app"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# RESTORE USER RIGHTS
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
# Restore permissions on app files
chown _biboumi /var/log/biboumi /var/lib/biboumi /etc/biboumi
yunohost service add $app --description="XMPP gateway for the IRC network" --log="/var/log/$app/$app.log"
#=================================================
# RESTORE THE METRONOME CONFIG
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_restore_file "/etc/metronome/conf.d/biboumi.cfg.lua"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD SERVICES
#=================================================
ynh_systemd_action --action=restart --service_name=metronome
ynh_systemd_action --action=restart --service_name=biboumi
ynh_systemd_action --service_name=$app --action="restart"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for Biboumi" --last
ynh_script_progression --message="Restoration completed for $app"

View file

@ -12,31 +12,27 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
ynh_script_progression --message="Loading installation settings..."
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
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
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
#=================================================
# 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
@ -49,81 +45,93 @@ ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# 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
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=9
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# CONFIGURE BIBOUMI
#=================================================
biboumi_config_file="/etc/biboumi/biboumi.cfg"
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different "$biboumi_config_file"
# Get shared_secret from the config file
shared_secret="$(grep password "$biboumi_config_file" | cut -d= -f2)"
# Biboumi needs at least one admin JID.
admin_jid="${admin}@biboumi.${domain}"
# Create the biboumi config file.
cp ../conf/biboumi.cfg /etc/biboumi/
ynh_replace_string --match_string="__DOMAIN__" --replace_string="${domain}" --target_file="$biboumi_config_file"
ynh_replace_string --match_string="__SECRET__" --replace_string="${shared_secret}" --target_file="$biboumi_config_file"
ynh_replace_string --match_string="__PORT__" --replace_string="${port}" --target_file="$biboumi_config_file"
ynh_replace_string --match_string="__ADMIN_JID__" --replace_string="${admin_jid}" --target_file="$biboumi_config_file"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$biboumi_config_file"
#=================================================
# UPGRADE METRONOME COMPONENT
#=================================================
ynh_script_progression --message="Upgrading Metronome component..."
# Upgrade metronome component
cp ../conf/biboumi.cfg.lua /etc/metronome/conf.d/
ynh_replace_string --match_string="__DOMAIN__" --replace_string="${domain}" --target_file="/etc/metronome/conf.d/biboumi.cfg.lua"
ynh_replace_string --match_string="__SECRET__" --replace_string="${shared_secret}" --target_file="/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"
ynh_systemd_action --service_name=metronome --action="restart"
#=================================================
# SETUP LOGROTATE
# CREATE DIRECTORIES
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
ynh_script_progression --message="Creating a data directory..."
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate /var/log/biboumi/ --non-append
mkdir -p /var/lib/$app
# Set permissions to app files
chown -R _biboumi:_biboumi "/var/lib/$app"
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="../conf/biboumi.cfg" --destination="/etc/$app/$app.cfg"
chown -R _biboumi:_biboumi "/etc/$app/$app.cfg"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
# Set permissions on app files
chown _biboumi /var/log/biboumi /var/lib/biboumi /etc/biboumi
mkdir -p /var/log/$app
chown -R _biboumi:_biboumi "/var/log/$app"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add biboumi --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"
#=================================================
# RELOAD SERVICES
# START SYSTEMD SERVICE
#=================================================
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
#=================================================
ynh_script_progression --message="Upgrade of Biboumi completed" --last
ynh_script_progression --message="Upgrade of $app completed"