X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plc.d%2Fnetwork;h=73ac47016483eb63a5dc27b3bba783e3f3e11fc0;hb=ff06429772867a55fa0e2bed31306392c67a4405;hp=141bc50bc9a2fb11247566d53457dc733b57bbb9;hpb=afe8464033406a91a976f85fa06cf06fea26f179;p=myplc.git diff --git a/plc.d/network b/plc.d/network index 141bc50..73ac470 100755 --- a/plc.d/network +++ b/plc.d/network @@ -7,79 +7,51 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ -# # Source function library and configuration -. /etc/plc.d/functions -. /etc/planetlab/plc_config +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 + 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 - done - ) > $hfile - if [ $PLC_DNS_ENABLED -eq 1 ] ; then - target=/etc/plc_hosts - sort -u $hfile > $target - else - target=/etc/hosts - cat /etc/hosts >> $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 - fi - chmod +r $target + 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 - rfile=$(mktemp) - # Set up nameservers - ( - [ -n "$PLC_NET_DNS1" ] && echo "nameserver $PLC_NET_DNS1" - [ -n "$PLC_NET_DNS2" -a "$PLC_NET_DNS1" != "$PLC_NET_DNS2" ] && echo "nameserver $PLC_NET_DNS2" - ) > $rfile - - if [ $PLC_DNS_ENABLED -eq 1 ] ; then - target=/etc/plc_resolv.conf + result "$MESSAGE" + ;; - r2file=$(mktemp) - echo "; generated by /etc/plc.d/network" >$r2file - if [ -n "${!PLC_BOOT_IP}" ] ; then - echo "nameserver ${!PLC_BOOT_IP}" >>$r2file - else - ip=$(gethostbyname ${!PLC_BOOT_HOST}) - if [ -n "$ip" ] ; then - echo "nameserver $ip" >>$r2file - fi - fi - changed=$(diff $r2file /etc/resolv.conf) - [ $changed -ne 0 ] && cp /etc/resolv.conf /etc/resolv.conf.bak - mv $r2file /etc/resolv.conf - else - target=/etc/resolv.conf + stop) + MESSAGE=$"Reverting network files" + if [ -f /etc/hosts_plc.backup ] ; then + mv -f /etc/hosts_plc.backup /etc/hosts fi - mv $rfile $target - chmod +r $target - + dialog "$MESSAGE" result "$MESSAGE" ;; esac