qubes-linux-template-builder/prepare_image

106 lines
3.3 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2010-06-18 23:41:29 +00:00
2015-08-10 20:58:07 +00:00
if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then
set -x
fi
2015-08-10 20:59:53 +00:00
set -e
# ------------------------------------------------------------------------------
# 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}
. ./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
if [ -z "$TEMPLATE_ROOT_SIZE" ]; then
TEMPLATE_ROOT_SIZE=10G
fi
# ------------------------------------------------------------------------------
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*..."
if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then
IMG_LOOP=$(/sbin/losetup -P -f --show "$IMG")
IMG_DEV=${IMG_LOOP}p3
else
IMG_LOOP=$(/sbin/losetup -f --show "$IMG")
IMG_DEV=${IMG_LOOP}
fi
2010-06-18 23:41:29 +00:00
else
echo "-> Initializing empty image..."
truncate -s "$TEMPLATE_ROOT_SIZE" "${IMG}" || exit 1
2010-06-18 23:41:29 +00:00
if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then
echo "-> Creating partition table"
# have static UUIDs to make partition table reproducible
sfdisk "$IMG" <<EOF || exit 1
label: gpt
label-id: f4796a2a-e377-45bd-b539-d6d49e569055
size=200MiB, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=fa4d6529-56da-47c7-ae88-e2dfecb72621, name="EFI System"
size=2MiB, type=21686148-6449-6E6F-744E-656564454649, uuid=1e6c9db4-1e91-46c4-846a-2030dcb13b8c, name="BIOS boot partition"
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=693244e6-3e07-47bf-ad79-acade4293fe7, name="Root filesystem"
EOF
IMG_LOOP=$(/sbin/losetup -P -f --show "$IMG")
IMG_DEV=${IMG_LOOP}p3
else
IMG_LOOP=$(/sbin/losetup -f --show "$IMG")
IMG_DEV=${IMG_LOOP}
fi
echo "-> Creating filesystem..."
/sbin/mkfs.ext4 -q -F "${IMG_DEV}" || exit 1
2010-06-18 23:41:29 +00:00
fi
mount "${IMG_DEV}" "${INSTALLDIR}" || exit 1
2015-02-10 15:07:44 +00:00
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
/sbin/losetup -d ${IMG_LOOP}
2011-09-25 20:41:27 +00:00
2015-02-10 15:07:44 +00:00
exit ${RETCODE}