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.
This commit is contained in:
Cobra
2026-04-07 14:02:32 -04:00
parent 0e49eb914e
commit ab34023c51
+3 -2
View File
@@ -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)"