From ed4bcea68377a5de7d16041d2bf88ae7dd7a9bfe Mon Sep 17 00:00:00 2001 From: Drew Bonasera Date: Thu, 28 Apr 2016 01:35:12 -0400 Subject: [PATCH] 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 --- README.md | 4 ++-- pishrink.sh | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) 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'`