Fixed #368 allowing mixed case YES values for bastille_zfs_enable
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.
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.
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
Yes, definitely. I just prefer knowing the data is always formatted than to expect everyone to test it correctly every time.
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.
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
}
closing . Thank you for the PR.