Skip to content

Commit 0fc6697

Browse files
ajorpheusigorpecovnik
authored andcommitted
fix(manage_zsh): abort shell change if zsh package install fails
Previously, /etc/default/useradd, /etc/adduser.conf, and /etc/passwd were all updated to use /bin/zsh before pkg_install was called. If the install failed (e.g. package unavailable, no network), /bin/zsh would be set as the shell for root and all users even though it was never installed and not listed in /etc/shells. pam_shells blocks all authentication (including SSH public key auth) for any user whose shell is not present in /etc/shells, effectively locking every user out of the system with no obvious recovery path. Fix: call pkg_install first and abort with an error message if it fails, so shell config files and /etc/passwd are only modified after a successful install.
1 parent 68f4b29 commit 0fc6697

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/modules/system/manage_zsh.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ function manage_zsh() {
1616

1717
if [[ "$1" == "enable" ]]; then
1818

19-
sed -i "s|^SHELL=.*|SHELL=/bin/zsh|" /etc/default/useradd
20-
sed -i -E "s|(^\|#)DSHELL=.*|DSHELL=/bin/zsh|" /etc/adduser.conf
21-
2219
pkg_update
2320

24-
# install
25-
pkg_install armbian-zsh zsh-common zsh tmux
21+
# install zsh before changing any shells — if install fails, abort
22+
# to avoid setting an invalid shell that locks all users out via pam_shells
23+
if ! pkg_install armbian-zsh zsh-common zsh tmux; then
24+
echo "Failed to install zsh packages; shell not changed"
25+
return 1
26+
fi
27+
28+
sed -i "s|^SHELL=.*|SHELL=/bin/zsh|" /etc/default/useradd
29+
sed -i -E "s|(^\|#)DSHELL=.*|DSHELL=/bin/zsh|" /etc/adduser.conf
2630

2731
update_skel
2832

0 commit comments

Comments
 (0)