diff --git a/packages/site/public/install.ps1 b/packages/site/public/install.ps1 index 2498e01..cfeb04b 100644 --- a/packages/site/public/install.ps1 +++ b/packages/site/public/install.ps1 @@ -1,6 +1,10 @@ # Ashlr Stack -- Windows PowerShell one-liner installer. # -# irm stack.ashlr.ai/install.ps1 | iex +# irm https://stack.ashlr.ai/install.ps1 | iex +# +# Note: the explicit https:// scheme is required. Without it, PowerShell 5.1's +# Invoke-RestMethod defaults to http://, the host 308-redirects to https://, and +# IRM refuses cross-scheme redirects -- aborting with a (308) Permanent Redirect. # # Mirrors scripts/install.sh for the macOS/Linux side. It tries, in order: # @@ -139,8 +143,15 @@ function Install-AshlrStack { $binDir = $fallback } else { $binDir = $fallback - Write-StackWarn "$binDir isn't on PATH -- add it (user scope):" - Write-StackWarn " [Environment]::SetEnvironmentVariable('Path', `"$binDir;`" + [Environment]::GetEnvironmentVariable('Path','User'), 'User')" + $userPath = [Environment]::GetEnvironmentVariable('Path','User') + $userPathDirs = if ($userPath) { $userPath -split ';' | Where-Object { $_ } } else { @() } + if ($userPathDirs -notcontains $binDir) { + $newUserPath = if ($userPath) { "$binDir;$userPath" } else { $binDir } + [Environment]::SetEnvironmentVariable('Path', $newUserPath, 'User') + # Make the new PATH visible to this same session, too. + $env:Path = "$binDir;$env:Path" + Write-StackSay "added $binDir to user PATH" + } } if (-not (Test-Path $binDir)) { @@ -179,7 +190,7 @@ bun run "$mcpEntry" %* # ----------------------------------------------------------------------- if (-not (Test-CommandExists 'stack')) { - Write-StackWarn 'stack binary installed but not yet on PATH. Open a new shell or add the bin dir to your PATH.' + Write-StackWarn 'stack binary installed and PATH updated. Open a new shell and re-run `stack --help`.' return } diff --git a/packages/site/public/install.sh b/packages/site/public/install.sh index c3e59ce..5dba9fa 100755 --- a/packages/site/public/install.sh +++ b/packages/site/public/install.sh @@ -19,6 +19,32 @@ say() { printf " \033[1;35m▲\033[0m stack: %s\n" "$1"; } warn() { printf " \033[1;33m!\033[0m stack: %s\n" "$1" >&2; } die() { printf " \033[1;31m✗\033[0m stack: %s\n" "$1" >&2; exit 1; } +# Idempotently add a directory to the user's PATH by appending an export line +# to their shell's rc file. Detects bash/zsh/fish from $SHELL. +add_to_user_path() { + local bin="$1" + local marker="# ashlr-stack PATH" + local shell_name rc + shell_name="$(basename "${SHELL:-bash}")" + case "$shell_name" in + zsh) rc="$HOME/.zshrc" ;; + fish) rc="$HOME/.config/fish/config.fish" ;; + *) rc="$HOME/.bashrc" ;; + esac + mkdir -p "$(dirname "$rc")" + touch "$rc" + if grep -qF "$marker" "$rc" 2>/dev/null; then + say "$bin already wired into $rc" + return 0 + fi + if [ "$shell_name" = "fish" ]; then + printf '\n%s\nset -gx PATH %s $PATH\n' "$marker" "$bin" >> "$rc" + else + printf '\n%s\nexport PATH="%s:$PATH"\n' "$marker" "$bin" >> "$rc" + fi + say "added $bin to PATH in $rc (open a new shell or run: source $rc)" +} + REPO="${STACK_REPO:-ashlrai/ashlr-stack}" REPO_URL="${STACK_REPO_URL:-https://github.com/${REPO}.git}" INSTALL_DIR="${STACK_INSTALL_DIR:-$HOME/.local/share/ashlr-stack}" @@ -119,8 +145,7 @@ install_via_binary() { say "stack installed to $bin_dir/stack" if ! echo "$PATH" | tr ':' '\n' | grep -qx "$bin_dir"; then - warn "$bin_dir is not on your PATH — add to your shell init:" - warn " export PATH=\"\$HOME/.ashlr/bin:\$PATH\"" + add_to_user_path "$bin_dir" fi return 0 } @@ -159,7 +184,7 @@ install_via_clone() { else mkdir -p "$HOME/.local/bin" BIN_DIR="$HOME/.local/bin" - warn "$BIN_DIR isn't on your PATH — add it: export PATH=\"\$HOME/.local/bin:\$PATH\"" + add_to_user_path "$BIN_DIR" fi # Write a thin wrapper script so we don't rely on `bun link`. @@ -194,7 +219,7 @@ fi # --------------------------------------------------------------------------- if ! command -v stack >/dev/null 2>&1; then - warn "stack binary installed but not yet on PATH. Open a new shell or add the bin dir to your PATH." + warn "stack binary installed and PATH updated. Open a new shell (or 'source' your shell rc) and re-run 'stack --help'." exit 0 fi diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 2498e01..cfeb04b 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -1,6 +1,10 @@ # Ashlr Stack -- Windows PowerShell one-liner installer. # -# irm stack.ashlr.ai/install.ps1 | iex +# irm https://stack.ashlr.ai/install.ps1 | iex +# +# Note: the explicit https:// scheme is required. Without it, PowerShell 5.1's +# Invoke-RestMethod defaults to http://, the host 308-redirects to https://, and +# IRM refuses cross-scheme redirects -- aborting with a (308) Permanent Redirect. # # Mirrors scripts/install.sh for the macOS/Linux side. It tries, in order: # @@ -139,8 +143,15 @@ function Install-AshlrStack { $binDir = $fallback } else { $binDir = $fallback - Write-StackWarn "$binDir isn't on PATH -- add it (user scope):" - Write-StackWarn " [Environment]::SetEnvironmentVariable('Path', `"$binDir;`" + [Environment]::GetEnvironmentVariable('Path','User'), 'User')" + $userPath = [Environment]::GetEnvironmentVariable('Path','User') + $userPathDirs = if ($userPath) { $userPath -split ';' | Where-Object { $_ } } else { @() } + if ($userPathDirs -notcontains $binDir) { + $newUserPath = if ($userPath) { "$binDir;$userPath" } else { $binDir } + [Environment]::SetEnvironmentVariable('Path', $newUserPath, 'User') + # Make the new PATH visible to this same session, too. + $env:Path = "$binDir;$env:Path" + Write-StackSay "added $binDir to user PATH" + } } if (-not (Test-Path $binDir)) { @@ -179,7 +190,7 @@ bun run "$mcpEntry" %* # ----------------------------------------------------------------------- if (-not (Test-CommandExists 'stack')) { - Write-StackWarn 'stack binary installed but not yet on PATH. Open a new shell or add the bin dir to your PATH.' + Write-StackWarn 'stack binary installed and PATH updated. Open a new shell and re-run `stack --help`.' return } diff --git a/scripts/install.sh b/scripts/install.sh index c3e59ce..5dba9fa 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -19,6 +19,32 @@ say() { printf " \033[1;35m▲\033[0m stack: %s\n" "$1"; } warn() { printf " \033[1;33m!\033[0m stack: %s\n" "$1" >&2; } die() { printf " \033[1;31m✗\033[0m stack: %s\n" "$1" >&2; exit 1; } +# Idempotently add a directory to the user's PATH by appending an export line +# to their shell's rc file. Detects bash/zsh/fish from $SHELL. +add_to_user_path() { + local bin="$1" + local marker="# ashlr-stack PATH" + local shell_name rc + shell_name="$(basename "${SHELL:-bash}")" + case "$shell_name" in + zsh) rc="$HOME/.zshrc" ;; + fish) rc="$HOME/.config/fish/config.fish" ;; + *) rc="$HOME/.bashrc" ;; + esac + mkdir -p "$(dirname "$rc")" + touch "$rc" + if grep -qF "$marker" "$rc" 2>/dev/null; then + say "$bin already wired into $rc" + return 0 + fi + if [ "$shell_name" = "fish" ]; then + printf '\n%s\nset -gx PATH %s $PATH\n' "$marker" "$bin" >> "$rc" + else + printf '\n%s\nexport PATH="%s:$PATH"\n' "$marker" "$bin" >> "$rc" + fi + say "added $bin to PATH in $rc (open a new shell or run: source $rc)" +} + REPO="${STACK_REPO:-ashlrai/ashlr-stack}" REPO_URL="${STACK_REPO_URL:-https://github.com/${REPO}.git}" INSTALL_DIR="${STACK_INSTALL_DIR:-$HOME/.local/share/ashlr-stack}" @@ -119,8 +145,7 @@ install_via_binary() { say "stack installed to $bin_dir/stack" if ! echo "$PATH" | tr ':' '\n' | grep -qx "$bin_dir"; then - warn "$bin_dir is not on your PATH — add to your shell init:" - warn " export PATH=\"\$HOME/.ashlr/bin:\$PATH\"" + add_to_user_path "$bin_dir" fi return 0 } @@ -159,7 +184,7 @@ install_via_clone() { else mkdir -p "$HOME/.local/bin" BIN_DIR="$HOME/.local/bin" - warn "$BIN_DIR isn't on your PATH — add it: export PATH=\"\$HOME/.local/bin:\$PATH\"" + add_to_user_path "$BIN_DIR" fi # Write a thin wrapper script so we don't rely on `bun link`. @@ -194,7 +219,7 @@ fi # --------------------------------------------------------------------------- if ! command -v stack >/dev/null 2>&1; then - warn "stack binary installed but not yet on PATH. Open a new shell or add the bin dir to your PATH." + warn "stack binary installed and PATH updated. Open a new shell (or 'source' your shell rc) and re-run 'stack --help'." exit 0 fi