From 9a2c7fe949ec2ffed410aa1e3adf520d4b85ef4a Mon Sep 17 00:00:00 2001 From: framp Date: Mon, 20 Apr 2020 13:24:55 +0200 Subject: [PATCH] Fixed pishrink issue #133 --- pishrink.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pishrink.sh b/pishrink.sh index 6551e28..5f04ae5 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -178,14 +178,14 @@ trap cleanup ERR EXIT #Gather info info "Gathering data" beforesize="$(ls -lh "$img" | cut -d ' ' -f 5)" -if ! parted_output=$(parted -ms "$img" unit B print); then - rc=$? +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" + info "Possibly invalid image. Run 'parted $img unit B print' manually to investigate" exit -6 fi partnum="$(echo "$parted_output" | cut -d ':' -f 1)" -partstart="$(echo "$parted_output" | cut -d ':' -f 2 | tr -d 'B')" +partstart="$(echo "$parted_output" | tail -n 1 | cut -d ':' -f 2 | tr -d 'B')" loopback="$(losetup -f --show -o "$partstart" "$img")" tune2fs_output="$(tune2fs -l "$loopback")" currentsize="$(echo "$tune2fs_output" | grep '^Block count:' | tr -d ' ' | cut -d ':' -f 2)"