Files
Public/Bash Scripts/[chown] Container Check/chown_check.sh
2025-04-07 16:53:11 +00:00

39 lines
1.1 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
echo "🔍 Ermittele Benutzerrechte für Docker-Container mit Volumes …"
echo
containers=$(docker ps --format '{{.Names}}')
for container in $containers; do
echo "📦 Container: $container"
# UID/GID aus dem Container lesen
uid=$(docker exec "$container" sh -c 'id -u 2>/dev/null' || echo "❌")
gid=$(docker exec "$container" sh -c 'id -g 2>/dev/null' || echo "❌")
if [[ "$uid" == "❌" || "$gid" == "❌" ]]; then
echo " ❗ Konnte UID/GID nicht ermitteln. Container nutzt evtl. kein POSIX-System oder keine Shell."
continue
fi
# Volumes auslesen
mounts=$(docker inspect "$container" --format '{{range .Mounts}}{{println .Source "->" .Destination}}{{end}}')
if [[ -z "$mounts" ]]; then
echo " Keine gemounteten Host-Verzeichnisse gefunden."
continue
fi
echo " 🧾 UID:GID = $uid:$gid"
echo " 📁 Empfohlene chown-Befehle:"
while read -r line; do
host_path=$(echo "$line" | awk '{print $1}')
container_path=$(echo "$line" | awk '{print $3}')
echo " sudo chown -R $uid:$gid \"$host_path\" # für $container_path"
done <<< "$mounts"
echo
done