Add option to compress output file.
This commit is contained in:
parent
76d2254d90
commit
8b26638bc7
|
@ -2,10 +2,12 @@
|
||||||
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.
|
||||||
|
|
||||||
## Usage ##
|
## Usage ##
|
||||||
`sudo pishrink.sh [-s] imagefile.img [newimagefile.img]`
|
`sudo pishrink.sh [-s] [-z] imagefile.img [newimagefile.img]`
|
||||||
|
|
||||||
If the `-s` option is given the script will skip the autoexpanding part of the process. 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.
|
If the `-s` option is given the script will skip the autoexpanding part of the process. 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.
|
||||||
|
|
||||||
|
If the `-z` option is specified, the script will compress the output file to a tarball (*.tar.gz). Note: it does not automatically delete the original `.img` file.
|
||||||
|
|
||||||
## Prerequisites ##
|
## Prerequisites ##
|
||||||
If you are trying to shrink a [NOOBS](https://github.com/raspberrypi/noobs) image it will likely fail. This is due to [NOOBS partitioning](https://github.com/raspberrypi/noobs/wiki/NOOBS-partitioning-explained) being significantly different than Raspbian's. Hopefully PiShrink will be able to support NOOBS in the near future.
|
If you are trying to shrink a [NOOBS](https://github.com/raspberrypi/noobs) image it will likely fail. This is due to [NOOBS partitioning](https://github.com/raspberrypi/noobs/wiki/NOOBS-partitioning-explained) being significantly different than Raspbian's. Hopefully PiShrink will be able to support NOOBS in the near future.
|
||||||
|
|
||||||
|
|
16
pishrink.sh
16
pishrink.sh
|
@ -6,13 +6,15 @@ function cleanup() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() { echo "Usage: $0 [-s] imagefile.img [newimagefile.img]"; exit -1; }
|
usage() { echo "Usage: $0 [-s] [-z] imagefile.img [newimagefile.img]"; exit -1; }
|
||||||
|
|
||||||
should_skip_autoexpand=false
|
should_skip_autoexpand=false
|
||||||
|
compress_output=false
|
||||||
|
|
||||||
while getopts ":s" opt; do
|
while getopts ":s:z" opt; do
|
||||||
case "${opt}" in
|
case "${opt}" in
|
||||||
s) should_skip_autoexpand=true ;;
|
s) should_skip_autoexpand=true ;;
|
||||||
|
z) compress_output=true ;;
|
||||||
*) usage ;;
|
*) usage ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -35,7 +37,7 @@ if (( EUID != 0 )); then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Check that what we need is installed
|
#Check that what we need is installed
|
||||||
for command in parted losetup tune2fs md5sum e2fsck resize2fs; do
|
for command in parted losetup tune2fs md5sum e2fsck resize2fs tar; do
|
||||||
which $command 2>&1 >/dev/null
|
which $command 2>&1 >/dev/null
|
||||||
if (( $? != 0 )); then
|
if (( $? != 0 )); then
|
||||||
echo "ERROR: $command is not installed."
|
echo "ERROR: $command is not installed."
|
||||||
|
@ -186,3 +188,11 @@ truncate -s $endresult "$img"
|
||||||
aftersize=$(ls -lh "$img" | cut -d ' ' -f 5)
|
aftersize=$(ls -lh "$img" | cut -d ' ' -f 5)
|
||||||
|
|
||||||
echo "Shrunk $img from $beforesize to $aftersize"
|
echo "Shrunk $img from $beforesize to $aftersize"
|
||||||
|
|
||||||
|
#Compress the new image
|
||||||
|
if [ "$compress_output" = true ]; then
|
||||||
|
img_dir=$(dirname "$img");
|
||||||
|
img_filename=$(basename -- "$img");
|
||||||
|
echo "Compressing "
|
||||||
|
tar -C "$img_dir" -czvf "$img_dir/${img_filename%.*}.tar.gz" "$img_filename"
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue