#!/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 $_HOSTNAME $_HOSTDOMAIN prepare_custom_baseconfig() { local _OSROOT="$1" local _HOSTNAME="$2" local _HOSTDOMAIN="$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 ${_HOSTNAME} ]] then echo "no _HOSTNAME given" return 1 fi if [[ -z ${_HOSTDOMAIN} ]] then echo "no _HOSTDOMAIN 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 "${_HOSTNAME}" > ${_OSROOT}/etc/hostname echo "127.0.0.1 localhost ${_HOSTNAME}.${_HOSTDOMAIN} ${_HOSTNAME}" > ${_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 ${_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() { local INSTALL_BASESYSTEM local INSTALL_FLAVOR local INSTALL_ISOROOT local INSTALL_CHROOT INSTALL_BASESYSTEM="$1" INSTALL_FLAVOR="${1//basesystem/install}" INSTALL_ISOROOT="${CDISOROOT}/${INSTALL_FLAVOR//install/system}" INSTALL_CHROOT="${LIVECDROOT}/${INSTALL_FLAVOR}-chroot" if [[ -z ${INSTALL_BASESYSTEM} ]] then INSTALL_BASESYSTEM="basesystem" INSTALL_ISOROOT="${CDISOROOT}/system" INSTALL_CHROOT="${LIVECDROOT}/install-chroot" fi install -d ${INSTALL_CHROOT} install -d ${INSTALL_ISOROOT} # use all settings from the global config, but the basesystem # has to be the normal install basesystem not for livecds mage-bootstrap \ --root ${INSTALL_CHROOT} \ --profile ${MAGE_PROFILE} \ --magerc ${MAGERC} \ --toolchain ${TOOLCHAIN} \ --update-tarball \ --basesystem ${INSTALL_BASESYSTEM} || die "bootstrapping target system failed!" ## DEV SERVER ## # NEW_MCORE_CONTROL_SERVER="alx-control-dev.dom-aka-nt.intern" # CONFIG="${INSTALL_CHROOT}/etc/mcore/mcore.conf" # updateconfig MCORE_CONTROL_SERVER ### # fix missing symlink if [ ! -L ${INSTALL_CHROOT}/usr/bin/X ] then ln -snf Xorg ${INSTALL_CHROOT}/usr/bin/X fi # remove .bash_history [ -f ${INSTALL_CHROOT}/root/.bash_history ] && rm ${INSTALL_CHROOT}/root/.bash_history # os config prepare_custom_baseconfig "${INSTALL_CHROOT}" "alx-${CDOSARCH}" "magellan-linux.de" # create tarball prepare_custom_installertarball "${INSTALL_CHROOT}" "alx-${CDOSARCH}" "${INSTALL_ISOROOT}" } ## # create the network image ## create_netboot_image() { local NETBOOT_BASESYSTEM local NETBOOT_FLAVOR local NETBOOT_ISOROOT local NETBOOT_CHROOT local NETBOOT_SQUASHFS NETBOOT_BASESYSTEM="$1" NETBOOT_FLAVOR="${1//system}" NETBOOT_ISOROOT="${CDISOROOT}/${NETBOOT_FLAVOR}" NETBOOT_CHROOT="${LIVECDROOT}/${NETBOOT_FLAVOR}-chroot" NETBOOT_SQUASHFS="${LIVECDROOT}/${NETBOOT_FLAVOR}-squashfs" if [[ -z ${NETBOOT_BASESYSTEM} ]] then NETBOOT_BASESYSTEM="netbootsystem" NETBOOT_ISOROOT="${CDISOROOT}/netboot" NETBOOT_CHROOT="${LIVECDROOT}/netboot-chroot" NETBOOT_SQUASHFS="${LIVECDROOT}/netboot-squashfs" fi install -d ${NETBOOT_ISOROOT} install -d ${NETBOOT_CHROOT} install -d ${NETBOOT_SQUASHFS} # use all settings from the global config, but use netbootsysten as basesystem mage-bootstrap \ --root ${NETBOOT_CHROOT} \ --profile ${MAGE_PROFILE} \ --magerc ${MAGERC} \ --toolchain ${TOOLCHAIN} \ --update-tarball \ --basesystem ${NETBOOT_BASESYSTEM} || die "bootstrapping target system failed!" # os config prepare_custom_baseconfig "${NETBOOT_CHROOT}" "alx-${CDOSARCH}" "magellan-linux.de" # creating netboot image from here on install -d ${NETBOOT_SQUASHFS}/{LiveOS,mnt} || die # fix fstab, use the livecd fstab without rootfs and swap install -m 0644 $(get_profile fstab) ${NETBOOT_CHROOT}/etc/fstab || die # remove .bash_history [ -f ${NETBOOT_CHROOT}/root/.bash_history ] && rm ${NETBOOT_CHROOT}/root/.bash_history # get the actual size of the chroot size=$(du -s ${NETBOOT_CHROOT} | sed 's:^\(.*\)[[:space:]].*:\1:') # generate a ext3fs file for devicemapper dd if=/dev/zero of=${NETBOOT_SQUASHFS}/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 20000 )) || die # create a filesystem mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${NETBOOT_SQUASHFS}/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 ${NETBOOT_SQUASHFS}/LiveOS/ext3fs.img || die # strip the journal # tune2fs -O^has_journal ${NETBOOT_SQUASHFS}/LiveOS/ext3fs.img || die # fsck after journal removal # fsck ${NETBOOT_SQUASHFS}/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} ${NETBOOT_SQUASHFS}/LiveOS/ext3fs.img || die mount ${loopdev} ${NETBOOT_SQUASHFS}/mnt || die # copy everything to the image file and preserve permissions ( cd ${NETBOOT_CHROOT} && tar cpf - . ) | ( cd ${NETBOOT_SQUASHFS}/mnt && tar xvpf - ) sleep 3 # now umount everything and create the squashfs image umount ${NETBOOT_SQUASHFS}/mnt || die losetup -d ${loopdev} || die # remove mount to not ending up in the squashfs image if [[ -d ${NETBOOT_SQUASHFS}/mnt ]] then rm -r ${NETBOOT_SQUASHFS}/mnt || die fi mksquashfs ${NETBOOT_SQUASHFS} ${NETBOOT_ISOROOT}/squashfs.img || die # copy kernel, bootloader and create initramfs to isoroot/netboot install -d ${NETBOOT_ISOROOT} || die # kernel kimg="$(find ${NETBOOT_CHROOT}/boot -name kernel-\* -printf '%f\n')" install ${NETBOOT_CHROOT}/boot/${kimg} ${NETBOOT_ISOROOT}/${CDKERNELNAME} || die # initrd install -d ${NETBOOT_CHROOT}/etc/dracut.conf.d || die echo 'add_dracutmodules+=" livenet busybox "' > ${NETBOOT_CHROOT}/etc/dracut.conf.d/03-netboot.conf || die echo 'omit_dracutmodules+=" mcored "' >> ${NETBOOT_CHROOT}/etc/dracut.conf.d/03-netboot.conf || die echo 'hostonly="no"' >> ${NETBOOT_CHROOT}/etc/dracut.conf.d/03-netboot.conf || die # install dracut-dev package to have all modules CUSTOM_PACKAGES_CHROOT="${NETBOOT_CHROOT}" custom_packages install "dracut-dev curl curl-dev" || die ## mlivecdbuild function INITRD_CHROOT="${NETBOOT_CHROOT}" generate_initrd mv ${CDISOROOT}/isolinux/initrd.gz ${NETBOOT_ISOROOT}/ || die # fix initrd permissions chmod 0644 ${NETBOOT_ISOROOT}/initrd.gz || die if [ -e ${NETBOOT_CHROOT}/etc/dracut.conf.d/03-netboot.conf ] then rm ${NETBOOT_CHROOT}/etc/dracut.conf.d/03-netboot.conf fi # bootloader pxelinux install -d ${NETBOOT_ISOROOT}/pxelinux/pxelinux.cfg # bios [ -f $(get_profile netboot/pxelinux.0) ] && install -m0644 $(get_profile netboot/pxelinux.0) ${NETBOOT_ISOROOT}/pxelinux/ [ -f $(get_profile netboot/ldlinux.c32) ] && install -m0644 $(get_profile netboot/ldlinux.c32) ${NETBOOT_ISOROOT}/pxelinux/ # efi-x32 [ -f $(get_profile netboot/bootx32.efi) ] && install -m0644 $(get_profile netboot/bootx32.efi) ${NETBOOT_ISOROOT}/pxelinux/ [ -f $(get_profile netboot/ldlinux.e32) ] && install -m0644 $(get_profile netboot/ldlinux.e32) ${NETBOOT_ISOROOT}/pxelinux/ # efi-x64 [ -f $(get_profile netboot/bootx64.efi) ] && install -m0644 $(get_profile netboot/bootx64.efi) ${NETBOOT_ISOROOT}/pxelinux/ [ -f $(get_profile netboot/ldlinux.e64) ] && install -m0644 $(get_profile netboot/ldlinux.e64) ${NETBOOT_ISOROOT}/pxelinux/ # common pxelinux config [ -f $(get_profile netboot/pxelinux.cfg/pxelinux-default) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/pxelinux-default) ${NETBOOT_ISOROOT}/pxelinux/pxelinux.cfg [ -f $(get_profile netboot/pxelinux.cfg/boot.cat) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/boot.cat) ${NETBOOT_ISOROOT}/pxelinux/ [ -f $(get_profile boot.lss) ] && install -m0644 $(get_profile boot.lss) ${NETBOOT_ISOROOT}/pxelinux/ [ -f $(get_profile boot.msg) ] && install -m0644 $(get_profile boot.msg) ${NETBOOT_ISOROOT}/pxelinux/ [ -f $(get_profile debug.msg) ] && install -m0644 $(get_profile debug.msg) ${NETBOOT_ISOROOT}/pxelinux/ [ -f $(get_profile help.msg) ] && install -m0644 $(get_profile help.msg) ${NETBOOT_ISOROOT}/pxelinux/ [ -f $(get_profile index.msg) ] && install -m0644 $(get_profile index.msg) ${NETBOOT_ISOROOT}/pxelinux/ # bootloader lpxelinux install -d ${NETBOOT_ISOROOT}/lpxelinux/pxelinux.cfg # bios [ -f $(get_profile netboot/lpxelinux.0) ] && install -m0644 $(get_profile netboot/lpxelinux.0) ${NETBOOT_ISOROOT}/lpxelinux/ [ -f $(get_profile netboot/ldlinux.c32) ] && install -m0644 $(get_profile netboot/ldlinux.c32) ${NETBOOT_ISOROOT}/lpxelinux/ # efi-x32 [ -f $(get_profile netboot/bootx32.efi) ] && install -m0644 $(get_profile netboot/bootx32.efi) ${NETBOOT_ISOROOT}/lpxelinux/ [ -f $(get_profile netboot/ldlinux.e32) ] && install -m0644 $(get_profile netboot/ldlinux.e32) ${NETBOOT_ISOROOT}/lpxelinux/ # efi-x64 [ -f $(get_profile netboot/bootx64.efi) ] && install -m0644 $(get_profile netboot/bootx64.efi) ${NETBOOT_ISOROOT}/lpxelinux/ [ -f $(get_profile netboot/ldlinux.e64) ] && install -m0644 $(get_profile netboot/ldlinux.e64) ${NETBOOT_ISOROOT}/lpxelinux/ # common lpxelinux config [ -f $(get_profile netboot/pxelinux.cfg/lpxelinux-default) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/lpxelinux-default) ${NETBOOT_ISOROOT}/lpxelinux/pxelinux.cfg [ -f $(get_profile netboot/pxelinux.cfg/boot.cat) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/boot.cat) ${NETBOOT_ISOROOT}/lpxelinux/ [ -f $(get_profile boot.lss) ] && install -m0644 $(get_profile boot.lss) ${NETBOOT_ISOROOT}/lpxelinux/ [ -f $(get_profile boot.msg) ] && install -m0644 $(get_profile boot.msg) ${NETBOOT_ISOROOT}/lpxelinux/ [ -f $(get_profile debug.msg) ] && install -m0644 $(get_profile debug.msg) ${NETBOOT_ISOROOT}/lpxelinux/ [ -f $(get_profile help.msg) ] && install -m0644 $(get_profile help.msg) ${NETBOOT_ISOROOT}/lpxelinux/ [ -f $(get_profile index.msg) ] && install -m0644 $(get_profile index.msg) ${NETBOOT_ISOROOT}/lpxelinux/ # final cleanup if [[ -z ${SKIP_REMOVE_INSTALLROOT} ]] then if [[ -d ${NETBOOT_SQUASHFS} ]] then rm -r ${NETBOOT_SQUASHFS} || die fi if [[ -d ${NETBOOT_CHROOT} ]] then rm -r ${NETBOOT_CHROOT} fi fi } ## # create the server tarball ## create_server_tarball() { local SERVER_BASESYSTEM local SERVER_FLAVOR local SERVER_ISOROOT local SERVER_CHROOT SERVER_BASESYSTEM="$1" SERVER_FLAVOR="${1//system}" SERVER_ISOROOT="${CDISOROOT}/${SERVER_FLAVOR}" SERVER_CHROOT="${LIVECDROOT}/${SERVER_FLAVOR}-chroot" if [[ -z ${SERVER_BASESYSTEM} ]] then SERVER_BASESYSTEM="serversystem" SERVER_ISOROOT="${CDISOROOT}/server" SERVER_CHROOT="${LIVECDROOT}/server-chroot" fi install -d ${SERVER_CHROOT} install -d ${SERVER_ISOROOT} mage-bootstrap \ --root ${SERVER_CHROOT} \ --profile ${MAGE_PROFILE} \ --magerc ${MAGERC} \ --toolchain ${TOOLCHAIN} \ --update-tarball \ --basesystem serversystem || die "bootstrapping target system failed!" # enable getty1 install -d ${SERVER_CHROOT}/etc/systemd/system/getty.target.wants ln -snf /usr/lib/systemd/system/getty@.service ${SERVER_CHROOT}/etc/systemd/system/getty.target.wants/getty@tty1.service # be more verbose sed -i 's:^\(export GRUB_CMDLINE_LINUX_DEFAULT=\).*:\1"rd.info":' ${SERVER_CHROOT}/etc/conf.d/grub # remove phpmyadmin configuration directory if [ -d ${SERVER_CHROOT}/usr/share/phpmyadmin/config ] then rm -r ${SERVER_CHROOT}/usr/share/phpmyadmin/config fi # os config prepare_custom_baseconfig "${SERVER_CHROOT}" "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" >> ${SERVER_CHROOT}/etc/hosts # remove .bash_history [ -f ${SERVER_CHROOT}/root/.bash_history ] && rm ${SERVER_CHROOT}/root/.bash_history # create tarball prepare_custom_installertarball "${SERVER_CHROOT}" "alx-svr-${CDOSARCH}" "${SERVER_ISOROOT}" } # 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 basesystem [[ -n ${SKIP_CREATE_INSTALL_TARBALL} ]] || create_install_tarball basesystem-legacy # stop here if the user don't want to create the netboot image [[ -n ${SKIP_CREATE_NETBOOT_TARBALL} ]] || create_netboot_image netbootsystem [[ -n ${SKIP_CREATE_NETBOOT_TARBALL} ]] || create_netboot_image netbootsystem-legacy # stop here if the user don't want to create the server tarball [[ -n ${SKIP_CREATE_SERVER_TARBALL} ]] || create_server_tarball serversystem # 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