Neues Chown Script

This commit is contained in:
2025-04-07 16:53:11 +00:00
parent b4cdd0272c
commit 54f0d6b9e4

View File

@@ -0,0 +1,38 @@
#!/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