diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.yml new file mode 100644 index 00000000..416adef6 --- /dev/null +++ b/.github/workflows/test-install.yml @@ -0,0 +1,51 @@ +name: Test Install Script + +on: + pull_request: + paths: + - 'install.sh' + - 'e2e/install/**' + - '.github/workflows/test-install.yml' + push: + branches: [main] + paths: + - 'install.sh' + - 'e2e/install/**' + - '.github/workflows/test-install.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + test-install: + name: install.sh (${{ matrix.shell }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - shell: sh + test: e2e/install/sh_test.sh + run: sh e2e/install/sh_test.sh + - shell: bash + test: e2e/install/bash_test.sh + run: bash e2e/install/bash_test.sh + - shell: zsh + test: e2e/install/zsh_test.sh + run: zsh e2e/install/zsh_test.sh + install: zsh + - shell: fish + test: e2e/install/fish_test.fish + run: fish e2e/install/fish_test.fish + install: fish + + steps: + - uses: actions/checkout@v4 + + - name: Install ${{ matrix.shell }} + if: matrix.install + run: sudo apt-get update && sudo apt-get install -y ${{ matrix.install }} + + - name: Run tests (${{ matrix.shell }}) + run: ${{ matrix.run }} diff --git a/e2e/install/bash_test.sh b/e2e/install/bash_test.sh new file mode 100755 index 00000000..2b4db1ca --- /dev/null +++ b/e2e/install/bash_test.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Bash e2e tests for install.sh. +# +# Downloads the latest release for real and validates: +# - Binary is installed to the correct directory +# - Binary is executable and runs +# - PATH guidance shows the correct export command for bash +# +set -euo pipefail + +. "$(dirname "$0")/helpers.sh" + +# --------------------------------------------------------------------------- +# Tests +# --------------------------------------------------------------------------- + +test_binary_installed() { + printf 'TEST: binary exists in install directory\n' + + if [ -f "$INSTALL_DIR/openshell" ]; then + pass "openshell binary exists at $INSTALL_DIR/openshell" + else + fail "openshell binary exists" "not found at $INSTALL_DIR/openshell" + fi +} + +test_binary_executable() { + printf 'TEST: binary is executable\n' + + if [ -x "$INSTALL_DIR/openshell" ]; then + pass "openshell binary is executable" + else + fail "openshell binary is executable" "$INSTALL_DIR/openshell is not executable" + fi +} + +test_binary_runs() { + printf 'TEST: binary runs successfully\n' + + if _version="$("$INSTALL_DIR/openshell" --version 2>/dev/null)"; then + pass "openshell --version succeeds: $_version" + else + fail "openshell --version succeeds" "exit code: $?" + fi +} + +test_guidance_shows_export_path() { + printf 'TEST: guidance shows export PATH for bash users\n' + + assert_output_contains "$INSTALL_OUTPUT" 'export PATH="' "shows export PATH command" + assert_output_not_contains "$INSTALL_OUTPUT" "fish_add_path" "does not show fish command" +} + +test_guidance_mentions_not_on_path() { + printf 'TEST: guidance mentions install dir is not on PATH\n' + + assert_output_contains "$INSTALL_OUTPUT" "is not on your PATH" "mentions PATH issue" + assert_output_contains "$INSTALL_OUTPUT" "$INSTALL_DIR" "includes install dir in guidance" +} + +# --------------------------------------------------------------------------- +# Runner +# --------------------------------------------------------------------------- + +printf '=== install.sh e2e tests: bash ===\n\n' + +printf 'Installing openshell...\n' +SHELL="/bin/bash" run_install +printf 'Done.\n\n' + +test_binary_installed; echo "" +test_binary_executable; echo "" +test_binary_runs; echo "" +test_guidance_shows_export_path; echo "" +test_guidance_mentions_not_on_path + +print_summary diff --git a/e2e/install/fish_test.fish b/e2e/install/fish_test.fish new file mode 100755 index 00000000..10176071 --- /dev/null +++ b/e2e/install/fish_test.fish @@ -0,0 +1,152 @@ +#!/usr/bin/env fish +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Fish e2e tests for install.sh. +# +# Downloads the latest release for real and validates: +# - Binary is installed to the correct directory +# - Binary is executable and runs +# - PATH guidance shows fish_add_path (not export PATH) + +set -g PASS 0 +set -g FAIL 0 + +# Resolve paths relative to this script +set -g SCRIPT_DIR (builtin cd (dirname (status filename)) && pwd) +set -g REPO_ROOT (builtin cd "$SCRIPT_DIR/../.." && pwd) +set -g INSTALL_SCRIPT "$REPO_ROOT/install.sh" + +# Set by run_install +set -g INSTALL_DIR "" +set -g INSTALL_OUTPUT "" + +# --------------------------------------------------------------------------- +# Helpers +# --------------------------------------------------------------------------- + +function pass + set -g PASS (math $PASS + 1) + printf ' PASS: %s\n' $argv[1] +end + +function fail + set -g FAIL (math $FAIL + 1) + printf ' FAIL: %s\n' $argv[1] >&2 + if test (count $argv) -gt 1 + printf ' %s\n' $argv[2] >&2 + end +end + +function assert_output_contains + set -l output $argv[1] + set -l pattern $argv[2] + set -l label $argv[3] + + if string match -q -- "*$pattern*" "$output" + pass "$label" + else + fail "$label" "expected '$pattern' in output" + end +end + +function assert_output_not_contains + set -l output $argv[1] + set -l pattern $argv[2] + set -l label $argv[3] + + if string match -q -- "*$pattern*" "$output" + fail "$label" "unexpected '$pattern' found in output" + else + pass "$label" + end +end + +function run_install + set -g INSTALL_DIR (mktemp -d)/bin + + set -g INSTALL_OUTPUT (OPENSHELL_INSTALL_DIR="$INSTALL_DIR" \ + SHELL="/usr/bin/fish" \ + PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" \ + sh "$INSTALL_SCRIPT" 2>&1) + + if test $status -ne 0 + printf 'install.sh failed:\n%s\n' "$INSTALL_OUTPUT" >&2 + return 1 + end +end + +# --------------------------------------------------------------------------- +# Tests +# --------------------------------------------------------------------------- + +function test_binary_installed + printf 'TEST: binary exists in install directory\n' + + if test -f "$INSTALL_DIR/openshell" + pass "openshell binary exists at $INSTALL_DIR/openshell" + else + fail "openshell binary exists" "not found at $INSTALL_DIR/openshell" + end +end + +function test_binary_executable + printf 'TEST: binary is executable\n' + + if test -x "$INSTALL_DIR/openshell" + pass "openshell binary is executable" + else + fail "openshell binary is executable" "$INSTALL_DIR/openshell is not executable" + end +end + +function test_binary_runs + printf 'TEST: binary runs successfully\n' + + set -l version_output ("$INSTALL_DIR/openshell" --version 2>/dev/null) + if test $status -eq 0 + pass "openshell --version succeeds: $version_output" + else + fail "openshell --version succeeds" "exit code: $status" + end +end + +function test_guidance_shows_fish_add_path + printf 'TEST: guidance shows fish_add_path for fish users\n' + + assert_output_contains "$INSTALL_OUTPUT" "fish_add_path" "shows fish_add_path command" + assert_output_not_contains "$INSTALL_OUTPUT" 'export PATH="' "does not show POSIX export" +end + +function test_guidance_mentions_not_on_path + printf 'TEST: guidance mentions install dir is not on PATH\n' + + assert_output_contains "$INSTALL_OUTPUT" "is not on your PATH" "mentions PATH issue" + assert_output_contains "$INSTALL_OUTPUT" "$INSTALL_DIR" "includes install dir in guidance" +end + +# --------------------------------------------------------------------------- +# Runner +# --------------------------------------------------------------------------- + +printf '=== install.sh e2e tests: fish ===\n\n' + +printf 'Installing openshell...\n' +run_install +printf 'Done.\n\n' + +test_binary_installed +echo "" +test_binary_executable +echo "" +test_binary_runs +echo "" +test_guidance_shows_fish_add_path +echo "" +test_guidance_mentions_not_on_path + +printf '\n=== Results: %d passed, %d failed ===\n' $PASS $FAIL + +if test $FAIL -gt 0 + exit 1 +end diff --git a/e2e/install/helpers.sh b/e2e/install/helpers.sh new file mode 100644 index 00000000..ff5f6637 --- /dev/null +++ b/e2e/install/helpers.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Shared test helpers for install.sh e2e tests. +# Sourced by each per-shell test file (except fish, which has its own helpers). +# +# Provides: +# - pass / fail / print_summary +# - assert_output_contains / assert_output_not_contains +# - run_install (runs the real install.sh to a temp dir, captures output) +# - REPO_ROOT / INSTALL_SCRIPT paths +# - INSTALL_DIR / INSTALL_OUTPUT (set after run_install) + +HELPERS_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "$HELPERS_DIR/../.." && pwd)" +INSTALL_SCRIPT="$REPO_ROOT/install.sh" + +_PASS=0 +_FAIL=0 + +# Set by run_install +INSTALL_DIR="" +INSTALL_OUTPUT="" + +# --------------------------------------------------------------------------- +# Assertions +# --------------------------------------------------------------------------- + +pass() { + _PASS=$((_PASS + 1)) + printf ' PASS: %s\n' "$1" +} + +fail() { + _FAIL=$((_FAIL + 1)) + printf ' FAIL: %s\n' "$1" >&2 + if [ -n "${2:-}" ]; then + printf ' %s\n' "$2" >&2 + fi +} + +assert_output_contains() { + _aoc_output="$1" + _aoc_pattern="$2" + _aoc_label="$3" + + if printf '%s' "$_aoc_output" | grep -qF "$_aoc_pattern"; then + pass "$_aoc_label" + else + fail "$_aoc_label" "expected '$_aoc_pattern' in output" + fi +} + +assert_output_not_contains() { + _aonc_output="$1" + _aonc_pattern="$2" + _aonc_label="$3" + + if printf '%s' "$_aonc_output" | grep -qF "$_aonc_pattern"; then + fail "$_aonc_label" "unexpected '$_aonc_pattern' found in output" + else + pass "$_aonc_label" + fi +} + +# --------------------------------------------------------------------------- +# Install runner +# --------------------------------------------------------------------------- + +# Run the real install.sh, installing to a temp directory with the install +# dir removed from PATH so we always get PATH guidance output. +# +# Sets INSTALL_DIR and INSTALL_OUTPUT for subsequent assertions. +# The SHELL variable is passed through so tests can control which shell +# guidance is shown. +# +# Usage: +# SHELL="/bin/bash" run_install +run_install() { + INSTALL_DIR="$(mktemp -d)/bin" + + # Remove the install dir from PATH (it won't be there, but be explicit). + # Keep a minimal PATH so curl/tar/install are available. + INSTALL_OUTPUT="$(OPENSHELL_INSTALL_DIR="$INSTALL_DIR" \ + PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" \ + sh "$INSTALL_SCRIPT" 2>&1)" || { + printf 'install.sh failed:\n%s\n' "$INSTALL_OUTPUT" >&2 + return 1 + } +} + +# --------------------------------------------------------------------------- +# Summary +# --------------------------------------------------------------------------- + +print_summary() { + printf '\n=== Results: %d passed, %d failed ===\n' "$_PASS" "$_FAIL" + [ "$_FAIL" -eq 0 ] +} diff --git a/e2e/install/sh_test.sh b/e2e/install/sh_test.sh new file mode 100755 index 00000000..320c00ef --- /dev/null +++ b/e2e/install/sh_test.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# POSIX sh e2e tests for install.sh. +# +# Downloads the latest release for real and validates: +# - Binary is installed to the correct directory +# - Binary is executable and runs +# - PATH guidance shows the correct export command for sh +# - No rc files or env scripts are created +# +set -eu + +. "$(dirname "$0")/helpers.sh" + +# --------------------------------------------------------------------------- +# Tests +# --------------------------------------------------------------------------- + +test_binary_installed() { + printf 'TEST: binary exists in install directory\n' + + if [ -f "$INSTALL_DIR/openshell" ]; then + pass "openshell binary exists at $INSTALL_DIR/openshell" + else + fail "openshell binary exists" "not found at $INSTALL_DIR/openshell" + fi +} + +test_binary_executable() { + printf 'TEST: binary is executable\n' + + if [ -x "$INSTALL_DIR/openshell" ]; then + pass "openshell binary is executable" + else + fail "openshell binary is executable" "$INSTALL_DIR/openshell is not executable" + fi +} + +test_binary_runs() { + printf 'TEST: binary runs successfully\n' + + if _version="$("$INSTALL_DIR/openshell" --version 2>/dev/null)"; then + pass "openshell --version succeeds: $_version" + else + fail "openshell --version succeeds" "exit code: $?" + fi +} + +test_guidance_shows_export_path() { + printf 'TEST: guidance shows export PATH for sh users\n' + + assert_output_contains "$INSTALL_OUTPUT" 'export PATH="' "shows export PATH command" + assert_output_not_contains "$INSTALL_OUTPUT" "fish_add_path" "does not show fish command" +} + +test_guidance_mentions_not_on_path() { + printf 'TEST: guidance mentions install dir is not on PATH\n' + + assert_output_contains "$INSTALL_OUTPUT" "is not on your PATH" "mentions PATH issue" + assert_output_contains "$INSTALL_OUTPUT" "$INSTALL_DIR" "includes install dir in guidance" +} + +test_guidance_mentions_restart() { + printf 'TEST: guidance tells user to restart shell\n' + + assert_output_contains "$INSTALL_OUTPUT" "restart your shell" "mentions shell restart" +} + +test_no_env_scripts_created() { + printf 'TEST: no env scripts are created in install dir\n' + + if [ -f "$INSTALL_DIR/env" ]; then + fail "no env script created" "found $INSTALL_DIR/env" + else + pass "no env script created" + fi + + if [ -f "$INSTALL_DIR/env.fish" ]; then + fail "no env.fish script created" "found $INSTALL_DIR/env.fish" + else + pass "no env.fish script created" + fi +} + +# --------------------------------------------------------------------------- +# Runner +# --------------------------------------------------------------------------- + +printf '=== install.sh e2e tests: sh ===\n\n' + +printf 'Installing openshell...\n' +SHELL="/bin/sh" run_install +printf 'Done.\n\n' + +test_binary_installed; echo "" +test_binary_executable; echo "" +test_binary_runs; echo "" +test_guidance_shows_export_path; echo "" +test_guidance_mentions_not_on_path; echo "" +test_guidance_mentions_restart; echo "" +test_no_env_scripts_created + +print_summary diff --git a/e2e/install/zsh_test.sh b/e2e/install/zsh_test.sh new file mode 100755 index 00000000..621d35f8 --- /dev/null +++ b/e2e/install/zsh_test.sh @@ -0,0 +1,80 @@ +#!/bin/zsh +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Zsh e2e tests for install.sh. +# +# Downloads the latest release for real and validates: +# - Binary is installed to the correct directory +# - Binary is executable and runs +# - PATH guidance shows the correct export command for zsh +# +set -eu + +. "$(dirname "$0")/helpers.sh" + +# --------------------------------------------------------------------------- +# Tests +# --------------------------------------------------------------------------- + +test_binary_installed() { + printf 'TEST: binary exists in install directory\n' + + if [ -f "$INSTALL_DIR/openshell" ]; then + pass "openshell binary exists at $INSTALL_DIR/openshell" + else + fail "openshell binary exists" "not found at $INSTALL_DIR/openshell" + fi +} + +test_binary_executable() { + printf 'TEST: binary is executable\n' + + if [ -x "$INSTALL_DIR/openshell" ]; then + pass "openshell binary is executable" + else + fail "openshell binary is executable" "$INSTALL_DIR/openshell is not executable" + fi +} + +test_binary_runs() { + printf 'TEST: binary runs successfully\n' + + if _version="$("$INSTALL_DIR/openshell" --version 2>/dev/null)"; then + pass "openshell --version succeeds: $_version" + else + fail "openshell --version succeeds" "exit code: $?" + fi +} + +test_guidance_shows_export_path() { + printf 'TEST: guidance shows export PATH for zsh users\n' + + assert_output_contains "$INSTALL_OUTPUT" 'export PATH="' "shows export PATH command" + assert_output_not_contains "$INSTALL_OUTPUT" "fish_add_path" "does not show fish command" +} + +test_guidance_mentions_not_on_path() { + printf 'TEST: guidance mentions install dir is not on PATH\n' + + assert_output_contains "$INSTALL_OUTPUT" "is not on your PATH" "mentions PATH issue" + assert_output_contains "$INSTALL_OUTPUT" "$INSTALL_DIR" "includes install dir in guidance" +} + +# --------------------------------------------------------------------------- +# Runner +# --------------------------------------------------------------------------- + +printf '=== install.sh e2e tests: zsh ===\n\n' + +printf 'Installing openshell...\n' +SHELL="/bin/zsh" run_install +printf 'Done.\n\n' + +test_binary_installed; echo "" +test_binary_executable; echo "" +test_binary_runs; echo "" +test_guidance_shows_export_path; echo "" +test_guidance_mentions_not_on_path + +print_summary diff --git a/install.sh b/install.sh index d945cde7..faec3bb2 100755 --- a/install.sh +++ b/install.sh @@ -14,16 +14,11 @@ # OPENSHELL_VERSION - Release tag to install (default: latest tagged release) # OPENSHELL_INSTALL_DIR - Directory to install into (default: ~/.local/bin) # -# CLI flags: -# --help - Print usage information -# --no-modify-path - Skip PATH modification in shell profiles -# set -eu APP_NAME="openshell" REPO="NVIDIA/OpenShell" GITHUB_URL="https://github.com/${REPO}" -NO_MODIFY_PATH=0 # --------------------------------------------------------------------------- # Logging @@ -55,8 +50,7 @@ USAGE: ./install.sh [OPTIONS] OPTIONS: - --no-modify-path Don't add the install directory to PATH - --help Print this help message + --help Print this help message ENVIRONMENT VARIABLES: OPENSHELL_VERSION Release tag to install (default: latest tagged release) @@ -111,8 +105,8 @@ resolve_redirect() { if has_cmd curl; then curl -fLsS -o /dev/null -w '%{url_effective}' "$_url" elif has_cmd wget; then - # wget --spider follows redirects and prints the final URL - wget --spider -q --max-redirect=10 "$_url" 2>&1 | grep -oP 'Location: \K\S+' | tail -1 + # wget --spider follows redirects; capture the final Location from stderr + wget --spider --max-redirect=10 "$_url" 2>&1 | sed -n 's/^.*Location: \([^ ]*\).*/\1/p' | tail -1 fi } @@ -182,21 +176,21 @@ resolve_version() { # --------------------------------------------------------------------------- verify_checksum() { - _archive="$1" - _checksums="$2" - _filename="$3" + _vc_archive="$1" + _vc_checksums="$2" + _vc_filename="$3" - _expected="$(grep "$_filename" "$_checksums" | awk '{print $1}')" + _vc_expected="$(grep "$_vc_filename" "$_vc_checksums" | awk '{print $1}')" - if [ -z "$_expected" ]; then - warn "no checksum found for $_filename, skipping verification" + if [ -z "$_vc_expected" ]; then + warn "no checksum found for $_vc_filename, skipping verification" return 0 fi if has_cmd shasum; then - echo "$_expected $_archive" | shasum -a 256 -c --quiet 2>/dev/null + echo "$_vc_expected $_vc_archive" | shasum -a 256 -c --quiet 2>/dev/null elif has_cmd sha256sum; then - echo "$_expected $_archive" | sha256sum -c --quiet 2>/dev/null + echo "$_vc_expected $_vc_archive" | sha256sum -c --quiet 2>/dev/null else warn "sha256sum/shasum not found, skipping checksum verification" return 0 @@ -204,25 +198,14 @@ verify_checksum() { } # --------------------------------------------------------------------------- -# Install location and PATH management +# Install location # --------------------------------------------------------------------------- -get_home() { - if [ -n "${HOME:-}" ]; then - echo "$HOME" - elif [ -n "${USER:-}" ]; then - getent passwd "$USER" | cut -d: -f6 - else - getent passwd "$(id -un)" | cut -d: -f6 - fi -} - -get_default_install_dir() { - if [ -n "${XDG_BIN_HOME:-}" ]; then - echo "$XDG_BIN_HOME" +get_install_dir() { + if [ -n "${OPENSHELL_INSTALL_DIR:-}" ]; then + echo "$OPENSHELL_INSTALL_DIR" else - _home="$(get_home)" - echo "${_home}/.local/bin" + echo "${HOME}/.local/bin" fi } @@ -235,132 +218,6 @@ is_on_path() { esac } -# Write a small env script that conditionally prepends the install dir to PATH. -write_env_script_sh() { - _install_dir_expr="$1" - _env_script="$2" - - cat < "$_env_script" -#!/bin/sh -# Add OpenShell to PATH if not already present -case ":\${PATH}:" in - *:"${_install_dir_expr}":*) - ;; - *) - export PATH="${_install_dir_expr}:\$PATH" - ;; -esac -ENVEOF -} - -write_env_script_fish() { - _install_dir_expr="$1" - _env_script="$2" - - cat < "$_env_script" -# Add OpenShell to PATH if not already present -if not contains "${_install_dir_expr}" \$PATH - set -gx PATH "${_install_dir_expr}" \$PATH -end -ENVEOF -} - -# Add a `. /path/to/env` line to a shell rc file if not already present. -add_source_line() { - _env_script_path="$1" - _rcfile="$2" - _shell_type="$3" - - if [ "$_shell_type" = "fish" ]; then - _line="source \"${_env_script_path}\"" - else - _line=". \"${_env_script_path}\"" - fi - - # Check if line already exists - if [ -f "$_rcfile" ] && grep -qF "$_line" "$_rcfile" 2>/dev/null; then - return 0 - fi - - # Append with a leading newline in case the file doesn't end with one - printf '\n%s\n' "$_line" >> "$_rcfile" - return 1 -} - -# Set up PATH modification in common shell rc files. -setup_path() { - _install_dir="$1" - _home="$(get_home)" - _env_script="${_install_dir}/env" - _fish_env_script="${_install_dir}/env.fish" - _needs_source=0 - - # Replace $HOME in the expression for late-bound references in rc files - if [ -n "${HOME:-}" ]; then - # shellcheck disable=SC2016 - _install_dir_expr='$HOME'"${_install_dir#"$_home"}" - else - _install_dir_expr="$_install_dir" - fi - - # Write the env scripts - write_env_script_sh "$_install_dir_expr" "$_env_script" - write_env_script_fish "$_install_dir_expr" "$_fish_env_script" - - # POSIX shells: .profile, .bashrc, .bash_profile, .zshrc, .zshenv - for _rcfile_rel in .profile .bashrc .bash_profile .zshrc .zshenv; do - _rcdir="$_home" - # zsh respects ZDOTDIR - case "$_rcfile_rel" in - .zsh*) _rcdir="${ZDOTDIR:-$_home}" ;; - esac - _rcfile="${_rcdir}/${_rcfile_rel}" - if [ -f "$_rcfile" ]; then - if ! add_source_line "$_env_script" "$_rcfile" "sh"; then - _needs_source=1 - fi - fi - done - - # If none of the above existed, create .profile - if [ "$_needs_source" = "0" ]; then - _found_any=0 - for _rcfile_rel in .profile .bashrc .bash_profile .zshrc .zshenv; do - if [ -f "${_home}/${_rcfile_rel}" ]; then - _found_any=1 - break - fi - done - if [ "$_found_any" = "0" ]; then - if ! add_source_line "$_env_script" "${_home}/.profile" "sh"; then - _needs_source=1 - fi - fi - fi - - # Fish shell - _fish_conf_dir="${_home}/.config/fish/conf.d" - if [ -d "${_home}/.config/fish" ]; then - mkdir -p "$_fish_conf_dir" - add_source_line "$_fish_env_script" "${_fish_conf_dir}/${APP_NAME}.env.fish" "fish" || true - fi - - # GitHub Actions: write to GITHUB_PATH for CI environments - if [ -n "${GITHUB_PATH:-}" ]; then - echo "$_install_dir" >> "$GITHUB_PATH" - fi - - if [ "$_needs_source" = "1" ] || ! is_on_path "$_install_dir"; then - echo "" - info "to add ${APP_NAME} to your PATH, restart your shell or run:" - info "" - info " source \"${_env_script}\" (sh, bash, zsh)" - if [ -d "${_home}/.config/fish" ]; then - info " source \"${_fish_env_script}\" (fish)" - fi - fi -} - # --------------------------------------------------------------------------- # Main # --------------------------------------------------------------------------- @@ -373,9 +230,6 @@ main() { usage exit 0 ;; - --no-modify-path) - NO_MODIFY_PATH=1 - ;; *) error "unknown option: $arg" ;; @@ -389,15 +243,7 @@ main() { _filename="${APP_NAME}-${_target}.tar.gz" _download_url="${GITHUB_URL}/releases/download/${_version}/${_filename}" _checksums_url="${GITHUB_URL}/releases/download/${_version}/${APP_NAME}-checksums-sha256.txt" - - # Determine install directory - _using_default_dir=0 - if [ -n "${OPENSHELL_INSTALL_DIR:-}" ]; then - _install_dir="$OPENSHELL_INSTALL_DIR" - else - _install_dir="$(get_default_install_dir)" - _using_default_dir=1 - fi + _install_dir="$(get_install_dir)" info "downloading ${APP_NAME} ${_version} (${_target})..." @@ -436,11 +282,27 @@ main() { _installed_version="$("${_install_dir}/${APP_NAME}" --version 2>/dev/null || echo "${_version}")" info "installed ${APP_NAME} ${_installed_version} to ${_install_dir}/${APP_NAME}" - # Set up PATH for default install location - if [ "$_using_default_dir" = "1" ] && [ "$NO_MODIFY_PATH" = "0" ]; then - if ! is_on_path "$_install_dir"; then - setup_path "$_install_dir" - fi + # If the install directory isn't on PATH, print instructions + if ! is_on_path "$_install_dir"; then + echo "" + info "${_install_dir} is not on your PATH." + info "" + info "Add it by appending the following to your shell configuration file" + info "(e.g. ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish):" + info "" + + _current_shell="$(basename "${SHELL:-sh}" 2>/dev/null || echo "sh")" + case "$_current_shell" in + fish) + info " fish_add_path ${_install_dir}" + ;; + *) + info " export PATH=\"${_install_dir}:\$PATH\"" + ;; + esac + + info "" + info "Then restart your shell or run the command above in your current session." fi }