Skip to content

fix(install): use sudo for .env writes in --upgrade#2736

Merged
chocobar merged 1 commit into
mainfrom
fix-upgrade-perms
Jun 25, 2026
Merged

fix(install): use sudo for .env writes in --upgrade#2736
chocobar merged 1 commit into
mainfrom
fix-upgrade-perms

Conversation

@chocobar

Copy link
Copy Markdown
Collaborator

Problem

./install.sh --upgrade fails on a standard controlplane install:

cp: cannot create regular file '/opt/HelixML/.env.bak.20260625-165718': Permission denied

do_upgrade() writes to $INSTALL_DIR/.env (typically /opt/HelixML, root-owned from the original sudo install) without sudo: the backup cp, the sed -i rewrite, and the append all run as the unprivileged operator. Docker commands succeed because the user is in the docker group, which masks that the file writes still need root.

Fix

Compute a SUDO prefix in do_upgrade() only when .env is not writable (and not Git Bash), and apply it to the file mutations:

  • $SUDO cp for the backup
  • $SUDO sed -i / $SUDO rm for the in-place rewrite
  • printf ... | $SUDO tee -a for the append (the old >> file redirect runs in the unprivileged shell, so sudo on printf wouldn't help)

User-owned installs are unaffected: SUDO stays empty. bash -n passes.

Test

  • Root-owned /opt/HelixML, operator in docker group: upgrade now backs up and rewrites .env, then pulls and recreates.
  • User-owned install dir: SUDO empty, behaviour unchanged.

🤖 Generated with Claude Code

do_upgrade() mutates $INSTALL_DIR/.env (typically /opt/HelixML, root-owned
from a sudo install) without sudo, so the backup cp, sed -i, and append
fail with "Permission denied" whenever the operator runs install.sh as a
non-root user. Docker itself works because the user is in the docker group,
which masks that the file writes still need root.

Compute a SUDO prefix only when .env is not writable (and not Git Bash),
and apply it to cp/sed/rm. Switch the append from `>> file` to `tee -a`
since the redirect runs in the unprivileged shell where sudo can't help.
User-owned installs are unaffected (SUDO stays empty).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chocobar chocobar merged commit 8b84501 into main Jun 25, 2026
3 of 4 checks passed
@chocobar chocobar deleted the fix-upgrade-perms branch June 25, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant