소스 검색

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 달 전
부모
커밋
8ce9954911
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  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"
 }