From ab34023c51734063b531b97a46756f6a6ac4f3e7 Mon Sep 17 00:00:00 2001 From: Cobra Date: Tue, 7 Apr 2026 14:02:32 -0400 Subject: [PATCH] Fix set -e crash in image detection and device selection ls glob on empty cache dir exits non-zero and kills script under set -euo pipefail. Switched to find which exits 0 on no matches. Same fix for grep|sed pipeline in device selection; added empty DEVICE guard. --- scripts/operator_setup.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/operator_setup.sh b/scripts/operator_setup.sh index 8047d06..9d916c6 100755 --- a/scripts/operator_setup.sh +++ b/scripts/operator_setup.sh @@ -83,9 +83,10 @@ echo -n -e "${CYAN}Enter device number (1-9):${NC} " read -r device_num [[ "$device_num" =~ ^[1-9]$ ]] || error "Invalid selection" -device_row=$(lsblk -ndo NAME,SIZE,LABEL,TYPE | grep -E "^(sd|mmc)" | sed -n "${device_num}p") +device_row=$(lsblk -ndo NAME,SIZE,LABEL,TYPE | grep -E "^(sd|mmc)" | sed -n "${device_num}p" || true) DEVICE=$(echo "$device_row" | awk '{print $1}') DEVICE_SIZE=$(echo "$device_row" | awk '{print $2}') +[[ -n "$DEVICE" ]] || error "Invalid selection — no device at that number" info "Selected: /dev/${DEVICE} (${DEVICE_SIZE})" warn "This will OVERWRITE all data on /dev/${DEVICE}" @@ -101,7 +102,7 @@ info "Device confirmed: /dev/${DEVICE}" section "Image Management" # Look for existing cached image -CACHED_IMAGE=$(ls -1 "$CACHE_DIR"/Armbian_*_Orangepizero3_bookworm_current_*_minimal.img.xz 2>/dev/null | head -1) +CACHED_IMAGE=$(find "$CACHE_DIR" -maxdepth 1 -name 'Armbian_*_Orangepizero3_bookworm_current_*_minimal.img.xz' 2>/dev/null | head -1 || true) if [[ -n "$CACHED_IMAGE" ]]; then info "Found cached image: $(basename $CACHED_IMAGE)"