From c1c8a0b4a2bc61221d907d033c63e967e2e84d30 Mon Sep 17 00:00:00 2001 From: framp Date: Sat, 23 May 2020 11:11:49 +0200 Subject: [PATCH 1/3] Fixed required tools bug --- pishrink.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pishrink.sh b/pishrink.sh index 7e308aa..ce8754b 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -91,7 +91,6 @@ parallel=false verbose=false prep=false ziptool="" -required_tools="$REQUIRED_TOOLS" while getopts ":adhprsvzZ" opt; do case "${opt}" in @@ -142,7 +141,7 @@ if [[ -n $ziptool ]]; then error $LINENO "$ziptool is an unsupported ziptool." exit -17 else - if [[ $parallel == true && ziptool == "gzip" ]]; then + if [[ $parallel == true && $ziptool == "gzip" ]]; then REQUIRED_TOOLS="$REQUIRED_TOOLS pigz" else REQUIRED_TOOLS="$REQUIRED_TOOLS $ziptool" From 198e6c944f23cd911766d64b0409ddf2daa485f5 Mon Sep 17 00:00:00 2001 From: framp Date: Sat, 23 May 2020 11:40:53 +0200 Subject: [PATCH 2/3] Remove zip extension in target --- pishrink.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pishrink.sh b/pishrink.sh index ce8754b..1e17bdd 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -160,15 +160,19 @@ done #Copy to new file if requested if [ -n "$2" ]; then - info "Copying $1 to $2..." - cp --reflink=auto --sparse=always "$1" "$2" + f="$2" + if [[ -n $ziptool && "${f##*.}" == ${ZIPEXTENSIONS[$ziptool]} ]]; then # remove zip extension if zip requested because zip tool will complain about extension + f="${f%.*}" + fi + info "Copying $1 to $f..." + cp --reflink=auto --sparse=always "$1" "$f" if (( $? != 0 )); then error $LINENO "Could not copy file..." exit -5 fi old_owner=$(stat -c %u:%g "$1") - chown "$old_owner" "$2" - img="$2" + chown "$old_owner" "$f" + img="$f" fi # cleanup at script exit From 0a45a5fdae643b28a99d85a0e7ee73f50fc09646 Mon Sep 17 00:00:00 2001 From: framp Date: Sun, 31 May 2020 21:09:51 +0200 Subject: [PATCH 3/3] Deleted ERR cleanup and added check for rc.local existance --- pishrink.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pishrink.sh b/pishrink.sh index 7e308aa..fcaf23d 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -173,7 +173,7 @@ if [ -n "$2" ]; then fi # cleanup at script exit -trap cleanup ERR EXIT +trap cleanup EXIT #Gather info info "Gathering data" @@ -200,10 +200,11 @@ if [ "$should_skip_autoexpand" = false ]; then mountdir=$(mktemp -d) mount "$loopback" "$mountdir" - if [ "$(md5sum "$mountdir/etc/rc.local" | cut -d ' ' -f 1)" != "0542054e9ff2d2e0507ea1ffe7d4fc87" ]; then + if [[ -f "$mountdir/etc/rc.local" ]] && [[ "$(md5sum "$mountdir/etc/rc.local" | cut -d ' ' -f 1)" != "0542054e9ff2d2e0507ea1ffe7d4fc87" ]]; then echo "Creating new /etc/rc.local" mv "$mountdir/etc/rc.local" "$mountdir/etc/rc.local.bak" - #####Do not touch the following lines##### + +#####Do not touch the following lines##### cat <<\EOF1 > "$mountdir/etc/rc.local" #!/bin/bash @@ -238,7 +239,10 @@ cat < /etc/rc.local && #!/bin/sh echo "Expanding /dev/$ROOT_PART" resize2fs /dev/$ROOT_PART -rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local +if [[ -f /etc/rc.local.bak ]]; then + cp -f /etc/rc.local.bak /etc/rc.local + /etc/rc.local +fi EOF reboot @@ -363,7 +367,7 @@ if [[ -n $ziptool ]]; then [[ $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 if requested - + if [[ $parallel == true ]]; then parallel_tool="${ZIP_PARALLEL_TOOL[$ziptool]}" info "Using $parallel_tool on the shrunk image" @@ -372,7 +376,7 @@ if [[ -n $ziptool ]]; then error $LINENO "$parallel_tool failed with rc $rc" exit -18 fi - + else # sequential info "Using $ziptool on the shrunk image" if ! $ziptool ${options} $img; then