Skip to content

Commit 755dbe1

Browse files
lugouesKerambad
andcommitted
Apply suggestions from code review
Co-authored-by: Marek Schütze <[email protected]>
1 parent 99a9576 commit 755dbe1

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

hooks/tailscale

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,21 @@ fi
4343
# whether or not we requested tailscale ssh support at setup time, which is
4444
# redundant, but we at least avoid doing it when dropbear-initramfs is present
4545
# as it will prevent that from working.
46-
if [ ! -e "/etc/dropbear/initramfs" ]; then
47-
# create home
48-
home=$(mktemp -d "$DESTDIR/root-XXXXXX")
49-
chmod 0700 "$home"
50-
mkdir -m0700 "$home/.ssh"
51-
52-
#Create user/group required for login
53-
for x in passwd group; do echo "$x: files"; done >"$DESTDIR/etc/nsswitch.conf"
54-
echo "root:x:0:0:root:/root:/bin/sh" > "$DESTDIR/etc/passwd"
55-
echo "root:!:19808:0:99999:7:::" > "$DESTDIR/etc/shadow"
56-
echo "root:x:0:" >"$DESTDIR/etc/group"
46+
if home=$(grep -s '^root:' "$DESTDIR/etc/passwd" | cut -d: -f6) && [ -n "$home" ]; then
47+
# Ensure /etc/passwd points at password stored in /etc/shadow
48+
sed -Ei -e 's/^root:[^:]+/root:x/' "$DESTDIR/etc/passwd"
49+
else
50+
# create home
51+
home=$(mktemp -d "$DESTDIR/root-XXXXXX")
52+
chmod 0700 "$home"
53+
mkdir -m0700 "$home/.ssh"
54+
home=${home#"$DESTDIR"}
5755
fi
5856

57+
#Create user/group required for login
58+
for x in passwd group; do echo "$x: files"; done >"$DESTDIR/etc/nsswitch.conf"
59+
echo "root:x:0:0:root:$home:/bin/sh" > "$DESTDIR/etc/passwd"
60+
echo "root:!:19808:0:99999:7:::" > "$DESTDIR/etc/shadow"
61+
echo "root:x:0:" >"$DESTDIR/etc/group"
62+
5963
exit 0

0 commit comments

Comments
 (0)