1#!/bin/bash -e 2 3source "${POST_HELPER:-$(dirname "$(realpath "$0")")/../post-hooks/post-helper}" 4 5# buildroot would fixup owner in its fakeroot script 6if grep -q "^ID=buildroot$" "$TARGET_DIR/etc/os-release"; then 7 exit 0 8fi 9 10echo "Fixing up owner for $TARGET_DIR..." 11 12ID=$(stat --format %u "$SDK_DIR") 13if [ "$ID" -ne 0 ]; then 14 NAME=$(grep -E "^[^:]*:x:$ID:" /etc/passwd | cut -d':' -f1) 15 echo "Fixing up uid=$ID($NAME) to 0(root)..." 16 find . -user $ID -exec chown -h 0:0 {} \; 17fi 18 19if [ -d home ]; then 20 for u in $(ls home/); do 21 ID=$(grep "^$u:" etc/passwd | cut -d':' -f3 || true) 22 [ "$ID" ] || continue 23 echo "Fixing up /home/$u for uid=$ID($u)..." 24 chown -h -R $ID:$ID home/$u 25 done 26fi 27 28ID=$(stat --format %u "$RK_OUTDIR") 29if [ "$(id -u)" -eq 0 -a "$ID" -ne 0 ]; then 30 echo "Fixing up owner for $RK_OUTDIR..." 31 find "$RK_OUTDIR" -user 0 -exec chown -h $ID:$ID {} \; 32fi 33