Add --local option to force installation to user bin directory, preventing automatic fallback when sudo is unavailable
This commit is contained in:
@@ -278,28 +278,53 @@ check_version_symlink() {
|
|||||||
|
|
||||||
# Function to determine installation strategy
|
# Function to determine installation strategy
|
||||||
determine_install_strategy() {
|
determine_install_strategy() {
|
||||||
|
local local_install="$1"
|
||||||
local current_info=$(get_current_version)
|
local current_info=$(get_current_version)
|
||||||
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: Prefer system installation for all users
|
# Strategy: Check installation type preference
|
||||||
if [[ $EUID -eq 0 ]]; then
|
if [[ "$local_install" == "true" ]]; then
|
||||||
print_status "Running as root, installing system-wide"
|
print_status "Local installation requested"
|
||||||
INSTALL_STRATEGY="system_install"
|
if check_user_bin_setup; then
|
||||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
print_status "User bin directory is available and in PATH"
|
||||||
elif sudo -n true 2>/dev/null; then
|
INSTALL_STRATEGY="user_install"
|
||||||
print_status "Passwordless sudo available, installing system-wide"
|
TARGET_DIR="$USER_BIN_DIR"
|
||||||
INSTALL_STRATEGY="system_install"
|
else
|
||||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
print_error "User bin directory not available for local installation"
|
||||||
elif command_exists sudo; then
|
exit 1
|
||||||
print_status "Testing sudo access (you may be prompted for password)..."
|
fi
|
||||||
if sudo -v 2>/dev/null; then
|
else
|
||||||
print_success "Sudo access confirmed, installing system-wide"
|
# Prefer system installation for all users
|
||||||
|
if [[ $EUID -eq 0 ]]; then
|
||||||
|
print_status "Running as root, installing system-wide"
|
||||||
INSTALL_STRATEGY="system_install"
|
INSTALL_STRATEGY="system_install"
|
||||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
elif sudo -n true 2>/dev/null; then
|
||||||
|
print_status "Passwordless sudo available, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
elif command_exists sudo; then
|
||||||
|
print_status "Testing sudo access (you may be prompted for password)..."
|
||||||
|
if sudo -v 2>/dev/null; then
|
||||||
|
print_success "Sudo access confirmed, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
else
|
||||||
|
print_error "Sudo access failed. Use --local to install to user bin directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
print_warning "Sudo access failed, falling back to user installation"
|
print_error "Sudo not available. Use --local to install to user bin directory"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Warn if user bin has borg (only for system installs)
|
||||||
|
if [[ "$INSTALL_STRATEGY" == "system_install" ]] && [[ -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
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
print_warning "Sudo not available, using user installation"
|
print_warning "Sudo not available, using user installation"
|
||||||
fi
|
fi
|
||||||
@@ -463,6 +488,7 @@ show_usage() {
|
|||||||
echo " -v, --version Install specific version (default: latest)"
|
echo " -v, --version Install specific version (default: latest)"
|
||||||
echo " -f, --force Force reinstall even if up-to-date"
|
echo " -f, --force Force reinstall even if up-to-date"
|
||||||
echo " -r, --reinstall Reinstall the current installed version"
|
echo " -r, --reinstall Reinstall the current installed version"
|
||||||
|
echo " -l, --local Force installation to user bin directory (~/.bin)"
|
||||||
echo " -p, --package Force installation from package manager"
|
echo " -p, --package Force installation from package manager"
|
||||||
echo " -b, --binary Force installation from binary"
|
echo " -b, --binary Force installation from binary"
|
||||||
echo
|
echo
|
||||||
@@ -470,6 +496,7 @@ show_usage() {
|
|||||||
echo " $0 # Install latest version using best method"
|
echo " $0 # Install latest version using best method"
|
||||||
echo " $0 -v v1.2.7 # Install specific version"
|
echo " $0 -v v1.2.7 # Install specific version"
|
||||||
echo " $0 --reinstall # Reinstall current version"
|
echo " $0 --reinstall # Reinstall current version"
|
||||||
|
echo " $0 --local # Force installation to user bin"
|
||||||
echo " $0 --package # Force installation from package manager"
|
echo " $0 --package # Force installation from package manager"
|
||||||
echo " $0 --binary # Force installation from binary"
|
echo " $0 --binary # Force installation from binary"
|
||||||
echo
|
echo
|
||||||
@@ -480,6 +507,7 @@ main() {
|
|||||||
local target_version=""
|
local target_version=""
|
||||||
local force_reinstall=false
|
local force_reinstall=false
|
||||||
local reinstall_current=false
|
local reinstall_current=false
|
||||||
|
local local_install=false
|
||||||
local install_method="auto"
|
local install_method="auto"
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
@@ -501,6 +529,10 @@ main() {
|
|||||||
reinstall_current=true
|
reinstall_current=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-l|--local)
|
||||||
|
local_install=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-p|--package)
|
-p|--package)
|
||||||
install_method="package"
|
install_method="package"
|
||||||
shift
|
shift
|
||||||
@@ -553,7 +585,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Determine installation strategy
|
# Determine installation strategy
|
||||||
determine_install_strategy
|
determine_install_strategy "$local_install"
|
||||||
|
|
||||||
# Check if update is needed
|
# Check if update is needed
|
||||||
if ! check_update_needed "$target_version"; then
|
if ! check_update_needed "$target_version"; then
|
||||||
|
|||||||
@@ -511,6 +511,7 @@ show_usage() {
|
|||||||
echo " -v, --version Install specific version (default: latest)"
|
echo " -v, --version Install specific version (default: latest)"
|
||||||
echo " -f, --force Force reinstall even if already installed"
|
echo " -f, --force Force reinstall even if already installed"
|
||||||
echo " -r, --reinstall Reinstall the current installed version"
|
echo " -r, --reinstall Reinstall the current installed version"
|
||||||
|
echo " -l, --local Force installation to user bin directory (~/.bin)"
|
||||||
echo " -p, --package Force installation from package manager"
|
echo " -p, --package Force installation from package manager"
|
||||||
echo " -d, --deb Force installation from DEB package"
|
echo " -d, --deb Force installation from DEB package"
|
||||||
echo " -t, --tarball Force installation from tarball"
|
echo " -t, --tarball Force installation from tarball"
|
||||||
@@ -520,6 +521,7 @@ show_usage() {
|
|||||||
echo " $0 # Install latest version using best method"
|
echo " $0 # Install latest version using best method"
|
||||||
echo " $0 -v v2.6.0 # Install specific version"
|
echo " $0 -v v2.6.0 # Install specific version"
|
||||||
echo " $0 --reinstall # Reinstall current version"
|
echo " $0 --reinstall # Reinstall current version"
|
||||||
|
echo " $0 --local # Force installation to user bin"
|
||||||
echo " $0 --package # Force installation from package manager"
|
echo " $0 --package # Force installation from package manager"
|
||||||
echo " $0 --deb # Force installation from DEB package"
|
echo " $0 --deb # Force installation from DEB package"
|
||||||
echo " $0 --checks # Check configuration without installing"
|
echo " $0 --checks # Check configuration without installing"
|
||||||
@@ -556,6 +558,7 @@ main() {
|
|||||||
local target_version=""
|
local target_version=""
|
||||||
local force_reinstall=false
|
local force_reinstall=false
|
||||||
local reinstall_current=false
|
local reinstall_current=false
|
||||||
|
local local_install=false
|
||||||
local install_method="auto"
|
local install_method="auto"
|
||||||
local checks_only=false
|
local checks_only=false
|
||||||
|
|
||||||
@@ -578,6 +581,10 @@ main() {
|
|||||||
reinstall_current=true
|
reinstall_current=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-l|--local)
|
||||||
|
local_install=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-p|--package)
|
-p|--package)
|
||||||
install_method="package"
|
install_method="package"
|
||||||
shift
|
shift
|
||||||
@@ -643,21 +650,20 @@ main() {
|
|||||||
# Detect system
|
# Detect system
|
||||||
detect_os
|
detect_os
|
||||||
ARCH=$(get_arch)
|
ARCH=$(get_arch)
|
||||||
|
|
||||||
# Create temporary directory
|
# Check for local installation
|
||||||
mkdir -p "$TEMP_DIR"
|
if [[ "$local_install" == "true" ]]; then
|
||||||
|
print_error "Git Credential Manager requires system installation for proper integration"
|
||||||
# Trap cleanup on exit
|
exit 1
|
||||||
trap cleanup EXIT
|
fi
|
||||||
|
|
||||||
# Installation logic based on method
|
# Get latest version if not specified
|
||||||
case $install_method in
|
if [[ -z "$target_version" ]]; then
|
||||||
auto)
|
get_latest_release
|
||||||
# Try package manager first
|
target_version="$LATEST_VERSION"
|
||||||
if install_from_package_manager; then
|
else
|
||||||
verify_installation
|
print_status "Using specified version: $target_version"
|
||||||
exit 0
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Fall back to distribution-specific methods
|
# Fall back to distribution-specific methods
|
||||||
case $OS in
|
case $OS in
|
||||||
|
|||||||
@@ -154,67 +154,52 @@ check_version_symlink() {
|
|||||||
|
|
||||||
# Function to determine installation strategy
|
# Function to determine installation strategy
|
||||||
determine_install_strategy() {
|
determine_install_strategy() {
|
||||||
|
local local_install="$1"
|
||||||
local current_info=$(get_current_version)
|
local current_info=$(get_current_version)
|
||||||
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: Prefer system installation for all users
|
# Strategy: Check installation type preference
|
||||||
if [[ $EUID -eq 0 ]]; then
|
if [[ "$local_install" == "true" ]]; then
|
||||||
print_status "Running as root, installing system-wide"
|
print_status "Local installation requested"
|
||||||
INSTALL_STRATEGY="system_install"
|
|
||||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
|
||||||
elif sudo -n true 2>/dev/null; then
|
|
||||||
print_status "Passwordless sudo available, installing system-wide"
|
|
||||||
INSTALL_STRATEGY="system_install"
|
|
||||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
|
||||||
elif command_exists sudo; then
|
|
||||||
print_status "Testing sudo access (you may be prompted for password)..."
|
|
||||||
if sudo -v 2>/dev/null; then
|
|
||||||
print_success "Sudo access confirmed, installing system-wide"
|
|
||||||
INSTALL_STRATEGY="system_install"
|
|
||||||
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
|
||||||
else
|
|
||||||
print_warning "Sudo access failed, falling back to user installation"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_warning "Sudo not available, using user installation"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Warn if user bin has tea (only for system installs)
|
|
||||||
if [[ "$INSTALL_STRATEGY" == "system_install" ]] && [[ -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
|
|
||||||
|
|
||||||
# If not system install, check user bin
|
|
||||||
if [[ "$INSTALL_STRATEGY" != "system_install" ]]; then
|
|
||||||
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"
|
||||||
|
INSTALL_STRATEGY="user_install"
|
||||||
# Check if tea exists in user bin
|
TARGET_DIR="$USER_BIN_DIR"
|
||||||
if [[ -f "$USER_BIN_DIR/tea" ]]; then
|
else
|
||||||
print_status "Tea CLI found in user bin directory"
|
print_error "User bin directory not available for local installation"
|
||||||
|
exit 1
|
||||||
# Check for version symlink
|
fi
|
||||||
if check_version_symlink; then
|
else
|
||||||
print_status "Version symlink found: $CURRENT_SYMLINK_VERSION"
|
# Prefer system installation for all users
|
||||||
INSTALL_STRATEGY="user_update"
|
if [[ $EUID -eq 0 ]]; then
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
print_status "Running as root, installing system-wide"
|
||||||
else
|
INSTALL_STRATEGY="system_install"
|
||||||
print_status "No version symlink found, will create one"
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
INSTALL_STRATEGY="user_upgrade"
|
elif sudo -n true 2>/dev/null; then
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
print_status "Passwordless sudo available, installing system-wide"
|
||||||
fi
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
|
elif command_exists sudo; then
|
||||||
|
print_status "Testing sudo access (you may be prompted for password)..."
|
||||||
|
if sudo -v 2>/dev/null; then
|
||||||
|
print_success "Sudo access confirmed, installing system-wide"
|
||||||
|
INSTALL_STRATEGY="system_install"
|
||||||
|
TARGET_DIR="$SYSTEM_INSTALL_DIR"
|
||||||
else
|
else
|
||||||
print_status "Tea CLI not found in user bin, will install there"
|
print_error "Sudo access failed. Use --local to install to user bin directory"
|
||||||
INSTALL_STRATEGY="user_install"
|
exit 1
|
||||||
TARGET_DIR="$USER_BIN_DIR"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
print_error "Cannot install system-wide (no sudo) and user bin not available"
|
print_error "Sudo not available. Use --local to install to user bin directory"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Warn if user bin has tea (only for system installs)
|
||||||
|
if [[ "$INSTALL_STRATEGY" == "system_install" ]] && [[ -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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_status "Installation strategy: $INSTALL_STRATEGY"
|
print_status "Installation strategy: $INSTALL_STRATEGY"
|
||||||
@@ -453,6 +438,7 @@ show_usage() {
|
|||||||
echo " -v, --version Install specific version (default: latest)"
|
echo " -v, --version Install specific version (default: latest)"
|
||||||
echo " -f, --force Force reinstall even if up-to-date"
|
echo " -f, --force Force reinstall even if up-to-date"
|
||||||
echo " -r, --reinstall Reinstall the current installed version"
|
echo " -r, --reinstall Reinstall the current installed version"
|
||||||
|
echo " -l, --local Force installation to user bin directory (~/.bin)"
|
||||||
echo " -p, --package Force installation from package manager"
|
echo " -p, --package Force installation from package manager"
|
||||||
echo " -b, --binary Force installation from binary"
|
echo " -b, --binary Force installation from binary"
|
||||||
echo
|
echo
|
||||||
@@ -460,6 +446,7 @@ show_usage() {
|
|||||||
echo " $0 # Install latest version using best method"
|
echo " $0 # Install latest version using best method"
|
||||||
echo " $0 -v v0.10.0 # Install specific version"
|
echo " $0 -v v0.10.0 # Install specific version"
|
||||||
echo " $0 --reinstall # Reinstall current version"
|
echo " $0 --reinstall # Reinstall current version"
|
||||||
|
echo " $0 --local # Force installation to user bin"
|
||||||
echo " $0 --package # Force installation from package manager"
|
echo " $0 --package # Force installation from package manager"
|
||||||
echo " $0 --binary # Force installation from binary"
|
echo " $0 --binary # Force installation from binary"
|
||||||
echo
|
echo
|
||||||
@@ -470,6 +457,7 @@ main() {
|
|||||||
local target_version=""
|
local target_version=""
|
||||||
local force_reinstall=false
|
local force_reinstall=false
|
||||||
local reinstall_current=false
|
local reinstall_current=false
|
||||||
|
local local_install=false
|
||||||
local install_method="auto"
|
local install_method="auto"
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
@@ -491,6 +479,10 @@ main() {
|
|||||||
reinstall_current=true
|
reinstall_current=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-l|--local)
|
||||||
|
local_install=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-p|--package)
|
-p|--package)
|
||||||
install_method="package"
|
install_method="package"
|
||||||
shift
|
shift
|
||||||
@@ -543,7 +535,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Determine installation strategy
|
# Determine installation strategy
|
||||||
determine_install_strategy
|
determine_install_strategy "$local_install"
|
||||||
|
|
||||||
# Check if update is needed
|
# Check if update is needed
|
||||||
if ! check_update_needed "$target_version"; then
|
if ! check_update_needed "$target_version"; then
|
||||||
|
|||||||
Reference in New Issue
Block a user