8c7cf95556fca4a50dcdc1650779177c9d721124
[myplc.git] / plc.d / network
1 #!/bin/bash
2 #
3 # priority: 100
4 #
5 # Manage network related configuration files
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 #
10 # $Id: network,v 1.4 2006/05/23 18:10:08 mlhuang Exp $
11 #
12
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
16
17 # Be verbose
18 set -x
19
20 case "$1" in
21     start)
22         MESSAGE=$"Generating network files"
23         dialog "$MESSAGE"
24
25         # Minimal /etc/hosts
26         echo "127.0.0.1 localhost.localdomain localhost" >/etc/hosts
27         (
28             for server in API BOOT WWW ; do
29                 hostname=PLC_${server}_HOST
30                 ip=PLC_${server}_IP
31                 if [ -n "${!ip}" ] ; then
32                     echo "${!ip}        ${!hostname}"
33                 else
34                     ip=$(gethostbyname ${!hostname})
35                     if [ -n "$ip" ] ; then
36                         echo "$ip       ${!hostname}"
37                     fi
38                 fi
39             done
40         ) >>/etc/hosts
41
42         # Set up nameservers
43         (
44             [ -n "$PLC_NET_DNS1" ] && echo "nameserver $PLC_NET_DNS1"
45             [ -n "$PLC_NET_DNS2" ] && echo "nameserver $PLC_NET_DNS2"
46         ) >/etc/resolv.conf
47
48         result "$MESSAGE"
49         ;;
50 esac
51
52 exit $ERRORS