chibisafe_ynh/scripts/config

75 lines
1.8 KiB
Text
Raw Normal View History

2020-11-03 15:28:45 -05:00
#!/bin/bash
2020-11-03 15:48:58 -05:00
# In most simple cases, you don't need a config script (or just to reload services).
# With a simple config_panel.toml, you can write in the app settings, in the
# upstream config file or replace complete files (logo ...).
# The config scripts allows you to go further, to handle specific cases
# (validation of several interdependent fields, specific getter/setter for a value,
# pre-loading of config type .cube ).
2020-11-03 15:28:45 -05:00
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__user() {
if [ -s $final_path/keys/credentials ]
then
sed -n 1p $final_path/keys/credentials
fi
}
get__passphrase() {
if [ -s $final_path/keys/credentials ]
then
sed -n 2p $final_path/keys/credentials
fi
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
validate__user() {
[[ -n "$passphrase" && -z "$user" ]] &&
echo 'A Username is needed when you suggest a Password'
}
validate__passphrase() {
[[ -n "$user" && -z "$passphrase" ]] &&
echo 'A Password is needed when you suggest a Username'
}
#=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__user() {
if [ -z "$user" ]
then
echo "$user\n$passphrase" > $final_path/keys/credentials
else
echo "" > $final_path/keys/credentials
fi
}
set__passphrase() {
:
}
#=================================================
# OVERWRITING APPLY STEP
#=================================================
ynh_panel_apply() {
_ynh_panel_apply
2020-11-03 15:48:58 -05:00
# Reload app service
2020-11-03 15:28:45 -05:00
systemctl reload APP
}