#!/bin/bash MCORE_LIBDIR="@@MCORE_LIBDIR@@" source @@SYSCONFDIR@@/mcore/mcore.conf source @@SYSCONFDIR@@/mcore/control.conf source ${MCORE_LIBDIR}/include/common.global.class source ${MCORE_LIBDIR}/include/daemon.global.class source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class TFTP_DIRECTORY="@@TFTP_DIRECTORY@@" create_pxe_config() { local locations local loc local client_locations_location local client_locations_controlserver local client_locations_pxe_default_entry local client_locations_pxe_prompt local client_locations_pxe_timeout local client_locations_set_default # cleanup find ${TFTP_DIRECTORY} -name lpxelinux-default-\* | xargs --no-run-if-empty rm [[ -L ${TFTP_DIRECTORY}/default ]] && rm ${TFTP_DIRECTORY}/default locations=$(mysqldo "select location from client_locations where enabled='1';") for loc in ${locations} do evaluate_table_xml client_locations "where location='${loc}'" sed \ -e "s:@@DEFAULTENTRY@@:${client_locations_pxe_default_entry}:g" \ -e "s:@@TIMEOUT@@:${client_locations_pxe_timeout}:g" \ -e "s:@@PROMPT@@:${client_locations_pxe_prompt}:g" \ -e "s:@@CONTROLSERVER@@:${client_locations_controlserver}:g" \ \ "${TFTP_DIRECTORY}"/lpxelinux-skeleton \ > "${TFTP_DIRECTORY}"/lpxelinux-default-"${client_locations_location}" if [[ ${client_locations_set_default} = 1 ]] then ln -snf lpxelinux-default-"${client_locations_location}" "${TFTP_DIRECTORY}"/default fi done } symlink_pxe_clients() { local i local ids local serial local config # remove all symlinks but keep file based configs for i in $(find ${TFTP_DIRECTORY} -name 01-\*) do [[ -L ${TFTP_DIRECTORY}/${i} ]] && rm ${TFTP_DIRECTORY}/${i} done ids=$(mysqldo "select serial from client_serials where enabled='1' and location <> '';") for serial in ${ids} do evaluate_table_xml client_serials "where serial='${serial}'" if [[ -n ${client_serials_mac} ]] then config="${TFTP_DIRECTORY}/01-${client_serials_mac//:/-}" # do not update if an individual config file exist if [[ -e ${config} ]] then echo "A config file named '${config}' already exist" else # 01- is the prefix identifier of the pxe/tftpd server for mac adresses ln -snf lpxelinux-default-"${client_serials_location}" "${config}" fi fi done } case $1 in create-config) create_pxe_config ;; symlink-clients) symlink_pxe_clients ;; *) echo "Unknown command, user either 'create-config' or 'symlink-clients'"; exit 1 ;; esac