-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathqubeize_image
executable file
·166 lines (140 loc) · 5.26 KB
/
qubeize_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
if [ "$VERBOSE" -ge 2 -o "$DEBUG" == "1" ]; then
set -x
fi
set -e
# ------------------------------------------------------------------------------
# Configurations and Conditionals
# ------------------------------------------------------------------------------
export CLEANIMG="$1"
export NAME="$2"
export LC_ALL=POSIX
. ./builder_setup >/dev/null
. ./umount_kill.sh >/dev/null
if [ $# -eq 0 ]; then
echo "usage $0 <clean_image_file> <template_name>"
exit
fi
if [ "x$CLEANIMG" = x ]; then
echo "Image file not specified!"
exit 1
fi
if [ "x$NAME" = x ]; then
echo "Name not given!"
exit 1
fi
ID=$(id -ur)
if [ $ID != 0 ] ; then
echo "This script should be run as root user."
exit 1
fi
if [ "$VERBOSE" == "1" ]; then
export YUM_OPTS="$YUM_OPTS -q"
fi
# ------------------------------------------------------------------------------
# Cleanup function
# ------------------------------------------------------------------------------
function cleanup() {
errval=$?
trap - ERR
trap
umount_kill "$PWD/mnt" || true
/sbin/losetup -d ${IMG_LOOP}
exit $errval
}
trap cleanup ERR
# ------------------------------------------------------------------------------
# Mount qubeized_image
# ------------------------------------------------------------------------------
export IMG="qubeized_images/$NAME/root.img"
mkdir -p "qubeized_images/$NAME"
if [ "0$DISCARD_PREPARED_IMAGE" -eq "1" ]; then
echo "--> Moving $CLEANIMG to $IMG..."
mv "$CLEANIMG" "$IMG" || exit 1
else
echo "--> Copying $CLEANIMG to $IMG..."
cp "$CLEANIMG" "$IMG" || exit 1
fi
echo "--> Mounting $IMG"
mkdir -p mnt
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"
mount "$IMG_DEV" mnt || exit 1
export INSTALLDIR=mnt
# prepare for template.conf, so the qubeize script may generate it dynamically
export TEMPLATE_CONF="${PWD}/template.conf"
rm -f "$TEMPLATE_CONF"
# Support for builderv2
export INSTALL_DIR="${INSTALLDIR}"
# shellcheck disable=SC2153
export CACHE_DIR="${CACHEDIR}"
# ------------------------------------------------------------------------------
# Run qubeize script
# ------------------------------------------------------------------------------
"$SCRIPTSDIR/04_install_qubes.sh"
# ------------------------------------------------------------------------------
# Create App Menus
# ------------------------------------------------------------------------------
echo "--> Choosing appmenus whitelists..."
_appmenus_dir="${APPMENUS_DIR:-${SCRIPTSDIR}}"
rm -f appmenus
if [ -d "${_appmenus_dir}/appmenus_${DIST}_${TEMPLATE_FLAVOR}" ]; then
ln -s "${_appmenus_dir}/appmenus_${DIST}_${TEMPLATE_FLAVOR}" appmenus
elif [ -d "${_appmenus_dir}/appmenus_${DIST//[0-9]*}_${TEMPLATE_FLAVOR}" ]; then
ln -s "${_appmenus_dir}/appmenus_${DIST//[0-9]*}_${TEMPLATE_FLAVOR}" appmenus
elif [ -d "${_appmenus_dir}/appmenus_$DIST" ]; then
ln -s "${_appmenus_dir}/appmenus_$DIST" appmenus
elif [ -d "${_appmenus_dir}/appmenus_${DIST//[0-9]*}" ]; then
ln -s "${_appmenus_dir}/appmenus_${DIST//[0-9]*}" appmenus
elif [ -d "${_appmenus_dir}/appmenus" ]; then
ln -s "${_appmenus_dir}/appmenus" appmenus
else
ln -s "appmenus_generic" appmenus
fi
# ------------------------------------------------------------------------------
# Create Template Config File
# ------------------------------------------------------------------------------
echo "--> Creating template config file..."
if ! [ -e "$TEMPLATE_CONF" ]; then
_conf_dir="${CONFIG_DIR:-${SCRIPTSDIR}}"
if [ -f "${_conf_dir}/template_${DIST}_${TEMPLATE_FLAVOR}.conf" ]; then
cp "${_conf_dir}/template_${DIST}_${TEMPLATE_FLAVOR}.conf" "$TEMPLATE_CONF"
elif [ -f "${_conf_dir}/template_${DIST//[0-9]*}_${TEMPLATE_FLAVOR}.conf" ]; then
cp "${_conf_dir}/template_${DIST//[0-9]*}_${TEMPLATE_FLAVOR}.conf" "$TEMPLATE_CONF"
elif [ -f "${_conf_dir}/template_$DIST.conf" ]; then
cp "${_conf_dir}/template_$DIST.conf" "$TEMPLATE_CONF"
elif [ -f "${_conf_dir}/template_${DIST//[0-9]*}.conf" ]; then
cp "${_conf_dir}/template_${DIST//[0-9]*}.conf" "$TEMPLATE_CONF"
elif [ -f "${_conf_dir}/template.conf" ]; then
cp "${_conf_dir}/template.conf" "$TEMPLATE_CONF"
else
cp template_generic.conf "$TEMPLATE_CONF"
fi
fi
# ------------------------------------------------------------------------------
# Link directories so they can be mounted
# ------------------------------------------------------------------------------
echo "--> Linking /home to /rw/home..."
mv mnt/home mnt/home.orig
mkdir mnt/home
echo "--> Linking /usr/local to /rw/usrlocal..."
mv mnt/usr/local mnt/usr/local.orig
mkdir mnt/usr/local
echo "Reducing image size (calling cleanup_image)..."
ls -als $IMG
./cleanup_image "$INSTALLDIR"
ls -als $IMG
# ------------------------------------------------------------------------------
# Finsh - unmount image
# ------------------------------------------------------------------------------
echo "--> Unmounting $IMG"
umount_kill "$PWD/mnt" || true
/sbin/losetup -d ${IMG_LOOP}
echo "Qubeized image stored at: $IMG"
chown -R --reference=. qubeized_images/$NAME