diff --git a/README.md b/README.md index 075b823..db3b9df 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pishrink.sh b/pishrink.sh index 0610c9c..fb24736 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -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'`