bastille icon indicating copy to clipboard operation
bastille copied to clipboard

Fixed #368 allowing mixed case YES values for bastille_zfs_enable

Open indgy opened this issue 4 years ago • 5 comments

It took me quite a while to realise the bastille_zfs_enable value had to be UPPERCASE. This adds a function to capitalise any case 'yes' value, it also avoids touching the logical if statements in the various files. I've added the necessary code in any file where bastille_zfs_enable is used. It may be preferred to source a normalise.sh file at the top of every script, just after sourcing bastille.conf to avoid this cruft and ensure it's called in any new scripts, if the normalise method is preferred I'll submit another fix.

indgy avatar Apr 23 '21 12:04 indgy

After leaving the last comment, I looked at what it would take to do this in one place instead of many. The problem was that we were running the command scripts with exec, so they all had to include the common script and conf file. I created PR #397 to address that.

chriswells0 avatar Jun 12 '21 17:06 chriswells0

Hello, another suggested simple solution is to use [Yy][Ee][Ss] instead:

$ case yes in [Yy][Ee][Ss]) echo 'WORKS';; esac
WORKS
$ case YES in [Yy][Ee][Ss]) echo 'WORKS';; esac
WORKS
$ case yEs in [Yy][Ee][Ss]) echo 'WORKS';; esac
WORKS
$ case YeS in [Yy][Ee][Ss]) echo 'WORKS';; esac
WORKS

Regards

JRGTH avatar Jun 12 '21 17:06 JRGTH

Yes, definitely. I just prefer knowing the data is always formatted than to expect everyone to test it correctly every time.

chriswells0 avatar Jun 12 '21 18:06 chriswells0

I'd just look to see what FreeBSD does for rc.conf. sysrc can use both "YES" or "yes" when setting knobs in rc.conf. I wouldn't reinvent the wheel, just do what the project does.

X86BSD avatar Apr 09 '22 01:04 X86BSD

I'd just look to see what FreeBSD does for rc.conf. sysrc can use both "YES" or "yes" when setting knobs in rc.conf. I wouldn't reinvent the wheel, just do what the project does.

From /etc/rc.subr

#
# checkyesno var
#       Test $1 variable, and warn if not set to YES or NO.
#       Return 0 if it's "yes" (et al), nonzero otherwise.
#
checkyesno()
{
        eval _value=\$${1}
        debug "checkyesno: $1 is set to $_value."
        case $_value in

                #       "yes", "true", "on", or "1"
        [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
                return 0
                ;;

                #       "no", "false", "off", or "0"
        [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
                return 1
                ;;
        *)
                warn "\$${1} is not set properly - see rc.conf(5)."
                return 1
                ;;
        esac
}

bdrewery avatar Aug 08 '22 18:08 bdrewery

closing . Thank you for the PR.

bmac2 avatar Oct 18 '23 16:10 bmac2