if [[ ${hostonly-} ]]; then
# check if other dracut modules already created an entry for root in /etc/shadow
if grep -q '^root:' "$initdir/etc/shadow"; then
- # replace root password in the existing entry in etc/shadow
- # root password from host takes precedence over root password set by systemd-sysuser in hostonly mode
- root_password=$(grep '^root:' "${dracutsysrootdir-}"/etc/shadow | cut -d':' -f2)
- sed -i "/^root:/s/:[^:]*:/:$root_password:/" "$initdir/etc/shadow"
- else
- # create a new entry for root in /etc/shadow
- grep '^root:' "${dracutsysrootdir-}"/etc/shadow >> "$initdir/etc/shadow"
+ grep -v '^root:' "$initdir/etc/shadow" > "$initdir/etc/shadow-"
+ mv "$initdir/etc/shadow-" "$initdir/etc/shadow"
fi
+ # replace root password in the existing entry in etc/shadow
+ # root password from host takes precedence over root password set by systemd-sysuser in hostonly mode
+ # create a new entry for root in /etc/shadow
+ grep '^root:' "${dracutsysrootdir-}"/etc/shadow >> "$initdir/etc/shadow"
fi
# install our scripts and hooks
ln -s / "$TESTDIR"/sysroot
test_dracut --sysroot "$TESTDIR"/sysroot
+
+ if grep -q '^root:' /etc/shadow; then
+ if ! grep -q '^root:' "$TESTDIR"/initrd/dracut.*/initramfs/etc/shadow; then
+ echo "Entry for root in /etc/shadow is missing, failing the test."
+ rm "$TESTDIR"/initramfs.testing
+ fi
+
+ root_password=$(grep '^root:' "/etc/shadow" | cut -d':' -f2)
+ initramfs_root_password=$(grep '^root:' "$TESTDIR"/initrd/dracut.*/initramfs/etc/shadow | cut -d':' -f2)
+
+ if [ "$root_password" != "$initramfs_root_password" ]; then
+ echo "The password for root does not match, failing the test."
+ rm "$TESTDIR"/initramfs.testing
+ fi
+ fi
}
# shellcheck disable=SC1090