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,33 +282,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 borg exists in user bin
# Warn if user bin has borg
if [[ -f "$USER_BIN_DIR/borg" ]]; then
print_status "Borg CLI found in user bin directory"
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
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 borg exists in user bin
if [[ -f "$USER_BIN_DIR/borg" ]]; then
print_status "Borg 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 "Borg CLI not found in user bin, will install there"
INSTALL_STRATEGY="user_install"
TARGET_DIR="$USER_BIN_DIR"
fi
else
print_status "Borg 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"
@@ -427,6 +439,34 @@ verify_borg_installation() {
if command_exists borg; then
local version=$(borg --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1)
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
else
print_error "Borg CLI installation verification failed"