Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved error handling, removed RC=$? noops #262

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions grml-debootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,17 @@
fi
done

[ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1 || true

Check warning on line 275 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Note that A && B || C is not if-then-else. C may run when A is true. [SC2015](https://github.com/koalaman/shellcheck/wiki/SC2015) Raw Output: ./grml-debootstrap:275:37:info:Note that A && B || C is not if-then-else. C may run when A is true. [SC2015](https://github.com/koalaman/shellcheck/wiki/SC2015)

# ugly, but make sure we really don't leave anything (/proc /proc and
# /dev /dev are intended, trying to work around timing issues, see #657023)
for ARG in /run/udev /sys /proc /proc /dev/pts /dev/pts /dev /dev ; do
[ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true

Check warning on line 280 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Note that A && B || C is not if-then-else. C may run when A is true. [SC2015](https://github.com/koalaman/shellcheck/wiki/SC2015) Raw Output: ./grml-debootstrap:280:39:info:Note that A && B || C is not if-then-else. C may run when A is true. [SC2015](https://github.com/koalaman/shellcheck/wiki/SC2015)
umount "$MNTPOINT"/$ARG >/dev/null 2>&1 || true
done

if [ -n "$ISODIR" ] ; then
[ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1 || true

Check warning on line 285 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Note that A && B || C is not if-then-else. C may run when A is true. [SC2015](https://github.com/koalaman/shellcheck/wiki/SC2015) Raw Output: ./grml-debootstrap:285:36:info:Note that A && B || C is not if-then-else. C may run when A is true. [SC2015](https://github.com/koalaman/shellcheck/wiki/SC2015)
fi

if [ -n "$DIRECTORY" ] ; then
Expand Down Expand Up @@ -791,7 +791,7 @@
prompt_for_release()
{
[ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='bullseye'
RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \

Check warning on line 794 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086) Raw Output: ./grml-debootstrap:794:61:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 794 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:794:- RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \ grml-debootstrap:794:+ RELEASE="$(dialog --stdout --title "${PN}" --default-item "$DEFAULT_RELEASE" --menu \
"Please enter the Debian release you would like to use for installation:" \
0 50 8 \
buster Debian/10 \
Expand Down Expand Up @@ -843,7 +843,7 @@
{
[ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'

CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \

Check warning on line 846 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086) Raw Output: ./grml-debootstrap:846:64:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 846 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:846:- CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \ grml-debootstrap:846:+ CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item "$DEFAULT_MIRROR" \
--menu "Where do you want to install from?" 0 0 0 \
net "install via network (downloading from mirror)" \
local "install from local directory/mirror"
Expand All @@ -853,13 +853,13 @@
[ -n "$MIRROR" ] || MIRROR='http://deb.debian.org/debian'
MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
"Please enter Debian mirror you would like to use for installing packages." \
0 0 $MIRROR)" || bailout

Check warning on line 856 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086) Raw Output: ./grml-debootstrap:856:20:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 856 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:856:- 0 0 $MIRROR)" || bailout grml-debootstrap:856:+ 0 0 "$MIRROR")" || bailout

else # CHOOSE_MIRROR == local
[ -n "$ISO" ] || ISO='/mnt/mirror'
ISO="$(dialog --stdout --title "${PN}" --inputbox \
"Please enter directory name you would like to use for installing packages." \
0 0 $ISO)" || bailout

Check warning on line 862 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086) Raw Output: ./grml-debootstrap:862:20:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 862 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:862:- 0 0 $ISO)" || bailout grml-debootstrap:862:+ 0 0 "$ISO")" || bailout
fi
}
# }}}
Expand Down Expand Up @@ -906,10 +906,12 @@
done < "$TMPFILE"

ERRORFILE=$(mktemp)

local RC=0
# shellcheck disable=SC2086
yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
--raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE
RC=$?
--raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE || RC=$?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The github diff looks weird. But if you look at the full file it looks simple and correct.

local RC=0
# shellcheck disable=SC2086
yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
      --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE || RC=$?

if [ "$RC" = 0 ] ; then
   dialog --title "$PN" --msgbox \
   "Creating $TARGET was successful." 0 0
   rm -f "$TMPFILE" "$ERRORFILE"
else

Could have used:

if yes | mdadm ... ; then

but given the already long and complex mdadm command, I opted for a simpler fix. That is, on top of the command local RC=0 and at the end of the command || RC=$?.


if [ "$RC" = 0 ] ; then
dialog --title "$PN" --msgbox \
"Creating $TARGET was successful." 0 0
Expand Down Expand Up @@ -967,9 +969,7 @@
einfo "EFI partition $EFI seems to have a FAT filesystem, not modifying."
else
einfo "EFI partition $EFI doesn't seem to be formatted, creating filesystem."
mkfs.fat -F32 -n "EFI" "$EFI"
RC=$?
if [ ! $RC -eq 0 ] ; then
if ! mkfs.fat -F32 -n "EFI" "$EFI" ; then
eerror "Error while creating filesystem on ${EFI}."
bailout 1
fi
Expand Down Expand Up @@ -1315,7 +1315,7 @@

einfo "Running $MKFS $MKFS_OPTS on $TARGET"
# shellcheck disable=SC2086
"$MKFS" $MKFS_OPTS "$TARGET" ; RC=$?
"$MKFS" $MKFS_OPTS "$TARGET"

if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
if ! echo "$MKFS" | grep -q "mkfs.ext" ; then
Expand Down Expand Up @@ -1352,7 +1352,6 @@
# race conditions :-/
sleep 2

eend $RC
fi
}
# }}}
Expand Down Expand Up @@ -1728,16 +1727,14 @@
einfo "Executing: $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
# shellcheck disable=SC2086
"$DEBOOTSTRAP" $ARCHCMD $DEBOOTSTRAP_OPT "$RELEASE" "$MNTPOINT" "$ISO"
RC=$?
else
einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}"
einfo "Executing: $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
# shellcheck disable=SC2086
"$DEBOOTSTRAP" $ARCHCMD $DEBOOTSTRAP_OPT "$RELEASE" "$MNTPOINT" "$MIRROR"
RC=$?
fi

if [ $RC -ne 0 ] ; then

Check warning on line 1737 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086) Raw Output: ./grml-debootstrap:1737:8:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 1737 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1737:- if [ $RC -ne 0 ] ; then grml-debootstrap:1737:+ if [ "$RC" -ne 0 ] ; then
if [ -r "$MNTPOINT/debootstrap/debootstrap.log" ] && \
[ -s "$MNTPOINT/debootstrap/debootstrap.log" ] ; then
einfo "Presenting last ten lines of debootstrap.log:"
Expand All @@ -1746,7 +1743,6 @@
fi
fi

eend $RC
}
# }}}

Expand Down Expand Up @@ -1807,12 +1803,12 @@
[ -n "$TUNE2FS" ] && echo "TUNE2FS='${TUNE2FS//\'/\'\\\'\'}'" >> "$CHROOT_VARIABLES"
[ -n "$VMSIZE" ] && echo "VMSIZE='${VMSIZE//\'/\'\\\'\'}'" >> "$CHROOT_VARIABLES"

cp $VERBOSE "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script

Check warning on line 1806 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086) Raw Output: ./grml-debootstrap:1806:6:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 1806 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1806:- cp $VERBOSE "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script grml-debootstrap:1806:+ cp "$VERBOSE" "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script
chmod 755 "${MNTPOINT}"/bin/chroot-script
[ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/

# make sure we have our files for later use via chroot-script
cp $VERBOSE "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/

Check warning on line 1811 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086) Raw Output: ./grml-debootstrap:1811:6:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 1811 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1811:- cp $VERBOSE "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/ grml-debootstrap:1811:+ cp "$VERBOSE" "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/
# make sure we adjust the configuration variables accordingly:
sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" "${MNTPOINT}"/etc/debootstrap/config
sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" "${MNTPOINT}"/etc/debootstrap/config
Expand All @@ -1831,14 +1827,14 @@
PACKAGES_FILE="packages-arm64"
fi

cp $VERBOSE "${_opt_packages:-$CONFFILES/$PACKAGES_FILE}" \

Check failure on line 1830 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1830:- cp $VERBOSE "${_opt_packages:-$CONFFILES/$PACKAGES_FILE}" \ grml-debootstrap:1830:+ cp "$VERBOSE" "${_opt_packages:-$CONFFILES/$PACKAGES_FILE}" \
"${MNTPOINT}/etc/debootstrap/${PACKAGES_FILE}"
fi

# debconf preseeding:
_opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
[ -f "${_opt_debconf}" ] && [ "$DEBCONF" = 'yes' ] && \
cp $VERBOSE "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections

Check failure on line 1837 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1837:- cp $VERBOSE "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections grml-debootstrap:1837:+ cp "$VERBOSE" "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections

# copy scripts that should be executed inside the chroot:
_opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
Expand Down Expand Up @@ -2065,13 +2061,12 @@
mount -t devtmpfs udev "${MNTPOINT}"/dev
mount -t devpts devpts "${MNTPOINT}"/dev/pts
if [ "$DEBUG" = "true" ] ; then
chroot "$MNTPOINT" /bin/bash -x /bin/chroot-script ; RC=$?
chroot "$MNTPOINT" /bin/bash -x /bin/chroot-script
else
chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
chroot "$MNTPOINT" /bin/chroot-script
fi
try_umount 3 "$MNTPOINT"/dev/pts
try_umount 3 "$MNTPOINT"/dev
eend $RC
fi

# finally get rid of chroot-script again, there's no good reason to
Expand Down
Loading