#!/bin/sh

# Step 1 - netenv must be called during boot
if grep 'SuSE Linux' /etc/issue > /dev/null; then
   echo seems to be a SuSE ...
   if grep '^/usr/sbin/netenv' /etc/rc.d/boot.local > /dev/null; then
      echo Found a call to netenv in /etc/rc.d/boot.local ...
   else
      echo Installing call to netenv in /etc/rc.d/boot.local ...
      echo '# Added by package netenv on '`date '+%x %X'` >> /etc/rc.d/boot.local
      echo /usr/sbin/netenv >> /etc/rc.d/boot.local
   fi
   NETWORK_CONFIG_BASEDIR=/etc/sysconfig/network
elif grep -i 'Red' /etc/issue | grep -i 'Hat' > /dev/null; then
   echo seems to be a Redhat ...
   if grep '^/usr/sbin/netenv' /etc/rc.d/rc.sysinit > /dev/null; then
      echo Found a call to netenv in /etc/rc.d/rc.sysinit ...
   else
      echo Installing call to netenv in /etc/rc.d/rc.sysinit ...
      echo '# Added by package netenv on '`date '+%x %X'` >> /etc/rc.d/rc.sysinit
      echo /usr/sbin/netenv >> /etc/rc.d/rc.sysinit
   fi
   NETWORK_CONFIG_BASEDIR=/etc/sysconfig/network-scripts
else
   echo Neither SuSE nor RedHat - Please read the docs in /usr/share/doc/packages/netenv
   exit 1
fi

# Check for multiple NIC's
if dmesg | grep eth1 > /dev/null 2>&1; then
   echo according to dmesg you have two or more NICS
   echo netenv assumes eth0 to be active. Fix manually if this is wrong !
fi

# Step 2 - Make the netenv-data (in /tmp/netenv) available to the
# system's network configuration procedure
if grep '. /tmp/netenv' $NETWORK_CONFIG_BASEDIR/ifcfg-eth0 > /dev/null; then
   echo /tmp/netenv seems to be already sourced from $NETWORK_CONFIG_BASEDIR/ifcfg-eth0 ...
else
   echo Installing sourcing /tmp/netenv in $NETWORK_CONFIG_BASEDIR/ifcfg-eth0 ...
   echo '# Added by package netenv on '`date '+%x %X'` >> $NETWORK_CONFIG_BASEDIR/ifcfg-eth0
   echo 'if [ -r /tmp/netenv ]; then . /tmp/netenv; fi' >> $NETWORK_CONFIG_BASEDIR/ifcfg-eth0
fi

