Fix home dir ownership as a last step (#1036)

because users might be created in various stages (like "network")

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis
2024-09-10 11:34:34 +03:00
committed by GitHub
parent 99029b0705
commit b4695722b4
3 changed files with 28 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
packages:
- name: "kairos-overlay-files"
category: "static"
version: "1.1.48"
version: "1.1.49"

View File

@@ -1,17 +1,6 @@
name: "Fix home directory permissions (kairos issue #2797)"
stages:
initramfs.after:
- name: "Fix permissions"
if: '[ ! -f "/usr/local/.kairos/skip-home-directory-ownership-fix" ]'
network.after:
- name: "Fix home dir ownership"
commands:
- |
# Iterate over users in /etc/passwd and chown their directories
awk -F: '$3 >= 1000 && $6 ~ /^\/home\// {print $1, $6}' /etc/passwd | while read -r user homedir; do
if [ -d "$homedir" ]; then # Check if the home directory exists
echo "Changing ownership of $homedir to $user"
chown -R "$user":"$user" "$homedir"
else
echo "Directory $homedir does not exist for user $user"
fi
done
echo "https://github.com/kairos-io/kairos/issues/2843" > /usr/local/.kairos/skip-home-directory-ownership-fix
- "/usr/bin/fix-home-dir-ownership"

View File

@@ -0,0 +1,24 @@
#!/bin/bash
set -e
SENTINEL_FILE="/usr/local/.kairos/skip-home-directory-ownership-fix"
if [ -f $SENTINEL_FILE ]; then
echo "Skipping ownership fix because sentinel file was found: $SENTINEL_FILE"
exit 0
fi
# Iterate over users in /etc/passwd and chown their directories
awk -F: '$3 >= 1000 && $6 ~ /^\/home\// {print $1, $6}' /etc/passwd | while read -r user homedir; do
if [ -d "$homedir" ]; then # Check if the home directory exists
echo "Changing ownership of $homedir to $user"
chown -R "$user":"$user" "$homedir"
else
echo "Directory $homedir does not exist for user $user"
fi
done
# Write the sentinel file
mkdir -p "$(dirname $SENTINEL_FILE)"
echo "https://github.com/kairos-io/kairos/issues/2843" > $SENTINEL_FILE