#!/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 } # prepare_custom_baseconfig $_OSROOT $_OSHOSTNAME $_OSHOSTDOMAIN prepare_custom_baseconfig() { local _OSROOT="$1" local _OSHOSTNAME="$2" local _OSHOSTDOMAIN="$3" if [[ -z ${_OSROOT} ]] then echo "no _OSROOT given" return 1 fi if [[ ! -d ${_OSROOT} ]] then echo "Root dir '${_OSROOT}' does not exist" return 1 fi if [[ -z ${_OSHOSTNAME} ]] then echo "no _OSHOSTNAME given" return 1 fi if [[ -z ${_OSHOSTDOMAIN} ]] then echo "no _OSHOSTDOMAIN given" return 1 fi # generate a new machine-id on first-boot :> ${_OSROOT}/etc/machine-id # fix localtime symlink ln -snf ../usr/share/zoneinfo/Europe/Berlin ${_OSROOT}/etc/localtime # activate timeserver via dhcp (NTP - option 42) CDCHROOTDIR=${_OSROOT} custom_services add systemd-timesyncd.service # empty root password chroot ${_OSROOT} passwd -d root # empty user password chroot ${_OSROOT} passwd -d station if [ -x ${_OSROOT}/usr/bin/mcorepasswd ] || [ -L ${_OSROOT}/usr/bin/mcorepasswd ] then # add mcored default user ( echo "foobar"; sleep 0.1; echo "foobar" ) | chroot ${_OSROOT} /usr/bin/mcorepasswd mcore fi # fix hostname and hosts file echo "${_OSHOSTNAME}" > ${_OSROOT}/etc/hostname echo "127.0.0.1 localhost ${_OSHOSTNAME}.${_OSHOSTDOMAIN} ${_OSHOSTNAME}" > ${_OSROOT}/etc/hosts cat >> ${_OSROOT}/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 } # prepare_custom_installertarball $_OSROOT $_TARBALLNAME $_TARBALLTARGET prepare_custom_installertarball() { local _OSROOT="$1" local _TARBALLNAME="$2" local _TARBALLTARGET="$3" if [[ -z ${_OSROOT} ]] then echo "no _OSROOT given" return 1 fi if [[ ! -d ${_OSROOT} ]] then echo "Root dir '${_OSROOT}' does not exist" return 1 fi if [[ -z ${_TARBALLNAME} ]] then echo "no _TARBALLNAME given" return 1 fi if [[ -z ${_TARBALLTARGET} ]] then echo "no _TARBALLTARGET given" return 1 fi # create tarball [[ -f ${_TARBALLTARGET}/${_TARBALLNAME}.tar.bz2 ]] && rm ${_TARBALLTARGET}/${_TARBALLNAME}.tar.bz2 ( cd ${_OSROOT}; tar cvjpf ${CDISOROOT}/${_TARBALLTARGET}/${_TARBALLNAME}.tar.bz2 ./ | tee ${LIVECDROOT}/${_TARBALLNAME}.log ) # create images.conf echo "CDIMAGENAME=${_TARBALLNAME}.tar.bz2" > ${_TARBALLTARGET}/images.conf echo "TOTALLINES=$(wc -l ${LIVECDROOT}/${_TARBALLNAME}.log | cut -d' ' -f1)" >> ${_TARBALLTARGET}/images.conf # clean up if [[ -z ${SKIP_REMOVE_INSTALLROOT} ]] then if [[ -d ${_OSROOT} ]] then rm -r ${_OSROOT} fi if [[ -f ${LIVECDROOT}/${_TARBALLNAME}.log ]] then rm ${LIVECDROOT}/${_TARBALLNAME}.log fi fi } ## # 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 # os config prepare_custom_baseconfig "${LIVECDROOT}/install-temp" "alx-${CDOSARCH}" "magellan-linux.de" # create tarball prepare_custom_installertarball "${LIVECDROOT}/install-temp" "alx-${CDOSARCH}" "${CDISOROOT}/system" } ## # create the network image ## create_netboot_image() { install -d ${CDISOROOT}/netboot install -d ${LIVECDROOT}/netboot-temp install -d ${LIVECDROOT}/network-squashfs-temp # use all settings from the global config, but use netbootsysten as basesystem mage-bootstrap \ --root ${LIVECDROOT}/netboot-temp \ --profile ${MAGE_PROFILE} \ --magerc ${MAGERC} \ --toolchain ${TOOLCHAIN} \ --update-tarball \ --basesystem netbootsystem || die "bootstrapping target system failed!" # os config prepare_custom_baseconfig "${LIVECDROOT}/netboot-temp" "alx-${CDOSARCH}" "magellan-linux.de" # creating netboot image from here on install -d ${LIVECDROOT}/network-squashfs-temp/{LiveOS,mnt} || die # fix fstab, use the livecd fstab without rootfs and swap install -m 0644 $(get_profile fstab) ${LIVECDROOT}/netboot-temp/etc/fstab || die # get the actual size of the chroot size=$(du -s ${LIVECDROOT}/netboot-temp | sed 's:^\(.*\)[[:space:]].*:\1:') # generate a ext3fs file for devicemapper dd if=/dev/zero of=${LIVECDROOT}/network-squashfs-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-squashfs-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-squashfs-temp/LiveOS/ext3fs.img || die # strip the journal # tune2fs -O^has_journal ${LIVECDROOT}/network-squashfs-temp/LiveOS/ext3fs.img || die # fsck after journal removal # fsck ${LIVECDROOT}/network-squashfs-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-squashfs-temp/LiveOS/ext3fs.img || die mount ${loopdev} ${LIVECDROOT}/network-squashfs-temp/mnt || die # copy everything to the image file and preserve permissions ( cd ${LIVECDROOT}/netboot-temp && tar cpf - . ) | ( cd ${LIVECDROOT}/network-squashfs-temp/mnt && tar xvpf - ) sleep 3 # now umount everything and create the squashfs image umount ${LIVECDROOT}/network-squashfs-temp/mnt || die losetup -d ${loopdev} || die # remove mount to not ending up in the squashfs image if [[ -d ${LIVECDROOT}/network-squashfs-temp/mnt ]] then rm -r ${LIVECDROOT}/network-squashfs-temp/mnt || die fi mksquashfs ${LIVECDROOT}/network-squashfs-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+=" 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 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 [[ -z ${SKIP_REMOVE_INSTALLROOT} ]] then if [[ -d ${LIVECDROOT}/network-squasfs-temp ]] then rm -r ${LIVECDROOT}/network-squasfs-temp || die fi if [[ -d ${LIVECDROOT}/netboot-temp ]] then rm -r ${LIVECDROOT}/netboot-temp fi 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!" # 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 # remove phpmyadmin configuration directory if [ -d ${LIVECDROOT}/server-temp/usr/share/phpmyadmin/config ] then rm -r ${LIVECDROOT}/server-temp/usr/share/phpmyadmin/config fi # os config prepare_custom_baseconfig "${LIVECDROOT}/server-temp" "alx-svr-${CDOSARCH}" "magellan-linux.de" # 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 # create tarball prepare_custom_installertarball "${LIVECDROOT}/server-temp" "alx-svr-${CDOSARCH}" "${CDISOROOT}/server" } # 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 netboot image [[ -n ${SKIP_CREATE_NETBOOT_TARBALL} ]] || create_netboot_image # 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