Borrow certain /etc/passwd and /etc/group clean-up steps from hhd-dev/rechunk
Some checks failed
Build container image / Build and push image (push) Failing after 3m31s

This commit is contained in:
2025-12-01 17:46:09 +09:00
parent 9e45c8ac23
commit e4afe6923f

View File

@@ -122,6 +122,68 @@ systemctl enable tailscaled
# Remove dnf5 versionlocks
dnf5 versionlock clear
## Handle files that rpm-ostree would normally remove
## Borrowed from: https://github.com/hhd-dev/rechunk/blob/master/1_prune.sh#L33
if [ -f /etc/passwd ]; then
echo
echo Appending the following passwd users to /usr/lib/passwd
out=$(grep -v "root" /etc/passwd)
echo "$out"
echo "$out" >>/usr/lib/passwd
fi
if [ -f /etc/group ]; then
echo
echo Appending the following group entries to /usr/lib/group
out=$(grep -v "root\|wheel" /etc/group)
echo "$out"
echo "$out" >>/usr/lib/group
fi
if [ -f /etc/passwd ] || [ -f /etc/group ]; then
echo
echo "Warning: Make sure processed users and groups are from installed programs!"
fi
# Create defaults for /etc/passwd, /etc/group
cat <<EOT >/etc/passwd
root:x:0:0:root:/root:/bin/bash
EOT
cat <<EOT >/etc/group
root:x:0:
wheel:x:10:
EOT
# Extra lock files created by container processes that might cause issues
rm -rf \
/etc/.pwd.lock \
/etc/passwd- \
/etc/group- \
/etc/shadow- \
/etc/gshadow- \
/etc/subuid- \
/etc/subgid- \
/.dockerenv
# Merge /usr/etc to /etc
# OSTree will error out if both dirs exist
# And rpm-ostree will be confused and use only one of them
if [ -d /usr/etc ]; then
echo
echo WARNING: FOUND /usr/etc. MERGING TO ETC FOR COMPATIBILITY
echo EXPECT PERMISSIONS ISSUES ON THE MERGED PATHS
echo The following files from /usr/etc will be merged to /etc:
tree /usr/etc
echo
rsync -aAX --numeric-ids --checksum --links /usr/etc/ /etc
rm -rf /usr/etc
fi
# Move /etc to /usr/etc
mv /etc /usr/
# ...normal ublue-inspired steps continue.
# Remove tmp files and everything in dirs that make bootc unhappy
rm -rf /tmp/* || true
rm -rf /usr/etc