From 468643ee829ac40dd900258235dac1e02cdfd27a Mon Sep 17 00:00:00 2001 From: Jonathon Hall Date: Fri, 24 Mar 2023 17:30:27 -0400 Subject: [PATCH] functions: Add toggle_config function for use in config GUI toggle_config() toggles the value of a config. Signed-off-by: Jonathon Hall --- initrd/etc/functions | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/initrd/etc/functions b/initrd/etc/functions index 007c2c1f..f3cf513d 100755 --- a/initrd/etc/functions +++ b/initrd/etc/functions @@ -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() {