mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers 2.1: Simplify ynh_app_upstream_version and ynh_read_manifest
This commit is contained in:
parent
88684c7937
commit
7c1b07ee0f
1 changed files with 9 additions and 77 deletions
|
@ -149,7 +149,7 @@ ynh_setup_source() {
|
||||||
source_id="${source_id:-main}"
|
source_id="${source_id:-main}"
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
local sources_json=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[\"$source_id\"]")
|
local sources_json=$(ynh_read_manifest ".resources.sources[\"$source_id\"]")
|
||||||
if jq -re ".url" <<< "$sources_json"
|
if jq -re ".url" <<< "$sources_json"
|
||||||
then
|
then
|
||||||
local arch_prefix=""
|
local arch_prefix=""
|
||||||
|
@ -453,9 +453,9 @@ ynh_add_config() {
|
||||||
local template
|
local template
|
||||||
local destination
|
local destination
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
local template_path
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
|
local template_path
|
||||||
if [ -f "$YNH_APP_BASEDIR/conf/$template" ]; then
|
if [ -f "$YNH_APP_BASEDIR/conf/$template" ]; then
|
||||||
template_path="$YNH_APP_BASEDIR/conf/$template"
|
template_path="$YNH_APP_BASEDIR/conf/$template"
|
||||||
elif [ -f "$template" ]; then
|
elif [ -f "$template" ]; then
|
||||||
|
@ -827,95 +827,27 @@ ynh_secure_remove() {
|
||||||
set -o xtrace # set -x
|
set -o xtrace # set -x
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read the value of a key in a ynh manifest file
|
# Read the value of a key in the app's manifest
|
||||||
#
|
#
|
||||||
# usage: ynh_read_manifest --manifest="manifest.json" --key="key"
|
# usage: ynh_read_manifest "key"
|
||||||
# | arg: -m, --manifest= - Path of the manifest to read
|
# | arg: key - Name of the key to find
|
||||||
# | arg: -k, --key= - Name of the key to find
|
|
||||||
# | ret: the value associate to that key
|
# | ret: the value associate to that key
|
||||||
#
|
#
|
||||||
# Requires YunoHost version 3.5.0 or higher.
|
# Requires YunoHost version 3.5.0 or higher.
|
||||||
ynh_read_manifest() {
|
ynh_read_manifest() {
|
||||||
# ============ Argument parsing =============
|
cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".$manifest_key" --raw-output
|
||||||
local -A args_array=([m]=manifest= [k]=manifest_key=)
|
|
||||||
local manifest
|
|
||||||
local manifest_key
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
# ===========================================
|
|
||||||
|
|
||||||
if [ ! -e "${manifest:-}" ]; then
|
|
||||||
# If the manifest isn't found, try the common place for backup and restore script.
|
|
||||||
if [ -e "$YNH_APP_BASEDIR/manifest.json" ]
|
|
||||||
then
|
|
||||||
manifest="$YNH_APP_BASEDIR/manifest.json"
|
|
||||||
elif [ -e "$YNH_APP_BASEDIR/manifest.toml" ]
|
|
||||||
then
|
|
||||||
manifest="$YNH_APP_BASEDIR/manifest.toml"
|
|
||||||
else
|
|
||||||
ynh_die --message="No manifest found !?"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if echo "$manifest" | grep -q '\.json$'
|
|
||||||
then
|
|
||||||
jq ".$manifest_key" "$manifest" --raw-output
|
|
||||||
else
|
|
||||||
cat "$manifest" | python3 -c 'import json, toml, sys; print(json.dumps(toml.load(sys.stdin)))' | jq ".$manifest_key" --raw-output
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read the upstream version from the manifest or `$YNH_APP_MANIFEST_VERSION`
|
# Return the app upstream version, deduced from `$YNH_APP_MANIFEST_VERSION` and strippig the `~ynhX` part
|
||||||
#
|
#
|
||||||
# usage: ynh_app_upstream_version [--manifest="manifest.json"]
|
# usage: ynh_app_upstream_version
|
||||||
# | arg: -m, --manifest= - Path of the manifest to read
|
|
||||||
# | ret: the version number of the upstream app
|
# | ret: the version number of the upstream app
|
||||||
#
|
#
|
||||||
# If the `manifest` is not specified, the envvar `$YNH_APP_MANIFEST_VERSION` will be used.
|
|
||||||
#
|
|
||||||
# The version number in the manifest is defined by `<upstreamversion>~ynh<packageversion>`.
|
|
||||||
#
|
|
||||||
# For example, if the manifest contains `4.3-2~ynh3` the function will return `4.3-2`
|
# For example, if the manifest contains `4.3-2~ynh3` the function will return `4.3-2`
|
||||||
#
|
#
|
||||||
# Requires YunoHost version 3.5.0 or higher.
|
# Requires YunoHost version 3.5.0 or higher.
|
||||||
ynh_app_upstream_version() {
|
ynh_app_upstream_version() {
|
||||||
# ============ Argument parsing =============
|
echo "${$YNH_APP_MANIFEST_VERSION/~ynh*/}"
|
||||||
local -A args_array=([m]=manifest=)
|
|
||||||
local manifest
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
manifest="${manifest:-}"
|
|
||||||
# ===========================================
|
|
||||||
|
|
||||||
if [[ "$manifest" != "" ]] && [[ -e "$manifest" ]]; then
|
|
||||||
version_key_=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
|
||||||
else
|
|
||||||
version_key_=$YNH_APP_MANIFEST_VERSION
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${version_key_/~ynh*/}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read package version from the manifest
|
|
||||||
#
|
|
||||||
# [internal]
|
|
||||||
#
|
|
||||||
# usage: ynh_app_package_version [--manifest="manifest.json"]
|
|
||||||
# | arg: -m, --manifest= - Path of the manifest to read
|
|
||||||
# | ret: the version number of the package
|
|
||||||
#
|
|
||||||
# The version number in the manifest is defined by `<upstreamversion>~ynh<packageversion>`.
|
|
||||||
#
|
|
||||||
# For example, if the manifest contains `4.3-2~ynh3` the function will return `3`
|
|
||||||
#
|
|
||||||
# Requires YunoHost version 3.5.0 or higher.
|
|
||||||
ynh_app_package_version() {
|
|
||||||
# ============ Argument parsing =============
|
|
||||||
local -A args_array=([m]=manifest=)
|
|
||||||
local manifest
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
# ===========================================
|
|
||||||
|
|
||||||
version_key_=$YNH_APP_MANIFEST_VERSION
|
|
||||||
echo "${version_key_/*~ynh/}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks the app version to upgrade with the existing app version and returns:
|
# Checks the app version to upgrade with the existing app version and returns:
|
||||||
|
|
Loading…
Add table
Reference in a new issue