Răsfoiți Sursa

fix: chown repo directory after clone/pull when run with sudo

The git clone/pull runs as root under sudo, creating files owned by
root. This prevents the real user from creating .venv inside the repo.
Fix by chowning the entire repo to the real user immediately after
clone/pull.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
tuanchris 4 luni în urmă
părinte
comite
8ce9954911
1 a modificat fișierele cu 9 adăugiri și 0 ștergeri
  1. 9 0
      setup-pi.sh

+ 9 - 0
setup-pi.sh

@@ -232,12 +232,21 @@ ensure_repo() {
         cd "$INSTALL_DIR"
         echo "Pulling latest changes..."
         git pull
+        # Fix ownership after pull (new files may be created as root)
+        if [[ $EUID -eq 0 && -n "$SUDO_USER" ]]; then
+            chown -R "$SUDO_USER:$SUDO_USER" "$INSTALL_DIR"
+        fi
         return
     fi
 
     # Clone the repository
     print_step "Cloning dune-weaver repository..."
     git clone "$REPO_URL" --single-branch "$INSTALL_DIR"
+    # When running as sudo, git clone creates files as root.
+    # Fix ownership so the real user can write to the repo (e.g. create .venv).
+    if [[ $EUID -eq 0 && -n "$SUDO_USER" ]]; then
+        chown -R "$SUDO_USER:$SUDO_USER" "$INSTALL_DIR"
+    fi
     cd "$INSTALL_DIR"
     print_success "Cloned to $INSTALL_DIR"
 }