#!/bin/sh

# Load Global Settings
. ./settings.sh

# create directories
mkdir -p ${TFTP}
mkdir -p ${TFTP}/pxelinux.cfg

# copy Files from the Resource-Dir to the correct places:
cp ./resources/lighttpd.conf /etc/lighttpd/lighttpd.conf
cp ./resources/exports /etc/exports
if ! [ -e ${TFTP}/pxelinux.cfg/default ]; then
  cp ./resources/default-minimal ${TFTP}/pxelinux.cfg/default
fi
cp ./resources/splash.png ${TFTP}/
cp -a /usr/lib/syslinux/modules/bios ${TFTP}/

# Link needed Files from installed Debian Packages to the TFTP-Root:
ln /usr/lib/PXELINUX/pxelinux.0 ${TFTP}/
ln /boot/ipxe.lkrn              ${TFTP}/
ln /usr/lib/syslinux/memdisk    ${TFTP}/
ln ${TFTP}/bios/ldlinux.c32     ${TFTP}/
ln ${TFTP}/pxelinux.cfg/default ${TFTP}/default -s

# set file access
chown ${USERID}:${GROUPID} * -R
chmod a+rw * -R

chown ${USERID}:${GROUPID} ${TFTP}/* -R
chmod a+rwx ${TFTP} -R

# restart services
systemctl restart tftpd-hpa lighttpd nfs-kernel-server
