Added support for XZ compression
This commit is contained in:
parent
4f61a3244a
commit
1a731f48b2
25
pishrink.sh
25
pishrink.sh
|
@ -69,6 +69,8 @@ Usage: $0 [-sdrpzh] 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
|
||||
-x: XZ compress image after shrinking
|
||||
-e: XZ extreme compress image after shrinking
|
||||
-z: Gzip compress image after shrinking
|
||||
EOM
|
||||
echo "$help"
|
||||
|
@ -82,6 +84,8 @@ usage() {
|
|||
echo " -d: Debug mode on"
|
||||
echo " -r: Use advanced repair options"
|
||||
echo " -p: Remove logs, apt archives, dhcp leases and ssh hostkeys"
|
||||
echo " -x: XZ compress image after shrinking"
|
||||
echo " -e: XZ extreme compress image after shrinking"
|
||||
echo " -z: Gzip compress image after shrinking"
|
||||
echo " -h: display help text"
|
||||
exit -1
|
||||
|
@ -90,6 +94,8 @@ usage() {
|
|||
should_skip_autoexpand=false
|
||||
debug=false
|
||||
repair=false
|
||||
xzip_compress=false
|
||||
exzip_compress=false
|
||||
gzip_compress=false
|
||||
prep=false
|
||||
|
||||
|
@ -99,6 +105,8 @@ while getopts ":sdrpzh" opt; do
|
|||
d) debug=true;;
|
||||
r) repair=true;;
|
||||
p) prep=true;;
|
||||
x) xzip_compress=true;;
|
||||
e) exzip_compress=true;;
|
||||
z) gzip_compress=true;;
|
||||
h) help;;
|
||||
*) usage ;;
|
||||
|
@ -154,7 +162,7 @@ if [ -n "$2" ]; then
|
|||
img="$2"
|
||||
fi
|
||||
|
||||
# cleanup at script exit
|
||||
# Cleanup at script exit
|
||||
trap cleanup ERR EXIT
|
||||
|
||||
#Gather info
|
||||
|
@ -254,7 +262,6 @@ if [[ $prep == true ]]; then
|
|||
umount "$mountdir"
|
||||
fi
|
||||
|
||||
|
||||
# Make sure filesystem is ok
|
||||
checkFilesystem
|
||||
|
||||
|
@ -326,6 +333,20 @@ if ! truncate -s "$endresult" "$img"; then
|
|||
exit -16
|
||||
fi
|
||||
|
||||
if [[ $xzip_compress == true ]]; then
|
||||
info "XZipping the shrunk image"
|
||||
if [[ ! $(xz -9v "$img") ]]; then
|
||||
img=$img.xz
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $exzip_compress == true ]]; then
|
||||
info "Extreme XZipping the shrunk image"
|
||||
if [[ ! $(xz -9ve "$img") ]]; then
|
||||
img=$img.xz
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $gzip_compress == true ]]; then
|
||||
info "Gzipping the shrunk image"
|
||||
if [[ ! $(gzip -f9 "$img") ]]; then
|
||||
|
|
Loading…
Reference in New Issue