enable local DNS server that can provide minimal forward DNS resolution for MyPLC...
[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.3 2006/05/16 17:09:34 mlhuang Exp $
11 #
12
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
16
17 case "$1" in
18     start)
19         MESSAGE=$"Generating network files"
20         dialog "$MESSAGE"
21
22         # Minimal /etc/hosts
23         echo "127.0.0.1 localhost.localdomain localhost" >/etc/hosts
24         (
25             for server in API BOOT WWW ; do
26                 hostname=PLC_${server}_HOST
27                 ip=PLC_${server}_IP
28                 if [ -n "${!ip}" ] ; then
29                     echo "${!ip}        ${!hostname}"
30                 else
31                     ip=$(gethostbyname ${!hostname})
32                     if [ -n "$ip" ] ; then
33                         echo "$ip       ${!hostname}"
34                     fi
35                 fi
36             done
37         ) >>/etc/hosts
38
39         # Set up nameservers
40         (
41             [ -n "$PLC_NET_DNS1" ] && echo "nameserver $PLC_NET_DNS1"
42             [ -n "$PLC_NET_DNS2" ] && echo "nameserver $PLC_NET_DNS2"
43         ) >/etc/resolv.conf
44
45         result "$MESSAGE"
46         ;;
47 esac
48
49 exit $ERRORS