From 433b5a4ed806b87d8d047ebffa84ad1374150468 Mon Sep 17 00:00:00 2001 From: cclohmar Date: Wed, 3 Jun 2026 08:14:18 +0000 Subject: [PATCH] fix: chown .go build cache before build to prevent permission errors - Build cache may be root-owned from previous builds - Added sudo_if chown before both update and fresh build steps - Prevents 'permission denied' on go mod cache writes --- install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/install.sh b/install.sh index 3ac7a1a..1b50204 100755 --- a/install.sh +++ b/install.sh @@ -96,6 +96,8 @@ if [ "${1:-}" = "-update" ]; then export GOPATH="${INSTALL_DIR}/.go" export GOCACHE="${INSTALL_DIR}/.go/build" mkdir -p "${GOMODCACHE}" "${GOCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" "${GOCACHE}" + # Ensure the build cache is owned by the app user (was root from earlier builds). + sudo_if chown -R "${APP_USER:-${SUDO_USER:-$(whoami)}}" "${INSTALL_DIR}/.go" 2>/dev/null || true CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w" -o app . else warn "Go not found — downloading pre-built binary..." @@ -201,6 +203,8 @@ if command -v go &>/dev/null; then export GOPATH="${INSTALL_DIR}/.go" export GOCACHE="${INSTALL_DIR}/.go/build" mkdir -p "${GOMODCACHE}" "${GOCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" "${GOCACHE}" + # Ensure cache is owned by the app user. + sudo_if chown -R "$(whoami):$(whoami)" "${INSTALL_DIR}/.go" 2>/dev/null || true CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w" -o app . else info "Go not found — downloading pre-built binary..."