OpenCluely icon indicating copy to clipboard operation
OpenCluely copied to clipboard

setup.sh fails when writing Whisper command path containing slashes

Open syndicalt opened this issue 6 months ago • 0 comments

Problem

Running ./setup.sh --build on Linux can fail during local Whisper setup after openai-whisper is installed:

Unknown regexp modifier "/b" at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

Reproduction

On Linux, run:

./setup.sh --build

The script configures local Whisper and attempts to write this value into .env:

WHISPER_COMMAND=.venv-whisper/bin/whisper

Root cause

setup.sh currently updates existing .env keys with this Perl substitution:

perl -0pi -e "s/^${key}=.*\$/${key}=${value}/m" .env

When value contains /, such as .venv-whisper/bin/whisper, the slash is interpreted as the Perl substitution delimiter. The /b in /bin is then parsed as an invalid regexp modifier, causing the setup script to abort.

This is not machine-specific; any value containing unescaped / can trigger it.

Suggested fix

Avoid embedding unescaped values directly into a Perl substitution. For example, replace the existing-key path in upsert_env with a delimiter-safe/plain-text update using awk:

upsert_env() {
  local key="$1"
  local value="$2"
  local tmp_file

  if grep -q "^${key}=" .env 2>/dev/null; then
    tmp_file=$(mktemp ".env.tmp.XXXXXX")
    awk -v key="$key" -v value="$value" '
      $0 ~ "^" key "=" {
        print key "=" value
        next
      }
      { print }
    ' .env > "$tmp_file"
    mv "$tmp_file" .env
  else
    printf "%s=%s\n" "$key" "$value" >> .env
  fi
}

I verified the original failure with a minimal reproduction using WHISPER_COMMAND=.venv-whisper/bin/whisper, and the awk approach writes the expected line without the Perl parsing error.

syndicalt avatar May 25 '26 06:05 syndicalt