Bladeren bron

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 maanden geleden
bovenliggende
commit
8ce9954911
1 gewijzigde bestanden met toevoegingen van 9 en 0 verwijderingen
  1. 9 0
      setup-pi.sh

+ 9 - 0
setup-pi.sh

@@ -232,12 +232,21 @@ ensure_repo() {
         cd "$INSTALL_DIR"
         cd "$INSTALL_DIR"
         echo "Pulling latest changes..."
         echo "Pulling latest changes..."
         git pull
         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
         return
     fi
     fi
 
 
     # Clone the repository
     # Clone the repository
     print_step "Cloning dune-weaver repository..."
     print_step "Cloning dune-weaver repository..."
     git clone "$REPO_URL" --single-branch "$INSTALL_DIR"
     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"
     cd "$INSTALL_DIR"
     print_success "Cloned to $INSTALL_DIR"
     print_success "Cloned to $INSTALL_DIR"
 }
 }