14 |
local locations |
local locations |
15 |
local loc |
local loc |
16 |
local client_locations_location |
local client_locations_location |
17 |
|
local client_locations_bootserver |
18 |
|
local client_locations_bootsubdir |
19 |
local client_locations_controlserver |
local client_locations_controlserver |
20 |
local client_locations_pxe_default_entry |
local client_locations_pxe_default_entry |
21 |
local client_locations_pxe_prompt |
local client_locations_pxe_prompt |
31 |
do |
do |
32 |
evaluate_table_xml client_locations "where location='${loc}'" |
evaluate_table_xml client_locations "where location='${loc}'" |
33 |
|
|
34 |
|
# fallback to honor old database versions in transition phase of the upgrade |
35 |
|
if [[ -z ${client_locations_bootserver} ]] || [[ ${client_locations_bootserver} = NULL ]] |
36 |
|
then |
37 |
|
client_locations_bootserver="${client_locations_controlserver}" |
38 |
|
fi |
39 |
|
|
40 |
|
# fallback subdir |
41 |
|
if [[ ${client_locations_bootsubdir} = NULL ]] |
42 |
|
then |
43 |
|
client_locations_bootsubdir="" |
44 |
|
fi |
45 |
|
# fallback subdir |
46 |
|
if [[ -n ${client_locations_bootsubdir} ]] && [[ ${client_locations_bootsubdir:0:1} != / ]] |
47 |
|
then |
48 |
|
client_locations_bootsubdir="/${client_locations_bootsubdir}" |
49 |
|
fi |
50 |
|
|
51 |
sed \ |
sed \ |
52 |
-e "s:@@DEFAULTENTRY@@:${client_locations_pxe_default_entry}:g" \ |
-e "s:@@DEFAULTENTRY@@:${client_locations_pxe_default_entry}:g" \ |
53 |
-e "s:@@TIMEOUT@@:${client_locations_pxe_timeout}:g" \ |
-e "s:@@TIMEOUT@@:${client_locations_pxe_timeout}:g" \ |
54 |
-e "s:@@PROMPT@@:${client_locations_pxe_prompt}:g" \ |
-e "s:@@PROMPT@@:${client_locations_pxe_prompt}:g" \ |
55 |
|
-e "s:@@BOOTSERVER@@:${client_locations_bootserver}:g" \ |
56 |
|
-e "s:@@BOOTSUBDIR@@:${client_locations_bootsubdir}:g" \ |
57 |
-e "s:@@CONTROLSERVER@@:${client_locations_controlserver}:g" \ |
-e "s:@@CONTROLSERVER@@:${client_locations_controlserver}:g" \ |
58 |
-e "s:@@LOCATION@@:${client_locations_location}:g" \ |
-e "s:@@LOCATION@@:${client_locations_location}:g" \ |
59 |
\ |
\ |
67 |
done |
done |
68 |
} |
} |
69 |
|
|
70 |
symlink_pxe_clients() |
update_pxe_clients() |
71 |
{ |
{ |
72 |
local i |
local i |
73 |
local ids |
local ids |
74 |
local serial |
local serial |
75 |
local config |
local config |
76 |
|
|
77 |
# remove all symlinks but keep file based configs |
# remove all client symlinks and files |
78 |
find ${TFTP_DIRECTORY} -name 01-\* -type l | xargs --no-run-if-empty rm |
# 01- is the prefix identifier of the pxe/tftpd server for mac adresses |
79 |
|
find ${TFTP_DIRECTORY} -name 01-\* -type l -o -name 01-\* -type f | xargs --no-run-if-empty rm |
80 |
|
|
81 |
ids=$(mysqldo "select serial from client_serials where enabled='1' and location <> '';") |
ids=$(mysqldo "select serial from client_serials where enabled='1' and location <> '';") |
82 |
for serial in ${ids} |
for serial in ${ids} |
83 |
do |
do |
84 |
evaluate_table_xml client_serials "where serial='${serial}'" |
evaluate_table_xml client_serials "where serial='${serial}'" |
85 |
|
evaluate_table_xml client_boot "where serial='${serial}'" |
86 |
if [[ -n ${client_serials_mac} ]] |
if [[ -n ${client_serials_mac} ]] |
87 |
then |
then |
88 |
|
# 01- is the prefix identifier of the pxe/tftpd server for mac adresses |
89 |
config="${TFTP_DIRECTORY}/01-${client_serials_mac//:/-}" |
config="${TFTP_DIRECTORY}/01-${client_serials_mac//:/-}" |
90 |
# do not update if an individual config file exist |
# do not symlink if an individual config is requested |
91 |
if [[ -f ${config} ]] |
if [[ -n ${client_boot_cmdline} ]] && [[ ${client_boot_cmdline} != NULL ]] |
92 |
then |
then |
93 |
echo "A config file named '${config}' already exist" |
echo "Using an individual configuration for '${config}'" |
94 |
|
sed -e "s:^\([[:space:]]append .*\):\1 ${client_boot_cmdline}:" \ |
95 |
|
${TFTP_DIRECTORY}/lpxelinux-default-"${client_serials_location}" > "${config}" |
96 |
else |
else |
|
# 01- is the prefix identifier of the pxe/tftpd server for mac adresses |
|
97 |
ln -snf lpxelinux-default-"${client_serials_location}" "${config}" |
ln -snf lpxelinux-default-"${client_serials_location}" "${config}" |
98 |
fi |
fi |
99 |
fi |
fi |
102 |
|
|
103 |
case $1 in |
case $1 in |
104 |
create-config) create_pxe_config ;; |
create-config) create_pxe_config ;; |
105 |
symlink-clients) symlink_pxe_clients ;; |
# keep symlink-clients for compat reasons atm |
106 |
*) echo "Unknown command, user either 'create-config' or 'symlink-clients'"; exit 1 ;; |
symlink-clients|update-clients) update_pxe_clients ;; |
107 |
|
*) echo "Unknown command, user either 'create-config' or 'update|symlink-clients'"; exit 1 ;; |
108 |
esac |
esac |