feat: enhance installer to add binary directory to user's PATH

rabbitprincess committed Jun 2, 2026 at 22:32 UTC 2c28c28bc00bb59e1993fdcd8af896f8c0ad74e7
3 files changed +31 -3
cmd/portal-tunnel/README.md
+2 -1
@@ -394,7 +394,8 @@ resource = "/"
394
395 ## Install Behavior
396
397 -- `install.sh` installs the downloaded binary as `portal`.
397 +- `install.sh` installs the downloaded binary as `portal` and adds the install
398 + directory to the user's shell profile when it is not already on `PATH`.
399 - `install.ps1` installs `portal.exe` for the current Windows user and updates
400 the user `PATH`.
401 - The installer does not write a config file.
cmd/portal-tunnel/installer/install.sh
+27 -1
@@ -144,7 +144,33 @@ echo "Installed portal to $INSTALL_PATH" >&2
144 case ":$PATH:" in
145 *":$INSTALL_DIR:"*) ;;
146 *)
147 - echo "Warning: $INSTALL_DIR is not on PATH. Add it before running 'portal expose 3000'." >&2
147 + PROFILE_PATH=""
148 + if [ -n "${HOME:-}" ]; then
149 + SHELL_NAME="${SHELL:-}"
150 + SHELL_NAME="${SHELL_NAME##*/}"
151 + case "$SHELL_NAME" in
152 + zsh) PROFILE_PATH="$HOME/.zshrc" ;;
153 + bash) PROFILE_PATH="$HOME/.bashrc" ;;
154 + *) PROFILE_PATH="$HOME/.profile" ;;
155 + esac
156 + fi
157 +
158 + if [ -n "$PROFILE_PATH" ]; then
159 + mkdir -p "$(dirname "$PROFILE_PATH")" 2>/dev/null || true
160 + if [ ! -f "$PROFILE_PATH" ] || ! grep -F "$INSTALL_DIR" "$PROFILE_PATH" >/dev/null 2>&1; then
161 + {
162 + printf '\n# Added by Portal installer\n'
163 + printf 'export PATH="%s:$PATH"\n' "$INSTALL_DIR"
164 + } >> "$PROFILE_PATH" || PROFILE_PATH=""
165 + fi
166 + fi
167 +
168 + if [ -n "$PROFILE_PATH" ]; then
169 + echo "Added $INSTALL_DIR to PATH in $PROFILE_PATH" >&2
170 + echo "Open a new shell or run: export PATH=\"$INSTALL_DIR:\$PATH\"" >&2
171 + else
172 + echo "Warning: $INSTALL_DIR is not on PATH. Add it before running 'portal expose 3000'." >&2
173 + fi
174 ;;
175 esac
176
docs/src/routes/cli-reference/+page.md
+2 -1
@@ -32,7 +32,8 @@ If your relay publishes its own installer:
32 curl -sSL https://portal.example.com/api/install.sh | bash
33 ```
34
35 -The installer writes the `portal` binary only. It does not write a config file.
35 +The installer downloads the `portal` binary and adds it to your `PATH`. It does
36 +not create a config file.
37
38 ## Command Overview
39