1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pytition_ynh.git synced 2024-09-03 20:16:08 +02:00
pytition_ynh/scripts/config
2020-11-03 21:48:58 +01:00

74 lines
1.8 KiB
Bash

#!/bin/bash
# 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 ).
#=================================================
# 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
# Reload app service
systemctl reload APP
}