Changeset View
Standalone View
usr.sbin/bsdinstall/scripts/rootpass
Show All 27 Lines | |||||
BSDCFG_SHARE="/usr/share/bsdconfig" | BSDCFG_SHARE="/usr/share/bsdconfig" | ||||
. $BSDCFG_SHARE/common.subr || exit 1 | . $BSDCFG_SHARE/common.subr || exit 1 | ||||
clear | clear | ||||
echo "$OSNAME Installer" | echo "$OSNAME Installer" | ||||
echo "========================" | echo "========================" | ||||
echo | echo | ||||
if [ -n "$ROOTPASS_ENC" ]; then | |||||
printf '%s\n' "$ROOTPASS_ENC" | pw -R $BSDINSTALL_CHROOT usermod root -H 0 | |||||
elif [ -n "$ROOTPASS_PLAIN" ]; then | |||||
printf '%s\n' "$ROOTPASS_PLAIN" | pw -R $BSDINSTALL_CHROOT usermod root -h 0 | |||||
jilles: Perhaps this `echo` won't cause any problems (nobody sets their root password to `-e` and `-n`… | |||||
Done Inline ActionsI tried to break it, and could not: > cat test.sh #!/bin/sh echo -nooo > sh -x ./test.sh + echo -nooo -nooo Try #2: > cat test.sh #!/bin/sh echo -nooo lkjsldjf > sh -x ./test.sh + echo -nooo lkjsldjf -nooo lkjsldjf Anything else I should try? brd: I tried to break it, and could not:
```
> cat test.sh
#!/bin/sh
echo -nooo
```
```
> sh… | |||||
else | |||||
echo "Please select a password for the system management account (root):" | echo "Please select a password for the system management account (root):" | ||||
echo "Typed characters will not be visible." | echo "Typed characters will not be visible." | ||||
Done Inline ActionsThis can just be if [ -z "$ROOTPASS_ENC" -a -z "$ROOTPASS_PLAIN" ]; then kithrup_mac.com: This can just be
```
if [ -z "$ROOTPASS_ENC" -a -z "$ROOTPASS_PLAIN" ]; then
```
| |||||
Done Inline ActionsActually, 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 dteske: Actually, it can be just:
```
if [ -z "$ROOTPASS_ENC$ROOTPASS_PLAIN" ]; then
```
As an aside… | |||||
Done Inline ActionsOoooh clever and optimized, I like it. kithrup_mac.com: Ooooh clever and optimized, I like it. | |||||
Done Inline ActionsAlso see the BUGS section of test(1).. I chose to go with the way Allan suggested since it looks cleaner to me. brd: Also see the BUGS section of test(1)..
I chose to go with the way Allan suggested since it… | |||||
chroot $BSDINSTALL_CHROOT passwd root 2>&1 | chroot $BSDINSTALL_CHROOT passwd root 2>&1 | ||||
fi |
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
but that has the ugliness of a here-document.