#!/bin/bash # # priority: 100 # # Manage network related configuration files # # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # # Source function library and configuration source /etc/plc.d/functions source /etc/planetlab/plc_config # Be verbose set -x [ "$PLC_HOSTS_ENABLED" -ne 1 ] && exit 0 case "$1" in start) MESSAGE=$"Generating network files" dialog "$MESSAGE" mv -f /etc/hosts /etc/hosts_plc.backup hfile=$(mktemp) # Minimal /etc/hosts for server in DB API BOOT WWW ; do hostname=PLC_${server}_HOST ip=PLC_${server}_IP if [ -n "${!ip}" ] ; then echo "${!ip} ${!hostname}" else ip=$(gethostbyname ${!hostname}) if [ -n "$ip" ] ; then echo "$ip ${!hostname}" fi fi done > $hfile echo "#generated by /etc/plc.d/network" >/etc/hosts echo "127.0.0.1 localhost.localdomain localhost" >> /etc/hosts sort -u $hfile >> /etc/hosts chmod +r /etc/hosts rm -f $hfile result "$MESSAGE" ;; stop) MESSAGE=$"Reverting network files" if [ -f /etc/hosts_plc.backup ] ; then mv -f /etc/hosts_plc.backup /etc/hosts fi dialog "$MESSAGE" result "$MESSAGE" ;; esac exit $ERRORS