From c99b053afb0f7ce2f4416a8c225d467fbb087c5d Mon Sep 17 00:00:00 2001 From: kmpm Date: Thu, 9 Apr 2020 18:17:47 +0200 Subject: [PATCH] stop on parted error --- pishrink.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pishrink.sh b/pishrink.sh index d2f922a..4ddce81 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -160,7 +160,13 @@ trap cleanup ERR EXIT #Gather info info "Gathering data" beforesize=$(ls -lh "$img" | cut -d ' ' -f 5) -parted_output=$(parted -ms "$img" unit B print | tail -n 1) +if ! parted_output=$(parted -ms "$img" unit B print); then + rc=$? + error $LINENO "parted failed with rc $rc" + info "Possibly invalid image. Run 'parted $img unit B print' manually to investigate" + exit -6 +fi +parted_output=$(echo "$parted_output" | tail -n 1) partnum=$(echo "$parted_output" | cut -d ':' -f 1) partstart=$(echo "$parted_output" | cut -d ':' -f 2 | tr -d 'B') loopback=$(losetup -f --show -o "$partstart" "$img")