Statistiques
| Révision :

root / trunk / shell / generate-dhcp-hostsfile @ 19

Historique | Voir | Annoter | Télécharger (1,24 ko)

1 3 storres
#! /bin/bash
2 3 storres
#
3 3 storres
# Generate a dhcp-hostsfile for dnsmasq.
4 3 storres
# MAC_address,node_name,IP_address
5 3 storres
#
6 3 storres
# Get the directory of the script.
7 3 storres
SCRIPT_PATH=`dirname $0`
8 3 storres
# Get the script name.
9 3 storres
SCRIPT_NAME=`basename $0`
10 3 storres
# Source the common configuration variables.
11 3 storres
. $SCRIPT_PATH/c-i-a-b.common
12 3 storres
# Clean up the file
13 3 storres
DHCP_HOSTSFILE="${SCRIPT_PATH}/${TEMPLATES_DIR}/etc/${DHCP_HOSTSFILE_BASENAME}"
14 3 storres
rm -f $DHCP_HOSTSFILE
15 3 storres
# Compute the file entries.
16 3 storres
for i in `seq 1 $COMPUTE_NODE_MAX_NUM`
17 3 storres
  do
18 3 storres
    NODE_NUMBER=$i
19 3 storres
    NODE_NUMBER_STRING=$NODE_NUMBER
20 3 storres
    # Normalize the node numbers for the node names on 3 characters.
21 3 storres
    while [ ${#NODE_NUMBER_STRING} -lt 3 ]
22 3 storres
      do
23 3 storres
        NODE_NUMBER_STRING="0$NODE_NUMBER_STRING"
24 3 storres
    done
25 3 storres
    # Transform the decimal node number in hexadecimal for the MAC address.
26 3 storres
    NODE_NUMBER_HEXA=`printf "%X" $NODE_NUMBER`
27 3 storres
    while [ ${#NODE_NUMBER_HEXA} -lt 2 ]
28 3 storres
      do
29 3 storres
        NODE_NUMBER_HEXA="0$NODE_NUMBER_HEXA"
30 3 storres
    done
31 3 storres
    MAC_ADDRESS="${COMPUTE_NODE_MAC_ADDRESS_PREFIX}:$NODE_NUMBER_HEXA"
32 3 storres
    COMPUTE_NODE_NAME="${COMPUTE_NODE_NAME_PREFIX}${NODE_NUMBER_STRING}"
33 3 storres
    echo "${MAC_ADDRESS},id:*,${COMPUTE_NODE_STATIC_NETWORK_PREFIX}.${NODE_NUMBER},${COMPUTE_NODE_NAME}" >> $DHCP_HOSTSFILE
34 3 storres
35 3 storres
done
36 3 storres
echo
37 3 storres
echo Copy the file to the front end!
38 3 storres
echo
39 3 storres
exit 0