From 1c682a338c7b29a1d07e7bec9e16336d471b347d Mon Sep 17 00:00:00 2001 From: kdusek Date: Thu, 13 Nov 2025 18:11:25 +0100 Subject: [PATCH] Update sudo access check to prompt for password when needed, allowing system-wide installation even with password-protected sudo --- install-borg-cli.sh | 26 +++++++++++++++++++------- install-tea-cli.sh | 32 +++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/install-borg-cli.sh b/install-borg-cli.sh index 269848e..3a47e65 100755 --- a/install-borg-cli.sh +++ b/install-borg-cli.sh @@ -283,17 +283,29 @@ determine_install_strategy() { local install_type=$(echo "$current_info" | cut -d: -f2) # 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" + if [[ $EUID -eq 0 ]]; then + print_status "Running as root, installing system-wide" 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" + 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 + + # 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 print_status "User bin directory is available and in PATH" diff --git a/install-tea-cli.sh b/install-tea-cli.sh index b55fe4f..66e4307 100755 --- a/install-tea-cli.sh +++ b/install-tea-cli.sh @@ -159,17 +159,35 @@ determine_install_strategy() { local install_type=$(echo "$current_info" | cut -d: -f2) # 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" + if [[ $EUID -eq 0 ]]; then + print_status "Running as root, installing system-wide" 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" + 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 print_status "User bin directory is available and in PATH"