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
|
-d: Write debug messages in a debug log file
|
||||||
-r: Use advanced filesystem repair option if the normal one fails
|
-r: Use advanced filesystem repair option if the normal one fails
|
||||||
-p: Remove logs, apt archives, dhcp leases and ssh hostkeys
|
-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
|
-z: Gzip compress image after shrinking
|
||||||
EOM
|
EOM
|
||||||
echo "$help"
|
echo "$help"
|
||||||
|
@ -82,6 +84,8 @@ usage() {
|
||||||
echo " -d: Debug mode on"
|
echo " -d: Debug mode on"
|
||||||
echo " -r: Use advanced repair options"
|
echo " -r: Use advanced repair options"
|
||||||
echo " -p: Remove logs, apt archives, dhcp leases and ssh hostkeys"
|
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 " -z: Gzip compress image after shrinking"
|
||||||
echo " -h: display help text"
|
echo " -h: display help text"
|
||||||
exit -1
|
exit -1
|
||||||
|
@ -90,6 +94,8 @@ usage() {
|
||||||
should_skip_autoexpand=false
|
should_skip_autoexpand=false
|
||||||
debug=false
|
debug=false
|
||||||
repair=false
|
repair=false
|
||||||
|
xzip_compress=false
|
||||||
|
exzip_compress=false
|
||||||
gzip_compress=false
|
gzip_compress=false
|
||||||
prep=false
|
prep=false
|
||||||
|
|
||||||
|
@ -99,6 +105,8 @@ while getopts ":sdrpzh" opt; do
|
||||||
d) debug=true;;
|
d) debug=true;;
|
||||||
r) repair=true;;
|
r) repair=true;;
|
||||||
p) prep=true;;
|
p) prep=true;;
|
||||||
|
x) xzip_compress=true;;
|
||||||
|
e) exzip_compress=true;;
|
||||||
z) gzip_compress=true;;
|
z) gzip_compress=true;;
|
||||||
h) help;;
|
h) help;;
|
||||||
*) usage ;;
|
*) usage ;;
|
||||||
|
@ -154,7 +162,7 @@ if [ -n "$2" ]; then
|
||||||
img="$2"
|
img="$2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# cleanup at script exit
|
# Cleanup at script exit
|
||||||
trap cleanup ERR EXIT
|
trap cleanup ERR EXIT
|
||||||
|
|
||||||
#Gather info
|
#Gather info
|
||||||
|
@ -254,7 +262,6 @@ if [[ $prep == true ]]; then
|
||||||
umount "$mountdir"
|
umount "$mountdir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Make sure filesystem is ok
|
# Make sure filesystem is ok
|
||||||
checkFilesystem
|
checkFilesystem
|
||||||
|
|
||||||
|
@ -326,6 +333,20 @@ if ! truncate -s "$endresult" "$img"; then
|
||||||
exit -16
|
exit -16
|
||||||
fi
|
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
|
if [[ $gzip_compress == true ]]; then
|
||||||
info "Gzipping the shrunk image"
|
info "Gzipping the shrunk image"
|
||||||
if [[ ! $(gzip -f9 "$img") ]]; then
|
if [[ ! $(gzip -f9 "$img") ]]; then
|
||||||
|
|
Loading…
Reference in New Issue