From f4282842da54a7f5bd1e211f804e839ff32efa23 Mon Sep 17 00:00:00 2001 From: Drew Bonasera Date: Wed, 27 Apr 2016 02:10:23 -0400 Subject: [PATCH] Remove the use of awk The awks being used were not reliably giving the correct data across different distros. They were replaced with cut and tr, this should give the script better stability. --- pishrink.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pishrink.sh b/pishrink.sh index efb29de..6f2b1ff 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -30,9 +30,7 @@ fi #Gather info beforesize=`ls -lah $img | cut -d ' ' -f 5` -partinfo=`parted -m $img unit B print` -partnumber=`echo "$partinfo" | grep ext4 | awk -F: ' { print $img } '` -partstart=`echo "$partinfo" | grep ext4 | awk -F: ' { print substr($2,0,length($2)-1) } '` +partstart=`parted -m $img unit B print | tail -n 1 | cut -d ':' -f 2 | tr -d 'B\n'` loopback=`losetup -f --show -o $partstart $img` #Make pi expand rootfs on next boot @@ -54,7 +52,7 @@ umount $mountdir #Shrink filesystem e2fsck -f $loopback -minsize=`resize2fs -P $loopback | awk -F': ' ' { print $2 } '` +minsize=`resize2fs -P $loopback | cut -d ':' -f 2 | tr -d ' '` minsize=`echo $minsize+20000 | bc` resize2fs -p $loopback $minsize if [[ $? != 0 ]]; then @@ -75,7 +73,7 @@ part1=`parted $img rm 2` part2=`parted $img unit B mkpart primary $partstart $newpartend` #Truncate the file -endresult=`parted -m $img unit B print free | tail -1 | awk -F: ' { print substr($2,0,length($2)-1) } '` +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`