Skip to content

Commit 78fcc3d

Browse files
authored
fix: fallback mechanism Merge pull request #5 from UncleJ4ck/patch-1
fix: fallback mechanism
2 parents ffdba5d + 0125da9 commit 78fcc3d

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

install.sh

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/bin/bash
22

3-
# Function to print colored messages
43
RED='\033[0;31m'
54
GREEN='\033[0;32m'
65
YELLOW='\033[0;33m'
76
BLUE='\033[0;34m'
8-
NC='\033[0m' # No Color
7+
NC='\033[0m'
98

109
print_error() {
1110
echo -e "${RED}Error: $1${NC}"
@@ -23,14 +22,11 @@ print_info() {
2322
echo -e "${BLUE}$1${NC}"
2423
}
2524

26-
# Install PHPV script and update PATH
2725
install_phpv() {
28-
# Create required directories if they don't exist
2926
print_info "Crafting directories like a master builder..."
3027
mkdir -p "$HOME/src"
3128
mkdir -p "$HOME/bin"
3229

33-
# Check if phpv script exists locally, otherwise download from GitHub
3430
if [ -f "phpv" ]; then
3531
print_info "Found a local copy of phpv, because we believe in magic!"
3632
else
@@ -41,15 +37,12 @@ install_phpv() {
4137
fi
4238
fi
4339

44-
# Install main script
4540
print_info "Enchanting the main script into $HOME/bin/phpv..."
4641
cp phpv "$HOME/bin/phpv"
4742
chmod +x "$HOME/bin/phpv"
4843

49-
# Update PATH environment variable
5044
print_info "Updating the enchanted PATH environment..."
5145

52-
# Check various shell configuration files and update PATH
5346
update_shell_config() {
5447
local config_file="$1"
5548
local shell_name="$2"
@@ -61,31 +54,30 @@ install_phpv() {
6154
print_warning "PATH was already enchanted in $shell_name, no extra magic needed."
6255
fi
6356
else
64-
print_error "Could not find $config_file to enchant with PATH magic."
57+
print_warning "$config_file not found. Checking for the next shell configuration file."
6558
fi
6659
}
6760

68-
update_shell_config "$HOME/.bashrc" "bash"
6961
update_shell_config "$HOME/.bash_profile" "bash profile"
62+
update_shell_config "$HOME/.bashrc" "bash"
7063
update_shell_config "$HOME/.zshrc" "zsh"
7164
update_shell_config "$HOME/.profile" "profile"
7265

73-
# Refresh shell configuration
7466
print_info "Casting spells to refresh your magical settings..."
75-
source "$HOME/.bashrc" 2>/dev/null || source "$HOME/.bash_profile" 2>/dev/null || source "$HOME/.zshrc" 2>/dev/null || true
67+
source "$HOME/.bash_profile" 2>/dev/null || \
68+
source "$HOME/.bashrc" 2>/dev/null || \
69+
source "$HOME/.zshrc" 2>/dev/null || \
70+
source "$HOME/.profile" 2>/dev/null || true
7671

77-
# Final verification
7872
if command -v phpv >/dev/null; then
7973
print_success "Installation complete! Your PHPV wand is now ready to wield."
8074
else
8175
print_error "Oops! The installation ritual failed. Time to consult the ancient scrolls of PATH configuration."
8276
fi
8377

84-
# Enlighten the user with PHPV incantations
8578
print_info "To summon the powers of PHPV:"
8679
print_info "For installation or update: phpv -i <version>"
8780
print_info "For switching PHP versions: phpv <version>"
8881
}
8982

90-
# Begin the installation journey
9183
install_phpv

0 commit comments

Comments
 (0)