Merge pull request #55 from framps/master
Added cleanup of loop device in case of execution errors Closes #54
This commit is contained in:
commit
fd6c0b1ba4
10
pishrink.sh
10
pishrink.sh
|
@ -1,5 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
function cleanup() {
|
||||
if losetup $loopback &>/dev/null; then
|
||||
losetup -d "$loopback"
|
||||
fi
|
||||
}
|
||||
|
||||
usage() { echo "Usage: $0 [-s] imagefile.img [newimagefile.img]"; exit -1; }
|
||||
|
||||
should_skip_autoexpand=false
|
||||
|
@ -50,6 +56,9 @@ if [ -n "$2" ]; then
|
|||
img="$2"
|
||||
fi
|
||||
|
||||
# cleanup at script exit
|
||||
trap cleanup ERR EXIT
|
||||
|
||||
#Gather info
|
||||
beforesize=$(ls -lh "$img" | cut -d ' ' -f 5)
|
||||
parted_output=$(parted -ms "$img" unit B print | tail -n 1)
|
||||
|
@ -166,7 +175,6 @@ fi
|
|||
sleep 1
|
||||
|
||||
#Shrink partition
|
||||
losetup -d "$loopback"
|
||||
partnewsize=$(($minsize * $blocksize))
|
||||
newpartend=$(($partstart + $partnewsize))
|
||||
parted -s -a minimal "$img" rm $partnum >/dev/null
|
||||
|
|
Loading…
Reference in New Issue