mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Better upgrade management
This commit is contained in:
parent
edef077c74
commit
c5885000ec
2 changed files with 22 additions and 3 deletions
|
@ -326,12 +326,25 @@ ynh_bind_or_cp() {
|
|||
ynh_store_file_checksum () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=f
|
||||
local -A args_array=( [f]=file= )
|
||||
local -A args_array=( [f]=file= [u]=update_only )
|
||||
local file
|
||||
local update_only
|
||||
update_only="${update_only:-0}"
|
||||
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
||||
|
||||
# If update only, we don't save the new checksum if no old checksum exist
|
||||
if [ $update_only -eq 1 ] ; then
|
||||
local checksum_value=$(ynh_app_setting_get --app=$app --key=$checksum_setting_name)
|
||||
if [ -z "${checksum_value}" ] ; then
|
||||
unset backup_file_checksum
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
ynh_app_setting_set --app=$app --key=$checksum_setting_name --value=$(md5sum "$file" | cut --delimiter=' ' --fields=1)
|
||||
|
||||
# If backup_file_checksum isn't empty, ynh_backup_if_checksum_is_different has made a backup
|
||||
|
|
|
@ -96,10 +96,14 @@ _ynh_app_config_apply() {
|
|||
fi
|
||||
local source_file="$(echo "$source" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
||||
if [[ "${!short_setting}" == "" ]] ; then
|
||||
ynh_backup_if_checksum_is_different --file="$source_file"
|
||||
rm -f "$source_file"
|
||||
ynh_delete_file_checksum --file="$source_file" --update_only
|
||||
ynh_print_info "File '$source_file' removed"
|
||||
else
|
||||
ynh_backup_if_checksum_is_different --file="$source_file"
|
||||
cp "${!short_setting}" "$source_file"
|
||||
ynh_store_file_checksum --file="$source_file" --update_only
|
||||
ynh_print_info "File '$source_file' overwrited with ${!short_setting}"
|
||||
fi
|
||||
|
||||
|
@ -114,7 +118,9 @@ _ynh_app_config_apply() {
|
|||
ynh_die "For technical reasons, multiline text '${short_setting}' can't be stored automatically in a variable file, you have to create custom getter/setter"
|
||||
fi
|
||||
local source_file="$(echo "$source" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
||||
ynh_backup_if_checksum_is_different --file="$source_file"
|
||||
echo "${!short_setting}" > "$source_file"
|
||||
ynh_store_file_checksum --file="$source_file" --update_only
|
||||
ynh_print_info "File '$source_file' overwrited with the content you provieded in '${short_setting}' question"
|
||||
|
||||
# Set value into a kind of key/value file
|
||||
|
@ -122,10 +128,10 @@ _ynh_app_config_apply() {
|
|||
local source_key="$(echo "$source" | cut -d: -f1)"
|
||||
source_key=${source_key:-$short_setting}
|
||||
local source_file="$(echo "$source" | cut -d: -f2 | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
||||
|
||||
|
||||
ynh_backup_if_checksum_is_different --file="$source_file"
|
||||
ynh_set_var --file="${source_file}" --key="${source_key}" --value="${!short_setting}"
|
||||
ynh_store_file_checksum --file="$source_file"
|
||||
ynh_store_file_checksum --file="$source_file" --update_only
|
||||
|
||||
# We stored the info in settings in order to be able to upgrade the app
|
||||
ynh_app_setting_set $app $short_setting "${!short_setting}"
|
||||
|
|
Loading…
Add table
Reference in a new issue