diff --git a/scripts-download.sh b/scripts-download.sh index 615c8fd..12366dc 100644 --- a/scripts-download.sh +++ b/scripts-download.sh @@ -20,7 +20,8 @@ readonly YELLOW='\033[1;33m' # Configuration readonly FILES_URL="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main" -readonly REQUIRED_PACKAGES=("zip" "unzip" "sha256sum" "curl" "crontab") +readonly REQUIRED_PACKAGES=("zip" "unzip" "curl") +readonly REQUIRED_COMMANDS=("zip" "unzip" "sha256sum" "curl" "crontab") readonly AVAILABLE_SCRIPTS=("clean.sh" "backup.sh" "docker-updater.sh") # Format: [script_name]="cron_schedule" @@ -76,13 +77,23 @@ detect_operating_system() { get_missing_packages() { local missing=() - for package in "${REQUIRED_PACKAGES[@]}"; do - if ! command_exists "$package"; then - missing+=("$package") - fi - done + # Check each required command and map to package names + if ! command_exists "zip"; then + missing+=("zip") + fi + if ! command_exists "unzip"; then + missing+=("unzip") + fi + if ! command_exists "curl"; then + missing+=("curl") + fi + # sha256sum is part of coreutils (usually pre-installed) + # crontab is part of cron package, but we'll check for cron service later - printf '%s\n' "${missing[@]}" + # Only print if there are missing packages + if [[ ${#missing[@]} -gt 0 ]]; then + printf '%s\n' "${missing[@]}" + fi } # Install packages based on the detected OS @@ -92,10 +103,12 @@ install_packages() { local packages=("$@") if [[ ${#packages[@]} -eq 0 ]]; then + log_info "No packages to install" return 0 fi log_info "Installing required packages: ${packages[*]}" + log_info "Debug: Installing ${#packages[@]} packages on $os" case "$os" in "Alpine") @@ -152,16 +165,17 @@ check_crontab_service() { select_scripts() { local selected=() - log_info "Available scripts for download and installation:" - echo + echo >&2 # Send to stderr so it doesn't get captured + echo -e "${GREY}[i] Available scripts for download and installation:${NC}" >&2 + echo >&2 for script in "${AVAILABLE_SCRIPTS[@]}"; do local schedule="${CRONTAB_SCHEDULES[$script]:-"0 0 * * *"}" - echo -e " ${LIGHT_BLUE}$script${NC} - Schedule: ${GREY}$schedule${NC}" + echo -e " ${LIGHT_BLUE}$script${NC} - Schedule: ${GREY}$schedule${NC}" >&2 done - echo - log_info "Select scripts to download and install:" + echo >&2 + echo -e "${GREY}[i] Select scripts to download and install:${NC}" >&2 for script in "${AVAILABLE_SCRIPTS[@]}"; do read -p "Install $script? [Y/n]: " choice &2 + exit 1 fi + # Only output the selected scripts to stdout printf '%s\n' "${selected[@]}" } @@ -268,6 +284,21 @@ main() { local missing_packages readarray -t missing_packages < <(get_missing_packages) + # Filter out empty strings + local filtered_packages=() + for pkg in "${missing_packages[@]}"; do + if [[ -n "$pkg" ]]; then + filtered_packages+=("$pkg") + fi + done + missing_packages=("${filtered_packages[@]}") + + # Debug output + log_info "Debug: Found ${#missing_packages[@]} missing packages" + for i in "${!missing_packages[@]}"; do + log_info "Debug: Missing package $((i+1)): '${missing_packages[i]}'" + done + if [[ ${#missing_packages[@]} -gt 0 ]]; then log_warning "Missing packages detected: ${missing_packages[*]}" install_packages "$detected_os" "${missing_packages[@]}"