From 512895089270d4beea156adf26280587f57d65ad Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 5 Feb 2019 23:21:30 +0100 Subject: [PATCH] add ynh_read_manifest_2 --- scripts/upgrade | 1 + scripts/ynh_read_manifest_2 | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 scripts/ynh_read_manifest_2 diff --git a/scripts/upgrade b/scripts/upgrade index d27d835..543fc89 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,6 +8,7 @@ source _common.sh source ynh_systemd_action +source ynh_read_manifest_2 source ynh_check_app_version_changed source /usr/share/yunohost/helpers diff --git a/scripts/ynh_read_manifest_2 b/scripts/ynh_read_manifest_2 new file mode 100644 index 0000000..c2dd5a3 --- /dev/null +++ b/scripts/ynh_read_manifest_2 @@ -0,0 +1,51 @@ +#!/bin/bash + +# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args + +# Read the value of a key in a ynh manifest file +# +# usage: ynh_read_manifest manifest key +# | arg: -m, --manifest= - Path of the manifest to read +# | arg: -k, --key= - Name of the key to find +ynh_read_manifest () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [m]=manifest= [k]=key= ) + local manifest + local key + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$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="$manifest_path" --key="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="$manifest_path" --key="version") + echo "${version_key/*~ynh/}" +}