Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2688 - (hide annotations) (download)
Fri Dec 11 10:19:48 2015 UTC (8 years, 5 months ago) by niro
File size: 2448 byte(s)
-fixed deletion logic
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     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 niro 2688 find ${TFTP_DIRECTORY} -name 01-\* -type l | xargs --no-run-if-empty rm
57 niro 2674
58     ids=$(mysqldo "select serial from client_serials where enabled='1' and location <> '';")
59     for serial in ${ids}
60     do
61     evaluate_table_xml client_serials "where serial='${serial}'"
62     if [[ -n ${client_serials_mac} ]]
63     then
64     config="${TFTP_DIRECTORY}/01-${client_serials_mac//:/-}"
65     # do not update if an individual config file exist
66 niro 2688 if [[ -f ${config} ]]
67 niro 2674 then
68     echo "A config file named '${config}' already exist"
69     else
70     # 01- is the prefix identifier of the pxe/tftpd server for mac adresses
71     ln -snf lpxelinux-default-"${client_serials_location}" "${config}"
72     fi
73     fi
74     done
75     }
76    
77     case $1 in
78     create-config) create_pxe_config ;;
79     symlink-clients) symlink_pxe_clients ;;
80     *) echo "Unknown command, user either 'create-config' or 'symlink-clients'"; exit 1 ;;
81     esac