2014-10-14 16:02:12 +00:00
|
|
|
#!/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
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Configurations
|
|
|
|
# ------------------------------------------------------------------------------
|
2015-02-10 15:07:44 +00:00
|
|
|
export IMG="${1}"
|
2014-07-28 16:53:49 +00:00
|
|
|
export LC_ALL=POSIX
|
2010-06-18 23:41:29 +00:00
|
|
|
|
2011-09-25 20:41:27 +00:00
|
|
|
RETCODE=0
|
|
|
|
|
2011-09-24 09:58:14 +00:00
|
|
|
: ${DIST=fc14}
|
|
|
|
|
2015-03-10 03:19:28 +00:00
|
|
|
. ./builder_setup >/dev/null
|
|
|
|
. ./umount_kill.sh >/dev/null
|
|
|
|
|
2013-01-25 08:03:51 +00:00
|
|
|
if ! [ $# -eq 1 ]; then
|
2015-02-10 15:07:44 +00:00
|
|
|
echo "usage ${0} <img_file_name>"
|
2014-10-14 16:02:12 +00:00
|
|
|
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"
|
2012-11-18 03:01:49 +00:00
|
|
|
fi
|
2010-06-18 23:41:29 +00:00
|
|
|
|
2018-03-10 01:02:21 +00:00
|
|
|
if [ -z "$TEMPLATE_ROOT_SIZE" ]; then
|
|
|
|
TEMPLATE_ROOT_SIZE=10G
|
|
|
|
fi
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2015-02-10 15:07:44 +00:00
|
|
|
# Make sure INSTALLDIR exists
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2014-11-06 01:11:07 +00:00
|
|
|
export INSTALLDIR="$(readlink -m mnt)"
|
2015-02-10 15:07:44 +00:00
|
|
|
mkdir -p "${INSTALLDIR}"
|
2014-10-14 16:02:12 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2015-02-10 15:07:44 +00:00
|
|
|
# Prepare for mount
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2015-02-10 15:07:44 +00:00
|
|
|
echo "-> Preparing instalation of ${DIST} template..."
|
|
|
|
"${SCRIPTSDIR}/00_prepare.sh"
|
2014-10-14 20:30:12 +00:00
|
|
|
|
2015-02-10 15:07:44 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Mount image and install core OS
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
if [ -f "${IMG}" ]; then
|
2014-10-14 16:02:12 +00:00
|
|
|
echo "-> Image file already exists, assuming *update*..."
|
2017-06-14 08:53:22 +00:00
|
|
|
if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then
|
|
|
|
IMG_LOOP=$(losetup -P -f --show "$IMG")
|
2017-10-17 21:59:00 +00:00
|
|
|
IMG_DEV=${IMG_LOOP}p3
|
2017-06-14 08:53:22 +00:00
|
|
|
else
|
|
|
|
IMG_LOOP=$(losetup -f --show "$IMG")
|
|
|
|
IMG_DEV=${IMG_LOOP}
|
|
|
|
fi
|
2010-06-18 23:41:29 +00:00
|
|
|
else
|
2014-10-14 16:02:12 +00:00
|
|
|
echo "-> Initializing empty image..."
|
2018-03-10 01:02:21 +00:00
|
|
|
truncate -s "$TEMPLATE_ROOT_SIZE" "${IMG}" || exit 1
|
2010-06-18 23:41:29 +00:00
|
|
|
|
2017-06-14 08:53:22 +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"
|
2017-10-17 21:59:00 +00:00
|
|
|
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=693244e6-3e07-47bf-ad79-acade4293fe7, name="Root filesystem"
|
2017-06-14 08:53:22 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
IMG_LOOP=$(losetup -P -f --show "$IMG")
|
2017-10-17 21:59:00 +00:00
|
|
|
IMG_DEV=${IMG_LOOP}p3
|
2017-06-14 08:53:22 +00:00
|
|
|
else
|
|
|
|
IMG_LOOP=$(losetup -f --show "$IMG")
|
|
|
|
IMG_DEV=${IMG_LOOP}
|
|
|
|
fi
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
echo "-> Creating filesystem..."
|
2017-06-14 08:53:22 +00:00
|
|
|
mkfs.ext4 -q -F "${IMG_DEV}" || exit 1
|
2010-06-18 23:41:29 +00:00
|
|
|
fi
|
|
|
|
|
2017-06-14 08:53:22 +00:00
|
|
|
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"
|
2014-10-14 20:30:12 +00:00
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# 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
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Cleanup
|
|
|
|
# ------------------------------------------------------------------------------
|
2014-05-13 02:30:01 +00:00
|
|
|
trap - EXIT
|
2014-10-14 16:02:12 +00:00
|
|
|
|
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
|
2017-06-14 08:53:22 +00:00
|
|
|
losetup -d ${IMG_LOOP}
|
2011-09-25 20:41:27 +00:00
|
|
|
|
2015-02-10 15:07:44 +00:00
|
|
|
exit ${RETCODE}
|