From 4f54fe164cb6d1a618a01f79bbfed54fecfce04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Wed, 31 Jan 2018 16:07:43 +0100 Subject: [PATCH] Add title for each part of code and use helper upstream_version --- manifest.json | 2 +- scripts/_common.sh | 20 ++++++++-------- scripts/backup | 8 +++++++ scripts/change_url | 8 +++++++ scripts/experimental_helper.sh | 42 ++++++++++++++++++++++++++++++++++ scripts/install | 23 +++++++++++++------ scripts/remove | 12 +++++++--- scripts/restore | 13 +++++++++++ scripts/upgrade | 15 ++++++++++-- 9 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 scripts/experimental_helper.sh diff --git a/manifest.json b/manifest.json index f25b79d..54795e8 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A monitoring tools", "fr": "Un outils de monitoring" }, - "version": "3.10.0", + "version": "3.10.0~ynh1", "url": "http://monitorix.org", "license": "GPL-2.0", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index cac6df0..37eeb21 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,18 +1,16 @@ -#!/bin/bash - -app=$YNH_APP_INSTANCE_NAME +#================================================= +# SET ALL CONSTANTS +#================================================= ## Adapt md5sum while you update app sha256sum="3fb8b4a4f7aeeeafccc6dc5b232f82d5761be80fe8e82008bc768f805fe5a744" -ynh_app_version() { - manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - echo $(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. -} -APP_VERSION=$(ynh_app_version) +app=$YNH_APP_INSTANCE_NAME +APP_VERSION=$(ynh_app_upstream_version) + +#================================================= +# DEFINE ALL COMMON FONCTIONS +#================================================= install_dependances() { ynh_install_app_dependencies rrdtool perl libwww-perl libmailtools-perl libmime-lite-perl librrds-perl libdbi-perl libxml-simple-perl libhttp-server-simple-perl libconfig-general-perl pflogsumm diff --git a/scripts/backup b/scripts/backup index d11c1b0..b808d9f 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # Source YunoHost helpers source /usr/share/yunohost/helpers @@ -7,11 +11,15 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh # Retrieve arguments domain=$(ynh_app_setting_get $app domain) +#================================================= +# STANDARD BACKUP STEPS +#================================================= # Copy NGINX configuration domain=$(ynh_app_setting_get "$app" domain) diff --git a/scripts/change_url b/scripts/change_url index f389245..f4f2564 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # Source YunoHost helpers source /usr/share/yunohost/helpers @@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ./experimental_helper.sh source ./_common.sh # Retrive arguments @@ -37,7 +42,10 @@ then change_path=1 fi +#================================================= # STANDARD MODIFICATIONS +#================================================= + # MODIFY URL IN NGINX CONF nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh new file mode 100644 index 0000000..2d5527e --- /dev/null +++ b/scripts/experimental_helper.sh @@ -0,0 +1,42 @@ +# Read the value of a key in a ynh manifest file +# +# usage: ynh_read_manifest manifest key +# | arg: manifest - Path of the manifest to read +# | arg: key - Name of the key to find +ynh_read_manifest () { + manifest="$1" + key="$2" + python3 -c "import sys, json;print(json.load(open('$manifest'))['$key'])" +} + +# Read the upstream version from the manifest +# The version number in the manifest is defined by ~ynh +# For example : 4.3-2~ynh3 +# This include the number before ~ynh +# In the last example it return 4.3-2 +# +# usage: ynh_app_upstream_version +ynh_app_upstream_version () { + manifest_path="../manifest.json" + if [ ! -e "$manifest_path" ]; then + manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place + fi + version_key=$(ynh_read_manifest "$manifest_path" "version") + echo "${version_key/~ynh*/}" +} + +# Read package version from the manifest +# The version number in the manifest is defined by ~ynh +# For example : 4.3-2~ynh3 +# This include the number after ~ynh +# In the last example it return 3 +# +# usage: ynh_app_package_version +ynh_app_package_version () { + manifest_path="../manifest.json" + if [ ! -e "$manifest_path" ]; then + manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place + fi + version_key=$(ynh_read_manifest "$manifest_path" "version") + echo "${version_key/*~ynh/}" +} diff --git a/scripts/install b/scripts/install index 1f08918..a070f8a 100755 --- a/scripts/install +++ b/scripts/install @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # Source YunoHost helpers source /usr/share/yunohost/helpers @@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ./experimental_helper.sh source ./_common.sh # Retrieve arguments @@ -17,6 +22,17 @@ path=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) test $(ynh_webpath_available $domain $path) == 'True' || ynh_die "$domain$path is not available, please use an other domain or path." ynh_webpath_register $app $domain $path +# Find a port for built-in monitorix HTTP server +http_port=$(ynh_find_port 8080) +nginx_status_port=$(ynh_find_port $(($http_port +1))) + +ynh_app_setting_set $app http_port $http_port +ynh_app_setting_set $app nginx_status_port $nginx_status_port + +#================================================= +# STANDARD MODIFICATIONS +#================================================= + # Install package install_dependances @@ -29,13 +45,6 @@ dbpass=$(ynh_string_random 12) ynh_app_setting_set "$app" mysqlpwd "$dbpass" ynh_mysql_create_user $dbuser $dbpass -# Find a port for built-in monitorix HTTP server -http_port=$(ynh_find_port 8080) -nginx_status_port=$(ynh_find_port $(($http_port +1))) - -ynh_app_setting_set $app http_port $http_port -ynh_app_setting_set $app nginx_status_port $nginx_status_port - # Config nginx config_nginx diff --git a/scripts/remove b/scripts/remove index 396e735..3fe8b6e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,17 +1,23 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # Source YunoHost helpers source /usr/share/yunohost/helpers -# Stop script if errors -set -u - # Import common cmd +source ./experimental_helper.sh source ./_common.sh # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# STANDARD REMOVE +#================================================= + # Stop service systemctl stop monitorix.service diff --git a/scripts/restore b/scripts/restore index adb75d0..77a658f 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # Source YunoHost helpers source /usr/share/yunohost/helpers @@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh # Retrieve old app settings @@ -16,6 +21,10 @@ path=$(ynh_normalize_url_path $(ynh_app_setting_get "$app" path)) # Check domain/path availability ynh_webpath_available $domain $path || ynh_die "$domain/$path is not available, please use an other domain or path." +#================================================= +# STANDARD RESTORATION STEPS +#================================================= + # Install package install_dependances @@ -32,6 +41,10 @@ ynh_secure_remove /etc/monitorix # we remove the directory because if it is not ynh_secure_remove /var/lib/monitorix ynh_restore +#================================================= +# GENERIC FINALIZATION +#================================================= + # Set access set_permission diff --git a/scripts/upgrade b/scripts/upgrade index f965977..b138ff1 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # Source YunoHost helpers source /usr/share/yunohost/helpers @@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ./experimental_helper.sh source ./_common.sh # Retrieve app settings @@ -21,8 +26,6 @@ dbpass=$(ynh_app_setting_get "$app" mysqlpwd) # Stop services systemctl stop monitorix.service -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP - # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { @@ -32,6 +35,10 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# STANDARD UPGRADE STEPS +#================================================= + # Download package and install it get_install_source @@ -41,6 +48,10 @@ config_nginx # Update monitorix configuration config_monitorix +#================================================= +# GENERIC FINALIZATION +#================================================= + # Set access set_permission