You could probably simplify it by just an if/elif/else instead of having to indent a separate if/else in the first else block, but, I don't think it is a big deal
Reviewed by: allanjude
Sorry for being late to the party
Actually, it can be just:
if [ -z "$ROOTPASS_ENC$ROOTPASS_PLAIN" ]; then
As an aside …
You would want to avoid passing greater than 4 args to [ because many (all?) implementations only combinatorically guarantee syntactically correct results for handling up to 4 arguments (that for example passing 20 arguments, chaining many “-a” arguments, is not deterministically tested whereas there are test units for every possible combination up to — and including — 4 arguments). So using && was actually more correct from a portability standpoint, and I cannot condone the change to use -a.
However, the whole discussion of && vs [ … -a … ] is registered moot when you realize that you can just expand both variables into a single string and then test the results. If either string is non-NULL, the desired results are achieved without having to resort to using either && or -a
Perhaps this echo won't cause any problems (nobody sets their root password to -e and -n, and nobody is going to run this with a shell with different echo behaviour?) but something like printf '%s\n' "$ROOTPASS_PLAIN" is more obviously correct.
An alternative is something like
pw -R $BSDINSTALL_CHROOT usermod root -h 0 <<END $ROOTPASS_PLAIN END
but that has the ugliness of a here-document.
I tried to break it, and could not:
> cat test.sh #!/bin/sh echo -nooo
> sh -x ./test.sh + echo -nooo -nooo
> cat test.sh #!/bin/sh echo -nooo lkjsldjf
> sh -x ./test.sh + echo -nooo lkjsldjf -nooo lkjsldjf
Anything else I should try?