#!/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_bootserver local client_locations_bootsubdir 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}'" # fallback to honor old database versions in transition phase of the upgrade if [[ -z ${client_locations_bootserver} ]] || [[ ${client_locations_bootserver} = NULL ]] then client_locations_bootserver="${client_locations_controlserver}" fi # fallback subdir if [[ ${client_locations_bootsubdir} = NULL ]] then client_locations_bootsubdir="" fi # fallback subdir if [[ -n ${client_locations_bootsubdir} ]] && [[ ${client_locations_bootsubdir:0:1} != / ]] then client_locations_bootsubdir="/${client_locations_bootsubdir}" fi 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:@@BOOTSERVER@@:${client_locations_bootserver}:g" \ -e "s:@@BOOTSUBDIR@@:${client_locations_bootsubdir}:g" \ -e "s:@@CONTROLSERVER@@:${client_locations_controlserver}:g" \ -e "s:@@LOCATION@@:${client_locations_location}: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 } update_pxe_clients() { local i local ids local serial local config # remove all client symlinks and files # 01- is the prefix identifier of the pxe/tftpd server for mac adresses find ${TFTP_DIRECTORY} -name 01-\* -type l -o -name 01-\* -type f | xargs --no-run-if-empty rm 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}'" evaluate_table_xml client_boot "where serial='${serial}'" if [[ -n ${client_serials_mac} ]] then # 01- is the prefix identifier of the pxe/tftpd server for mac adresses config="${TFTP_DIRECTORY}/01-${client_serials_mac//:/-}" # do not symlink if an individual config is requested if [[ -n ${client_boot_cmdline} ]] && [[ ${client_boot_cmdline} != NULL ]] then echo "Using an individual configuration for '${config}'" sed -e "s:^\([[:space:]]append .*\):\1 ${client_boot_cmdline}:" \ ${TFTP_DIRECTORY}/lpxelinux-default-"${client_serials_location}" > "${config}" else ln -snf lpxelinux-default-"${client_serials_location}" "${config}" fi fi done } case $1 in create-config) create_pxe_config ;; # keep symlink-clients for compat reasons atm symlink-clients|update-clients) update_pxe_clients ;; *) echo "Unknown command, user either 'create-config' or 'update|symlink-clients'"; exit 1 ;; esac