2014-10-16 16:03:05 +00:00
|
|
|
#!/bin/bash -x
|
|
|
|
# vim: set ts=4 sw=4 sts=4 et :
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Allows a pre-built image to be used (if it exists) for installing
|
|
|
|
# Whonix. This option is useful only for debugging Whonix installations
|
|
|
|
#
|
|
|
|
# To use, first create a regualr wheezy template and manually copy the prepared
|
|
|
|
# image to debian-7-x64-prepard.img
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# cp ~/qubes-builder/qubes-src/linux-template-builder/prepared_images/debian-7-x64.img ~/qubes-builder/qubes-src/linux-template-builder/prepared_images/debian-7-x64-whonix-gateway-prepard.img
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2014-10-16 20:05:28 +00:00
|
|
|
# Return if SNAPSHOT is not "1"
|
2014-10-16 16:03:05 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2014-10-16 20:05:28 +00:00
|
|
|
# This script is only used if SNAPSHOT is set
|
2014-10-28 08:09:55 +00:00
|
|
|
if [ ! "${SNAPSHOT}" == "1" ]; then
|
2014-10-16 16:03:05 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Source external scripts
|
|
|
|
# ------------------------------------------------------------------------------
|
2014-10-28 08:09:55 +00:00
|
|
|
. ${SCRIPTSDIR}/vars.sh
|
2014-10-16 16:03:05 +00:00
|
|
|
. ./umount_kill.sh >/dev/null
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Configurations
|
|
|
|
# ------------------------------------------------------------------------------
|
2014-10-28 08:09:55 +00:00
|
|
|
if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then
|
2014-10-16 16:03:05 +00:00
|
|
|
set -x
|
|
|
|
else
|
|
|
|
set -e
|
|
|
|
fi
|
|
|
|
|
|
|
|
INSTALLDIR="$(readlink -m mnt)"
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2014-10-16 20:05:28 +00:00
|
|
|
# Use a snapshot of the debootstraped debian image to install Whonix (for DEBUGGING)
|
2014-10-16 16:03:05 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2014-10-19 08:23:19 +00:00
|
|
|
manage_snapshot() {
|
2014-10-28 08:09:55 +00:00
|
|
|
umount_kill "${INSTALLDIR}" || :
|
2014-10-19 08:23:19 +00:00
|
|
|
|
2014-10-28 08:09:55 +00:00
|
|
|
mount -o loop "${IMG}" "${INSTALLDIR}" || exit 1
|
2014-10-19 08:23:19 +00:00
|
|
|
# Remove old snapshots if whonix completed
|
2014-10-28 08:09:55 +00:00
|
|
|
if [ -f "${INSTALLDIR}/tmp/.whonix_post" ]; then
|
2014-10-19 08:23:19 +00:00
|
|
|
warn "Removing stale snapshots"
|
2014-10-28 08:09:55 +00:00
|
|
|
umount_kill "${INSTALLDIR}" || :
|
2014-10-19 08:23:19 +00:00
|
|
|
rm -rf "$debootstrap_snapshot"
|
|
|
|
rm -rf "$updated_snapshot"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2014-10-28 08:09:55 +00:00
|
|
|
warn "Copying $1 to ${IMG}"
|
|
|
|
mount -o loop "$1" "${INSTALLDIR}" || exit 1
|
|
|
|
rm -f "${INSTALLDIR}/tmp/.prepared_groups"
|
|
|
|
umount_kill "${INSTALLDIR}" || :
|
|
|
|
cp -f "$1" "${IMG}"
|
2014-10-16 22:00:26 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 08:09:55 +00:00
|
|
|
splitPath "${IMG}" path_parts
|
2014-10-16 22:00:26 +00:00
|
|
|
debootstrap_snapshot="${path_parts[dir]}${path_parts[base]}-debootstrap${path_parts[dotext]}"
|
|
|
|
updated_snapshot="${path_parts[dir]}${path_parts[base]}-updated${path_parts[dotext]}"
|
|
|
|
|
|
|
|
if [ -f "$updated_snapshot" ]; then
|
2014-10-19 08:23:19 +00:00
|
|
|
manage_snapshot "$updated_snapshot"
|
2014-10-16 22:00:26 +00:00
|
|
|
elif [ -f "$debootstrap_snapshot" ]; then
|
2014-10-19 08:23:19 +00:00
|
|
|
manage_snapshot "$debootstrap_snapshot"
|
2014-10-16 16:03:05 +00:00
|
|
|
fi
|
|
|
|
|