Magellan Linux

Diff of /trunk/mlivecdbuild/mlivecdbuild2.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 348 by niro, Sun Mar 5 02:18:28 2006 UTC revision 2098 by niro, Thu Mar 28 15:39:45 2013 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    
3  # some default settings - gets overidden with the profile config  # some default settings - gets overidden with the profile config
4  CDPROFILE="$1"  CDPROFILE="$2"
5  [[ -z ${CDPROFILE} ]] && CDPROFILE="default"  [[ -z ${CDPROFILE} ]] && CDPROFILE="default"
6  LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}"  LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}"
7  CDCHROOTDIR="${LIVECDROOT}/chroot"  CDCHROOTDIR="${LIVECDROOT}/chroot"
# Line 19  CDID="mlcd-$(date +%F-%k%M)" Line 19  CDID="mlcd-$(date +%F-%k%M)"
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
# Line 43  bootstrap_system() Line 54  bootstrap_system()
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    
61    custom_services()
62    {
63     local cmd="$1"
64     local services="$2"
65     local systemdcmd
66    
67     case ${cmd} in
68     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}";;
99     esac
100    }
101    
102    add_initrc()
103    {
104     local var="$1"
105    
106     # sanity checks
107     [[ -z ${CDCHROOTDIR} ]] && die "\$CDCHROOTDIR not given."
108     echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var"
109    }
110    
111    custom_packages()
112    {
113     local cmd="$1"
114     local packages="$2"
115    
116     case ${cmd} in
117     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}";;
150     esac
151    }
152    
153    read_config()
154    {
155     local file="$1"
156     local pkg
157    
158     ( cat ${file}; echo ) | while read pkg
159     do
160     case "${pkg}" in
161     \#*|"") continue ;;
162     esac
163     echo "${pkg}"
164     done
165    }
166    
167  prepare_iso()  prepare_iso()
168  {  {
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}  groupadd -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}  groupadd -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}  groupadd -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}  useradd -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   # change mountfs with mountfslivecd   # install systemd default services
232   MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs"   if [[ -x ${CDCHROOTDIR}/bin/systemctl ]]
233   MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd"   then
234     # 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   # add hardware detection   if [[ -x ${CDCHROOTDIR}/bin/systemctl ]] || [[ -x ${CDCHROOTDIR}/usr/bin/systemctl ]]
253   MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect"   then
254     install -m 0644 $(get_profile getty) ${CDCHROOTDIR}/etc/conf.d/getty || die
255    
256     custom_services add getty@.service
257     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
276     [[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}"
277     [ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))"
278    
279     # del custom packages
280     [[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}"
281     [ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))"
282    
283     # add given services from profile
284     [[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}"
285     [ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))"
286    
287     # del given services from profile
288     [[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}"
289     [ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))"
290    
291     # setup default runlevel
292     [[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}"
293    
294     if [ -f $(get_profile prepare_custom) ]
295     then
296     echo Running custom user script ...
297     source $(get_profile prepare_custom) || die "running custom user script"
298     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
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    
357     # now umount everything and create the squashfs image
358     umount ${LIVECDROOT}/loop/mnt || die
359     losetup -d ${loopdev} || die
360     # remove mount to not ending up in the squashfs image
361     if [[ -d ${LIVECDROOT}/loop/mnt ]]
362     then
363     rm -r ${LIVECDROOT}/loop/mnt || die
364     fi
365     mksquashfs ${LIVECDROOT}/loop ${LIVECDROOT}/livecdrootfs.sqsh || die
366    
367     # final cleanup
368     if [[ -d ${LIVECDROOT}/loop ]]
369     then
370     rm -r ${LIVECDROOT}/loop || die
371     fi
372     else
373     mksquashfs ${CDCHROOTDIR} ${LIVECDROOT}/livecdrootfs.sqsh || die
374     fi
375    
376   echo Moving rootfs loopfile to isoroot ...   echo Moving rootfs loopfile to isoroot ...
377   install -d ${CDISOROOT}   install -d ${CDISOROOT}
378   mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}   if [[ -x ${CDCHROOTDIR}/sbin/dracut ]] ||
379     [[ -x ${CDCHROOTDIR}/usr/sbin/dracut ]] ||
380     [[ -x ${CDCHROOTDIR}/usr/bin/dracut ]]
381     then
382     install -d ${CDISOROOT}/LiveOS
383     mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}/LiveOS/squashfs.img
384     else
385     mv ${LIVECDROOT}/livecdrootfs.sqsh ${CDISOROOT}
386     fi
387  }  }
388    
389  install_bootloader()  install_bootloader()
# Line 96  install_bootloader() Line 392  install_bootloader()
392    
393   # iso linux binary   # iso linux binary
394   install -d ${CDISOROOT}/isolinux   install -d ${CDISOROOT}/isolinux
395   install /usr/lib/mkinitrd/isolinux.bin ${CDISOROOT}/isolinux || die   install ${ISOLINUX_BIN} ${CDISOROOT}/isolinux || die
396    
397   # kernel   # kernel
398   local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))"   local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))"
# Line 106  install_bootloader() Line 402  install_bootloader()
402   install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die   install -m 0644 $(get_profile boot.lss) ${CDISOROOT}/isolinux || die
403   install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die   install -m 0644 $(get_profile boot.msg) ${CDISOROOT}/isolinux || die
404   install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die   install -m 0644 $(get_profile help.msg) ${CDISOROOT}/isolinux || die
405     # support the new layout too
406     if [[ -f $(get_profile index.msg) ]]
407     then
408     install -m 0644 $(get_profile index.msg) ${CDISOROOT}/isolinux || die
409     fi
410     if [[ -f $(get_profile debug.msg) ]]
411     then
412     install -m 0644 $(get_profile debug.msg) ${CDISOROOT}/isolinux || die
413     fi
414    
415   return 0   return 0
416  }  }
# Line 113  install_bootloader() Line 418  install_bootloader()
418  generate_initrd()  generate_initrd()
419  {  {
420   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"   local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})"
421   echo "DEBUG: ${CHROOTSH}"  
422     is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys
423     is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc
424     is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev
425    
426   echo Generating initrd image ...   echo Generating initrd image ...
427   echo '#!/bin/bash' > ${CHROOTSH} || die   echo '#!/bin/bash' > ${CHROOTSH} || die
428     echo 'export LC_ALL=C' >> ${CHROOTSH} || die
429   echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die   echo 'kv="$(readlink /boot/vmlinuz)"' >> ${CHROOTSH} || die
430   echo 'kv="${kv/kernel-}/"' >> ${CHROOTSH} || die   echo 'kv="${kv/kernel-}/"' >> ${CHROOTSH} || die
431   echo 'mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die   # prefer dracut
432     echo 'if [[ -x /sbin/dracut ]] || [[ -x /usr/sbin/dracut ]] || [[ -x /usr/bin/dracut ]]' >> ${CHROOTSH} || die
433     echo 'then' >> ${CHROOTSH} || die
434     echo ' dracut -v -f /initrd.gz ${kv}' >> ${CHROOTSH} || die
435     echo 'else' >> ${CHROOTSH} || die
436     echo ' mkinitrd-livecd -f --initramfs /initrd.gz ${kv}' >> ${CHROOTSH} || die
437     echo 'fi' >> ${CHROOTSH} || die
438   chmod +x ${CHROOTSH} || die   chmod +x ${CHROOTSH} || die
439   chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die   chroot ${CDCHROOTDIR} /$(basename ${CHROOTSH}) || die
440   [[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die   [[ -f ${CHROOTSH} ]] && rm ${CHROOTSH} || die
441    
442     is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev
443     is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc
444     is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys
445    
446   # move initrd to isoroot   # move initrd to isoroot
447   install -d ${CDISOROOT}/isolinux || die   install -d ${CDISOROOT}/isolinux || die
448   mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die   mv ${CDCHROOTDIR}/initrd.gz ${CDISOROOT}/isolinux || die
# Line 151  generate_iso() Line 470  generate_iso()
470    
471  enter_livecd()  enter_livecd()
472  {  {
473   mount -t sysfs sysfs ${CDCHROOTDIR}/proc   is_loc_mounted "${CDCHROOTDIR}/sys" || mount -t sysfs sysfs ${CDCHROOTDIR}/sys
474   mount -t proc proc ${CDCHROOTDIR}/proc   is_loc_mounted "${CDCHROOTDIR}/proc" || mount -t proc proc ${CDCHROOTDIR}/proc
475   mount -o bind /dev ${CDCHROOTDIR}/dev   is_loc_mounted "${CDCHROOTDIR}/dev" || mount -o bind /dev ${CDCHROOTDIR}/dev
476    
477   chroot ${CDCHROOTDIR} \   chroot ${CDCHROOTDIR} \
478   /usr/bin/env -i \   /usr/bin/env -i \
479   HOME=/root \   HOME=/root \
480   TERM=$TERM PS1='\u:\w\$ ' \   TERM=$TERM PS1='\u:\w\$ ' \
481   PATH=/bin:/usr/bin:/sbin:/usr/sbin \   PATH=/bin:/usr/bin:/sbin:/usr/sbin \
482     http_proxy=${http_proxy} \
483     ftp_proxy=${ftp_proxy} \
484     no_proxy=${no_proxy} \
485   /bin/bash -i   /bin/bash -i
486    
487     is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev
488     is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc
489     is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys
490    }
491    
492    is_loc_mounted()
493    {
494     local filesys
495     local i
496     filesys=$1
497    
498     i="$(cat /proc/mounts | grep " ${filesys} " | cut -d ' ' -f2)"
499     [[ ${i} != ${filesys} ]] && return 1
500    
501     return 0
502    }
503    
504    trap_exit()
505    {
506     is_loc_mounted "${CDCHROOTDIR}/dev" && umount ${CDCHROOTDIR}/dev
507     is_loc_mounted "${CDCHROOTDIR}/proc" && umount ${CDCHROOTDIR}/proc
508     is_loc_mounted "${CDCHROOTDIR}/sys" && umount ${CDCHROOTDIR}/sys
509  }  }
510    
511    usage()
512    {
513     echo "Usage: $(basename $0) [command] [profile] ..."
514     echo
515     echo "Commands:"
516     echo "    bootstrap  - bootstraps the rootfs for the livecd"
517     echo "    prepare    - prepare the rootfs to run from a livecd"
518     echo "    rootfs     - generates the squashfs rootfs image"
519     echo "    initrd     - generates a livecd suitable initrd"
520     echo "    bootloader - installs the bootloader"
521     echo "    isogen     - generate the final livecd iso image"
522     echo "    all        - runs all tasks to get a livecd from zero"
523     echo "    enter      - enters the rootfs of a livecd"
524     echo
525     echo "    for example '$(basename $0) all default'"
526     echo "    creates a livecd using the default profile."
527     echo
528    }
529    
530    # set some proper traps
531    trap "trap_exit" SIGINT SIGQUIT
532    
533  # source profile config - overrides all other vars  # source profile config - overrides all other vars
534  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config  [ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config
535    
536  bootstrap_system  case $1 in
537  prepare_iso   bootstrap) bootstrap_system;;
538  generate_rootfs   prepare) prepare_iso;;
539  generate_initrd   rootfs) generate_rootfs;;
540  install_bootloader   initrd) generate_initrd;;
541  generate_iso   bootloader) install_bootloader;;
542     isogen) generate_iso;;
543     all)
544     bootstrap_system
545     prepare_iso
546     generate_rootfs
547     generate_initrd
548     install_bootloader
549     generate_iso
550     ;;
551     enter) enter_livecd ;;
552     *|'') usage;;
553    esac

Legend:
Removed from v.348  
changed lines
  Added in v.2098