Add option to copy to new file before script executes

While not the most efficient method it will at least work for now

Closes issue #1 and issue #3
This commit is contained in:
Drew Bonasera 2016-04-28 01:35:12 -04:00
parent 1f91ea1f87
commit ed4bcea683
2 changed files with 14 additions and 3 deletions

View File

@ -1,9 +1,9 @@
# PiShrink #
PiShrink is a bash script that automatically shrink a pi image that will then resize to the max size of the SD card on boot. This will make putting the image back onto the SD card faster and the shrunk images will compress better.
WARNING: You should make a backup of your image before using this. If anything goes wrong during the shrinking the image could become corrupt.
`Usage: ./pishrink imagefile.img [newimagefile.img]`
`Usage: ./pishrink imagefile.img`
If you specify the `newimagefile.img` parameter, the script will make a copy of `imagefile.img` and work off that. You will need enough space to make a full copy of the image to use that option.
## Example ##
```bash

View File

@ -4,7 +4,7 @@ img=$1
#Usage checks
if [[ -z $img ]]; then
echo "Usage: $0 imagefile.img"
echo "Usage: $0 imagefile.img [newimagefile.img]"
exit -1
fi
if [[ ! -e $img ]]; then
@ -23,6 +23,17 @@ if (( $? != 0 )); then
exit -4
fi
#Copy to new file if requested
if [ -n "$2" ]; then
echo "Copying $1 to $2..."
cp "$1" "$2"
if (( $? != 0 )); then
echo "ERROR: Could not copy file..."
exit -5
fi
img=$2
fi
#Gather info
beforesize=`ls -lah $img | cut -d ' ' -f 5`
partnum=`parted -m $img unit B print | tail -n 1 | cut -d ':' -f 1 | tr -d '\n'`