Minor code cleanup and README update

This commit is contained in:
framp 2020-02-29 14:52:35 +01:00
parent b4db6c1a64
commit d80d48a645
2 changed files with 16 additions and 16 deletions

View File

@ -6,28 +6,27 @@ using multiple cores is supported.
## Usage ##
```
Usage: $0 [-sdiarpzZvh] imagefile.img [newimagefile.img]
Usage: $0 [-adhrspvzZ] imagefile.img [newimagefile.img]
-s Don't expand filesystem when image is booted the first time
-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
-v Be verbose
-r Use advanced filesystem repair option if the normal one fails
-z Compress image after shrinking with gzip
-Z Compress image after shrinking with xz
-a Compress image in parallel using multiple cores
-p Remove logs, apt archives, dhcp leases and ssh hostkeys
-d Write debug messages in a debug log file
```
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.
* `-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 compress the image after shrinking using gzip. `.gz` extension will be added to the filename.
* `-Z` will compress the image after shrinking using xz. `.xz` extension will be added to the filename.
* `-a` will use option -f9 for pigz and option -T0 for xz.
* `-a` will use option -f9 for pigz and option -T0 for xz and compress in parallel.
* `-d` will create a logfile `pishrink.log` which may help for problem analysis.
Default options for parallel compression can be overwritten by defining PISHRINK_GZIP or PSHRINK_XZ environment variables.
Default options for parallel compression can be overwritten by defining PISHRINK_GZIP or PSHRINK_XZ environment variables for gzip and xz.
## 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.

View File

@ -69,16 +69,16 @@ fi
help() {
local help
read -r -d '' help << EOM
Usage: $0 [-sdarpzZvh] imagefile.img [newimagefile.img]
Usage: $0 [-adhrspvzZ] imagefile.img [newimagefile.img]
-s Don't expand filesystem when image is booted the first time
-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
-v Be verbose
-r Use advanced filesystem repair option if the normal one fails
-z Compress image after shrinking with gzip
-Z Compress image after shrinking with xz
-a Compress image in parallel using multiple cores
-p Remove logs, apt archives, dhcp leases and ssh hostkeys
-d Write debug messages in a debug log file
EOM
echo "$help"
exit -1
@ -93,7 +93,7 @@ prep=false
ziptool=""
required_tools="$REQUIRED_TOOLS"
while getopts ":adhipr:svzZ" opt; do
while getopts ":adhprsvzZ" opt; do
case "${opt}" in
a) parallel=true;;
d) debug=true;;
@ -101,9 +101,9 @@ while getopts ":adhipr:svzZ" opt; do
p) prep=true;;
r) repair=true;;
s) should_skip_autoexpand=true ;;
v) verbose=true;;
z) ziptool="gzip";;
Z) ziptool="xz";;
v) verbose=true;;
*) help;;
esac
done
@ -344,12 +344,13 @@ if ! truncate -s "$endresult" "$img"; then
exit -16
fi
# handle compression
if [[ -n $ziptool ]]; then
options=""
envVarname="${MYNAME^^}_${ziptool^^}" # PISHRINK_GZIP or PISHRINK_XZ environment variables allow to override options
envVarname="${MYNAME^^}_${ziptool^^}" # PISHRINK_GZIP or PISHRINK_XZ environment variables allow to override all options for gzip or xz
[[ $parallel == true ]] && options="${ZIP_PARALLEL_OPTIONS[$ziptool]}"
[[ -v $envVarname ]] && options="${!envVarname}" # if environment variable defined use these options
[[ $verbose == true ]] && options="$options -v" # add verbose flag
[[ $verbose == true ]] && options="$options -v" # add verbose flag if requested
if [[ $parallel == true ]]; then
parallel_tool="${ZIP_PARALLEL_TOOL[$ziptool]}"