diff --git a/prepare_image b/prepare_image index 7763464..edb3489 100755 --- a/prepare_image +++ b/prepare_image @@ -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 diff --git a/qubeize_image b/qubeize_image index 6c5857c..08a1efa 100755 --- a/qubeize_image +++ b/qubeize_image @@ -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 " diff --git a/scripts_debian/00_prepare.sh b/scripts_debian/00_prepare.sh index 4e895cf..c87ccff 100755 --- a/scripts_debian/00_prepare.sh +++ b/scripts_debian/00_prepare.sh @@ -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 # ------------------------------------------------------------------------------ diff --git a/scripts_debian/04_install_qubes.sh b/scripts_debian/04_install_qubes.sh index f29612f..2b84b97 100755 --- a/scripts_debian/04_install_qubes.sh +++ b/scripts_debian/04_install_qubes.sh @@ -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 diff --git a/umount.sh b/umount.sh index 9fc7df6..248456a 100755 --- a/umount.sh +++ b/umount.sh @@ -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