
#!/bin/sh

. ./settings.sh

#
# Main Service
#
S_ENABLED=YES
S_NAME="none"
S_PACKAGES="git sudo p7zip p7zip-full ipxe pxelinux syslinux syslinux-common"

# handle services
fservice $S_ENABLED $1 $S_NAME "$S_PACKAGES"

case $1 in

  init)
    # create directories
     mkdir -p ${D_TFTP}
     mkdir -p ${D_TFTP}/pxelinux.cfg

    # copy Files some files:
     cp -a /usr/lib/syslinux/modules/bios ${D_TFTP}/
     cp -a ${D_RESRC}/default-minimal.txt ${D_TFTP}/pxelinux.cfg/default

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

    # download needed files:
     wget -O ${D_TFTP}/wimboot "https://github.com/ipxe/wimboot/releases/latest/download/wimboot"

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

     chown ${USERID}:${GROUPID} ${D_TFTP} -R
     chmod a+rwx ${D_TFTP} -R
  ;;

esac



