From 0125da9ceaf700f90898d7b80a05a2b66dfbd3c6 Mon Sep 17 00:00:00 2001 From: Sc4r3Cr0w <52085661+UncleJ4ck@users.noreply.github.com> Date: Wed, 1 Jan 2025 13:12:15 +0100 Subject: [PATCH] fix: fallback mechanism --- install.sh | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/install.sh b/install.sh index 658dd9c..737bdd9 100755 --- a/install.sh +++ b/install.sh @@ -1,11 +1,10 @@ #!/bin/bash -# Function to print colored messages RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;34m' -NC='\033[0m' # No Color +NC='\033[0m' print_error() { echo -e "${RED}Error: $1${NC}" @@ -23,14 +22,11 @@ print_info() { echo -e "${BLUE}$1${NC}" } -# Install PHPV script and update PATH install_phpv() { - # Create required directories if they don't exist print_info "Crafting directories like a master builder..." mkdir -p "$HOME/src" mkdir -p "$HOME/bin" - # Check if phpv script exists locally, otherwise download from GitHub if [ -f "phpv" ]; then print_info "Found a local copy of phpv, because we believe in magic!" else @@ -41,15 +37,12 @@ install_phpv() { fi fi - # Install main script print_info "Enchanting the main script into $HOME/bin/phpv..." cp phpv "$HOME/bin/phpv" chmod +x "$HOME/bin/phpv" - # Update PATH environment variable print_info "Updating the enchanted PATH environment..." - # Check various shell configuration files and update PATH update_shell_config() { local config_file="$1" local shell_name="$2" @@ -61,31 +54,30 @@ install_phpv() { print_warning "PATH was already enchanted in $shell_name, no extra magic needed." fi else - print_error "Could not find $config_file to enchant with PATH magic." + print_warning "$config_file not found. Checking for the next shell configuration file." fi } - update_shell_config "$HOME/.bashrc" "bash" update_shell_config "$HOME/.bash_profile" "bash profile" + update_shell_config "$HOME/.bashrc" "bash" update_shell_config "$HOME/.zshrc" "zsh" update_shell_config "$HOME/.profile" "profile" - # Refresh shell configuration print_info "Casting spells to refresh your magical settings..." - source "$HOME/.bashrc" 2>/dev/null || source "$HOME/.bash_profile" 2>/dev/null || source "$HOME/.zshrc" 2>/dev/null || true + source "$HOME/.bash_profile" 2>/dev/null || \ + source "$HOME/.bashrc" 2>/dev/null || \ + source "$HOME/.zshrc" 2>/dev/null || \ + source "$HOME/.profile" 2>/dev/null || true - # Final verification if command -v phpv >/dev/null; then print_success "Installation complete! Your PHPV wand is now ready to wield." else print_error "Oops! The installation ritual failed. Time to consult the ancient scrolls of PATH configuration." fi - # Enlighten the user with PHPV incantations print_info "To summon the powers of PHPV:" print_info "For installation or update: phpv -i " print_info "For switching PHP versions: phpv " } -# Begin the installation journey install_phpv