mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] tons of things
This commit is contained in:
parent
caf2a9d6d1
commit
ed0915cf81
1 changed files with 65 additions and 45 deletions
|
@ -99,13 +99,13 @@ ynh_value_set() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ynh_panel_get() {
|
_ynh_panel_get() {
|
||||||
|
set +x
|
||||||
# From settings
|
# From settings
|
||||||
local params_sources
|
local params_sources
|
||||||
params_sources=`python3 << EOL
|
params_sources=`python3 << EOL
|
||||||
import toml
|
import toml
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
with open("/etc/yunohost/apps/vpnclient/config_panel.toml", "r") as f:
|
with open("../config_panel.toml", "r") as f:
|
||||||
file_content = f.read()
|
file_content = f.read()
|
||||||
loaded_toml = toml.loads(file_content, _dict=OrderedDict)
|
loaded_toml = toml.loads(file_content, _dict=OrderedDict)
|
||||||
|
|
||||||
|
@ -114,20 +114,23 @@ for panel_name,panel in loaded_toml.items():
|
||||||
for section_name, section in panel.items():
|
for section_name, section in panel.items():
|
||||||
if isinstance(section, dict):
|
if isinstance(section, dict):
|
||||||
for name, param in section.items():
|
for name, param in section.items():
|
||||||
if isinstance(param, dict) and param.get('source', '') == 'settings':
|
if isinstance(param, dict) and param.get('type', 'string') not in ['info', 'warning', 'error']:
|
||||||
print("%s.%s.%s=%s" %(panel_name, section_name, name, param.get('source', 'settings')))
|
print("%s.%s.%s=%s" %(panel_name, section_name, name, param.get('source', 'settings')))
|
||||||
EOL
|
EOL
|
||||||
`
|
`
|
||||||
for param_source in params_sources
|
for param_source in $params_sources
|
||||||
do
|
do
|
||||||
local _dot_setting=$(echo "$param_source" | cut -d= -f1)
|
local _dot_setting=$(echo "$param_source" | cut -d= -f1)
|
||||||
local _snake_setting="YNH_CONFIG_$(ynh_lowerdot_to_uppersnake $dot_setting)"
|
local _snake_setting="YNH_CONFIG_$(ynh_lowerdot_to_uppersnake $_dot_setting)"
|
||||||
local short_setting=$(echo "$_dot_setting" | cut -d. -f3)
|
local short_setting=$(echo "$_dot_setting" | cut -d. -f3)
|
||||||
local getter="get__${short_setting}"
|
local getter="get__${short_setting}"
|
||||||
local source="$(echo $param_source | cut -d= -f2)"
|
local source="$(echo $param_source | cut -d= -f2)"
|
||||||
|
sources[${short_setting}]="$source"
|
||||||
|
file_hash[${short_setting}]=""
|
||||||
|
dot_settings[${short_setting}]="${_dot_setting}"
|
||||||
|
|
||||||
# Get value from getter if exists
|
# Get value from getter if exists
|
||||||
if type $getter | grep -q '^function$' 2>/dev/null; then
|
if type -t $getter 2>/dev/null | grep -q '^function$' 2>/dev/null; then
|
||||||
old[$short_setting]="$($getter)"
|
old[$short_setting]="$($getter)"
|
||||||
|
|
||||||
# Get value from app settings
|
# Get value from app settings
|
||||||
|
@ -144,26 +147,30 @@ EOL
|
||||||
# Specific case for files (all content of the file is the source)
|
# Specific case for files (all content of the file is the source)
|
||||||
else
|
else
|
||||||
old[$short_setting]="$source"
|
old[$short_setting]="$source"
|
||||||
|
file_hash[$short_setting]="true"
|
||||||
fi
|
fi
|
||||||
|
set +u
|
||||||
|
new[$short_setting]="${!_snake_setting}"
|
||||||
|
set -u
|
||||||
done
|
done
|
||||||
|
set -x
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ynh_panel_apply() {
|
_ynh_panel_apply() {
|
||||||
for short_setting in "${!dot_settings[@]}"
|
for short_setting in "${!old[@]}"
|
||||||
do
|
do
|
||||||
local setter="set__${short_setting}"
|
local setter="set__${short_setting}"
|
||||||
local source="$sources[$short_setting]"
|
local source="${sources[$short_setting]}"
|
||||||
|
if [ "${changed[$short_setting]}" == "true" ] ; then
|
||||||
# Apply setter if exists
|
# Apply setter if exists
|
||||||
if type $setter | grep -q '^function$' 2>/dev/null; then
|
if type -t $setter 2>/dev/null | grep -q '^function$' 2>/dev/null; then
|
||||||
$setter
|
$setter
|
||||||
|
|
||||||
# Copy file in right place
|
# Copy file in right place
|
||||||
elif [[ "$source" == "settings" ]] ; then
|
elif [[ "$source" == "settings" ]] ; then
|
||||||
ynh_app_setting_set $app $short_setting "$new[$short_setting]"
|
ynh_app_setting_set $app $short_setting "${new[$short_setting]}"
|
||||||
|
|
||||||
# Get value from a kind of key/value file
|
# Get value from a kind of key/value file
|
||||||
elif [[ "$source" == *":"* ]]
|
elif [[ "$source" == *":"* ]]
|
||||||
|
@ -171,11 +178,12 @@ _ynh_panel_apply() {
|
||||||
local source_key="$(echo "$source" | cut -d: -f1)"
|
local source_key="$(echo "$source" | cut -d: -f1)"
|
||||||
source_key=${source_key:-$short_setting}
|
source_key=${source_key:-$short_setting}
|
||||||
local source_file="$(echo "$source" | cut -d: -f2)"
|
local source_file="$(echo "$source" | cut -d: -f2)"
|
||||||
ynh_value_set --file="${source_file}" --key="${source_key}" --value="$new[$short_setting]"
|
ynh_value_set --file="${source_file}" --key="${source_key}" --value="${new[$short_setting]}"
|
||||||
|
|
||||||
# Specific case for files (all content of the file is the source)
|
# Specific case for files (all content of the file is the source)
|
||||||
else
|
else
|
||||||
cp "$new[$short_setting]" "$source"
|
cp "${new[$short_setting]}" "$source"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -189,35 +197,43 @@ _ynh_panel_show() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ynh_panel_validate() {
|
_ynh_panel_validate() {
|
||||||
|
set +x
|
||||||
# Change detection
|
# Change detection
|
||||||
local is_error=true
|
local is_error=true
|
||||||
#for changed_status in "${!changed[@]}"
|
#for changed_status in "${!changed[@]}"
|
||||||
for short_setting in "${!dot_settings[@]}"
|
for short_setting in "${!old[@]}"
|
||||||
do
|
do
|
||||||
#TODO file hash
|
|
||||||
file_hash[$setting]=$(sha256sum "$_source" | cut -d' ' -f1)
|
|
||||||
file_hash[$form_setting]=$(sha256sum "${!form_setting}" | cut -d' ' -f1)
|
|
||||||
if [[ "${file_hash[$setting]}" != "${file_hash[$form_setting]}" ]]
|
|
||||||
then
|
|
||||||
changed[$setting]=true
|
|
||||||
fi
|
|
||||||
if [[ "$new[$short_setting]" == "$old[$short_setting]" ]]
|
|
||||||
then
|
|
||||||
changed[$short_setting]=false
|
changed[$short_setting]=false
|
||||||
|
if [ ! -z "${file_hash[${short_setting}]}" ] ; then
|
||||||
|
file_hash[old__$short_setting]=""
|
||||||
|
file_hash[new__$short_setting]=""
|
||||||
|
if [ -f "${old[$short_setting]}" ] ; then
|
||||||
|
file_hash[old__$short_setting]=$(sha256sum "${old[$short_setting]}" | cut -d' ' -f1)
|
||||||
|
fi
|
||||||
|
if [ -f "${new[$short_setting]}" ] ; then
|
||||||
|
file_hash[new__$short_setting]=$(sha256sum "${new[$short_setting]}" | cut -d' ' -f1)
|
||||||
|
if [[ "${file_hash[old__$short_setting]}" != "${file_hash[new__$short_setting]}" ]]
|
||||||
|
then
|
||||||
|
changed[$short_setting]=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
if [[ "${new[$short_setting]}" != "${old[$short_setting]}" ]]
|
||||||
|
then
|
||||||
changed[$short_setting]=true
|
changed[$short_setting]=true
|
||||||
is_error=false
|
is_error=false
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Run validation if something is changed
|
# Run validation if something is changed
|
||||||
if [[ "$is_error" == "false" ]]
|
if [[ "$is_error" == "false" ]]
|
||||||
then
|
then
|
||||||
|
|
||||||
for short_setting in "${!dot_settings[@]}"
|
for short_setting in "${!old[@]}"
|
||||||
do
|
do
|
||||||
local result=""
|
local result=""
|
||||||
if type validate__$short_setting | grep -q '^function$' 2>/dev/null; then
|
if type -t validate__$short_setting | grep -q '^function$' 2>/dev/null; then
|
||||||
result="$(validate__$short_setting)"
|
result="$(validate__$short_setting)"
|
||||||
fi
|
fi
|
||||||
if [ -n "$result" ]
|
if [ -n "$result" ]
|
||||||
|
@ -233,6 +249,7 @@ _ynh_panel_validate() {
|
||||||
then
|
then
|
||||||
ynh_die
|
ynh_die
|
||||||
fi
|
fi
|
||||||
|
set -x
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,9 +270,12 @@ ynh_panel_apply() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_panel_run() {
|
ynh_panel_run() {
|
||||||
declare -A old=()
|
declare -Ag old=()
|
||||||
declare -A changed=()
|
declare -Ag new=()
|
||||||
declare -A file_hash=()
|
declare -Ag changed=()
|
||||||
|
declare -Ag file_hash=()
|
||||||
|
declare -Ag sources=()
|
||||||
|
declare -Ag dot_settings=()
|
||||||
|
|
||||||
ynh_panel_get
|
ynh_panel_get
|
||||||
case $1 in
|
case $1 in
|
||||||
|
|
Loading…
Add table
Reference in a new issue