From effd760f8bc79f1eb31ed2cf5378ea84ca91d5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Wed, 31 Jan 2018 16:08:58 +0100 Subject: [PATCH] Add title for each part of code and use helper upstream_version --- manifest.json | 2 +- scripts/_common.sh | 18 ++++---- scripts/backup | 10 ++++- scripts/change_url | 8 ++++ scripts/{psql.sh => experimental_helper.sh} | 47 +++++++++++++++++++++ scripts/install | 14 +++++- scripts/remove | 10 ++++- scripts/restore | 14 +++++- scripts/upgrade | 14 +++++- 9 files changed, 123 insertions(+), 14 deletions(-) rename scripts/{psql.sh => experimental_helper.sh} (71%) diff --git a/manifest.json b/manifest.json index 341f88a..315067c 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Manage PostgreSQL databases over the web", "fr": "Application web de gestion des bases de données PostgreSQL" }, - "version": "4-2.1", + "version": "4-2.1~ynh1", "url": "https://www.pgadmin.org", "license": "PostgreSQL", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index bc30839..da28201 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,18 +1,20 @@ +#================================================= +# SET ALL CONSTANTS +#================================================= + app=$YNH_APP_INSTANCE_NAME final_path=/opt/yunohost/$app pgadmin_user="pgadmin" -get_app_version_from_json() { - 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=$(get_app_version_from_json) +[[ -e "../settings/manifest.json" ]] || [[ -e "../manifest.json" ]] && \ + APP_VERSION=$(ynh_app_upstream_version) app_main_version=$(echo $APP_VERSION | cut -d'-' -f1) app_sub_version=$(echo $APP_VERSION | cut -d'-' -f2) +#================================================= +# DEFINE ALL COMMON FONCTIONS +#================================================= + install_dependance() { ynh_install_app_dependencies python-pip build-essential python-dev python-virtualenv postgresql uwsgi uwsgi-plugin-python expect } diff --git a/scripts/backup b/scripts/backup index bcabd7c..463c493 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -7,14 +11,18 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh -source ../settings/scripts/psql.sh # LOAD SETTINGS final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get $app db_name) +#================================================= +# STANDARD BACKUP STEPS +#================================================= + # BACKUP THE APP MAIN DIR ynh_backup "$final_path" diff --git a/scripts/change_url b/scripts/change_url index 10e793a..926c4bd 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/psql.sh b/scripts/experimental_helper.sh similarity index 71% rename from scripts/psql.sh rename to scripts/experimental_helper.sh index 9789a29..43b7df1 100644 --- a/scripts/psql.sh +++ b/scripts/experimental_helper.sh @@ -145,4 +145,51 @@ ynh_psql_test_if_first_run() { systemctl enable postgresql systemctl reload postgresql fi +} + +#================================================= +# OTHERS HELPERS +#================================================= + +# 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/}" } \ No newline at end of file diff --git a/scripts/install b/scripts/install index 43cf863..c8bbf7b 100644 --- a/scripts/install +++ b/scripts/install @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -7,8 +11,8 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ./experimental_helper.sh source ./_common.sh -source ./psql.sh # RETRIEVE ARGUMENTS FROM THE MANIFEST domain=$YNH_APP_ARG_DOMAIN @@ -40,6 +44,10 @@ ynh_app_setting_set $app admin_pwd "$admin_pwd" ynh_app_setting_set $app db_user "$db_user" ynh_app_setting_set $app db_pwd "$db_pwd" +#================================================= +# STANDARD MODIFICATIONS +#================================================= + # Install dependance install_dependance @@ -77,6 +85,10 @@ su --command="psql -c\"CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSE $final_path/bin/python2.7 config_database.py "$db_user" "$db_pwd" deactivate +#================================================= +# GENERIC FINALIZATION +#================================================= + # Set permission after initialisation set_permission diff --git a/scripts/remove b/scripts/remove index 5f5cb07..599c879 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # Source YunoHost helpers source /usr/share/yunohost/helpers @@ -7,14 +11,18 @@ source /usr/share/yunohost/helpers set -u # Import common cmd +source ./experimental_helper.sh source ./_common.sh -source ./psql.sh # LOAD SETTINGS domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get $app db_name) db_user="pgadmin" +#================================================= +# STANDARD REMOVE +#================================================= + # Remove db user ynh_psql_drop_user $db_user diff --git a/scripts/restore b/scripts/restore index 752bf55..8799944 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -7,8 +11,8 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh -source ../settings/scripts/psql.sh # LOAD SETTINGS domain=$(ynh_app_setting_get $app domain) @@ -19,6 +23,10 @@ db_name=$(ynh_app_setting_get $app db_name) db_user=$(ynh_app_setting_get $app db_user) db_pwd=$(ynh_app_setting_get $app db_pwd) +#================================================= +# STANDARD RESTORATION STEPS +#================================================= + # Install dependance install_dependance @@ -32,6 +40,10 @@ ynh_restore ynh_psql_test_if_first_run su --command="psql -c\"CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION\"" postgres +#================================================= +# GENERIC FINALIZATION +#================================================= + # Set the permission set_permission diff --git a/scripts/upgrade b/scripts/upgrade index ec24630..89e32e7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -7,8 +11,8 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd +source ./experimental_helper.sh source ./_common.sh -source ./psql.sh # LOAD SETTINGS domain=$(ynh_app_setting_get $app domain) @@ -21,6 +25,10 @@ ynh_clean_setup () { ynh_restore_upgradebackup # restore it if the upgrade fails } +#================================================= +# STANDARD UPGRADE STEPS +#================================================= + # Download, check integrity, uncompress and patch the source from app.src install_source @@ -30,6 +38,10 @@ config_pgadmin # Config uwsgi config_uwsgi +#================================================= +# GENERIC FINALIZATION +#================================================= + # Set permission after initialisation set_permission