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:
kdusek
2025-11-13 17:49:01 +01:00
parent fbaebfaae2
commit 979977d16e
3 changed files with 133 additions and 39 deletions

View File

@@ -282,7 +282,19 @@ determine_install_strategy() {
local current_version=$(echo "$current_info" | cut -d: -f1) local current_version=$(echo "$current_info" | cut -d: -f1)
local install_type=$(echo "$current_info" | cut -d: -f2) local install_type=$(echo "$current_info" | cut -d: -f2)
# Strategy 1: Check user bin directory first # 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"
# Warn if user bin has borg
if [[ -f "$USER_BIN_DIR/borg" ]]; then
print_warning "Borg 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 if check_user_bin_setup; then
print_status "User bin directory is available and in PATH" print_status "User bin directory is available and in PATH"
@@ -306,9 +318,9 @@ determine_install_strategy() {
TARGET_DIR="$USER_BIN_DIR" TARGET_DIR="$USER_BIN_DIR"
fi fi
else else
print_status "User bin directory not available, using system installation" print_error "Cannot install system-wide (no sudo) and user bin not available"
INSTALL_STRATEGY="system_install" exit 1
TARGET_DIR="$SYSTEM_INSTALL_DIR" fi
fi fi
print_status "Installation strategy: $INSTALL_STRATEGY" print_status "Installation strategy: $INSTALL_STRATEGY"
@@ -427,6 +439,34 @@ verify_borg_installation() {
if command_exists borg; then if command_exists borg; then
local version=$(borg --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1) local version=$(borg --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
print_success "Borg CLI installed: $version" print_success "Borg 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"/borg*; do
if [[ -f "$file" ]]; then
user_versions+=("$file")
fi
done
if [[ ${#user_versions[@]} -gt 0 ]]; then
print_warning "Found borg 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 return 0
else else
print_error "Borg CLI installation verification failed" print_error "Borg CLI installation verification failed"

View File

@@ -16,6 +16,7 @@ NC='\033[0m' # No Color
# Configuration # Configuration
GITHUB_REPO="git-ecosystem/git-credential-manager" GITHUB_REPO="git-ecosystem/git-credential-manager"
INSTALL_DIR="/usr/local/bin" INSTALL_DIR="/usr/local/bin"
USER_BIN_DIR="$HOME/bin"
TEMP_DIR="/tmp/gcm-install" TEMP_DIR="/tmp/gcm-install"
# Function to print colored output # Function to print colored output
@@ -451,6 +452,19 @@ verify_installation() {
# Check all presets # Check all presets
configure_git_presets configure_git_presets
# Check for user bin version and offer removal
if [[ -f "$USER_BIN_DIR/git-credential-manager" ]]; then
print_warning "Found git-credential-manager in user bin directory ($USER_BIN_DIR)"
print_status "This might take precedence if $USER_BIN_DIR is in PATH before system paths"
echo
read -p "Would you like to remove the user bin version? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -f "$USER_BIN_DIR/git-credential-manager"
print_success "Removed user bin version"
fi
fi
return 0 return 0
else else
print_error "git-credential-manager installation verification failed" print_error "git-credential-manager installation verification failed"

View File

@@ -158,7 +158,19 @@ determine_install_strategy() {
local current_version=$(echo "$current_info" | cut -d: -f1) local current_version=$(echo "$current_info" | cut -d: -f1)
local install_type=$(echo "$current_info" | cut -d: -f2) local install_type=$(echo "$current_info" | cut -d: -f2)
# Strategy 1: Check user bin directory first # 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"
# Warn if user bin has tea
if [[ -f "$USER_BIN_DIR/tea" ]]; then
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 if check_user_bin_setup; then
print_status "User bin directory is available and in PATH" print_status "User bin directory is available and in PATH"
@@ -182,9 +194,9 @@ determine_install_strategy() {
TARGET_DIR="$USER_BIN_DIR" TARGET_DIR="$USER_BIN_DIR"
fi fi
else else
print_status "User bin directory not available, using system installation" print_error "Cannot install system-wide (no sudo) and user bin not available"
INSTALL_STRATEGY="system_install" exit 1
TARGET_DIR="$SYSTEM_INSTALL_DIR" fi
fi fi
print_status "Installation strategy: $INSTALL_STRATEGY" print_status "Installation strategy: $INSTALL_STRATEGY"
@@ -411,6 +423,34 @@ verify_tea_installation() {
if command_exists tea; then if command_exists tea; then
local version=$(tea --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1) local version=$(tea --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
print_success "Tea CLI installed: $version" 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 return 0
else else
print_error "Tea CLI installation verification failed" print_error "Tea CLI installation verification failed"