mirror of
https://github.com/YunoHost-Apps/cheky_ynh.git
synced 2024-09-03 18:16:00 +02:00
[enh] fully automate upgrade process
Use new helper 'ynh_app_upstream_version' so no manual work is need by user Takes "version" from 'manifest.json' and modify cheky config file with new version during upgrade
This commit is contained in:
parent
6d3ba0e9d5
commit
b6db797e01
2 changed files with 45 additions and 1 deletions
|
@ -10,4 +10,38 @@
|
|||
ynh_delete_file_checksum () {
|
||||
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
||||
ynh_app_setting_delete $app $checksum_setting_name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
### Experimental helpers
|
||||
# Taken from https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_read_manifest/ynh_read_manifest_2#L14-L28
|
||||
# Idea from https://forum.yunohost.org/t/upgrade-script-how-to-modify-parameter-inside-configuration-file/5352/2
|
||||
|
||||
# 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', encoding='utf-8'))['$key'])"
|
||||
}
|
||||
|
||||
# Read the upstream version from the manifest
|
||||
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
|
||||
# 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*/}"
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ is_public=$(ynh_app_setting_get $app is_public)
|
|||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
|
||||
# Exerimental helper, see "_common.sh"
|
||||
upstream_version=$(ynh_app_upstream_version)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
|
@ -108,6 +111,13 @@ ynh_add_fpm_config
|
|||
# Recalculate and store the config file checksum into the app settings
|
||||
#ynh_store_file_checksum "$final_path/CONFIG_FILE"
|
||||
|
||||
# Needed so no manual operation has to be done by user while upgrading
|
||||
# and no need to make "$final_path/version.php" writable
|
||||
if [ -f "$final_path/var/config.ini" ]; then
|
||||
# Change the existing version by the new one taken from the app manifest
|
||||
ynh_replace_string "^version =.*" "version = \"$upstream_version\"" "$final_path/var/config.ini"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue