qubes-linux-template-builder/prepare_image

75 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2010-06-18 23:41:29 +00:00
# ------------------------------------------------------------------------------
# Configurations
# ------------------------------------------------------------------------------
2015-02-10 15:07:44 +00:00
export IMG="${1}"
export LC_ALL=POSIX
2010-06-18 23:41:29 +00:00
2011-09-25 20:41:27 +00:00
RETCODE=0
: ${DIST=fc14}
2015-02-10 15:07:44 +00:00
if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then
set -x
else
set -e
fi
2013-02-16 20:06:11 +00:00
. ./builder_setup >/dev/null
. ./umount_kill.sh >/dev/null
if ! [ $# -eq 1 ]; then
2015-02-10 15:07:44 +00:00
echo "usage ${0} <img_file_name>"
exit
2010-06-18 23:41:29 +00:00
fi
2015-02-10 15:07:44 +00:00
if [ "${VERBOSE}" == "1" ]; then
export YUM_OPTS="${YUM_OPTS} -q"
fi
2010-06-18 23:41:29 +00:00
# ------------------------------------------------------------------------------
2015-02-10 15:07:44 +00:00
# Make sure INSTALLDIR exists
# ------------------------------------------------------------------------------
export INSTALLDIR="$(readlink -m mnt)"
2015-02-10 15:07:44 +00:00
mkdir -p "${INSTALLDIR}"
# ------------------------------------------------------------------------------
2015-02-10 15:07:44 +00:00
# Prepare for mount
# ------------------------------------------------------------------------------
2015-02-10 15:07:44 +00:00
echo "-> Preparing instalation of ${DIST} template..."
"${SCRIPTSDIR}/00_prepare.sh"
2015-02-10 15:07:44 +00:00
# ------------------------------------------------------------------------------
# Mount image and install core OS
# ------------------------------------------------------------------------------
if [ -f "${IMG}" ]; then
echo "-> Image file already exists, assuming *update*..."
2010-06-18 23:41:29 +00:00
else
echo "-> Initializing empty image..."
2015-02-10 15:07:44 +00:00
truncate -s 10G "${IMG}" || exit 1
2010-06-18 23:41:29 +00:00
echo "-> Creating filesystem..."
2015-02-10 15:07:44 +00:00
mkfs.ext4 -q -F "${IMG}" || exit 1
2010-06-18 23:41:29 +00:00
fi
2015-02-10 15:07:44 +00:00
mount -o loop "${IMG}" "${INSTALLDIR}" || exit 1
trap "umount_kill $(readlink -m ${INSTALLDIR})" EXIT
"${SCRIPTSDIR}/01_install_core.sh"
# ------------------------------------------------------------------------------
# Install package groups
# ------------------------------------------------------------------------------
2010-06-18 23:41:29 +00:00
echo "-> Installing package groups..."
2015-02-10 15:07:44 +00:00
"${SCRIPTSDIR}/02_install_groups.sh"
2010-06-18 23:41:29 +00:00
# ------------------------------------------------------------------------------
# Cleanup
# ------------------------------------------------------------------------------
2014-05-13 02:30:01 +00:00
trap - EXIT
2013-02-16 20:18:20 +00:00
echo "-> Unmounting prepared_image..."
2015-02-10 15:07:44 +00:00
umount_kill "$(readlink -m ${INSTALLDIR})" || true
2011-09-25 20:41:27 +00:00
2015-02-10 15:07:44 +00:00
exit ${RETCODE}