Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/src/modules/pxeconfig/mcore-pxeconfig.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2768 - (show annotations) (download)
Wed Feb 10 15:29:02 2016 UTC (8 years, 2 months ago) by niro
File size: 2504 byte(s)
-provide MCORE_LOCATION at boot cmdline and use it to have a valid location on first boot client registration
1 #!/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 local client_locations_controlserver
18 local client_locations_pxe_default_entry
19 local client_locations_pxe_prompt
20 local client_locations_pxe_timeout
21 local client_locations_set_default
22
23 # cleanup
24 find ${TFTP_DIRECTORY} -name lpxelinux-default-\* | xargs --no-run-if-empty rm
25 [[ -L ${TFTP_DIRECTORY}/default ]] && rm ${TFTP_DIRECTORY}/default
26
27 locations=$(mysqldo "select location from client_locations where enabled='1';")
28 for loc in ${locations}
29 do
30 evaluate_table_xml client_locations "where location='${loc}'"
31
32 sed \
33 -e "s:@@DEFAULTENTRY@@:${client_locations_pxe_default_entry}:g" \
34 -e "s:@@TIMEOUT@@:${client_locations_pxe_timeout}:g" \
35 -e "s:@@PROMPT@@:${client_locations_pxe_prompt}:g" \
36 -e "s:@@CONTROLSERVER@@:${client_locations_controlserver}:g" \
37 -e "s:@@LOCATION@@:${client_locations_location}:g" \
38 \
39 "${TFTP_DIRECTORY}"/lpxelinux-skeleton \
40 > "${TFTP_DIRECTORY}"/lpxelinux-default-"${client_locations_location}"
41
42 if [[ ${client_locations_set_default} = 1 ]]
43 then
44 ln -snf lpxelinux-default-"${client_locations_location}" "${TFTP_DIRECTORY}"/default
45 fi
46 done
47 }
48
49 symlink_pxe_clients()
50 {
51 local i
52 local ids
53 local serial
54 local config
55
56 # remove all symlinks but keep file based configs
57 find ${TFTP_DIRECTORY} -name 01-\* -type l | xargs --no-run-if-empty rm
58
59 ids=$(mysqldo "select serial from client_serials where enabled='1' and location <> '';")
60 for serial in ${ids}
61 do
62 evaluate_table_xml client_serials "where serial='${serial}'"
63 if [[ -n ${client_serials_mac} ]]
64 then
65 config="${TFTP_DIRECTORY}/01-${client_serials_mac//:/-}"
66 # do not update if an individual config file exist
67 if [[ -f ${config} ]]
68 then
69 echo "A config file named '${config}' already exist"
70 else
71 # 01- is the prefix identifier of the pxe/tftpd server for mac adresses
72 ln -snf lpxelinux-default-"${client_serials_location}" "${config}"
73 fi
74 fi
75 done
76 }
77
78 case $1 in
79 create-config) create_pxe_config ;;
80 symlink-clients) symlink_pxe_clients ;;
81 *) echo "Unknown command, user either 'create-config' or 'symlink-clients'"; exit 1 ;;
82 esac