Run multithreaded compressors if available
This commit is contained in:
parent
8b49e9b616
commit
cbf0fd6f34
|
@ -1,6 +1,6 @@
|
|||
|
||||
# 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. Gzip/xz use maximum compression level.
|
||||
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. Gzip/xz use maximum compression level and thus memory. If pigz is in path it will be used instead of gzip.
|
||||
|
||||
## Usage ##
|
||||
```
|
||||
|
@ -8,7 +8,7 @@ sudo pishrink.sh [-sdrzh] imagefile.img [newimagefile.img]
|
|||
-s: Skip autoexpand
|
||||
-d: Debug mode on
|
||||
-r: Use advanced repair options
|
||||
-z: Gzip compress image after shrinking
|
||||
-z: Gzip compress image after shrinking (uses pigz if available)
|
||||
-x: xz compress image after shrinking
|
||||
-h: display help text
|
||||
```
|
||||
|
@ -18,8 +18,8 @@ If you specify the `newimagefile.img` parameter, the script will make a copy of
|
|||
* `-s` will skip the autoexpanding part of the process.
|
||||
* `-d` will create a logfile `pishrink.log` which may help for problem analysis.
|
||||
* `-r` will attempt to repair the filesystem if regular repairs fail
|
||||
* `-z` will Gzip compress the image after shrinking. The `.gz` extension will be added to the filename.
|
||||
* `-x` will xz compress the image after shrinking. The `.xz` extension will be added to the filename.
|
||||
* `-z` will Gzip compress the image after shrinking. If pigz is installed it will use that instead. The `.gz` extension will be added to the filename.
|
||||
* `-x` will xz compress the image after shrinking using as many threads as cpu cores available. The `.xz` extension will be added to the filename.
|
||||
|
||||
|
||||
## Prerequisites ##
|
||||
|
|
14
pishrink.sh
14
pishrink.sh
|
@ -69,7 +69,7 @@ Usage: $0 [-sdrpzxh] imagefile.img [newimagefile.img]
|
|||
-d: Write debug messages in a debug log file
|
||||
-r: Use advanced filesystem repair option if the normal one fails
|
||||
-p: Remove logs, apt archives, dhcp leases and ssh hostkeys
|
||||
-z: Gzip compress image after shrinking
|
||||
-z: Gzip compress image after shrinking (uses pigz if available)
|
||||
-x: xz compress image after shrinking
|
||||
EOM
|
||||
echo "$help"
|
||||
|
@ -83,7 +83,7 @@ usage() {
|
|||
echo " -d: Debug mode on"
|
||||
echo " -r: Use advanced repair options"
|
||||
echo " -p: Remove logs, apt archives, dhcp leases and ssh hostkeys"
|
||||
echo " -z: Gzip compress image after shrinking"
|
||||
echo " -z: Gzip compress image after shrinking (uses pigz if available)"
|
||||
echo " -x: xz compress image after shrinking"
|
||||
echo " -h: display help text"
|
||||
exit -1
|
||||
|
@ -330,16 +330,22 @@ if ! truncate -s "$endresult" "$img"; then
|
|||
exit -16
|
||||
fi
|
||||
|
||||
# https://stackoverflow.com/a/53798785
|
||||
function is_bin_in_path {
|
||||
builtin type -P "$1" &> /dev/null
|
||||
}
|
||||
|
||||
if [[ $gzip_compress == true ]]; then
|
||||
info "Gzipping the shrunk image"
|
||||
if [[ ! $(gzip -f9 "$img") ]]; then
|
||||
is_bin_in_path pigz && prg='pigz' || prg='gzip'
|
||||
if [[ ! $($prg -f9 "$img") ]]; then
|
||||
img="$img".gz
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $xz_compress == true ]]; then
|
||||
info "compressing the shrunk image with xz"
|
||||
if [[ ! $(xz -v -9 "$img") ]]; then
|
||||
if [[ ! $(xz -v -T0 -9 "$img") ]]; then
|
||||
img="$img".xz
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue