From f8d3cb6b33a7078d48b714956f41efca5d6844f8 Mon Sep 17 00:00:00 2001 From: cclohmar Date: Wed, 3 Jun 2026 08:15:58 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20remove=20old=20binary=20before=20rebuild?= =?UTF-8?q?=20=E2=80=94=20prevents=20permission=20denied=20when=20overwrit?= =?UTF-8?q?ing=20root-owned=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - go build can't overwrite a root-owned binary as app user - Added rm -f app before go build in both update and fresh install paths - Also chown the app binary alongside .go cache --- install.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 1b50204..bb3b4c0 100755 --- a/install.sh +++ b/install.sh @@ -96,8 +96,9 @@ 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 + # Ensure build cache and old binary are writable by the app user. + sudo_if chown -R "${APP_USER:-${SUDO_USER:-$(whoami)}}" "${INSTALL_DIR}/.go" "${INSTALL_DIR}/app" 2>/dev/null || true + rm -f app CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w" -o app . else warn "Go not found — downloading pre-built binary..." @@ -204,7 +205,8 @@ if command -v go &>/dev/null; then 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 + sudo_if chown -R "$(whoami):$(whoami)" "${INSTALL_DIR}/.go" "${INSTALL_DIR}/app" 2>/dev/null || true + rm -f app CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w" -o app . else info "Go not found — downloading pre-built binary..."