Change error codes so shellcheck will stop yelling at me
This commit is contained in:
parent
66355825bd
commit
2f5b275675
34
pishrink.sh
34
pishrink.sh
|
@ -62,7 +62,7 @@ if [[ $repair == true ]]; then
|
||||||
(( $? < 4 )) && return
|
(( $? < 4 )) && return
|
||||||
fi
|
fi
|
||||||
error $LINENO "Filesystem recoveries failed. Giving up..."
|
error $LINENO "Filesystem recoveries failed. Giving up..."
|
||||||
exit -9
|
exit 9
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ Usage: $0 [-adhrspvzZ] imagefile.img [newimagefile.img]
|
||||||
-d Write debug messages in a debug log file
|
-d Write debug messages in a debug log file
|
||||||
EOM
|
EOM
|
||||||
echo "$help"
|
echo "$help"
|
||||||
exit -1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
should_skip_autoexpand=false
|
should_skip_autoexpand=false
|
||||||
|
@ -214,18 +214,18 @@ fi
|
||||||
|
|
||||||
if [[ ! -f "$img" ]]; then
|
if [[ ! -f "$img" ]]; then
|
||||||
error $LINENO "$img is not a file..."
|
error $LINENO "$img is not a file..."
|
||||||
exit -2
|
exit 2
|
||||||
fi
|
fi
|
||||||
if (( EUID != 0 )); then
|
if (( EUID != 0 )); then
|
||||||
error $LINENO "You need to be running as root."
|
error $LINENO "You need to be running as root."
|
||||||
exit -3
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check selected compression tool is supported and installed
|
# check selected compression tool is supported and installed
|
||||||
if [[ -n $ziptool ]]; then
|
if [[ -n $ziptool ]]; then
|
||||||
if [[ ! " ${ZIPTOOLS[@]} " =~ $ziptool ]]; then
|
if [[ ! " ${ZIPTOOLS[@]} " =~ $ziptool ]]; then
|
||||||
error $LINENO "$ziptool is an unsupported ziptool."
|
error $LINENO "$ziptool is an unsupported ziptool."
|
||||||
exit -17
|
exit 17
|
||||||
else
|
else
|
||||||
if [[ $parallel == true && $ziptool == "gzip" ]]; then
|
if [[ $parallel == true && $ziptool == "gzip" ]]; then
|
||||||
REQUIRED_TOOLS="$REQUIRED_TOOLS pigz"
|
REQUIRED_TOOLS="$REQUIRED_TOOLS pigz"
|
||||||
|
@ -240,7 +240,7 @@ for command in $REQUIRED_TOOLS; do
|
||||||
command -v $command >/dev/null 2>&1
|
command -v $command >/dev/null 2>&1
|
||||||
if (( $? != 0 )); then
|
if (( $? != 0 )); then
|
||||||
error $LINENO "$command is not installed."
|
error $LINENO "$command is not installed."
|
||||||
exit -4
|
exit 4
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ if [ -n "$2" ]; then
|
||||||
cp --reflink=auto --sparse=always "$1" "$f"
|
cp --reflink=auto --sparse=always "$1" "$f"
|
||||||
if (( $? != 0 )); then
|
if (( $? != 0 )); then
|
||||||
error $LINENO "Could not copy file..."
|
error $LINENO "Could not copy file..."
|
||||||
exit -5
|
exit 5
|
||||||
fi
|
fi
|
||||||
old_owner=$(stat -c %u:%g "$1")
|
old_owner=$(stat -c %u:%g "$1")
|
||||||
chown "$old_owner" "$f"
|
chown "$old_owner" "$f"
|
||||||
|
@ -272,7 +272,7 @@ rc=$?
|
||||||
if (( $rc )); then
|
if (( $rc )); then
|
||||||
error $LINENO "parted failed with rc $rc"
|
error $LINENO "parted failed with rc $rc"
|
||||||
info "Possibly invalid image. Run 'parted $img unit B print' manually to investigate"
|
info "Possibly invalid image. Run 'parted $img unit B print' manually to investigate"
|
||||||
exit -6
|
exit 6
|
||||||
fi
|
fi
|
||||||
partnum="$(echo "$parted_output" | tail -n 1 | cut -d ':' -f 1)"
|
partnum="$(echo "$parted_output" | tail -n 1 | cut -d ':' -f 1)"
|
||||||
partstart="$(echo "$parted_output" | tail -n 1 | cut -d ':' -f 2 | tr -d 'B')"
|
partstart="$(echo "$parted_output" | tail -n 1 | cut -d ':' -f 2 | tr -d 'B')"
|
||||||
|
@ -319,13 +319,13 @@ checkFilesystem
|
||||||
if ! minsize=$(resize2fs -P "$loopback"); then
|
if ! minsize=$(resize2fs -P "$loopback"); then
|
||||||
rc=$?
|
rc=$?
|
||||||
error $LINENO "resize2fs failed with rc $rc"
|
error $LINENO "resize2fs failed with rc $rc"
|
||||||
exit -10
|
exit 10
|
||||||
fi
|
fi
|
||||||
minsize=$(cut -d ':' -f 2 <<< "$minsize" | tr -d ' ')
|
minsize=$(cut -d ':' -f 2 <<< "$minsize" | tr -d ' ')
|
||||||
logVariables $LINENO currentsize minsize
|
logVariables $LINENO currentsize minsize
|
||||||
if [[ $currentsize -eq $minsize ]]; then
|
if [[ $currentsize -eq $minsize ]]; then
|
||||||
error $LINENO "Image already shrunk to smallest size"
|
error $LINENO "Image already shrunk to smallest size"
|
||||||
exit -11
|
exit 11
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Add some free space to the end of the filesystem
|
#Add some free space to the end of the filesystem
|
||||||
|
@ -349,7 +349,7 @@ if (( $rc )); then
|
||||||
mv "$mountdir/etc/rc.local.bak" "$mountdir/etc/rc.local"
|
mv "$mountdir/etc/rc.local.bak" "$mountdir/etc/rc.local"
|
||||||
umount "$mountdir"
|
umount "$mountdir"
|
||||||
losetup -d "$loopback"
|
losetup -d "$loopback"
|
||||||
exit -12
|
exit 12
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
|
@ -361,14 +361,14 @@ parted -s -a minimal "$img" rm "$partnum"
|
||||||
rc=$?
|
rc=$?
|
||||||
if (( $rc )); then
|
if (( $rc )); then
|
||||||
error $LINENO "parted failed with rc $rc"
|
error $LINENO "parted failed with rc $rc"
|
||||||
exit -13
|
exit 13
|
||||||
fi
|
fi
|
||||||
|
|
||||||
parted -s "$img" unit B mkpart "$parttype" "$partstart" "$newpartend"
|
parted -s "$img" unit B mkpart "$parttype" "$partstart" "$newpartend"
|
||||||
rc=$?
|
rc=$?
|
||||||
if (( $rc )); then
|
if (( $rc )); then
|
||||||
error $LINENO "parted failed with rc $rc"
|
error $LINENO "parted failed with rc $rc"
|
||||||
exit -14
|
exit 14
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Truncate the file
|
#Truncate the file
|
||||||
|
@ -377,7 +377,7 @@ endresult=$(parted -ms "$img" unit B print free)
|
||||||
rc=$?
|
rc=$?
|
||||||
if (( $rc )); then
|
if (( $rc )); then
|
||||||
error $LINENO "parted failed with rc $rc"
|
error $LINENO "parted failed with rc $rc"
|
||||||
exit -15
|
exit 15
|
||||||
fi
|
fi
|
||||||
|
|
||||||
endresult=$(tail -1 <<< "$endresult" | cut -d ':' -f 2 | tr -d 'B')
|
endresult=$(tail -1 <<< "$endresult" | cut -d ':' -f 2 | tr -d 'B')
|
||||||
|
@ -386,7 +386,7 @@ truncate -s "$endresult" "$img"
|
||||||
rc=$?
|
rc=$?
|
||||||
if (( $rc )); then
|
if (( $rc )); then
|
||||||
error $LINENO "trunate failed with rc $rc"
|
error $LINENO "trunate failed with rc $rc"
|
||||||
exit -16
|
exit 16
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# handle compression
|
# handle compression
|
||||||
|
@ -402,7 +402,7 @@ if [[ -n $ziptool ]]; then
|
||||||
if ! $parallel_tool "${options}" "$img"; then
|
if ! $parallel_tool "${options}" "$img"; then
|
||||||
rc=$?
|
rc=$?
|
||||||
error $LINENO "$parallel_tool failed with rc $rc"
|
error $LINENO "$parallel_tool failed with rc $rc"
|
||||||
exit -18
|
exit 18
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else # sequential
|
else # sequential
|
||||||
|
@ -410,7 +410,7 @@ if [[ -n $ziptool ]]; then
|
||||||
if ! $ziptool "${options}" "$img"; then
|
if ! $ziptool "${options}" "$img"; then
|
||||||
rc=$?
|
rc=$?
|
||||||
error $LINENO "$ziptool failed with rc $rc"
|
error $LINENO "$ziptool failed with rc $rc"
|
||||||
exit -19
|
exit 19
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
img=$img.${ZIPEXTENSIONS[$ziptool]}
|
img=$img.${ZIPEXTENSIONS[$ziptool]}
|
||||||
|
|
Loading…
Reference in New Issue