#!/bin/sh

. ./settings.sh

WGET="-nv -nc"

echo "--- Knoppix V9.1 ------------------------------------------------------------------"
echo "------------------------------------------------------------------------------------"
KNX9URL="http://ftp.uni-kl.de/pub/linux/knoppix-dvd/KNOPPIX_V9.1DVD-2021-01-25-DE.iso"
FILENAME=KNOPPIX_V9.1DVD.iso

if ! [ -e ./temp/$FILENAME ]; then
  echo "Downloading Knoppix..."
   wget $WGET -O ./temp/$FILENAME $KNX9URL
else
  echo "Preparing Knoppix..."
   mkdir -p ${TFTP}/free/knx
   7z x -o${TFTP}/free/knx ./temp/${FILENAME}
   cp ./resources/knx-miniroot.gz ${TFTP}/free/knx/boot/isolinux/miniroot.gz
fi

echo "--- Debian Installer ---------------------------------------------------------------"
echo "------------------------------------------------------------------------------------"
DISTS="bullseye bookworm"
ARCHS="amd64 i386"

for DIST in $DISTS;
do
 for ARCH in ${ARCHS};
 do
  DEBURL="https://deb.debian.org/debian/dists/${DIST}/main/installer-${ARCH}/current/images/netboot/netboot.tar.gz"
  FILENAME="netboot-${DIST}-${ARCH}.tar.gz"
  if ! [ -e ./temp/${FILENAME} ]; then
    echo "Downloading Debian installer ${DIST}/${ARCH}..."
    wget $WGET -O ./temp/${FILENAME} $DEBURL
  else
    echo "Create directory in ${TFTP}/free/deb-${DIST}..."
     mkdir -p ${TFTP}/free/deb-${DIST}
    echo "Unpacking files..."
     tar xfzC ./temp/${FILENAME} ${TFTP}/free/deb-${DIST}
  fi
 done
done

chmod a+rwx ${TFTP}/ -R
