- moved all dns related functionality to the plc.d/dns file
[myplc.git] / plc.d / network
index 141bc50..d5f615f 100755 (executable)
@@ -22,6 +22,7 @@ case "$1" in
        MESSAGE=$"Generating network files"
        dialog "$MESSAGE"
 
+       mv -f /etc/hosts /etc/hosts_plc.backup
        hfile=$(mktemp)
        # Minimal /etc/hosts
        (
@@ -38,48 +39,21 @@ case "$1" in
                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
+       grep -v "^#" /etc/hosts >> $hfile
+       echo "#generated by /etc/plc.d/network" >/etc/hosts
+       echo "127.0.0.1 localhost.localdomain localhost" >> $hfile
+       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
-
        result "$MESSAGE"
        ;;
 esac