-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathprepare_image
executable file
·112 lines (90 loc) · 3.51 KB
/
prepare_image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/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} <img_file_name>"
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}"
# Support for builderv2
export INSTALL_DIR="${INSTALLDIR}"
# shellcheck disable=SC2153
export CACHE_DIR="${CACHEDIR}"
# ------------------------------------------------------------------------------
# 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 -P -f --show "$IMG")
IMG_DEV=${IMG_LOOP}p3
else
IMG_LOOP=$(/sbin/losetup -f --show "$IMG")
IMG_DEV=${IMG_LOOP}
fi
udevadm settle --exit-if-exists="$IMG_DEV"
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"
# have static UUIDs to make partition table reproducible
/usr/sbin/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
udevadm settle --exit-if-exists="$IMG_DEV"
echo "-> Creating filesystem..."
/sbin/mkfs.ext4 -q -F "${IMG_DEV}" || exit 1
fi
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}