PXE Downloader Script für Xbuntu

Script that automatically downloads and prepares ubuntu images (and variants) for pxe boot

#!/bin/bash 
 
 
NFS_HOST="192.168.101.9" 
NFS_BASE_PATH="/netboot/tftp" 
FLAVOUR_MIRROR="http://www.mirrorservice.org/sites/cdimage.ubuntu.com/cdimage"  #original ubuntu does not exist on that mirror for amd64 arch 
UBUNTU_MIRROR="http://releases.ubuntu.com" 
ARCH="amd64" 
AVAILABLE_FLAVOURS=['ubuntu','kubuntu','xubuntu','lubuntu','ubuntustudio','edubuntu'] 
 
 
set -e  # exit on error 
 
 
if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" == "" ] || ! echo ${AVAILABLE_FLAVOURS[@]} | grep -q -w "$1"; 
then 
        echo "Arguments: FLAVOUR CODENAME VERSIONNUMBER" 
        echo "e.g.: xubuntu xenial 16.04.2" 
        exit 1 
fi 
 
flavour=$1 
codename=$2 
version=$3 
variant="desktop" 
 
if [ -e "${flavour}_live/${codename}-${variant}-${version}/" ]; 
then 
        echo "Already exists" 
        exit 1 
fi 
 
 
if [ "$1" == "ubuntu" ]; 
then 
        IMAGE_MIRROR=$UBUNTU_MIRROR/${codename} 
else 
        IMAGE_MIRROR=$FLAVOUR_MIRROR/${flavour}/releases/${codename}/release 
fi 
 
 
wget -O /tmp/image.iso ${IMAGE_MIRROR}/${flavour}-${version}-${variant}-${ARCH}.iso 
mkdir -p ${flavour}_live/${codename}-${variant}-${version}/ 
7z x -o${flavour}_live/${codename}-${variant}-${version}/ /tmp/image.iso 
chmod -R +rx ${flavour}_live/${codename}-${variant}-${version}/ 
rm /tmp/image.iso
 echo "${NFS_BASE_PATH}/${flavour}_live/${codename}-${variant}-${version}       192.168.0.0/255.255.0.0(ro,async,subtree_check,no_root_squash)" >> /etc/exports 
/etc/init.d/nfs-kernel-server restart 
 
 
 
if ! [ -e "pxelinux.cfg/${flavour}_live" ]; 
then 
 
 
echo " 
LABEL      ${flavour} 
MENU LABEL ${flavour} ^Live 
KERNEL     vesamenu.c32 
APPEND     pxelinux.cfg/${flavour}_live 
" >> pxelinux.cfg/default 
 
echo " 
DEFAULT vesamenu.c32 
ALLOWOPTIONS 0 
PROMPT 0 
TIMEOUT 0 
 
MENU TITLE PXE Boot Menu - ${flavour} 
 
LABEL      back 
MENU LABEL <- 
KERNEL     vesamenu.c32 
APPEND     pxelinux.cfg/default 
" >> pxelinux.cfg/${flavour}_live 
 
fi 
 
 
echo "" >> pxelinux.cfg/${flavour}_live 
echo "LABEL ub${codename} ${version}" >> pxelinux.cfg/${flavour}_live 
echo "MENU LABEL ${flavour} ${codename} ${version} (${variant})" >> pxelinux.cfg/${flavour}_live 
echo "KERNEL ${flavour}_live/${codename}-${variant}-${version}/casper/vmlinuz.efi" >> pxelinux.cfg/${flavour}_live 
echo "APPEND root=/dev/nfs boot=casper netboot=nfs nfsroot=${NFS_HOST}:${NFS_BASE_PATH}/${flavour}_live/${codename}-${variant}-${version} initrd=${flavour}_live/${codename}-${variant}-${version}/casper/initrd.lz nomodeset -- locale=de_DE console-setup/layoutcode=de" >> pxelinux.cfg/${flavour}_live