Update sudo access check to prompt for password when needed, allowing system-wide installation even with password-protected sudo

This commit is contained in:
kdusek
2025-11-13 18:11:25 +01:00
parent 62cb59e645
commit 1c682a338c
2 changed files with 44 additions and 14 deletions

View File

@@ -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"