#!/bin/bash if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then set -x fi set -e # ------------------------------------------------------------------------------ # Configurations # ------------------------------------------------------------------------------ export IMG="${1}" export LC_ALL=POSIX RETCODE=0 : ${DIST=fc14} . ./builder_setup >/dev/null . ./umount_kill.sh >/dev/null if ! [ $# -eq 1 ]; then echo "usage ${0} " exit fi if [ "${VERBOSE}" == "1" ]; then export YUM_OPTS="${YUM_OPTS} -q" fi if [ -z "$TEMPLATE_ROOT_SIZE" ]; then TEMPLATE_ROOT_SIZE=10G fi # ------------------------------------------------------------------------------ # Make sure INSTALLDIR exists # ------------------------------------------------------------------------------ export INSTALLDIR="$(readlink -m mnt)" mkdir -p "${INSTALLDIR}" # ------------------------------------------------------------------------------ # Prepare for mount # ------------------------------------------------------------------------------ echo "-> Preparing instalation of ${DIST} template..." "${SCRIPTSDIR}/00_prepare.sh" # ------------------------------------------------------------------------------ # 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 -b 4096 -P -f --show "$IMG") # BUG: losetup's partscan (-P) does nothing when trying 4096 sectors formatted images on a 512 sectors backing device. # Hence it needs an additional partprobe run. /sbin/partprobe $IMG_LOOP IMG_DEV=${IMG_LOOP}p3 else IMG_LOOP=$(/sbin/losetup -b 4096 -f --show "$IMG") IMG_DEV=${IMG_LOOP} fi else echo "-> Initializing empty image..." truncate -s "$TEMPLATE_ROOT_SIZE" "${IMG}" || exit 1 if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then echo "-> Creating partition table" IMG_LOOP=$(/sbin/losetup -b 4096 -P -f --show "$IMG") # When a 4096 sectors formatted image gets created with the sfdisk, the partitions are automatically visible # to the system. Hence no need to run additional partprobe. # Have static UUIDs to make partition table reproducible sfdisk "$IMG_LOOP" < Creating filesystem..." /sbin/mkfs.ext4 -q -F "${IMG_DEV}" || exit 1 fi # make sure the IMG_DEV is present c=0; while [ ! -b $IMG_DEV ]; do sleep 1; c=$((c+1)); [ $c -ge 5 ] && break; done; unset c mount "${IMG_DEV}" "${INSTALLDIR}" || exit 1 trap "umount_kill $(readlink -m ${INSTALLDIR})" EXIT "${SCRIPTSDIR}/01_install_core.sh" # ------------------------------------------------------------------------------ # Install package groups # ------------------------------------------------------------------------------ echo "-> Installing package groups..." "${SCRIPTSDIR}/02_install_groups.sh" # ------------------------------------------------------------------------------ # Cleanup # ------------------------------------------------------------------------------ trap - EXIT echo "-> Unmounting prepared_image..." umount_kill "$(readlink -m ${INSTALLDIR})" || true /sbin/losetup -d ${IMG_LOOP} exit ${RETCODE}