Fixed issue with umounting when path ended with double slashes// and changed code that set INSTALLDIR to create proper full path without any trailing slashes

This commit is contained in:
Jason Mehring 2014-10-14 16:30:12 -04:00
parent c1938374e2
commit 574668f7d9
5 changed files with 23 additions and 25 deletions

View File

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/bash
#XXX: use bash #!/bin/sh
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Configurations # Configurations
@ -38,32 +37,23 @@ echo "-> Preparing instalation of $DIST template..."
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Mount image and install core OS # Mount image and install core OS
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
export INSTALLDIR="$(readlink -m mnt)"
if [ -f "$IMG" ]; then if [ -f "$IMG" ]; then
echo "-> Image file already exists, assuming *update*..." echo "-> Image file already exists, assuming *update*..."
mount -o loop "$IMG" mnt || exit 1
export INSTALLDIR="`pwd`/mnt/"
trap "umount_image ${INSTALLDIR::-1}" EXIT
# XXX: Temp; just for debugging
if ! [ -f "$INSTALLDIR/tmp/.prepared_debootstrap" ]; then
"$SCRIPTSDIR/01_install_core.sh"
fi
else else
echo "-> Initializing empty image..." echo "-> Initializing empty image..."
truncate -s 10G "$IMG" || exit 1 truncate -s 10G "$IMG" || exit 1
echo "-> Creating filesystem..." echo "-> Creating filesystem..."
mkfs.ext4 -q -F "$IMG" || exit 1 mkfs.ext4 -q -F "$IMG" || exit 1
mkdir -p mnt
mount -o loop "$IMG" mnt || exit 1
export INSTALLDIR="`pwd`/mnt/"
trap "umount_image ${INSTALLDIR::-1}" EXIT
"$SCRIPTSDIR/01_install_core.sh"
fi fi
mkdir -p "$INSTALLDIR"
mount -o loop "$IMG" "$INSTALLDIR" || exit 1
trap "umount_image $(readlink -m $INSTALLDIR)" EXIT
"$SCRIPTSDIR/01_install_core.sh"
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Install package groups # Install package groups
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -76,6 +66,6 @@ echo "-> Installing package groups..."
trap - EXIT trap - EXIT
echo "-> Unmounting prepared_image..." echo "-> Unmounting prepared_image..."
umount_image "$INSTALLDIR" || : umount_image "$(readlink -m $INSTALLDIR)" || :
exit $RETCODE exit $RETCODE

View File

@ -10,7 +10,11 @@ export LC_ALL=POSIX
. ./builder_setup >/dev/null . ./builder_setup >/dev/null
. ./umount.sh >/dev/null . ./umount.sh >/dev/null
if [ "$VERBOSE" -ge 2 -o "$DEBUG" == "1" ]; then
set -x
else
set -e set -e
fi
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
echo "usage $0 <clean_image_file> <template_name>" echo "usage $0 <clean_image_file> <template_name>"

View File

@ -6,8 +6,8 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
. ./umount.sh >/dev/null . ./umount.sh >/dev/null
INSTALLDIR="`pwd`/mnt/" INSTALLDIR="$(readlink -m mnt)"
umount_image "${INSTALLDIR::-1}" || : umount_image "$INSTALLDIR" || :
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set debug display # Set debug display
@ -39,7 +39,7 @@ if [ -f "$IMG" ]; then
fi fi
# Umount image; don't fail if its already umounted # Umount image; don't fail if its already umounted
umount_image "${INSTALLDIR::-1}" || : umount_image "$INSTALLDIR" || :
fi fi
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@ -131,20 +131,20 @@ EOF
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Update system; exit is not successful # Update system; exit is not successful
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
chroot "$INSTALLDIR" apt-get update || { umount "$INSTALLDIR/tmp/qubes_repo"; exit 1; } chroot "$INSTALLDIR" apt-get update || { umount_image "$INSTALLDIR"; exit 1; }
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Install Qubes packages # Install Qubes packages
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
chroot "$INSTALLDIR" apt-get -y --force-yes install `cat $SCRIPTSDIR/packages_qubes.list` || \ chroot "$INSTALLDIR" apt-get -y --force-yes install `cat $SCRIPTSDIR/packages_qubes.list` || \
{ umount "$INSTALLDIR/tmp/qubes_repo"; exit 1; } { umount_image "$INSTALLDIR"; exit 1; }
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Remove Quebes repo from sources.list.d # Remove Quebes repo from sources.list.d
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
rm -f "$INSTALLDIR"/etc/apt/sources.list.d/qubes*.list rm -f "$INSTALLDIR"/etc/apt/sources.list.d/qubes*.list
umount "$INSTALLDIR/tmp/qubes_repo" umount_image "$INSTALLDIR/tmp/qubes_repo"
rm -f "$INSTALLDIR/etc/apt/sources.list.d/qubes-builder.list" rm -f "$INSTALLDIR/etc/apt/sources.list.d/qubes-builder.list"
chroot "$INSTALLDIR" apt-get update || exit 1 chroot "$INSTALLDIR" apt-get update || exit 1

View File

@ -33,6 +33,10 @@ umount_image() {
MOUNTDIR="${PWD}/${MOUNTDIR}" MOUNTDIR="${PWD}/${MOUNTDIR}"
fi fi
# Strip any extra trailing slashes ('/') from path if they exist
# since we are doing an exact string match on the path
MOUNTDIR=$(echo "$MOUNTDIR" | sed s#//*#/#g)
echo "-> Attempting to kill any processes still running in '$MOUNTDIR' before un-mounting" echo "-> Attempting to kill any processes still running in '$MOUNTDIR' before un-mounting"
for dir in $(sudo grep "$MOUNTDIR" /proc/mounts | cut -f2 -d" " | sort -r | grep "^$MOUNTDIR") for dir in $(sudo grep "$MOUNTDIR" /proc/mounts | cut -f2 -d" " | sort -r | grep "^$MOUNTDIR")
do do