#!/bin/bash updateconfig() { local variables="$@" local value local i if [[ -z ${CONFIG} ]] then echo "You must define \$CONFIG varibale first!" return 1 fi for i in ${variables} do value="$(eval echo \${NEW_${i}})" if [[ ! -z $(grep "^${i}=" ${CONFIG}) ]] then echo "fixing ${i} -> ${value}" sed -i "s|^\(${i}=\).*|\1\"${value}\"|" ${CONFIG} else echo "adding ${i}=${value}" echo "${i}=\"${value}\"" >> ${CONFIG} fi done } ## # create the install tarball ## create_install_tarball() { install -d ${LIVECDROOT}/install-temp install -d ${CDISOROOT}/system # use all settings from the global config, but the basesystem # has to be the normal install basesystem not for livecds mage-bootstrap \ --root ${LIVECDROOT}/install-temp \ --profile ${MAGE_PROFILE} \ --magerc ${MAGERC} \ --toolchain ${TOOLCHAIN} \ --update-tarball \ --basesystem basesystem || die "bootstrapping target system failed!" ## DEV SERVER ## # NEW_MCORE_CONTROL_SERVER="alx-control-dev.dom-aka-nt.intern" # CONFIG="${LIVECDROOT}/install-temp/etc/mcore/mcore.conf" # updateconfig MCORE_CONTROL_SERVER ### # fix missing symlink if [ ! -L ${LIVECDROOT}/install-temp/usr/bin/X ] then ln -snf Xorg ${LIVECDROOT}/install-temp/usr/bin/X fi # generate a new machine-id on first-boot :> ${LIVECDROOT}/install-temp/etc/machine-id # fix localtime symlink ln -snf ../usr/share/zoneinfo/Europe/Berlin ${LIVECDROOT}/install-temp/etc/localtime # activate timeserver via dhcp (NTP - option 42) CDCHROOTDIR=${LIVECDROOT}/install-temp custom_services add systemd-timesyncd.service # empty root password chroot ${LIVECDROOT}/install-temp passwd -d root # empty user password chroot ${LIVECDROOT}/install-temp passwd -d station if [ -x ${LIVECDROOT}/install-temp/usr/bin/mcorepasswd ] || [ -L ${LIVECDROOT}/install-temp/usr/bin/mcorepasswd ] then # add mcored default user ( echo "foobar"; sleep 0.1; echo "foobar" ) | chroot ${LIVECDROOT}/install-temp /usr/bin/mcorepasswd mcore fi # fix hostname and hosts file echo "alx-i686" > ${LIVECDROOT}/install-temp/etc/hostname echo "127.0.0.1 localhost alx-i686.magellan-linux.de alx-i686" > ${LIVECDROOT}/install-temp/etc/hosts cat >> ${LIVECDROOT}/install-temp/etc/hosts << EOF ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts EOF # create tarball [[ -f ${CDISOROOT}/system/alx-i686.tar.bz2 ]] && rm ${CDISOROOT}/system/alx-i686.tar.bz2 ( cd ${LIVECDROOT}/install-temp; tar cvjpf ${CDISOROOT}/system/alx-i686.tar.bz2 ./ | tee ${LIVECDROOT}/install.log ) # create images.conf echo "CDIMAGENAME=alx-i686.tar.bz2" > ${CDISOROOT}/system/images.conf echo "TOTALLINES=$(wc -l ${LIVECDROOT}/install.log | cut -d' ' -f1)" >> ${CDISOROOT}/system/images.conf create_netboot_image # clean up if [[ -d ${LIVECDROOT}/install-temp ]] then rm -rf ${LIVECDROOT}/install-temp fi if [[ -f ${LIVECDROOT}/install.log ]] then rm ${LIVECDROOT}/install.log fi } ## # create the network image ## create_netboot_image() { install -d ${CDISOROOT}/netboot install -d ${LIVECDROOT}/network-temp install -d ${LIVECDROOT}/network-temp/{LiveOS,mnt} || die # fix fstab, use the livecd fstab without rootfs and swap install -m 0644 $(get_profile fstab) ${LIVECDROOT}/install-temp/etc/fstab || die # get the actual size of the chroot size=$(du -s ${LIVECDROOT}/install-temp | sed 's:^\(.*\)[[:space:]].*:\1:') # generate a ext3fs file for devicemapper dd if=/dev/zero of=${LIVECDROOT}/network-temp/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 20000 )) || die # create a filesystem mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die # set mount_counts and check_intervals to 0 # set dir_index top, to speed up things with hashed b-trees # allow acls too tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die # strip the journal # tune2fs -O^has_journal ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die # fsck after journal removal # fsck ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die # losetup the device loopdev=$(losetup -f) [[ -z ${loopdev} ]] && die "No unused loopdev found. Maybe you want 'modprobe loop'?" # mount the image losetup ${loopdev} ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die mount ${loopdev} ${LIVECDROOT}/network-temp/mnt || die # copy everything to the image file and preserve permissions ( cd ${LIVECDROOT}/install-temp && tar cpf - . ) | ( cd ${LIVECDROOT}/network-temp/mnt && tar xvpf - ) sleep 3 # now umount everything and create the squashfs image umount ${LIVECDROOT}/network-temp/mnt || die losetup -d ${loopdev} || die # remove mount to not ending up in the squashfs image if [[ -d ${LIVECDROOT}/network-temp/mnt ]] then rm -r ${LIVECDROOT}/network-temp/mnt || die fi mksquashfs ${LIVECDROOT}/network-temp ${CDISOROOT}/netboot/squashfs.img || die # copy kernel, bootloader and create initramfs to isoroot/netboot install -d ${CDISOROOT}/netboot || die # kernel kimg="$(find ${CDCHROOTDIR}/boot -name kernel-\* -printf '%f\n')" install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/netboot/${CDKERNELNAME} || die # initrd install -d ${CDCHROOTDIR}/etc/dracut.conf.d || die echo 'add_dracutmodules+=" livenet busybox "' > ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die #echo 'omit_dracutmodules+=" systemd plymouth mcored "' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die # use plymouth to get all kms modules, but boot with nosplash as default to fix some Xorg issues #echo 'omit_dracutmodules+=" systemd mcored "' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die echo 'omit_dracutmodules+=" mcored "' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die echo 'hostonly="no"' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die # install dracut-dev package to have all modules custom_packages install "dracut-dev curl curl-dev" || die ## mlivecdbuild function generate_initrd mv ${CDISOROOT}/isolinux/initrd.gz ${CDISOROOT}/netboot/ || die # fix initrd permissions chmod 0644 ${CDISOROOT}/netboot/initrd.gz || die # custom_packages uninstall "dracut-dev curl curl-dev" || die if [ -e ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf ] then rm ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf fi # bootloader pxelinux install -d ${CDISOROOT}/netboot/pxelinux/pxelinux.cfg [ -f $(get_profile netboot/pxelinux.0) ] && install -m0644 $(get_profile netboot/pxelinux.0) ${CDISOROOT}/netboot/pxelinux/ [ -f $(get_profile netboot/pxelinux.cfg/pxelinux-default) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/pxelinux-default) ${CDISOROOT}/netboot/pxelinux/pxelinux.cfg [ -f $(get_profile netboot/pxelinux.cfg/boot.cat) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/boot.cat) ${CDISOROOT}/netboot/pxelinux/ [ -f $(get_profile boot.lss) ] && install -m0644 $(get_profile boot.lss) ${CDISOROOT}/netboot/pxelinux/ [ -f $(get_profile boot.msg) ] && install -m0644 $(get_profile boot.msg) ${CDISOROOT}/netboot/pxelinux/ [ -f $(get_profile debug.msg) ] && install -m0644 $(get_profile debug.msg) ${CDISOROOT}/netboot/pxelinux/ [ -f $(get_profile help.msg) ] && install -m0644 $(get_profile help.msg) ${CDISOROOT}/netboot/pxelinux/ [ -f $(get_profile index.msg) ] && install -m0644 $(get_profile index.msg) ${CDISOROOT}/netboot/pxelinux/ # bootloader lpxelinux install -d ${CDISOROOT}/netboot/lpxelinux/pxelinux.cfg [ -f $(get_profile netboot/lpxelinux.0) ] && install -m0644 $(get_profile netboot/lpxelinux.0) ${CDISOROOT}/netboot/lpxelinux/ [ -f $(get_profile netboot/ldlinux.c32) ] && install -m0644 $(get_profile netboot/ldlinux.c32) ${CDISOROOT}/netboot/lpxelinux/ [ -f $(get_profile netboot/pxelinux.cfg/lpxelinux-default) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/lpxelinux-default) ${CDISOROOT}/netboot/lpxelinux/pxelinux.cfg [ -f $(get_profile netboot/pxelinux.cfg/boot.cat) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/boot.cat) ${CDISOROOT}/netboot/lpxelinux/ [ -f $(get_profile boot.lss) ] && install -m0644 $(get_profile boot.lss) ${CDISOROOT}/netboot/lpxelinux/ [ -f $(get_profile boot.msg) ] && install -m0644 $(get_profile boot.msg) ${CDISOROOT}/netboot/lpxelinux/ [ -f $(get_profile debug.msg) ] && install -m0644 $(get_profile debug.msg) ${CDISOROOT}/netboot/lpxelinux/ [ -f $(get_profile help.msg) ] && install -m0644 $(get_profile help.msg) ${CDISOROOT}/netboot/lpxelinux/ [ -f $(get_profile index.msg) ] && install -m0644 $(get_profile index.msg) ${CDISOROOT}/netboot/lpxelinux/ # final cleanup if [[ -d ${LIVECDROOT}/network-temp ]] then rm -r ${LIVECDROOT}/network-temp || die fi } ## # create the server tarball ## create_server_tarball() { install -d ${LIVECDROOT}/server-temp install -d ${CDISOROOT}/server mage-bootstrap \ --root ${LIVECDROOT}/server-temp \ --profile ${MAGE_PROFILE} \ --magerc ${MAGERC} \ --toolchain ${TOOLCHAIN} \ --update-tarball \ --basesystem serversystem || die "bootstrapping target system failed!" # generate a new machine-id on first-boot :> ${LIVECDROOT}/server-temp/etc/machine-id # enable getty1 install -d ${LIVECDROOT}/server-temp/etc/systemd/system/getty.target.wants ln -snf /usr/lib/systemd/system/getty@.service ${LIVECDROOT}/server-temp/etc/systemd/system/getty.target.wants/getty@tty1.service # be more verbose sed -i 's:^\(export GRUB_CMDLINE_LINUX_DEFAULT=\).*:\1"rd.info":' ${LIVECDROOT}/server-temp/etc/conf.d/grub # fix localtime symlink ln -snf ../usr/share/zoneinfo/Europe/Berlin ${LIVECDROOT}/server-temp/etc/localtime # activate timeserver via dhcp (NTP - option 42) CDCHROOTDIR=${LIVECDROOT}/server-temp custom_services add systemd-timesyncd.service # empty root password chroot ${LIVECDROOT}/server-temp passwd -d root # empty user password chroot ${LIVECDROOT}/server-temp passwd -d station if [ -x ${LIVECDROOT}/server-temp/usr/bin/mcorepasswd ] || [ -L ${LIVECDROOT}/server-temp/usr/bin/mcorepasswd ] then # add mcored default user ( echo "foobar"; sleep 0.1; echo "foobar" ) | chroot ${LIVECDROOT}/server-temp /usr/bin/mcorepasswd mcore fi # remove phpmyadmin configuration directory if [ -d ${LIVECDROOT}/server-temp/usr/share/phpmyadmin/config ] then rm -r ${LIVECDROOT}/server-temp/usr/share/phpmyadmin/config fi # fix hostname and hosts file echo "alx-svr-i686" > ${LIVECDROOT}/server-temp/etc/hostname echo "127.0.0.1 localhost alx-svr-i686.magellan-linux.de alx-svr-i686" > ${LIVECDROOT}/server-temp/etc/hosts # fix certificate issues with mcored (common name of cert issuer) and >php-5.4 echo "127.0.0.1 mcored" >> ${LIVECDROOT}/server-temp/etc/hosts cat >> ${LIVECDROOT}/server-temp/etc/hosts << EOF ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts EOF # create tarball [[ -f ${CDISOROOT}/server/alx-svr-i686.tar.bz2 ]] && rm ${CDISOROOT}/server/alx-svr-i686.tar.bz2 ( cd ${LIVECDROOT}/server-temp; tar cvjpf ${CDISOROOT}/server/alx-svr-i686.tar.bz2 ./ | tee ${LIVECDROOT}/server.log ) # create images.conf echo "CDIMAGENAME=alx-svr-i686.tar.bz2" > ${CDISOROOT}/server/images.conf echo "TOTALLINES=$(wc -l ${LIVECDROOT}/server.log | cut -d' ' -f1)" >> ${CDISOROOT}/server/images.conf # clean up if [[ -d ${LIVECDROOT}/server-temp ]] then rm -rf ${LIVECDROOT}/server-temp fi if [[ -f ${LIVECDROOT}/server.log ]] then rm ${LIVECDROOT}/server.log fi } # set an empty root password chroot ${CDCHROOTDIR} passwd -d root # install a custom boot-duration matching this livecd install -d ${CDCHROOTDIR}/var/lib/plymouth || die install -m 0644 $(get_profile boot-duration.livecd) ${CDCHROOTDIR}/var/lib/plymouth/boot-duration || die # setup de keymap and locales if [ -f ${CDCHROOTDIR}/etc/vconsole.conf ] then cat > ${CDCHROOTDIR}/etc/vconsole.conf << EOF || die KEYMAP=de KEYMAP_TOGGLE= FONT=lat9w-16 FONT_MAP=8859-1_to_uni FONT_UNIMAP= EOF fi if [ -f ${CDCHROOTDIR}/etc/locale.conf ] then sed -i "s:^\(LANG=\).*:\1\"de_DE.utf8\":" ${CDCHROOTDIR}/etc/locale.conf || die fi # stop here if the user don't want to create the install tarball [[ -n ${SKIP_CREATE_INSTALL_TARBALL} ]] || create_install_tarball # stop here if the user don't want to create the server tarball [[ -n ${SKIP_CREATE_SERVER_TARBALL} ]] || create_server_tarball # install usb-install script [ ! -d ${CDISOROOT}/usb-install ] && mkdir ${CDISOROOT}/usb-install [ -f $(get_profile usb-install/usb-install.cmd) ] && cp $(get_profile usb-install)/usb-install.cmd ${CDISOROOT}/usb-install [ -f $(get_profile usb-install/syslinux.exe) ] && cp $(get_profile usb-install)/syslinux.exe ${CDISOROOT}/usb-install [ -f $(get_profile usb-install/syslinux.cfg) ] && cp $(get_profile usb-install)/syslinux.cfg ${CDISOROOT}/usb-install # add installer-server script cat > ${CDCHROOTDIR}/usr/bin/installer-server << EOF #!/bin/bash /usr/bin/installer --imageroot /run/initramfs/live/server EOF chmod 0755 ${CDCHROOTDIR}/usr/bin/installer-server