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

pull/1/head
Jason Mehring 10 years ago
parent c1938374e2
commit 574668f7d9

@ -1,5 +1,4 @@
#!/bin/bash
#XXX: use bash #!/bin/sh
# ------------------------------------------------------------------------------
# Configurations
@ -38,32 +37,23 @@ echo "-> Preparing instalation of $DIST template..."
# ------------------------------------------------------------------------------
# Mount image and install core OS
# ------------------------------------------------------------------------------
export INSTALLDIR="$(readlink -m mnt)"
if [ -f "$IMG" ]; then
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
echo "-> Initializing empty image..."
truncate -s 10G "$IMG" || exit 1
echo "-> Creating filesystem..."
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
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
# ------------------------------------------------------------------------------
@ -76,6 +66,6 @@ echo "-> Installing package groups..."
trap - EXIT
echo "-> Unmounting prepared_image..."
umount_image "$INSTALLDIR" || :
umount_image "$(readlink -m $INSTALLDIR)" || :
exit $RETCODE

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

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

@ -131,20 +131,20 @@ EOF
# --------------------------------------------------------------------------
# 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
# --------------------------------------------------------------------------
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
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
# --------------------------------------------------------------------------
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"
chroot "$INSTALLDIR" apt-get update || exit 1

@ -33,6 +33,10 @@ umount_image() {
MOUNTDIR="${PWD}/${MOUNTDIR}"
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"
for dir in $(sudo grep "$MOUNTDIR" /proc/mounts | cut -f2 -d" " | sort -r | grep "^$MOUNTDIR")
do

Loading…
Cancel
Save