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:
parent
1f91ea1f87
commit
ed4bcea683
|
@ -1,9 +1,9 @@
|
||||||
# PiShrink #
|
# 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.
|
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 ##
|
## Example ##
|
||||||
```bash
|
```bash
|
||||||
|
|
13
pishrink.sh
13
pishrink.sh
|
@ -4,7 +4,7 @@ img=$1
|
||||||
|
|
||||||
#Usage checks
|
#Usage checks
|
||||||
if [[ -z $img ]]; then
|
if [[ -z $img ]]; then
|
||||||
echo "Usage: $0 imagefile.img"
|
echo "Usage: $0 imagefile.img [newimagefile.img]"
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
if [[ ! -e $img ]]; then
|
if [[ ! -e $img ]]; then
|
||||||
|
@ -23,6 +23,17 @@ if (( $? != 0 )); then
|
||||||
exit -4
|
exit -4
|
||||||
fi
|
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
|
#Gather info
|
||||||
beforesize=`ls -lah $img | cut -d ' ' -f 5`
|
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'`
|
partnum=`parted -m $img unit B print | tail -n 1 | cut -d ':' -f 1 | tr -d '\n'`
|
||||||
|
|
Loading…
Reference in New Issue