Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2674 - (show annotations) (download)
Fri Dec 11 08:48:44 2015 UTC (8 years, 4 months ago) by niro
File size: 2496 byte(s)
-added pxeconfig module
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 \
38 "${TFTP_DIRECTORY}"/lpxelinux-skeleton \
39 > "${TFTP_DIRECTORY}"/lpxelinux-default-"${client_locations_location}"
40
41 if [[ ${client_locations_set_default} = 1 ]]
42 then
43 ln -snf lpxelinux-default-"${client_locations_location}" "${TFTP_DIRECTORY}"/default
44 fi
45 done
46 }
47
48 symlink_pxe_clients()
49 {
50 local i
51 local ids
52 local serial
53 local config
54
55 # remove all symlinks but keep file based configs
56 for i in $(find ${TFTP_DIRECTORY} -name 01-\*)
57 do
58 [[ -L ${TFTP_DIRECTORY}/${i} ]] && rm ${TFTP_DIRECTORY}/${i}
59 done
60
61 ids=$(mysqldo "select serial from client_serials where enabled='1' and location <> '';")
62 for serial in ${ids}
63 do
64 evaluate_table_xml client_serials "where serial='${serial}'"
65 if [[ -n ${client_serials_mac} ]]
66 then
67 config="${TFTP_DIRECTORY}/01-${client_serials_mac//:/-}"
68 # do not update if an individual config file exist
69 if [[ -e ${config} ]]
70 then
71 echo "A config file named '${config}' already exist"
72 else
73 # 01- is the prefix identifier of the pxe/tftpd server for mac adresses
74 ln -snf lpxelinux-default-"${client_serials_location}" "${config}"
75 fi
76 fi
77 done
78 }
79
80 case $1 in
81 create-config) create_pxe_config ;;
82 symlink-clients) symlink_pxe_clients ;;
83 *) echo "Unknown command, user either 'create-config' or 'symlink-clients'"; exit 1 ;;
84 esac