From 57a69657c83e51da9e2f5a572533f430db6c637f Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Thu, 24 Nov 2016 11:59:51 +0100 Subject: [PATCH] do not truncate if used directly on the SD --- pishrink.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pishrink.sh b/pishrink.sh index f2df6b9..73b9b6e 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -150,8 +150,9 @@ part1=`parted $img rm $partnum` part2=`parted $img unit B mkpart primary $partstart $newpartend` #Truncate the file -endresult=`parted -m $img unit B print free | tail -1 | cut -d ':' -f 2 | tr -d 'B\n'` -truncate -s $endresult $img -aftersize=`ls -lah $img | cut -d ' ' -f 5` - -echo "Shrunk $img from $beforesize to $aftersize" +if [[ -f $img ]]; then + endresult=`parted -m $img unit B print free | tail -1 | cut -d ':' -f 2 | tr -d 'B\n'` + truncate -s $endresult $img + aftersize=`ls -lah $img | cut -d ' ' -f 5` + echo "Shrunk $img from $beforesize to $aftersize" +fi