Annotation of /mcore-src/trunk/mcore-tools/src/modules/pxeconfig/mcore-pxeconfig.in
Parent Directory | Revision Log
Revision 2868 -
(hide annotations)
(download)
Fri Aug 14 05:49:36 2020 UTC (3 years, 8 months ago) by niro
File size: 3678 byte(s)
Fri Aug 14 05:49:36 2020 UTC (3 years, 8 months ago) by niro
File size: 3678 byte(s)
-add support for bootsubdir variable
1 | niro | 2674 | #!/bin/bash |
2 | |||
3 | MCORE_LIBDIR="@@MCORE_LIBDIR@@" | ||
4 | source @@SYSCONFDIR@@/mcore/mcore.conf | ||
5 | source @@SYSCONFDIR@@/mcore/control.conf | ||
6 | source ${MCORE_LIBDIR}/include/common.global.class | ||
7 | source ${MCORE_LIBDIR}/include/daemon.global.class | ||
8 | source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class | ||
9 | |||
10 | TFTP_DIRECTORY="@@TFTP_DIRECTORY@@" | ||
11 | |||
12 | create_pxe_config() | ||
13 | { | ||
14 | local locations | ||
15 | local loc | ||
16 | local client_locations_location | ||
17 | niro | 2868 | local client_locations_bootserver |
18 | local client_locations_bootsubdir | ||
19 | niro | 2674 | local client_locations_controlserver |
20 | local client_locations_pxe_default_entry | ||
21 | local client_locations_pxe_prompt | ||
22 | local client_locations_pxe_timeout | ||
23 | local client_locations_set_default | ||
24 | |||
25 | # cleanup | ||
26 | find ${TFTP_DIRECTORY} -name lpxelinux-default-\* | xargs --no-run-if-empty rm | ||
27 | [[ -L ${TFTP_DIRECTORY}/default ]] && rm ${TFTP_DIRECTORY}/default | ||
28 | |||
29 | locations=$(mysqldo "select location from client_locations where enabled='1';") | ||
30 | for loc in ${locations} | ||
31 | do | ||
32 | evaluate_table_xml client_locations "where location='${loc}'" | ||
33 | |||
34 | niro | 2785 | # 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 | niro | 2868 | # 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 | niro | 2674 | sed \ |
52 | -e "s:@@DEFAULTENTRY@@:${client_locations_pxe_default_entry}:g" \ | ||
53 | -e "s:@@TIMEOUT@@:${client_locations_pxe_timeout}:g" \ | ||
54 | -e "s:@@PROMPT@@:${client_locations_pxe_prompt}:g" \ | ||
55 | niro | 2785 | -e "s:@@BOOTSERVER@@:${client_locations_bootserver}:g" \ |
56 | niro | 2868 | -e "s:@@BOOTSUBDIR@@:${client_locations_bootsubdir}:g" \ |
57 | niro | 2674 | -e "s:@@CONTROLSERVER@@:${client_locations_controlserver}:g" \ |
58 | niro | 2768 | -e "s:@@LOCATION@@:${client_locations_location}:g" \ |
59 | niro | 2674 | \ |
60 | "${TFTP_DIRECTORY}"/lpxelinux-skeleton \ | ||
61 | > "${TFTP_DIRECTORY}"/lpxelinux-default-"${client_locations_location}" | ||
62 | |||
63 | if [[ ${client_locations_set_default} = 1 ]] | ||
64 | then | ||
65 | ln -snf lpxelinux-default-"${client_locations_location}" "${TFTP_DIRECTORY}"/default | ||
66 | fi | ||
67 | done | ||
68 | } | ||
69 | |||
70 | niro | 2800 | update_pxe_clients() |
71 | niro | 2674 | { |
72 | local i | ||
73 | local ids | ||
74 | local serial | ||
75 | local config | ||
76 | |||
77 | niro | 2800 | # remove all client symlinks and files |
78 | # 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 | niro | 2674 | |
81 | ids=$(mysqldo "select serial from client_serials where enabled='1' and location <> '';") | ||
82 | for serial in ${ids} | ||
83 | do | ||
84 | evaluate_table_xml client_serials "where serial='${serial}'" | ||
85 | niro | 2800 | evaluate_table_xml client_boot "where serial='${serial}'" |
86 | niro | 2674 | if [[ -n ${client_serials_mac} ]] |
87 | then | ||
88 | niro | 2800 | # 01- is the prefix identifier of the pxe/tftpd server for mac adresses |
89 | niro | 2674 | config="${TFTP_DIRECTORY}/01-${client_serials_mac//:/-}" |
90 | niro | 2800 | # do not symlink if an individual config is requested |
91 | if [[ -n ${client_boot_cmdline} ]] && [[ ${client_boot_cmdline} != NULL ]] | ||
92 | niro | 2674 | then |
93 | niro | 2800 | 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 | niro | 2674 | else |
97 | ln -snf lpxelinux-default-"${client_serials_location}" "${config}" | ||
98 | fi | ||
99 | fi | ||
100 | done | ||
101 | } | ||
102 | |||
103 | case $1 in | ||
104 | create-config) create_pxe_config ;; | ||
105 | niro | 2800 | # keep symlink-clients for compat reasons atm |
106 | symlink-clients|update-clients) update_pxe_clients ;; | ||
107 | *) echo "Unknown command, user either 'create-config' or 'update|symlink-clients'"; exit 1 ;; | ||
108 | niro | 2674 | esac |