19 |
PROFILES_DIR="/usr/lib/mlivecdbuild/profiles" |
PROFILES_DIR="/usr/lib/mlivecdbuild/profiles" |
20 |
GLOBAL_PROFILE="${PROFILES_DIR}/global" |
GLOBAL_PROFILE="${PROFILES_DIR}/global" |
21 |
|
|
22 |
|
# get full path to isolinux.bin, may vary on multilib systems |
23 |
|
if [[ -f /usr/share/syslinux/isolinux.bin ]] |
24 |
|
then |
25 |
|
ISOLINUX_BIN=/usr/share/syslinux/isolinux.bin |
26 |
|
elif [[ -f /usr/lib64/mkinitrd/isolinux.bin ]] |
27 |
|
then |
28 |
|
ISOLINUX_BIN=/usr/lib64/mkinitrd/isolinux.bin |
29 |
|
else |
30 |
|
ISOLINUX_BIN=/usr/lib/mkinitrd/isolinux.bin |
31 |
|
fi |
32 |
|
|
33 |
die() { echo "ERROR: $@"; exit 1; } |
die() { echo "ERROR: $@"; exit 1; } |
34 |
|
|
35 |
# get_profile $filename |
# get_profile $filename |
54 |
--profile "${MAGE_PROFILE}" \ |
--profile "${MAGE_PROFILE}" \ |
55 |
--toolchain "${TOOLCHAIN}" \ |
--toolchain "${TOOLCHAIN}" \ |
56 |
--basesystem "${BASESYSTEM}" \ |
--basesystem "${BASESYSTEM}" \ |
57 |
|
--update-tarball \ |
58 |
|| die "bootstrapping toolchain" |
|| die "bootstrapping toolchain" |
59 |
} |
} |
60 |
|
|
62 |
{ |
{ |
63 |
local cmd="$1" |
local cmd="$1" |
64 |
local services="$2" |
local services="$2" |
65 |
|
local systemdcmd |
66 |
|
|
67 |
case ${cmd} in |
case ${cmd} in |
68 |
add|del|default) continue;; |
add|del|default) |
69 |
|
# add given services from profile |
70 |
|
if [[ -n ${services} ]] |
71 |
|
then |
72 |
|
local i |
73 |
|
for i in ${services} |
74 |
|
do |
75 |
|
# systemd |
76 |
|
if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
77 |
|
then |
78 |
|
case ${cmd} in |
79 |
|
add) chroot ${CDCHROOTDIR} systemctl enable ${i} ;; |
80 |
|
del) chroot ${CDCHROOTDIR} systemctl disable ${i} ;; |
81 |
|
default) |
82 |
|
# convert targets |
83 |
|
case ${i} in |
84 |
|
2|3|multi-user) service="multi-user.target" ;; |
85 |
|
5|graphical) service="graphical.target" ;; |
86 |
|
esac |
87 |
|
chroot ${CDCHROOTDIR} systemctl enable ${i} ;; |
88 |
|
esac |
89 |
|
fi |
90 |
|
# busybox and sysvinit |
91 |
|
if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] && [[ ! -x ${CDCHROOTDIR}/bin/systemctl ]] && [[ ! -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
92 |
|
then |
93 |
|
MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}" |
94 |
|
fi |
95 |
|
done |
96 |
|
fi |
97 |
|
;; |
98 |
*) die "custom_services: unkown command ${cmd}";; |
*) die "custom_services: unkown command ${cmd}";; |
99 |
esac |
esac |
|
|
|
|
# add given services from profile |
|
|
if [[ -n ${services} ]] |
|
|
then |
|
|
local i |
|
|
for i in ${services} |
|
|
do |
|
|
MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}" |
|
|
done |
|
|
fi |
|
100 |
} |
} |
101 |
|
|
102 |
add_initrc() |
add_initrc() |
104 |
local var="$1" |
local var="$1" |
105 |
|
|
106 |
# sanity checks |
# sanity checks |
107 |
[ -z "${CDCHROOTDIR}" ] && die "\$CDCHROOTDIR not given." |
[[ -z ${CDCHROOTDIR} ]] && die "\$CDCHROOTDIR not given." |
108 |
echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var" |
echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var" |
109 |
} |
} |
110 |
|
|
114 |
local packages="$2" |
local packages="$2" |
115 |
|
|
116 |
case ${cmd} in |
case ${cmd} in |
117 |
install|uninstall) continue;; |
install|uninstall) |
118 |
|
if [[ -n ${packages} ]] |
119 |
|
then |
120 |
|
:> ${CDCHROOTDIR}/.installrc |
121 |
|
|
122 |
|
# respect proxies |
123 |
|
[[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}" |
124 |
|
[[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}" |
125 |
|
[[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}" |
126 |
|
|
127 |
|
# do not auto-start any services! |
128 |
|
add_initrc "export MAGE_BOOTSTRAP=true" |
129 |
|
add_initrc 'die() { if [ $? -eq 1 ]; then echo "ERROR: $@"; exit 1; fi; }' |
130 |
|
|
131 |
|
local i |
132 |
|
for i in ${packages} |
133 |
|
do |
134 |
|
add_initrc "mage ${cmd} ${i} || die ${i}" |
135 |
|
done |
136 |
|
add_initrc "mage clean" |
137 |
|
|
138 |
|
# now run the .installrc script |
139 |
|
mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc" |
140 |
|
mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys" |
141 |
|
mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev" |
142 |
|
chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting" |
143 |
|
umount ${CDCHROOTDIR}/dev || die "umount dev" |
144 |
|
umount ${CDCHROOTDIR}/proc || die "umount proc" |
145 |
|
umount ${CDCHROOTDIR}/sys || die "umount sys" |
146 |
|
[ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc |
147 |
|
fi |
148 |
|
;; |
149 |
*) die "custom_packages: unkown command ${cmd}";; |
*) die "custom_packages: unkown command ${cmd}";; |
150 |
esac |
esac |
|
|
|
|
if [[ -n ${packages} ]] |
|
|
then |
|
|
|
|
|
:> ${CDCHROOTDIR}/.installrc |
|
|
local i |
|
|
for i in ${packages} |
|
|
do |
|
|
add_initrc "mage install ${i}" |
|
|
done |
|
|
add_initrc "mage clean" |
|
|
|
|
|
# now run the .installrc script |
|
|
mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc" |
|
|
mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys" |
|
|
mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev" |
|
|
chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting" |
|
|
umount ${CDCHROOTDIR}/dev || die "umount dev" |
|
|
umount ${CDCHROOTDIR}/proc || die "umount proc" |
|
|
umount ${CDCHROOTDIR}/sys || die "umount sys" |
|
|
[ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc |
|
|
fi |
|
151 |
} |
} |
152 |
|
|
153 |
read_config() |
read_config() |
169 |
echo Preparing LiveCD ISO Image ... |
echo Preparing LiveCD ISO Image ... |
170 |
|
|
171 |
# fixes some issues with xfree/xorg xkb |
# fixes some issues with xfree/xorg xkb |
172 |
if [ -L "${CDCHROOTDIR}/etc/X11/xkb" -a -d "/usr/X11R6/lib/X11/xkb" ] |
if [[ -L ${CDCHROOTDIR}/etc/X11/xkb ]] && |
173 |
|
[[ -d ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ]] |
174 |
then |
then |
175 |
rm ${CDCHROOTDIR}/etc/X11/xkb || die |
rm ${CDCHROOTDIR}/etc/X11/xkb || die |
176 |
mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die |
mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die |
177 |
ln -s ../../../../etc/X11/xkb ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb || die |
ln -s ../../../../etc/X11/xkb ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb || die |
178 |
fi |
fi |
179 |
|
|
180 |
install -m 0644 $(get_profile inittab) ${CDCHROOTDIR}/etc/inittab || die |
# fix issues with >=dracut-014 which drops some default modules like livecd |
181 |
|
if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] || |
182 |
|
[[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] || |
183 |
|
[[ -x ${CDCHROOTDIR}/usr/bin/dracut ]] |
184 |
|
then |
185 |
|
install -d ${CDCHROOTDIR}/etc/dracut.conf.d || die |
186 |
|
echo 'add_dracutmodules+=" dmsquash-live "' \ |
187 |
|
> ${CDCHROOTDIR}/etc/dracut.conf.d/02-livecd.conf || die |
188 |
|
fi |
189 |
|
|
190 |
|
# only on sysvinit or busybox systems |
191 |
|
if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] |
192 |
|
then |
193 |
|
install -m 0644 $(get_profile inittab) ${CDCHROOTDIR}/etc/inittab || die |
194 |
|
fi |
195 |
|
if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
196 |
|
then |
197 |
|
# check lock group on systemd systems |
198 |
|
if [[ -z $(chroot ${CDCHROOTDIR} getent group lock) ]] |
199 |
|
then |
200 |
|
echo "adding missing group 'lock'" |
201 |
|
chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 54" lock |
202 |
|
fi |
203 |
|
# dbus plugdev group |
204 |
|
if [[ -z $(chroot ${CDCHROOTDIR} getent group plugdev) ]] |
205 |
|
then |
206 |
|
echo "adding missing group 'plugdev'" |
207 |
|
chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 302" plugdev |
208 |
|
fi |
209 |
|
# dbus messagebus group |
210 |
|
if [[ -z $(chroot ${CDCHROOTDIR} getent group messagebus) ]] |
211 |
|
then |
212 |
|
echo "adding missing group 'messagebus'" |
213 |
|
chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 300" messagebus |
214 |
|
fi |
215 |
|
# dbus messagebus user |
216 |
|
if [[ -z $(chroot ${CDCHROOTDIR} getent passwd messagebus) ]] |
217 |
|
then |
218 |
|
echo "adding missing user 'messagebus'" |
219 |
|
chroot ${CDCHROOTDIR} /usr/lib/mage/museradd -o "-u 300 -g messagebus -d /dev/null -s /bin/false" messagebus |
220 |
|
fi |
221 |
|
fi |
222 |
install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die |
install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die |
223 |
install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die |
install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die |
224 |
install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die |
install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die |
225 |
|
install -m 0644 $(get_profile net.eth0) ${CDCHROOTDIR}/etc/conf.d/net.eth0 || die |
226 |
echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die |
echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die |
227 |
|
install -d ${CDCHROOTDIR}/mnt/magellan || die |
228 |
|
|
229 |
echo Setting up services ... |
echo Setting up services ... |
230 |
|
|
231 |
# not needed with initscripts 0.3.6-r2 |
# install systemd default services |
232 |
# # change mountfs with mountfslivecd |
if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] |
233 |
# MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs" |
then |
234 |
# MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd" |
# install tmpfs /tmp and /var/tmp |
235 |
|
install -m 0644 $(get_profile tmp.mount) ${CDCHROOTDIR}/lib/systemd/system/ || die |
236 |
|
install -m 0644 $(get_profile var-tmp.mount) ${CDCHROOTDIR}/lib/systemd/system/ || die |
237 |
|
# enable them |
238 |
|
ln -snf ../tmp.mount ${CDCHROOTDIR}/lib/systemd/system/local-fs.target.wants/tmp.mount || die |
239 |
|
ln -snf ../var-tmp.mount ${CDCHROOTDIR}/lib/systemd/system/local-fs.target.wants/var-tmp.mount || die |
240 |
|
fi |
241 |
|
# newer systemd goes to /usr/lib |
242 |
|
if [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
243 |
|
then |
244 |
|
# install tmpfs /tmp and /var/tmp |
245 |
|
install -m 0644 $(get_profile tmp.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/ || die |
246 |
|
install -m 0644 $(get_profile var-tmp.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/ || die |
247 |
|
# enable them |
248 |
|
ln -snf ../tmp.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/tmp.mount || die |
249 |
|
ln -snf ../var-tmp.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/var-tmp.mount || die |
250 |
|
fi |
251 |
|
|
252 |
|
if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]] |
253 |
|
then |
254 |
|
install -m 0644 $(get_profile getty) ${CDCHROOTDIR}/etc/conf.d/getty || die |
255 |
|
|
256 |
# add hardware detection |
custom_services add getty@.service |
257 |
MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect" |
custom_services add remote-fs.target |
258 |
|
# disable readahead |
259 |
|
custom_services del systemd-readahead-replay.service |
260 |
|
custom_services del systemd-readahead-collect.service |
261 |
|
fi |
262 |
|
|
263 |
|
# # add hardware detection |
264 |
|
# if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] |
265 |
|
# then |
266 |
|
# MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect" |
267 |
|
# fi |
268 |
|
|
269 |
# del checkfs |
# del checkfs |
270 |
MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs" |
if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] |
271 |
|
then |
272 |
|
MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs" |
273 |
|
fi |
274 |
|
|
275 |
# add custom packages |
# add custom packages |
276 |
[[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}" |
[[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}" |
298 |
fi |
fi |
299 |
|
|
300 |
echo Cleaning unwanted files ... |
echo Cleaning unwanted files ... |
301 |
:> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab" |
# do this only if not a symlink! |
302 |
|
if [[ ! -L ${CDCHROOTDIR}/etc/mtab ]] |
303 |
|
then |
304 |
|
:> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab" |
305 |
|
fi |
306 |
[ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history |
[ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history |
307 |
} |
} |
308 |
|
|
309 |
generate_rootfs() |
generate_rootfs() |
310 |
{ |
{ |
311 |
|
local loopdev |
312 |
|
local size |
313 |
|
|
314 |
|
if [ -f ${LIVECDROOT}/loop/LiveOS/ext3fs.img ] |
315 |
|
then |
316 |
|
rm ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die |
317 |
|
fi |
318 |
|
if [ -f ${CDISOROOT}/LiveOS/squashfs.img ] |
319 |
|
then |
320 |
|
rm ${CDISOROOT}/LiveOS/squashfs.img |
321 |
|
fi |
322 |
|
if [ -f ${CDISOROOT}/livecdrootfs.sqsh ] |
323 |
|
then |
324 |
|
rm ${CDISOROOT}/livecdrootfs.sqsh |
325 |
|
fi |
326 |
|
|
327 |
echo Generating squashfs compressed rootfs loopfile ... |
echo Generating squashfs compressed rootfs loopfile ... |
328 |
mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh #>/dev/null 2>&1 |
if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] || |
329 |
|
[[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] || |
330 |
|
[[ -x ${CDCHROOTDIR}/usr/bin/dracut ]] |
331 |
|
then |
332 |
|
install -d ${LIVECDROOT}/loop/{LiveOS,mnt} || die |
333 |
|
|
334 |
|
# get the actual size of the chroot |
335 |
|
size=$(du -s ${LIVECDROOT}/chroot | sed 's:^\(.*\)[[:space:]].*:\1:') |
336 |
|
|
337 |
|
# generate a ext3fs file for devicemapper |
338 |
|
dd if=/dev/zero of=${LIVECDROOT}/loop/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 10 )) || die |
339 |
|
# create a filesystem |
340 |
|
mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die |
341 |
|
# set mount_counts and check_intervals to 0 |
342 |
|
# set dir_index top, to speed up thing with hashed b-trees |
343 |
|
# allow acls too |
344 |
|
tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die |
345 |
|
|
346 |
|
# losetup the device |
347 |
|
loopdev=$(losetup -f) |
348 |
|
[[ -z ${loopdev} ]] && die "No unused loopdev found. Maybe you want 'modprobe loop'?" |
349 |
|
|
350 |
|
# mount the image |
351 |
|
losetup ${loopdev} ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die |
352 |
|
mount ${loopdev} ${LIVECDROOT}/loop/mnt || die |
353 |
|
|
354 |
|
# copy everything to the image file and preserve permissions |
355 |
|
( cd ${CDCHROOTDIR} && tar cpf - . ) | ( cd ${LIVECDROOT}/loop/mnt && tar xvpf - ) |
356 |
|
sleep 3 |
357 |
|
|
358 |
|
# now umount everything and create the squashfs image |
359 |
|
umount ${LIVECDROOT}/loop/mnt || die |
360 |
|
losetup -d ${loopdev} || die |
361 |
|
# remove mount to not ending up in the squashfs image |
362 |
|
if [[ -d ${LIVECDROOT}/loop/mnt ]] |
363 |
|
then |
364 |
|
rm -r ${LIVECDROOT}/loop/mnt || die |
365 |
|
fi |
366 |
|
mksquashfs ${LIVECDROOT}/loop ${LIVECDROOT}/livecdrootfs.sqsh || die |
367 |
|
|
368 |
|
# final cleanup |
369 |
|
if [[ -d ${LIVECDROOT}/loop ]] |
370 |
|
then |
371 |
|
rm -r ${LIVECDROOT}/loop || die |
372 |
|
fi |
373 |
|
else |
374 |
|
mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh || die |
375 |
|
fi |
376 |
|
|
377 |
echo Moving rootfs loopfile to isoroot ... |
echo Moving rootfs loopfile to isoroot ... |
378 |
install -d ${CDISOROOT} |
install -d ${CDISOROOT} |
379 |
mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT} |
if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] || |
380 |
|
[[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] || |
381 |
|
[[ -x ${CDCHROOTDIR}/usr/bin/dracut ]] |
382 |
|
then |
383 |
|
install -d ${CDISOROOT}/LiveOS |
384 |
|
mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}/LiveOS/squashfs.img |
385 |
|
else |
386 |
|
mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT} |
387 |
|
fi |
388 |
} |
} |
389 |
|
|
390 |
install_bootloader() |
install_bootloader() |
393 |
|
|
394 |
# iso linux binary |
# iso linux binary |
395 |
install -d ${CDISOROOT}/isolinux |
install -d ${CDISOROOT}/isolinux |
396 |
install /usr/lib/mkinitrd/isolinux.bin ${CDISOROOT}/isolinux || die |
install ${ISOLINUX_BIN} ${CDISOROOT}/isolinux || die |
397 |
|
|
398 |
# kernel |
# kernel |
399 |
local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))" |
local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))" |
403 |
install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die |
install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die |
404 |
install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die |
install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die |
405 |
install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die |
install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die |
406 |
|
# support the new layout too |
407 |
|
if [[ -f $(get_profile index.msg) ]] |
408 |
|
then |
409 |
|
install -m 0644 $(get_profile index.msg) ${CDISOROOT}/isolinux || die |
410 |
|
fi |
411 |
|
if [[ -f $(get_profile debug.msg) ]] |
412 |
|
then |
413 |
|
install -m 0644 $(get_profile debug.msg) ${CDISOROOT}/isolinux || die |
414 |
|
fi |
415 |
|
|
416 |
return 0 |
return 0 |
417 |
} |
} |
420 |
{ |
{ |
421 |
local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})" |
local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})" |
422 |
|
|
423 |
|
is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys |
424 |
|
is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc |
425 |
|
is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev |
426 |
|
|
427 |
echo Generating initrd image ... |
echo Generating initrd image ... |
428 |
echo '#!/bin/bash' > ${CHROOTSH} || die |
echo '#!/bin/bash' > ${CHROOTSH} || die |
429 |
|
echo 'export LC_ALL=C' >> ${CHROOTSH} || die |
430 |
echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die |
echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die |
431 |
echo 'kv="${kv/kernel-}/"' >> ${CHROOTSH} || die |
echo 'kv="${kv/kernel-}/"' >> ${CHROOTSH} || die |
432 |
echo 'mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die |
# prefer dracut |
433 |
|
echo 'if [[ -x /sbin/dracut ]] || [[ -x /usr/sbin/dracut ]] || [[ -x /usr/bin/dracut ]]' >> ${CHROOTSH} || die |
434 |
|
echo 'then' >> ${CHROOTSH} || die |
435 |
|
echo ' dracut -v -f /initrd.gz ${kv}' >> ${CHROOTSH} || die |
436 |
|
echo 'else' >> ${CHROOTSH} || die |
437 |
|
echo ' mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die |
438 |
|
echo 'fi' >> ${CHROOTSH} || die |
439 |
chmod +x ${CHROOTSH} || die |
chmod +x ${CHROOTSH} || die |
440 |
chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die |
chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die |
441 |
[[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die |
[[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die |
442 |
|
|
443 |
|
is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev |
444 |
|
is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc |
445 |
|
is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys |
446 |
|
|
447 |
# move initrd to isoroot |
# move initrd to isoroot |
448 |
install -d ${CDISOROOT}/isolinux || die |
install -d ${CDISOROOT}/isolinux || die |
449 |
mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die |
mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die |
471 |
|
|
472 |
enter_livecd() |
enter_livecd() |
473 |
{ |
{ |
474 |
mount -t sysfs sysfs ${CDCHROOTDIR}/proc |
is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys |
475 |
mount -t proc proc ${CDCHROOTDIR}/proc |
is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc |
476 |
mount -o bind /dev ${CDCHROOTDIR}/dev |
is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev |
477 |
|
|
478 |
chroot ${CDCHROOTDIR} \ |
chroot ${CDCHROOTDIR} \ |
479 |
/usr/bin/env -i \ |
/usr/bin/env -i \ |
480 |
HOME=/root \ |
HOME=/root \ |
481 |
TERM=$TERM PS1='\u:\w\$ ' \ |
TERM=$TERM PS1='\u:\w\$ ' \ |
482 |
PATH=/bin:/usr/bin:/sbin:/usr/sbin \ |
PATH=/bin:/usr/bin:/sbin:/usr/sbin \ |
483 |
|
http_proxy=${http_proxy} \ |
484 |
|
ftp_proxy=${ftp_proxy} \ |
485 |
|
no_proxy=${no_proxy} \ |
486 |
/bin/bash -i |
/bin/bash -i |
487 |
|
|
488 |
|
is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev |
489 |
|
is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc |
490 |
|
is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys |
491 |
|
} |
492 |
|
|
493 |
|
is_loc_mounted() |
494 |
|
{ |
495 |
|
local filesys |
496 |
|
local i |
497 |
|
filesys=$1 |
498 |
|
|
499 |
|
i="$(cat /proc/mounts | grep " ${filesys} " | cut -d ' ' -f2)" |
500 |
|
[[ ${i} != ${filesys} ]] && return 1 |
501 |
|
|
502 |
|
return 0 |
503 |
|
} |
504 |
|
|
505 |
|
trap_exit() |
506 |
|
{ |
507 |
|
is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev |
508 |
|
is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc |
509 |
|
is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys |
510 |
} |
} |
511 |
|
|
512 |
usage() |
usage() |
521 |
echo " bootloader - installs the bootloader" |
echo " bootloader - installs the bootloader" |
522 |
echo " isogen - generate the final livecd iso image" |
echo " isogen - generate the final livecd iso image" |
523 |
echo " all - runs all tasks to get a livecd from zero" |
echo " all - runs all tasks to get a livecd from zero" |
524 |
|
echo " enter - enters the rootfs of a livecd" |
525 |
echo |
echo |
526 |
echo " for example '$(basename $0) all default'" |
echo " for example '$(basename $0) all default'" |
527 |
echo " creates a livecd using the default profile." |
echo " creates a livecd using the default profile." |
528 |
echo |
echo |
529 |
} |
} |
530 |
|
|
531 |
|
# set some proper traps |
532 |
|
trap "trap_exit" SIGINT SIGQUIT |
533 |
|
|
534 |
# source profile config - overrides all other vars |
# source profile config - overrides all other vars |
535 |
[ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config |
[ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config |
536 |
|
|
|
#bootstrap_system |
|
|
#prepare_iso |
|
|
#generate_rootfs |
|
|
#generate_initrd |
|
|
#install_bootloader |
|
|
#generate_iso |
|
|
|
|
537 |
case $1 in |
case $1 in |
538 |
bootstrap) bootstrap_system;; |
bootstrap) bootstrap_system;; |
539 |
prepare) prepare_iso;; |
prepare) prepare_iso;; |
549 |
install_bootloader |
install_bootloader |
550 |
generate_iso |
generate_iso |
551 |
;; |
;; |
552 |
|
enter) enter_livecd ;; |
553 |
*|'') usage;; |
*|'') usage;; |
554 |
esac |
esac |