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

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