From f70e314bf6b060c295f6d844db8bc6d53ce3c205 Mon Sep 17 00:00:00 2001 From: Jose B Date: Thu, 11 Dec 2025 16:35:02 -0500 Subject: [PATCH] chore: improve PATH management and tool verification in installer Add centralized `add_to_path` function to consistently update shell profile files (.profile, .bash_profile, .bashrc, .zshrc) with PATH exports. Update just and uv installation to use direct binary verification instead of relying on `command -v`, ensuring tools are properly installed even when PATH isn't immediately updated. Enhance platform installation by explicitly setting PATH and using full CLI path for execution. --- install.sh | 110 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 36 deletions(-) diff --git a/install.sh b/install.sh index 9ecd4ac..45c919b 100755 --- a/install.sh +++ b/install.sh @@ -86,6 +86,44 @@ show_welcome() { # Utility Functions # ============================================================================ +add_to_path() { + local dir_to_add="$1" + local path_export="export PATH=\"$dir_to_add:\$PATH\"" + + # List of profile files to update (in order of preference) + local profile_files=( + "$HOME/.profile" + "$HOME/.bash_profile" + "$HOME/.bashrc" + "$HOME/.zshrc" + ) + + local added_to_file=false + + for profile_file in "${profile_files[@]}"; do + # Only add to existing files or create .profile/.bashrc if they don't exist + if [ -f "$profile_file" ] || [[ "$profile_file" == *".profile" ]] || [[ "$profile_file" == *".bashrc" ]]; then + # Check if PATH is already in the file + if [ -f "$profile_file" ] && grep -q "export PATH=\"$dir_to_add:\$PATH\"" "$profile_file" 2>/dev/null; then + continue + fi + + # Add PATH export to the file + echo "" >> "$profile_file" + echo "# Added by InternalAI installer" >> "$profile_file" + echo "$path_export" >> "$profile_file" + added_to_file=true + + log_info "Added $dir_to_add to PATH in $profile_file" + fi + done + + if [ "$added_to_file" = false ]; then + log_warning "Could not find suitable profile file to persist PATH" + log_info "Add this to your shell profile manually: $path_export" + fi +} + prompt() { local varname=$1 local prompt_text=$2 @@ -289,44 +327,39 @@ install_just() { if [[ ":$PATH:" != *":$install_dir:"* ]]; then log_info "Adding $install_dir to PATH..." export PATH="$install_dir:$PATH" - - # Add to shell profile - local shell_profile="" - if [ -n "$BASH_VERSION" ]; then - shell_profile="$HOME/.bashrc" - elif [ -n "$ZSH_VERSION" ]; then - shell_profile="$HOME/.zshrc" - fi - - if [ -n "$shell_profile" ]; then - echo "export PATH=\"$install_dir:\$PATH\"" >> "$shell_profile" - log_info "Added to $shell_profile (restart shell or run: source $shell_profile)" - fi fi - # Verify installation - if command -v just &> /dev/null; then + # Persist PATH to shell profiles + add_to_path "$install_dir" + + # Verify installation by checking the binary directly + if [ -x "$install_dir/just" ]; then log_success "just installed successfully to $install_dir/just" else - log_warning "just installed to $install_dir/just but not found in PATH" - log_info "You may need to restart your terminal or run:" - log_info " export PATH=\"$install_dir:\$PATH\"" + log_error "just binary not found or not executable at $install_dir/just" + exit 1 fi } install_uv() { log_info "Installing uv (Python package manager)..." + local install_dir="$HOME/.local/bin" + if curl -LsSf https://astral.sh/uv/install.sh | sh; then # Add uv to PATH for current session - export PATH="$HOME/.local/bin:$PATH" + if [[ ":$PATH:" != *":$install_dir:"* ]]; then + export PATH="$install_dir:$PATH" + fi - if command -v uv &> /dev/null; then - log_success "uv installed successfully ($(uv --version | head -n1))" + # Persist PATH to shell profiles + add_to_path "$install_dir" + + # Verify installation by checking the binary directly + if [ -x "$install_dir/uv" ]; then + log_success "uv installed successfully to $install_dir/uv" else - log_error "uv installation succeeded but not found in PATH" - log_info "You may need to restart your terminal or run:" - log_info " export PATH=\"\$HOME/.local/bin:\$PATH\"" + log_error "uv binary not found or not executable at $install_dir/uv" exit 1 fi else @@ -833,20 +866,25 @@ run_platform_install() { log_info "Starting platform configuration and installation..." echo "" - # Run internalai install - if command -v "$CLI_NAME" &> /dev/null; then - "$CLI_NAME" install + # Ensure PATH includes necessary directories for the internalai install command + # This is critical because internalai install may depend on just, uv, docker, etc. + export PATH="$HOME/.local/bin:$CLI_INSTALL_DIR:$PATH" + + # Run internalai install using the full path + local cli_path="" + if [ -x "$CLI_INSTALL_DIR/$CLI_NAME" ]; then + cli_path="$CLI_INSTALL_DIR/$CLI_NAME" + elif command -v "$CLI_NAME" &> /dev/null; then + cli_path=$(command -v "$CLI_NAME") else - log_error "$CLI_NAME command not found in PATH" - log_info "Trying direct path: $CLI_INSTALL_DIR/$CLI_NAME" - if [ -x "$CLI_INSTALL_DIR/$CLI_NAME" ]; then - "$CLI_INSTALL_DIR/$CLI_NAME" install - else - log_error "Failed to run $CLI_NAME install" - log_info "Please run manually: $CLI_NAME install" - exit 1 - fi + log_error "$CLI_NAME command not found" + log_info "Expected location: $CLI_INSTALL_DIR/$CLI_NAME" + log_info "Please run manually: $CLI_NAME install" + exit 1 fi + + log_info "Running: $cli_path install" + "$cli_path" install } # ============================================================================