Magellan Linux

Contents of /trunk/mlivecdbuild/mlivecdbuild2.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2319 - (show annotations) (download) (as text)
Fri Jan 3 08:19:48 2014 UTC (10 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 17664 byte(s)
custom_services(): support is-enabled and check if readahead services are enabled before disabling them
1 #!/bin/bash
2
3 # some default settings - gets overidden with the profile config
4 CDPROFILE="$2"
5 [[ -z ${CDPROFILE} ]] && CDPROFILE="default"
6 LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}"
7 CDCHROOTDIR="${LIVECDROOT}/chroot"
8 CDISONAME="livecd-${CDPROFILE}.iso"
9 CDISOROOT="${LIVECDROOT}/isoroot"
10 CDKERNELNAME="magelive"
11 CDHOSTNAME="livecd-${CDPROFILE}"
12 MAGERC="/etc/mage.rc"
13 MAGE_PROFILE="$(basename $(readlink /etc/mage-profile))"
14 #TOOLCHAIN=toolchain
15 BASESYSTEM=livecdsystem26
16 CDID="mlcd-$(date +%F-%k%M)"
17
18 # global profile pathes
19 PROFILES_DIR="/usr/lib/mlivecdbuild/profiles"
20 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; }
34
35 # get_profile $filename
36 get_profile()
37 {
38 local file="$1"
39
40 if [[ -z ${file} ]] || [[ ! -e ${PROFILES_DIR}/${CDPROFILE}/${file} ]]
41 then
42 echo "${GLOBAL_PROFILE}/${file}"
43 return 0
44 fi
45
46 echo "${PROFILES_DIR}/${CDPROFILE}/${file}"
47 }
48
49 bootstrap_system()
50 {
51 mage-bootstrap \
52 --root "${CDCHROOTDIR}" \
53 --magerc "${MAGERC}" \
54 --profile "${MAGE_PROFILE}" \
55 --toolchain "${TOOLCHAIN}" \
56 --basesystem "${BASESYSTEM}" \
57 --update-tarball \
58 || die "bootstrapping toolchain"
59 }
60
61 custom_services()
62 {
63 local cmd="$1"
64 local services="$2"
65 local systemdcmd
66
67 case ${cmd} in
68 add|del|default|is-enabled)
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 is-enabled) chroot ${CDCHROOTDIR} systemctl is-enabled ${i} ;;
82 default)
83 # convert targets
84 case ${i} in
85 2|3|multi-user) service="multi-user.target" ;;
86 5|graphical) service="graphical.target" ;;
87 esac
88 chroot ${CDCHROOTDIR} systemctl enable ${i} ;;
89 esac
90 fi
91 # busybox and sysvinit
92 if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]] && [[ ! -x ${CDCHROOTDIR}/bin/systemctl ]] && [[ ! -x ${CDCHROOTDIR}/usr/bin/systemctl ]]
93 then
94 MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}"
95 fi
96 done
97 fi
98 ;;
99 *) die "custom_services: unkown command ${cmd}";;
100 esac
101 }
102
103 add_initrc()
104 {
105 local var="$1"
106
107 # sanity checks
108 [[ -z ${CDCHROOTDIR} ]] && die "\$CDCHROOTDIR not given."
109 echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var"
110 }
111
112 custom_packages()
113 {
114 local cmd="$1"
115 local packages="$2"
116
117 case ${cmd} in
118 install|uninstall)
119 if [[ -n ${packages} ]]
120 then
121 :> ${CDCHROOTDIR}/.installrc
122
123 # respect proxies
124 [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}"
125 [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}"
126 [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}"
127
128 # do not auto-start any services!
129 add_initrc "export MAGE_BOOTSTRAP=true"
130 add_initrc 'die() { if [ $? -eq 1 ]; then echo "ERROR: $@"; exit 1; fi; }'
131
132 local i
133 for i in ${packages}
134 do
135 add_initrc "mage ${cmd} ${i} || die ${i}"
136 done
137 add_initrc "mage clean"
138
139 # now run the .installrc script
140 mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc"
141 mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys"
142 mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev"
143 chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting"
144 umount ${CDCHROOTDIR}/dev || die "umount dev"
145 umount ${CDCHROOTDIR}/proc || die "umount proc"
146 umount ${CDCHROOTDIR}/sys || die "umount sys"
147 [ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc
148 fi
149 ;;
150 *) die "custom_packages: unkown command ${cmd}";;
151 esac
152 }
153
154 read_config()
155 {
156 local file="$1"
157 local pkg
158
159 ( cat ${file}; echo ) | while read pkg
160 do
161 case "${pkg}" in
162 \#*|"") continue ;;
163 esac
164 echo "${pkg}"
165 done
166 }
167
168 prepare_iso()
169 {
170 echo Preparing LiveCD ISO Image ...
171
172 # fixes some issues with xfree/xorg xkb
173 if [[ -L ${CDCHROOTDIR}/etc/X11/xkb ]] &&
174 [[ -d ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ]]
175 then
176 rm ${CDCHROOTDIR}/etc/X11/xkb || die
177 mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die
178 ln -s ../../../../etc/X11/xkb ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb || die
179 fi
180
181 # fix issues with >=dracut-014 which drops some default modules like livecd
182 if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] ||
183 [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] ||
184 [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]]
185 then
186 install -d ${CDCHROOTDIR}/etc/dracut.conf.d || die
187 echo 'add_dracutmodules+=" dmsquash-live "' \
188 > ${CDCHROOTDIR}/etc/dracut.conf.d/02-livecd.conf || die
189 fi
190
191 # only on sysvinit or busybox systems
192 if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]]
193 then
194 install -m 0644 $(get_profile inittab) ${CDCHROOTDIR}/etc/inittab || die
195 fi
196 if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]]
197 then
198 # check lock group on systemd systems
199 if [[ -z $(chroot ${CDCHROOTDIR} getent group lock) ]]
200 then
201 echo "adding missing group 'lock'"
202 chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 54" lock
203 fi
204 # dbus plugdev group
205 if [[ -z $(chroot ${CDCHROOTDIR} getent group plugdev) ]]
206 then
207 echo "adding missing group 'plugdev'"
208 chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 302" plugdev
209 fi
210 # dbus messagebus group
211 if [[ -z $(chroot ${CDCHROOTDIR} getent group messagebus) ]]
212 then
213 echo "adding missing group 'messagebus'"
214 chroot ${CDCHROOTDIR} /usr/lib/mage/mgroupadd -o "-g 300" messagebus
215 fi
216 # dbus messagebus user
217 if [[ -z $(chroot ${CDCHROOTDIR} getent passwd messagebus) ]]
218 then
219 echo "adding missing user 'messagebus'"
220 chroot ${CDCHROOTDIR} /usr/lib/mage/museradd -o "-u 300 -g messagebus -d /dev/null -s /bin/false" messagebus
221 fi
222 fi
223 install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die
224 install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die
225 install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die
226 install -m 0644 $(get_profile net.eth0) ${CDCHROOTDIR}/etc/conf.d/net.eth0 || die
227 echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die
228 install -d ${CDCHROOTDIR}/mnt/magellan || die
229
230 echo Setting up services ...
231
232 # install systemd default services
233 if [[ -x ${CDCHROOTDIR}/bin/systemctl ]]
234 then
235 # install tmpfs /tmp and /var/tmp
236 install -m 0644 $(get_profile tmp.mount) ${CDCHROOTDIR}/lib/systemd/system/ || die
237 install -m 0644 $(get_profile var-tmp.mount) ${CDCHROOTDIR}/lib/systemd/system/ || die
238 # enable them
239 ln -snf ../tmp.mount ${CDCHROOTDIR}/lib/systemd/system/local-fs.target.wants/tmp.mount || die
240 ln -snf ../var-tmp.mount ${CDCHROOTDIR}/lib/systemd/system/local-fs.target.wants/var-tmp.mount || die
241 fi
242 # newer systemd goes to /usr/lib
243 if [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]]
244 then
245 # install tmpfs /tmp and /var/tmp
246 install -m 0644 $(get_profile tmp.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/ || die
247 install -m 0644 $(get_profile var-tmp.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/ || die
248 # enable them
249 ln -snf ../tmp.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/tmp.mount || die
250 ln -snf ../var-tmp.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/var-tmp.mount || die
251 fi
252
253 if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]]
254 then
255 install -m 0644 $(get_profile getty) ${CDCHROOTDIR}/etc/conf.d/getty || die
256
257 custom_services add getty@tty1.service
258 custom_services add remote-fs.target
259 # disable readahead
260 custom_services is-enabled systemd-readahead-replay.service && custom_services del systemd-readahead-replay.service
261 custom_services is-enabled systemd-readahead-collect.service && custom_services del systemd-readahead-collect.service
262 fi
263
264 # # add hardware detection
265 # if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]]
266 # then
267 # MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"
268 # fi
269
270 # del checkfs
271 if [[ -x ${CDCHROOTDIR}/sbin/rc-config ]]
272 then
273 MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs"
274 fi
275
276 # add custom packages
277 [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}"
278 [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))"
279
280 # del custom packages
281 [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}"
282 [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))"
283
284 # add given services from profile
285 [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}"
286 [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))"
287
288 # del given services from profile
289 [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}"
290 [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))"
291
292 # setup default runlevel
293 [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}"
294
295 if [ -f $(get_profile prepare_custom) ]
296 then
297 echo Running custom user script ...
298 source $(get_profile prepare_custom) || die "running custom user script"
299 fi
300
301 echo Cleaning unwanted files ...
302 # do this only if not a symlink!
303 if [[ ! -L ${CDCHROOTDIR}/etc/mtab ]]
304 then
305 :> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab"
306 fi
307 [ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history
308 }
309
310 generate_rootfs()
311 {
312 local loopdev
313 local size
314
315 if [ -f ${LIVECDROOT}/loop/LiveOS/ext3fs.img ]
316 then
317 rm ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die
318 fi
319 if [ -f ${CDISOROOT}/LiveOS/squashfs.img ]
320 then
321 rm ${CDISOROOT}/LiveOS/squashfs.img
322 fi
323 if [ -f ${CDISOROOT}/livecdrootfs.sqsh ]
324 then
325 rm ${CDISOROOT}/livecdrootfs.sqsh
326 fi
327
328 echo Generating squashfs compressed rootfs loopfile ...
329 if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] ||
330 [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] ||
331 [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]]
332 then
333 install -d ${LIVECDROOT}/loop/{LiveOS,mnt} || die
334
335 # get the actual size of the chroot
336 size=$(du -s ${LIVECDROOT}/chroot | sed 's:^\(.*\)[[:space:]].*:\1:')
337
338 # generate a ext3fs file for devicemapper
339 dd if=/dev/zero of=${LIVECDROOT}/loop/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 10 )) || die
340 # create a filesystem
341 mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die
342 # set mount_counts and check_intervals to 0
343 # set dir_index top, to speed up thing with hashed b-trees
344 # allow acls too
345 tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die
346
347 # losetup the device
348 loopdev=$(losetup -f)
349 [[ -z ${loopdev} ]] && die "No unused loopdev found. Maybe you want 'modprobe loop'?"
350
351 # mount the image
352 losetup ${loopdev} ${LIVECDROOT}/loop/LiveOS/ext3fs.img || die
353 mount ${loopdev} ${LIVECDROOT}/loop/mnt || die
354
355 # copy everything to the image file and preserve permissions
356 ( cd ${CDCHROOTDIR} && tar cpf - . ) | ( cd ${LIVECDROOT}/loop/mnt && tar xvpf - )
357 sleep 3
358
359 # now umount everything and create the squashfs image
360 umount ${LIVECDROOT}/loop/mnt || die
361 losetup -d ${loopdev} || die
362 # remove mount to not ending up in the squashfs image
363 if [[ -d ${LIVECDROOT}/loop/mnt ]]
364 then
365 rm -r ${LIVECDROOT}/loop/mnt || die
366 fi
367 mksquashfs ${LIVECDROOT}/loop ${LIVECDROOT}/livecdrootfs.sqsh || die
368
369 # final cleanup
370 if [[ -d ${LIVECDROOT}/loop ]]
371 then
372 rm -r ${LIVECDROOT}/loop || die
373 fi
374 else
375 mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh || die
376 fi
377
378 echo Moving rootfs loopfile to isoroot ...
379 install -d ${CDISOROOT}
380 if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] ||
381 [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] ||
382 [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]]
383 then
384 install -d ${CDISOROOT}/LiveOS
385 mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}/LiveOS/squashfs.img
386 else
387 mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}
388 fi
389 }
390
391 install_bootloader()
392 {
393 echo Installing Bootloader ...
394
395 # iso linux binary
396 install -d ${CDISOROOT}/isolinux
397 install ${ISOLINUX_BIN} ${CDISOROOT}/isolinux || die
398
399 # kernel
400 # support kernel installations without symlinks
401 if [ -L ${CDCHROOTDIR}/boot/vmlinuz ]
402 then
403 local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))"
404 else
405 local kimg="$(find ${CDCHROOTDIR}/boot -name kernel-\* -printf '%f\n')"
406 fi
407 install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/isolinux/${CDKERNELNAME} || die
408
409 install -m 0644 $(get_profile isolinux.cfg) ${CDISOROOT}/isolinux || die
410 install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die
411 install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die
412 install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die
413 # support the new layout too
414 if [[ -f $(get_profile index.msg) ]]
415 then
416 install -m 0644 $(get_profile index.msg) ${CDISOROOT}/isolinux || die
417 fi
418 if [[ -f $(get_profile debug.msg) ]]
419 then
420 install -m 0644 $(get_profile debug.msg) ${CDISOROOT}/isolinux || die
421 fi
422
423 return 0
424 }
425
426 generate_initrd()
427 {
428 local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"
429
430 is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys
431 is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc
432 is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev
433
434 echo Generating initrd image ...
435 echo '#!/bin/bash' > ${CHROOTSH} || die
436 echo 'export LC_ALL=C' >> ${CHROOTSH} || die
437 # support kernel installations without symlinks
438 if [ -L ${CDCHROOTDIR}/boot/vmlinuz ]
439 then
440 echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die
441 else
442 echo "kv=\$(find /boot -name kernel-\* -printf '%f\n')" >> ${CHROOTSH} || die
443 fi
444 echo 'kv="${kv/kernel-/}"' >> ${CHROOTSH} || die
445 # prefer dracut
446 echo 'if [[ -x /sbin/dracut ]] || [[ -x /usr/sbin/dracut ]] || [[ -x /usr/bin/dracut ]]' >> ${CHROOTSH} || die
447 echo 'then' >> ${CHROOTSH} || die
448 echo ' dracut -v -f /initrd.gz ${kv}' >> ${CHROOTSH} || die
449 echo 'else' >> ${CHROOTSH} || die
450 echo ' mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die
451 echo 'fi' >> ${CHROOTSH} || die
452 chmod +x ${CHROOTSH} || die
453 chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die
454 [[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die
455
456 is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev
457 is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc
458 is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys
459
460 # move initrd to isoroot
461 install -d ${CDISOROOT}/isolinux || die
462 mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die
463 }
464
465 generate_iso()
466 {
467 echo Generating ISO Image ...
468 install -d ${CDISOROOT}
469 pushd ${CDISOROOT} &&
470 mkisofs -rock \
471 -full-iso9660-filenames \
472 -allow-leading-dots \
473 -disable-deep-relocation \
474 -output ${LIVECDROOT}/${CDISONAME} \
475 -eltorito-boot isolinux/isolinux.bin \
476 -eltorito-catalog isolinux/boot.cat \
477 -no-emul-boot \
478 -boot-load-size 4 \
479 -boot-info-table \
480 -volid "${CDID}" \
481 ${CDISOROOT} #&> /dev/null
482 popd
483 }
484
485 enter_livecd()
486 {
487 is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys
488 is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc
489 is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev
490
491 chroot ${CDCHROOTDIR} \
492 /usr/bin/env -i \
493 HOME=/root \
494 TERM=$TERM PS1='\u:\w\$ ' \
495 PATH=/bin:/usr/bin:/sbin:/usr/sbin \
496 http_proxy=${http_proxy} \
497 ftp_proxy=${ftp_proxy} \
498 no_proxy=${no_proxy} \
499 /bin/bash -i
500
501 is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev
502 is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc
503 is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys
504 }
505
506 is_loc_mounted()
507 {
508 local filesys
509 local i
510 filesys=$1
511
512 i="$(cat /proc/mounts | grep " ${filesys} " | cut -d ' ' -f2)"
513 [[ ${i} != ${filesys} ]] && return 1
514
515 return 0
516 }
517
518 trap_exit()
519 {
520 is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev
521 is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc
522 is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys
523 }
524
525 usage()
526 {
527 echo "Usage: $(basename $0) [command] [profile] ..."
528 echo
529 echo "Commands:"
530 echo " bootstrap - bootstraps the rootfs for the livecd"
531 echo " prepare - prepare the rootfs to run from a livecd"
532 echo " rootfs - generates the squashfs rootfs image"
533 echo " initrd - generates a livecd suitable initrd"
534 echo " bootloader - installs the bootloader"
535 echo " isogen - generate the final livecd iso image"
536 echo " all - runs all tasks to get a livecd from zero"
537 echo " enter - enters the rootfs of a livecd"
538 echo
539 echo " for example '$(basename $0) all default'"
540 echo " creates a livecd using the default profile."
541 echo
542 }
543
544 # set some proper traps
545 trap "trap_exit" SIGINT SIGQUIT
546
547 # source profile config - overrides all other vars
548 [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config
549
550 case $1 in
551 bootstrap) bootstrap_system;;
552 prepare) prepare_iso;;
553 rootfs) generate_rootfs;;
554 initrd) generate_initrd;;
555 bootloader) install_bootloader;;
556 isogen) generate_iso;;
557 all)
558 bootstrap_system
559 prepare_iso
560 generate_rootfs
561 generate_initrd
562 install_bootloader
563 generate_iso
564 ;;
565 enter) enter_livecd ;;
566 *|'') usage;;
567 esac