From 86ca300413bcd9138f03bc68660507ccfc543b69 Mon Sep 17 00:00:00 2001 From: Jason Mehring Date: Sun, 19 Oct 2014 04:23:19 -0400 Subject: [PATCH] Remove stale snapshots --- .../custom_wheezy_whonix/00_prepare_pre.sh | 19 +++++++++++++++---- .../01_install_core_post.sh | 2 +- .../02_install_groups_packages_installed.sh | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts_debian/custom_wheezy_whonix/00_prepare_pre.sh b/scripts_debian/custom_wheezy_whonix/00_prepare_pre.sh index 421eb2b..32bd835 100755 --- a/scripts_debian/custom_wheezy_whonix/00_prepare_pre.sh +++ b/scripts_debian/custom_wheezy_whonix/00_prepare_pre.sh @@ -41,9 +41,20 @@ INSTALLDIR="$(readlink -m mnt)" # Use a snapshot of the debootstraped debian image to install Whonix (for DEBUGGING) # ------------------------------------------------------------------------------ -copy_snapshot() { - warn "Copying $1 to $IMG" +manage_snapshot() { umount_kill "$INSTALLDIR" || : + + mount -o loop "$IMG" "$INSTALLDIR" || exit 1 + # Remove old snapshots if whonix completed + if [ -f "$INSTALLDIR/tmp/.prepared_whonix" ]; then + warn "Removing stale snapshots" + umount_kill "$INSTALLDIR" || : + rm -rf "$debootstrap_snapshot" + rm -rf "$updated_snapshot" + return + fi + + warn "Copying $1 to $IMG" mount -o loop "$1" "$INSTALLDIR" || exit 1 rm -f "$INSTALLDIR/tmp/.prepared_groups" umount_kill "$INSTALLDIR" || : @@ -55,8 +66,8 @@ debootstrap_snapshot="${path_parts[dir]}${path_parts[base]}-debootstrap${path_pa updated_snapshot="${path_parts[dir]}${path_parts[base]}-updated${path_parts[dotext]}" if [ -f "$updated_snapshot" ]; then - copy_snapshot "$updated_snapshot" + manage_snapshot "$updated_snapshot" elif [ -f "$debootstrap_snapshot" ]; then - copy_snapshot "$debootstrap_snapshot" + manage_snapshot "$debootstrap_snapshot" fi diff --git a/scripts_debian/custom_wheezy_whonix/01_install_core_post.sh b/scripts_debian/custom_wheezy_whonix/01_install_core_post.sh index db7ec1b..2c53338 100755 --- a/scripts_debian/custom_wheezy_whonix/01_install_core_post.sh +++ b/scripts_debian/custom_wheezy_whonix/01_install_core_post.sh @@ -30,7 +30,7 @@ fi splitPath "$IMG" path_parts PREPARED_IMG="${path_parts[dir]}${path_parts[base]}-debootstrap${path_parts[dotext]}" -if ! [ -f "$PREPARED_IMG" ]; then +if ! [ -f "$PREPARED_IMG" ] && ! [ -f "$INSTALLDIR/tmp/.prepared_whonix" ]; then umount_kill "$INSTALLDIR" || : warn "Copying $IMG to $PREPARED_IMG" cp -f "$IMG" "$PREPARED_IMG" diff --git a/scripts_debian/custom_wheezy_whonix/02_install_groups_packages_installed.sh b/scripts_debian/custom_wheezy_whonix/02_install_groups_packages_installed.sh index 4614f35..9f80039 100755 --- a/scripts_debian/custom_wheezy_whonix/02_install_groups_packages_installed.sh +++ b/scripts_debian/custom_wheezy_whonix/02_install_groups_packages_installed.sh @@ -24,7 +24,7 @@ if [ "$SNAPSHOT" == "1" ]; then splitPath "$IMG" path_parts PREPARED_IMG="${path_parts[dir]}${path_parts[base]}-updated${path_parts[dotext]}" - if ! [ -f "$PREPARED_IMG" ]; then + if ! [ -f "$PREPARED_IMG" ] && ! [ -f "$INSTALLDIR/tmp/.prepared_whonix" ]; then umount_kill "$INSTALLDIR" || : warn "Copying $IMG to $PREPARED_IMG" cp -f "$IMG" "$PREPARED_IMG"