From 8c23cc631c718b497be3417f912b3b6766424446 Mon Sep 17 00:00:00 2001 From: Keith Smith Date: Sat, 31 Oct 2026 08:39:09 -0600 Subject: [PATCH] Fix install.sh failing with permission denied creating the venv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EVECTION_HOME (the venv's parent directory, e.g. /opt/evection) was never chowned to the service user — only the app checkout inside it was — so venv creation failed with Permission denied whenever EVECTION_HOME was created by root before running the script (the documented quick-install steps do exactly that: mkdir + git clone as root, then run install.sh). Also run the release-tag git fetch/checkout as root instead of sudo -u $EVECTION_USER in both install.sh and upgrade.sh: the service user has no reason to have its own git credentials configured, so running as it just means the private repo's auth prompt hangs the script (as seen on this install) or silently fails. Root already has working credentials from the initial clone. Added GIT_TERMINAL_PROMPT=0 so a credential problem fails fast instead of hanging on a prompt either way. Co-Authored-By: Claude Sonnet 5 --- scripts/install.sh | 22 +++++++++++++++++----- scripts/upgrade.sh | 13 +++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 330b4cc..fd48b03 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -61,23 +61,35 @@ if ! id -u "$EVECTION_USER" >/dev/null 2>&1; then else echo "==> System user '$EVECTION_USER' already exists" fi -chown -R "$EVECTION_USER:$EVECTION_USER" "$APP_DIR" # --- 2b. Pin to the latest release tag (if any exist) ---------------- - +# +# Run as root (this script already requires it), not as $EVECTION_USER: +# this repo was typically cloned by root (or whoever has git credentials +# configured), and the service user has no reason to have its own git +# auth set up. GIT_TERMINAL_PROMPT=0 means a credential problem fails +# fast instead of hanging the install on a silent username/password +# prompt. if [ -d "$APP_DIR/.git" ]; then - sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" fetch --tags --force || true - LATEST_TAG="$(sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" tag --sort=-creatordate | head -n1)" + GIT_TERMINAL_PROMPT=0 git -C "$APP_DIR" fetch --tags --force || true + LATEST_TAG="$(git -C "$APP_DIR" tag --sort=-creatordate | head -n1)" if [ -n "$LATEST_TAG" ]; then echo "==> Checking out latest release: $LATEST_TAG" # Detached HEAD, not a branch checkout — matches scripts/upgrade.sh, # which only ever deploys a tagged release, never a branch tip. - sudo -u "$EVECTION_USER" -H git -C "$APP_DIR" checkout --quiet --detach "$LATEST_TAG" + git -C "$APP_DIR" checkout --quiet --detach "$LATEST_TAG" else echo "==> No release tags found yet — staying on whatever's currently checked out." fi fi +# Everything under $EVECTION_HOME (not just $APP_DIR — the venv created +# below lives next to it, not inside it) needs to belong to the service +# user, whether $EVECTION_HOME already existed (e.g. you mkdir'd it +# yourself before cloning) or adduser just created it. +chown "$EVECTION_USER:$EVECTION_USER" "$EVECTION_HOME" +chown -R "$EVECTION_USER:$EVECTION_USER" "$APP_DIR" + # --- 3. Virtualenv + install --------------------------------------------- if [ ! -d "$VENV_DIR" ]; then diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index 9f01bef..cf31dc7 100755 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -46,14 +46,18 @@ fi echo "==> Fetching latest release" cd "$APP_DIR" -sudo -u "$EVECTION_USER" -H git fetch --tags --force -LATEST_TAG="$(sudo -u "$EVECTION_USER" -H git tag --sort=-creatordate | head -n1)" +# Run git as root (this script already requires it), not as $EVECTION_USER: +# the service user has no reason to have its own git credentials set up, +# and GIT_TERMINAL_PROMPT=0 means a credential problem fails fast instead +# of hanging the upgrade on a silent username/password prompt. +GIT_TERMINAL_PROMPT=0 git fetch --tags --force +LATEST_TAG="$(git tag --sort=-creatordate | head -n1)" if [ -z "$LATEST_TAG" ]; then echo "No tags found in this repo — nothing to deploy." \ "Cut and push a release tag first (e.g. git tag v$(date +%Y.%m.%d) && git push --tags)." >&2 exit 1 fi -CURRENT_REF="$(sudo -u "$EVECTION_USER" -H git describe --tags --exact-match 2>/dev/null || echo "none")" +CURRENT_REF="$(git describe --tags --exact-match 2>/dev/null || echo "none")" if [ "$CURRENT_REF" = "$LATEST_TAG" ]; then echo "Already on the latest tag ($LATEST_TAG) — nothing to do." exit 0 @@ -61,7 +65,8 @@ fi echo "Deploying $LATEST_TAG (currently on: $CURRENT_REF)" # Detached HEAD, not a branch checkout — this directory only ever runs a # tagged release, never whatever the default branch's tip happens to be. -sudo -u "$EVECTION_USER" -H git checkout --quiet --detach "$LATEST_TAG" +git checkout --quiet --detach "$LATEST_TAG" +chown -R "$EVECTION_USER:$EVECTION_USER" "$APP_DIR" echo "==> Installing updated dependencies" sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --upgrade "$APP_DIR"