functions: Add toggle_config function for use in config GUI

toggle_config() toggles the value of a config.

Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
This commit is contained in:
Jonathon Hall 2023-03-24 17:30:27 -04:00
parent 39c655ae1d
commit 468643ee82
No known key found for this signature in database
GPG Key ID: 1E9C3CA91AE25114

View File

@ -314,6 +314,22 @@ replace_config() {
rm -f ${CONFIG_FILE}.tmp
}
invert_yn() {
if [ "$1" = "y" ]; then
echo "n"
else
echo "y"
fi
}
toggle_config() {
CONFIG_FILE="$1"
CONFIG_OPTION="$2"
NEW_SETTING="$(invert_yn "$(load_config_value "$CONFIG_OPTION")")"
set_config "$CONFIG_FILE" "$CONFIG_SETTING" "$NEW_SETTING"
}
# Set a config variable to a given value - replace it if it exists, or add it.
# If added, the variable will be exported.
set_config() {