Change installer scripts to prefer system-wide installation in /usr/local/bin, warn about user bin precedence, and offer to remove user bin versions after successful system installation
This commit is contained in:
@@ -158,33 +158,45 @@ determine_install_strategy() {
|
||||
local current_version=$(echo "$current_info" | cut -d: -f1)
|
||||
local install_type=$(echo "$current_info" | cut -d: -f2)
|
||||
|
||||
# Strategy 1: Check user bin directory first
|
||||
if check_user_bin_setup; then
|
||||
print_status "User bin directory is available and in PATH"
|
||||
# Strategy: Prefer system installation for all users
|
||||
if [[ $EUID -eq 0 ]] || sudo -n true 2>/dev/null; then
|
||||
print_status "Installing system-wide for all users"
|
||||
INSTALL_STRATEGY="system_install"
|
||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||
|
||||
# Check if tea exists in user bin
|
||||
# Warn if user bin has tea
|
||||
if [[ -f "$USER_BIN_DIR/tea" ]]; then
|
||||
print_status "Tea CLI found in user bin directory"
|
||||
print_warning "Tea CLI found in user bin directory ($USER_BIN_DIR)"
|
||||
print_status "This might take precedence if $USER_BIN_DIR is in PATH before system paths"
|
||||
fi
|
||||
else
|
||||
print_status "No sudo access, checking user bin directory"
|
||||
if check_user_bin_setup; then
|
||||
print_status "User bin directory is available and in PATH"
|
||||
|
||||
# Check for version symlink
|
||||
if check_version_symlink; then
|
||||
print_status "Version symlink found: $CURRENT_SYMLINK_VERSION"
|
||||
INSTALL_STRATEGY="user_update"
|
||||
TARGET_DIR="$USER_BIN_DIR"
|
||||
# Check if tea exists in user bin
|
||||
if [[ -f "$USER_BIN_DIR/tea" ]]; then
|
||||
print_status "Tea CLI found in user bin directory"
|
||||
|
||||
# Check for version symlink
|
||||
if check_version_symlink; then
|
||||
print_status "Version symlink found: $CURRENT_SYMLINK_VERSION"
|
||||
INSTALL_STRATEGY="user_update"
|
||||
TARGET_DIR="$USER_BIN_DIR"
|
||||
else
|
||||
print_status "No version symlink found, will create one"
|
||||
INSTALL_STRATEGY="user_upgrade"
|
||||
TARGET_DIR="$USER_BIN_DIR"
|
||||
fi
|
||||
else
|
||||
print_status "No version symlink found, will create one"
|
||||
INSTALL_STRATEGY="user_upgrade"
|
||||
print_status "Tea CLI not found in user bin, will install there"
|
||||
INSTALL_STRATEGY="user_install"
|
||||
TARGET_DIR="$USER_BIN_DIR"
|
||||
fi
|
||||
else
|
||||
print_status "Tea CLI not found in user bin, will install there"
|
||||
INSTALL_STRATEGY="user_install"
|
||||
TARGET_DIR="$USER_BIN_DIR"
|
||||
print_error "Cannot install system-wide (no sudo) and user bin not available"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
print_status "User bin directory not available, using system installation"
|
||||
INSTALL_STRATEGY="system_install"
|
||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||
fi
|
||||
|
||||
print_status "Installation strategy: $INSTALL_STRATEGY"
|
||||
@@ -407,10 +419,38 @@ install_tea_from_binary() {
|
||||
# Function to verify Tea CLI installation
|
||||
verify_tea_installation() {
|
||||
print_status "Verifying Tea CLI installation..."
|
||||
|
||||
|
||||
if command_exists tea; then
|
||||
local version=$(tea --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
|
||||
print_success "Tea CLI installed: $version"
|
||||
|
||||
# Check for user bin versions and offer removal
|
||||
if [[ -d "$USER_BIN_DIR" ]] && [[ "$TARGET_DIR" == "$SYSTEM_INSTALL_DIR" ]]; then
|
||||
local user_versions=()
|
||||
for file in "$USER_BIN_DIR"/tea*; do
|
||||
if [[ -f "$file" ]]; then
|
||||
user_versions+=("$file")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#user_versions[@]} -gt 0 ]]; then
|
||||
print_warning "Found tea binaries in user bin directory:"
|
||||
for file in "${user_versions[@]}"; do
|
||||
echo " $file"
|
||||
done
|
||||
echo
|
||||
read -p "Would you like to remove these user bin versions? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
for file in "${user_versions[@]}"; do
|
||||
rm -f "$file"
|
||||
print_status "Removed $file"
|
||||
done
|
||||
print_success "Removed all user bin versions"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
else
|
||||
print_error "Tea CLI installation verification failed"
|
||||
|
||||
Reference in New Issue
Block a user