commit 6fc423d658344216575f830c2a6680a8f6198ba4 Author: root Date: Mon May 21 14:41:52 2018 +0200 first commit diff --git a/mklive b/mklive new file mode 100755 index 0000000..6b37589 --- /dev/null +++ b/mklive @@ -0,0 +1,11 @@ +#!/bin/bash + +export WORKDIR="." +export MKLIVE=$(dirname $0) + +[ -n "$1" ] || exit 0 +SCRIPT=$1 +shift + +[ -x "${MKLIVE}/scripts/$SCRIPT.sh" ] && ${MKLIVE}/scripts/$SCRIPT.sh $@ + diff --git a/mklive.conf.example b/mklive.conf.example new file mode 100644 index 0000000..5b7eef2 --- /dev/null +++ b/mklive.conf.example @@ -0,0 +1,65 @@ + + +#Bootstrap settings +ARCH=amd64 +DIST_RELEASE=bionic +DIST_MIRROR="http://de.archive.ubuntu.com/ubuntu/" +DIST_VARIANT="minbase" + +KERNEL_PACKAGE="linux-image-generic" + +PACKAGES="iproute2 isc-dhcp-client" + +LIVE_ROOTPW="foobar23" +LIVE_HOSTNAME="live" +LIVE_NAME="Test Live System" + + +#Source pathes +SYSLINUX_MODULESDIR="/usr/lib/syslinux/modules/bios/" + + +#working directoies +OUTDIR="./out" +STAGEDIR="./stage" +CHROOT="./chroot" + + +#iso filename - gets extended by .iso +ISO_FILENAME="live" + +#Include Memtest +ISO_INCLUDE_MEMTEST="true" + +#Include Hardware detetion tool +ISO_INCLUDE_HDT="true" + +#Include an ubuntu installer into the ISO? +ISO_INCLUDE_UBUNTU_INSTALLER="true" + +#Include a debian installer into the ISO? +ISO_INCLUDE_DEBIAN_INSTALLER="true" + + + +#Include Memtest +PXE_INCLUDE_MEMTEST="true" + +#Include Hardware detetion tool +PXE_INCLUDE_HDT="true" + +#Include an ubuntu installer into the ISO? +PXE_INCLUDE_UBUNTU_INSTALLER="true" + +#Include a debian installer into the ISO? +PXE_INCLUDE_DEBIAN_INSTALLER="true" + +#URL to the PXE dir via tftp +PXE_FETCH_TFTP="tftp://192.168.122.223/" + +# +SERIAL_PORT=0 +# +SERIAL_SPEED=115200 + + diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100755 index 0000000..c0bc627 --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +source ${WORKDIR}/mklive.conf +source $(dirname $0)/functions.sh + +echo "Build live" + +CHROOT=${WORKDIR}/chroot + +startstage bootstrap +#bootstrap basic system +[ -d $CHROOT ] || debootstrap --components=main,restricted,universe,multiverse --variant=$DIST_VARIANT --arch=$ARCH $DIST_RELEASE $CHROOT $DIST_MIRROR + +#prepair chroot +mount -t proc proc $CHROOT/proc/ +mount -t sysfs sys $CHROOT/sys/ +mount -o bind /dev $CHROOT/dev/ + +#install locales +if [ ! -e $STAGEDIR/_locales ]; then +chroot $CHROOT apt -y install locales + echo "de_DE.UTF-8 UTF-8" >> $CHROOT/etc/locale.gen + echo "en_US.UTF-8 UTF-8" >> $CHROOT/etc/locale.gen + chroot $CHROOT locale-gen + echo "done" > $STAGEDIR/_locales +fi + +#install systemd +chroot $CHROOT apt -y install systemd + +#install live-boot +chroot $CHROOT apt-get -y install live-boot + +#install additional packages +if [ -n "${PACKAGES}" ]; then + chroot $CHROOT apt-get -y install ${PACKAGES} +fi + +#set the rootpw +chpasswd -R $(readlink -f $CHROOT) <<< "root:${LIVE_ROOTPW}" + +#change to a full busybox - for tftp support +sed -i -r 's/=.+(\/bin\/busybox)/=\1/' chroot/usr/share/initramfs-tools/hooks/zz-busybox-initramfs + +#install kernel +chroot $CHROOT apt -y -o "APT::Install-Recommends=false" install ${KERNEL_PACKAGE} + +#clean chroot +chroot $CHROOT apt-get clean +umount $CHROOT/proc/ +umount $CHROOT/sys/ +umount $CHROOT/dev/ + +#final changes +echo "${LIVE_HOSTNAME}" > $CHROOT/etc/hostname + +endstage bootstrap diff --git a/scripts/clean.sh b/scripts/clean.sh new file mode 100755 index 0000000..ea30d1c --- /dev/null +++ b/scripts/clean.sh @@ -0,0 +1,37 @@ +#!/bin/bash +source ${WORKDIR}/mklive.conf +source $(dirname $0)/functions.sh + +[ -z "$1" ] && err "Nothing to clean" + +case "$1" in + bootstrap) + echo "Cleaning bootstrap stage" + rm -r "${WORKDIR}/chroot" + rm ${WORKDIR}/stage/_bootstrap + ;; + installer) + echo "cleaning installer stage" + rm -r "${WORKDIR}/INSTALLER" + rm ${WORKDIR}/stage/_installer + ;; + pxe) + echo "cleaning pxe stage" + rm -r "${WORKDIR}/PXE" + rm ${WORKDIR}/stage/_pxe + ;; + live) + echo "cleaning live stage" + rm -r "${WORKDIR}/LIVE" + rm ${WORKDIR}/stage/_live + ;; + iso) + echo "Cleaning iso stage" + rm -r "${WORKDIR}/ISO" + rm ${WORKDIR}/stage/_iso + ;; + *) + echo "unkown $1 stage" + ;; +esac + diff --git a/scripts/defaults.conf b/scripts/defaults.conf new file mode 100644 index 0000000..926a898 --- /dev/null +++ b/scripts/defaults.conf @@ -0,0 +1,3 @@ +MEMTEST_BIN="/boot/memtest86+.bin" +UBUNTU_INSTALL_NETBOOT="http://de.archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/netboot.tar.gz" +DEBIAN_INSTALL_NETBOOT="http://ftp.nl.debian.org/debian/dists/stretch/main/installer-amd64/current/images/netboot/netboot.tar.gz" diff --git a/scripts/functions.sh b/scripts/functions.sh new file mode 100644 index 0000000..3dc6082 --- /dev/null +++ b/scripts/functions.sh @@ -0,0 +1,22 @@ +function requiredir { + [ -n "$1" ] || exit 1 + [ -e $1 ] || mkdir $1 +} + +function err { + echo $1 + exit 1 +} + +function checkstage { + [ -e ${WORKDIR}/stage/_$1 ] || return 1 + [ "$(cat $WORKDIR/stage/_$1)" != "done" ] && return 2 + return 0 +} + +function startstage { + echo -n "started" > ${WORKDIR}/stage/_$1 +} +function endstage { + echo -n "done" > ${WORKDIR}/stage/_$1 +} diff --git a/scripts/installer.sh b/scripts/installer.sh new file mode 100755 index 0000000..d28c1fc --- /dev/null +++ b/scripts/installer.sh @@ -0,0 +1,32 @@ +#!/bin/bash +source $(dirname $0)/defaults.conf +source ${WORKDIR}/mklive.conf +source $(dirname $0)/functions.sh + +echo "Preparing Installer" + +startstage installer + +requiredir ${WORKDIR}/INSTALLER + +installerdists="" + +if [ "$ISO_INCLUDE_UBUNTU_INSTALLER" == "true" ] || [ "$PXE_INCLUDE_UBUNTU_INSTALLER" == "true" ]; then + installerdists="${installerdists} ubuntu" +fi + +if [ "$ISO_INCLUDE_DEBIAN_INSTALLER" == "true" ] || [ "$PXE_INCLUDE_DEBIAN_INSTALLER" == "true" ]; then + installerdists="${installerdists} debian" +fi + + +for dist in $installerdists +do + URLVAR="${dist^^}_INSTALL_NETBOOT" + [ -z "${!URLVAR}" ] && continue; + [ -e ${WORKDIR}/INSTALLER/${dist}_netboot.tar.gz ] || wget ${!URLVAR} -O ${WORKDIR}/INSTALLER/${dist}_netboot.tar.gz + tar -C ${WORKDIR}/INSTALLER -xzf ${WORKDIR}/INSTALLER/${dist}_netboot.tar.gz ./$dist-installer/amd64/linux ./${dist}-installer/amd64/initrd.gz + tar -C ${WORKDIR}/INSTALLER --transform "s/txt/${dist}/" --strip 4 -xzf ${WORKDIR}/INSTALLER/${dist}_netboot.tar.gz ./${dist}-installer/amd64/boot-screens/txt.cfg +done + +endstage installer diff --git a/scripts/iso.sh b/scripts/iso.sh new file mode 100755 index 0000000..fbd6223 --- /dev/null +++ b/scripts/iso.sh @@ -0,0 +1,68 @@ +#!/bin/bash +source $(dirname $0)/defaults.conf +source ${WORKDIR}/mklive.conf +source $(dirname $0)/functions.sh +source $(dirname $0)/menufunction.sh + +echo "Starting ISO creation" + +ISOLINUX_MODULES="ldlinux.c32 libmenu.c32 menu.c32" +ISOLINUX_BIN="/usr/lib/ISOLINUX/isolinux.bin" + +checkstage live || err "Previous stage (live) was not finished" + +startstage iso + +ISODIR=${WORKDIR}/ISO +requiredir $ISODIR +requiredir $ISODIR/isolinux +[ -L $ISODIR/live ] || ln -s ../LIVE $ISODIR/live + +#copy isolinux.bin +cp ${ISOLINUX_BIN} $ISODIR/isolinux/ + +#create isolinux.conf +menuhead > $ISODIR/isolinux/isolinux.cfg +menulivehead >> $ISODIR/isolinux/isolinux.cfg +menulive >> $ISODIR/isolinux/isolinux.cfg + +if [ "$ISO_INCLUDE_UBUNTU_INSTALLER" == "true" ] || [ "$ISO_INCLUDE_DEBIAN_INSTALLER" == "true" ]; then + menuinstallerhead >> $ISODIR/isolinux/isolinux.cfg +fi + +if [ "$ISO_INCLUDE_UBUNTU_INSTALLER" == "true" ]; then + menuinstaller ubuntu >> $ISODIR/isolinux/isolinux.cfg + [ -L $ISODIR/ubuntu-installer ] || ln -s ../INSTALLER/ubuntu-installer $ISODIR/ubuntu-installer +fi + + +if [ "$ISO_INCLUDE_HDT" == "true" ] || [ "$ISO_INCLUDE_MEMTEST" == "true" ]; then + menuhwhead >> $ISODIR/isolinux/isolinux.cfg +fi + +if [ "$ISO_INCLUDE_HDT" == "true" ]; then + ISOLINUX_MODULES="${ISOLINUX_MODULES} hdt.c32 libutil.c32 libgpl.c32 libcom32.c32" + menuhwhdt >> $ISODIR/isolinux/isolinux.cfg + [ -e /usr/share/misc/pci.ids ] && cp /usr/share/misc/pci.ids $ISODIR/isolinux/ +fi + +if [ "$ISO_INCLUDE_MEMTEST" == "true" ]; then + cp $MEMTEST_BIN $ISODIR/memtest + menuhwmemtest >> $ISODIR/isolinux/isolinux.cfg +fi + + + +#copy all modules +for m in $ISOLINUX_MODULES +do + cp ${SYSLINUX_MODULESDIR}/$m $ISODIR/isolinux/ +done + + + +#create isofile +mkisofs -f -boot-info-table -boot-load-size 4 -no-emul-boot -o ${ISO_FILENAME}.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -l -R -J $ISODIR + +endstage iso + diff --git a/scripts/live.sh b/scripts/live.sh new file mode 100755 index 0000000..0357ed9 --- /dev/null +++ b/scripts/live.sh @@ -0,0 +1,22 @@ +#!/bin/bash +source ${WORKDIR}/mklive.conf +source $(dirname $0)/functions.sh + +echo "Build live" + +startstage live + +requiredir ${WORKDIR}/LIVE + +CHROOT=${WORKDIR}/chroot + +#copy kernel and initrd +cp -L $CHROOT/initrd.img ${WORKDIR}/LIVE/ +cp -L $CHROOT/vmlinuz ${WORKDIR}/LIVE/ + +#mksquashfs +[ -e ${WORKDIR}/LIVE/filesystem.squashfs ] && rm ${WORKDIR}/LIVE/filesystem.squashfs +mksquashfs $CHROOT ${WORKDIR}/LIVE/filesystem.squashfs + +endstage live + diff --git a/scripts/menufunction.sh b/scripts/menufunction.sh new file mode 100644 index 0000000..c144931 --- /dev/null +++ b/scripts/menufunction.sh @@ -0,0 +1,189 @@ + +function menuhead { + +if [ -n $SERIAL_PORT ]; then + SERIAL="SERIAL $SERIAL_PORT $SERIAL_SPEED" +fi + +cat << EOF +$SERIAL +UI menu.c32 + +prompt 0 +menu title BOOT MENU + +timeout 300 +EOF +} + +function menulivehead { +cat << EOF +label - +menu label Live Systems: +menu disable + +EOF +} + +function menulive { +cat << EOF + +label live +menu label ${LIVE_NAME} +menu default +menu indent 1 +kernel ../live/vmlinuz +append initrd=../live/initrd.img boot=live + +EOF +} + +function menulivepxe { + +# FETCH +# ftp, http, tftp +num=$(echo "$PXE_FETCH_FTP $PXE_FETCH_HTTP $PXE_FETCH_TFTP" | wc -w) + +if [ $num -gt 1 ];then +cat << EOF +menu begin live-menu +menu label ${LIVE_NAME} +menu indent 1 +menu title ${LIVE_NAME} BOOT +EOF +fi + +if [ -n "$PXE_FETCH_FTP" ]; then +cat << EOF + +label live +menu label ${LIVE_NAME} (fetch via ftp) +menu default +menu indent 1 +kernel ../live/vmlinuz +append initrd=../live/initrd.img boot=live fetch=${PXE_FETCH_FTP}/live/filesystem.squashfs + +EOF +fi + +if [ -n "$PXE_FETCH_HTTP" ]; then +cat << EOF + +label live +menu label ${LIVE_NAME} (fetch via http) +menu default +menu indent 1 +kernel ../live/vmlinuz +append initrd=../live/initrd.img boot=live fetch=${PXE_FETCH_HTTP}/live/filesystem.squashfs + +EOF +fi + +if [ -n "$PXE_FETCH_TFTP" ]; then +cat << EOF + +label live +menu label ${LIVE_NAME} (fetch via tftp) +menu default +menu indent 1 +kernel ../live/vmlinuz +append initrd=../live/initrd.img boot=live fetch=${PXE_FETCH_TFTP}/live/filesystem.squashfs + +EOF +fi + + + + +if [ $num -gt 1 ];then +cat << EOF + +label exit-${dist}-installer +menu label Exit +menu exit +menu end + +EOF +fi + +} + + + +function menuhwhead { +cat << EOF + +label - +menu label Hardware tools: +menu disable + +EOF +} + +function menuhwhdt { +cat << EOF + +label hdt +menu label ^Hardware Detection Tool (HDT) +menu indent 1 +kernel hdt.c32 +text help +HDT displays low-level information about the systems hardware. +endtext + +EOF +} + +function menuhwmemtest { +cat << EOF +label memtest86+ +menu indent 1 +menu label ^Memory Failure Detection (memtest86+) +kernel ../memtest +EOF +} + +function menuinstallerhead { +cat << EOF +label - +menu label Installer: +menu disable + +EOF +} + +function menuinstaller { +dist=$1 + +cat << EOF +menu begin $dist-installer-menu +menu label ${dist^} Installer +menu indent 1 +menu title ${dist^^} INSTALLER + +EOF + +sed -r -e "s/(default .*)//g" \ + -e "s/(label) ([a-z]+)/\1 \2-${dist}/g" \ + -e "s/(${dist}-installer)/..\/\1/g" \ + $WORKDIR/INSTALLER/${dist}.cfg + +if [ -n "$SERIAL_PORT" ]; then + sed -r -e "s/(default .*)//g" \ + -e "s/(label) ([a-z]+)/\1 \2-${dist}-serial/g" \ + -e "s/(menu label .*)/\1 with Serial Console/g" \ + -e "s/(${dist}-installer)/..\/\1/g" \ + -e "s/(append.+)(--- quiet)/\1console=ttyS${SERIAL_PORT},${SERIAL_SPEED}n8 \2/" \ + $WORKDIR/INSTALLER/${dist}.cfg +fi + +cat << EOF + +label exit-${dist}-installer +menu label Exit +menu exit +menu end + +EOF +} + diff --git a/scripts/pxe.sh b/scripts/pxe.sh new file mode 100755 index 0000000..d75ddf4 --- /dev/null +++ b/scripts/pxe.sh @@ -0,0 +1,66 @@ +#!/bin/bash +source $(dirname $0)/defaults.conf +source ${WORKDIR}/mklive.conf +source $(dirname $0)/functions.sh +source $(dirname $0)/menufunction.sh + +echo "Starting PXE creation" + +PXELINUX_MODULES="ldlinux.c32 libmenu.c32 menu.c32" +PXELINUX_BIN="/usr/lib/PXELINUX/pxelinux.0" + +checkstage live || err "Previous stage (live) was not finished" + +startstage pxe + +PXEDIR=${WORKDIR}/PXE +requiredir $PXEDIR +requiredir $PXEDIR/pxelinux +requiredir $PXEDIR/pxelinux/pxelinux.cfg +[ -L $PXEDIR/live ] || ln -s ../LIVE $PXEDIR/live + +#copy pxelinux.bin +cp ${PXELINUX_BIN} $PXEDIR/pxelinux/ + +#create pxelinux.conf +menuhead > $PXEDIR/pxelinux/pxelinux.cfg/default +menulivehead >> $PXEDIR/pxelinux/pxelinux.cfg/default +menulivepxe >> $PXEDIR/pxelinux/pxelinux.cfg/default + +if [ "$PXE_INCLUDE_UBUNTU_INSTALLER" == "true" ] || [ "$PXE_INCLUDE_DEBIAN_INSTALLER" == "true" ]; then + menuinstallerhead >> $PXEDIR/pxelinux/pxelinux.cfg/default +fi + +if [ "$PXE_INCLUDE_UBUNTU_INSTALLER" == "true" ]; then + menuinstaller ubuntu >> $PXEDIR/pxelinux/pxelinux.cfg/default + [ -L $PXEDIR/ubuntu-installer ] || ln -s ../INSTALLER/ubuntu-installer $PXEDIR/ubuntu-installer +fi + + +if [ "$PXE_INCLUDE_HDT" == "true" ] || [ "$PXE_INCLUDE_MEMTEST" == "true" ]; then + menuhwhead >> $PXEDIR/pxelinux/pxelinux.cfg/default +fi + +if [ "$PXE_INCLUDE_HDT" == "true" ]; then + PXELINUX_MODULES="${PXELINUX_MODULES} hdt.c32 libutil.c32 libgpl.c32 libcom32.c32" + menuhwhdt >> $PXEDIR/pxelinux/pxelinux.cfg/default + [ -e /usr/share/misc/pci.ids ] && cp /usr/share/misc/pci.ids $PXEDIR/pxelinux/ +fi + +if [ "$PXE_INCLUDE_MEMTEST" == "true" ]; then + cp $MEMTEST_BIN $PXEDIR/memtest + menuhwmemtest >> $PXEDIR/pxelinux/pxelinux.cfg/default +fi + + +#copy all modules +for m in $PXELINUX_MODULES +do + cp ${SYSLINUX_MODULESDIR}/$m $PXEDIR/pxelinux/ +done + + +#create tarball + +endstage pxe +