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

Move try_umount above cleanup() #272

Merged
merged 1 commit into from
Feb 2, 2024
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
52 changes: 26 additions & 26 deletions grml-debootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,32 @@
}
# }}}

# unmount mountpoint {{{
try_umount() {
local tries=$1
local mountpoint="$2"

if ! mountpoint "$mountpoint" &>/dev/null ; then
return 0
fi

for (( try=1; try<=tries; try++ )); do
if [[ ${try} -eq ${tries} ]]; then
# Last time, show errors this time
umount "${mountpoint}" && return 0
else
# Not last time, hide errors until fatal
if umount "${mountpoint}" 2>/dev/null ; then
return 0
else
sleep 1
fi
fi
done
return 1 # Tried enough
}
# }}}

# helper functions {{{
cleanup() {
if [ -n "$CHROOT_VARIABLES" ] ; then
Expand Down Expand Up @@ -276,12 +302,12 @@
fi
done

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

Check warning on line 305 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:305: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 310 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:310: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

Expand Down Expand Up @@ -795,7 +821,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 824 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:824:61:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 824 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:824:- RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \ grml-debootstrap:824:+ 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 @@ -847,7 +873,7 @@
{
[ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'

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

Check warning on line 876 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:876:64:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 876 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:876:- CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \ grml-debootstrap:876:+ 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 @@ -857,13 +883,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 886 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:886:20:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 886 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:886:- 0 0 $MIRROR)" || bailout grml-debootstrap:886:+ 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 892 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:892:20:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 892 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:892:- 0 0 $ISO)" || bailout grml-debootstrap:892:+ 0 0 "$ISO")" || bailout
fi
}
# }}}
Expand Down Expand Up @@ -1790,12 +1816,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 1819 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:1819:6:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 1819 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1819:- cp $VERBOSE "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script grml-debootstrap:1819:+ 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 1824 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:1824:6:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 1824 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1824:- cp $VERBOSE "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/ grml-debootstrap:1824:+ 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 @@ -1814,20 +1840,20 @@
PACKAGES_FILE="packages-arm64"
fi

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

Check warning on line 1843 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:1843:8:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 1843 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1843:- cp $VERBOSE "${_opt_packages:-$CONFFILES/$PACKAGES_FILE}" \ grml-debootstrap:1843:+ 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 warning on line 1850 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:1850:8:info:Double quote to prevent globbing and word splitting. [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086)

Check failure on line 1850 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1850:- cp $VERBOSE "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections grml-debootstrap:1850:+ 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/}
[ -d "$_opt_chroot_scripts" ] && [ "$CHROOT_SCRIPTS" = 'yes' ] && {
mkdir -p "${MNTPOINT}"/etc/debootstrap/chroot-scripts
cp -a $VERBOSE "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/

Check failure on line 1856 in grml-debootstrap

View workflow job for this annotation

GitHub Actions / shellcheck grml-debootstrap

[shellcheck (suggestion)] reported by reviewdog 🐶 Raw Output: grml-debootstrap:1856:- cp -a $VERBOSE "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/ grml-debootstrap:1856:+ cp -a "$VERBOSE" "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/
}

# notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
Expand Down Expand Up @@ -2012,32 +2038,6 @@
}
# }}}

# unmount mountpoint {{{
try_umount() {
local tries=$1
local mountpoint="$2"

if ! mountpoint "$mountpoint" &>/dev/null ; then
return 0
fi

for (( try=1; try<=tries; try++ )); do
if [[ ${try} -eq ${tries} ]]; then
# Last time, show errors this time
umount "${mountpoint}" && return 0
else
# Not last time, hide errors until fatal
if umount "${mountpoint}" 2>/dev/null ; then
return 0
else
sleep 1
fi
fi
done
return 1 # Tried enough
}
# }}}

# execute chroot-script {{{
chrootscript() {
if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
Expand Down
Loading