From 54f0d6b9e4fcb60a07116c29304564254ce4942d Mon Sep 17 00:00:00 2001 From: eldov Date: Mon, 7 Apr 2025 16:53:11 +0000 Subject: [PATCH] Neues Chown Script --- .../[chown] Container Check/chown_check.sh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Bash Scripts/[chown] Container Check/chown_check.sh b/Bash Scripts/[chown] Container Check/chown_check.sh index e69de29..e26f717 100644 --- a/Bash Scripts/[chown] Container Check/chown_check.sh +++ b/Bash Scripts/[chown] Container Check/chown_check.sh @@ -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