From da05e9c602a96c562c052554406aff21f0907125 Mon Sep 17 00:00:00 2001 From: torlando-tech Date: Tue, 28 Oct 2025 20:39:00 -0400 Subject: [PATCH] fix: handle sudo absence in fresh Debian containers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Debian containers run as root without sudo installed by default. The script was trying to use sudo to install packages (including sudo itself), which failed with "sudo: command not found". Changes: - Check if running as root ($EUID -eq 0) before using sudo - If root: use package managers directly (apt-get, pacman) - If not root: use sudo as before Applied to: - Basic prerequisites installation (lines 108-113) - Arch prerequisites installation (lines 131-135) - System dependencies installation (lines 215-221) - Arch system dependencies (lines 228-232) This fixes installation in: - Fresh Debian containers (root, no sudo) - Fresh Ubuntu containers (root, has sudo but not needed) - User Debian/Ubuntu systems (not root, uses sudo) - User Arch systems (not root, uses sudo) Fixes Debian 12 CI failure: "sudo: command not found" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- install.sh | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 0e4468b..28c80c3 100755 --- a/install.sh +++ b/install.sh @@ -104,8 +104,14 @@ if command -v apt-get &> /dev/null; then if [ ${#MISSING_PACKAGES[@]} -gt 0 ]; then print_info "Installing basic prerequisites: ${MISSING_PACKAGES[*]}" - sudo apt-get update -qq - sudo apt-get install -y -q ${MISSING_PACKAGES[*]} + # Use sudo only if not running as root (Debian containers run as root without sudo) + if [ "$EUID" -eq 0 ]; then + apt-get update -qq + apt-get install -y -q ${MISSING_PACKAGES[*]} + else + sudo apt-get update -qq + sudo apt-get install -y -q ${MISSING_PACKAGES[*]} + fi print_success "Basic prerequisites installed" else print_success "Basic prerequisites already installed" @@ -121,7 +127,12 @@ elif command -v pacman &> /dev/null; then if [ ${#MISSING_PACKAGES[@]} -gt 0 ]; then print_info "Installing basic prerequisites: ${MISSING_PACKAGES[*]}" - sudo pacman -S --noconfirm ${MISSING_PACKAGES[*]} + # Use sudo only if not running as root + if [ "$EUID" -eq 0 ]; then + pacman -S --noconfirm ${MISSING_PACKAGES[*]} + else + sudo pacman -S --noconfirm ${MISSING_PACKAGES[*]} + fi print_success "Basic prerequisites installed" else print_success "Basic prerequisites already installed" @@ -200,14 +211,25 @@ if command -v apt-get &> /dev/null; then # Debian/Ubuntu/Raspberry Pi OS print_info "Detected Debian/Ubuntu-based system" echo "Installing: python3-pip python3-gi python3-dbus python3-cairo bluez" - sudo apt-get update - sudo apt-get install -y python3-pip python3-gi python3-dbus python3-cairo bluez + # Use sudo only if not running as root + if [ "$EUID" -eq 0 ]; then + apt-get update + apt-get install -y python3-pip python3-gi python3-dbus python3-cairo bluez + else + sudo apt-get update + sudo apt-get install -y python3-pip python3-gi python3-dbus python3-cairo bluez + fi print_success "System dependencies installed (using pre-compiled system packages)" elif command -v pacman &> /dev/null; then # Arch Linux print_info "Detected Arch Linux" echo "Installing: python-pip python-gobject python-dbus python-cairo bluez bluez-utils" - sudo pacman -S --noconfirm python-pip python-gobject python-dbus python-cairo bluez bluez-utils + # Use sudo only if not running as root + if [ "$EUID" -eq 0 ]; then + pacman -S --noconfirm python-pip python-gobject python-dbus python-cairo bluez bluez-utils + else + sudo pacman -S --noconfirm python-pip python-gobject python-dbus python-cairo bluez bluez-utils + fi print_success "System dependencies installed (using pre-compiled system packages)" else print_warning "Could not detect package manager"