mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
config panel: rename source into bind
This commit is contained in:
parent
4f0df2bcfe
commit
c55b96b94b
2 changed files with 44 additions and 43 deletions
|
@ -21,15 +21,16 @@ for panel_name, panel in loaded_toml.items():
|
||||||
print(';'.join([
|
print(';'.join([
|
||||||
name,
|
name,
|
||||||
param.get('type', 'string'),
|
param.get('type', 'string'),
|
||||||
param.get('source', 'settings' if param.get('type', 'string') != 'file' else '')
|
param.get('bind', 'settings' if param.get('type', 'string') != 'file' else '')
|
||||||
]))
|
]))
|
||||||
EOL
|
EOL
|
||||||
`
|
`
|
||||||
for line in $lines
|
for line in $lines
|
||||||
do
|
do
|
||||||
IFS=';' read short_setting type source <<< "$line"
|
# Split line into short_setting, type and bind
|
||||||
|
IFS=';' read short_setting type bind <<< "$line"
|
||||||
local getter="get__${short_setting}"
|
local getter="get__${short_setting}"
|
||||||
sources[${short_setting}]="$source"
|
binds[${short_setting}]="$bind"
|
||||||
types[${short_setting}]="$type"
|
types[${short_setting}]="$type"
|
||||||
file_hash[${short_setting}]=""
|
file_hash[${short_setting}]=""
|
||||||
formats[${short_setting}]=""
|
formats[${short_setting}]=""
|
||||||
|
@ -38,36 +39,36 @@ EOL
|
||||||
old[$short_setting]="$($getter)"
|
old[$short_setting]="$($getter)"
|
||||||
formats[${short_setting}]="yaml"
|
formats[${short_setting}]="yaml"
|
||||||
|
|
||||||
elif [[ "$source" == "" ]] ; then
|
elif [[ "$bind" == "" ]] ; then
|
||||||
old[$short_setting]="YNH_NULL"
|
old[$short_setting]="YNH_NULL"
|
||||||
|
|
||||||
# Get value from app settings or from another file
|
# Get value from app settings or from another file
|
||||||
elif [[ "$type" == "file" ]] ; then
|
elif [[ "$type" == "file" ]] ; then
|
||||||
if [[ "$source" == "settings" ]] ; then
|
if [[ "$bind" == "settings" ]] ; then
|
||||||
ynh_die "File '${short_setting}' can't be stored in settings"
|
ynh_die "File '${short_setting}' can't be stored in settings"
|
||||||
fi
|
fi
|
||||||
old[$short_setting]="$(ls $(echo $source | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/) 2> /dev/null || echo YNH_NULL)"
|
old[$short_setting]="$(ls $(echo $bind | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/) 2> /dev/null || echo YNH_NULL)"
|
||||||
file_hash[$short_setting]="true"
|
file_hash[$short_setting]="true"
|
||||||
|
|
||||||
# Get multiline text from settings or from a full file
|
# Get multiline text from settings or from a full file
|
||||||
elif [[ "$type" == "text" ]] ; then
|
elif [[ "$type" == "text" ]] ; then
|
||||||
if [[ "$source" == "settings" ]] ; then
|
if [[ "$bind" == "settings" ]] ; then
|
||||||
old[$short_setting]="$(ynh_app_setting_get $app $short_setting)"
|
old[$short_setting]="$(ynh_app_setting_get $app $short_setting)"
|
||||||
elif [[ "$source" == *":"* ]] ; then
|
elif [[ "$bind" == *":"* ]] ; then
|
||||||
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"
|
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"
|
||||||
else
|
else
|
||||||
old[$short_setting]="$(cat $(echo $source | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/) 2> /dev/null || echo YNH_NULL)"
|
old[$short_setting]="$(cat $(echo $bind | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/) 2> /dev/null || echo YNH_NULL)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get value from a kind of key/value file
|
# Get value from a kind of key/value file
|
||||||
else
|
else
|
||||||
if [[ "$source" == "settings" ]] ; then
|
if [[ "$bind" == "settings" ]] ; then
|
||||||
source=":/etc/yunohost/apps/$app/settings.yml"
|
bind=":/etc/yunohost/apps/$app/settings.yml"
|
||||||
fi
|
fi
|
||||||
local source_key="$(echo "$source" | cut -d: -f1)"
|
local bind_key="$(echo "$bind" | cut -d: -f1)"
|
||||||
source_key=${source_key:-$short_setting}
|
bind_key=${bind_key:-$short_setting}
|
||||||
local source_file="$(echo "$source" | cut -d: -f2 | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
local bind_file="$(echo "$bind" | cut -d: -f2 | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
||||||
old[$short_setting]="$(ynh_read_var_in_file --file="${source_file}" --key="${source_key}")"
|
old[$short_setting]="$(ynh_read_var_in_file --file="${bind_file}" --key="${bind_key}")"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -79,63 +80,63 @@ _ynh_app_config_apply() {
|
||||||
for short_setting in "${!old[@]}"
|
for short_setting in "${!old[@]}"
|
||||||
do
|
do
|
||||||
local setter="set__${short_setting}"
|
local setter="set__${short_setting}"
|
||||||
local source="${sources[$short_setting]}"
|
local bind="${binds[$short_setting]}"
|
||||||
local type="${types[$short_setting]}"
|
local type="${types[$short_setting]}"
|
||||||
if [ "${changed[$short_setting]}" == "true" ] ; then
|
if [ "${changed[$short_setting]}" == "true" ] ; then
|
||||||
# Apply setter if exists
|
# Apply setter if exists
|
||||||
if type -t $setter 2>/dev/null | grep -q '^function$' 2>/dev/null; then
|
if type -t $setter 2>/dev/null | grep -q '^function$' 2>/dev/null; then
|
||||||
$setter
|
$setter
|
||||||
|
|
||||||
elif [[ "$source" == "" ]] ; then
|
elif [[ "$bind" == "" ]] ; then
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Save in a file
|
# Save in a file
|
||||||
elif [[ "$type" == "file" ]] ; then
|
elif [[ "$type" == "file" ]] ; then
|
||||||
if [[ "$source" == "settings" ]] ; then
|
if [[ "$bind" == "settings" ]] ; then
|
||||||
ynh_die "File '${short_setting}' can't be stored in settings"
|
ynh_die "File '${short_setting}' can't be stored in settings"
|
||||||
fi
|
fi
|
||||||
local source_file="$(echo "$source" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
local bind_file="$(echo "$bind" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
||||||
if [[ "${!short_setting}" == "" ]] ; then
|
if [[ "${!short_setting}" == "" ]] ; then
|
||||||
ynh_backup_if_checksum_is_different --file="$source_file"
|
ynh_backup_if_checksum_is_different --file="$bind_file"
|
||||||
rm -f "$source_file"
|
rm -f "$bind_file"
|
||||||
ynh_delete_file_checksum --file="$source_file" --update_only
|
ynh_delete_file_checksum --file="$bind_file" --update_only
|
||||||
ynh_print_info "File '$source_file' removed"
|
ynh_print_info "File '$bind_file' removed"
|
||||||
else
|
else
|
||||||
ynh_backup_if_checksum_is_different --file="$source_file"
|
ynh_backup_if_checksum_is_different --file="$bind_file"
|
||||||
cp "${!short_setting}" "$source_file"
|
cp "${!short_setting}" "$bind_file"
|
||||||
ynh_store_file_checksum --file="$source_file" --update_only
|
ynh_store_file_checksum --file="$bind_file" --update_only
|
||||||
ynh_print_info "File '$source_file' overwrited with ${!short_setting}"
|
ynh_print_info "File '$bind_file' overwrited with ${!short_setting}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Save value in app settings
|
# Save value in app settings
|
||||||
elif [[ "$source" == "settings" ]] ; then
|
elif [[ "$bind" == "settings" ]] ; then
|
||||||
ynh_app_setting_set $app $short_setting "${!short_setting}"
|
ynh_app_setting_set $app $short_setting "${!short_setting}"
|
||||||
ynh_print_info "Configuration key '$short_setting' edited in app settings"
|
ynh_print_info "Configuration key '$short_setting' edited in app settings"
|
||||||
|
|
||||||
# Save multiline text in a file
|
# Save multiline text in a file
|
||||||
elif [[ "$type" == "text" ]] ; then
|
elif [[ "$type" == "text" ]] ; then
|
||||||
if [[ "$source" == *":"* ]] ; then
|
if [[ "$bind" == *":"* ]] ; then
|
||||||
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"
|
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
|
fi
|
||||||
local source_file="$(echo "$source" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
local bind_file="$(echo "$bind" | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
||||||
ynh_backup_if_checksum_is_different --file="$source_file"
|
ynh_backup_if_checksum_is_different --file="$bind_file"
|
||||||
echo "${!short_setting}" > "$source_file"
|
echo "${!short_setting}" > "$bind_file"
|
||||||
ynh_store_file_checksum --file="$source_file" --update_only
|
ynh_store_file_checksum --file="$bind_file" --update_only
|
||||||
ynh_print_info "File '$source_file' overwrited with the content you provieded in '${short_setting}' question"
|
ynh_print_info "File '$bind_file' overwrited with the content you provieded in '${short_setting}' question"
|
||||||
|
|
||||||
# Set value into a kind of key/value file
|
# Set value into a kind of key/value file
|
||||||
else
|
else
|
||||||
local source_key="$(echo "$source" | cut -d: -f1)"
|
local bind_key="$(echo "$bind" | cut -d: -f1)"
|
||||||
source_key=${source_key:-$short_setting}
|
bind_key=${bind_key:-$short_setting}
|
||||||
local source_file="$(echo "$source" | cut -d: -f2 | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
local bind_file="$(echo "$bind" | cut -d: -f2 | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)"
|
||||||
|
|
||||||
ynh_backup_if_checksum_is_different --file="$source_file"
|
ynh_backup_if_checksum_is_different --file="$bind_file"
|
||||||
ynh_write_var_in_file --file="${source_file}" --key="${source_key}" --value="${!short_setting}"
|
ynh_write_var_in_file --file="${bind_file}" --key="${bind_key}" --value="${!short_setting}"
|
||||||
ynh_store_file_checksum --file="$source_file" --update_only
|
ynh_store_file_checksum --file="$bind_file" --update_only
|
||||||
|
|
||||||
# We stored the info in settings in order to be able to upgrade the app
|
# We stored the info in settings in order to be able to upgrade the app
|
||||||
ynh_app_setting_set $app $short_setting "${!short_setting}"
|
ynh_app_setting_set $app $short_setting "${!short_setting}"
|
||||||
ynh_print_info "Configuration key '$source_key' edited into $source_file"
|
ynh_print_info "Configuration key '$bind_key' edited into $bind_file"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -251,7 +252,7 @@ ynh_app_config_run() {
|
||||||
declare -Ag old=()
|
declare -Ag old=()
|
||||||
declare -Ag changed=()
|
declare -Ag changed=()
|
||||||
declare -Ag file_hash=()
|
declare -Ag file_hash=()
|
||||||
declare -Ag sources=()
|
declare -Ag binds=()
|
||||||
declare -Ag types=()
|
declare -Ag types=()
|
||||||
declare -Ag formats=()
|
declare -Ag formats=()
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@ class ConfigPanel:
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"properties": ["ask", "type", "source", "help", "example",
|
"properties": ["ask", "type", "bind", "help", "example",
|
||||||
"style", "icon", "placeholder", "visible",
|
"style", "icon", "placeholder", "visible",
|
||||||
"optional", "choices", "yes", "no", "pattern",
|
"optional", "choices", "yes", "no", "pattern",
|
||||||
"limit", "min", "max", "step", "accept", "redact"],
|
"limit", "min", "max", "step", "accept", "redact"],
|
||||||
|
|
Loading…
Add table
Reference in a new issue