#!/usr/bin/perl
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Copyright (c) 1999 - 2000, Intel Corporation 
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, 
#    this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation 
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of Intel Corporation nor the names of its contributors 
#    may be used to endorse or promote products derived from this software 
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
#
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------

#   /***************************************************************************
#   **                                                                        **
#   ** INTEL CORPORATION                                                      **
#   **                                                                        **
#   ** This software is supplied under the terms of the license included      **
#   ** above.  All use of this software must be in accordance with the terms  **
#   ** of that license.                                                       **
#   **                                                                        **
#   **  Abstract:                                                             **
#   **    Configuration script for ANS -step 1/3- Base Driver installation    **
#   **    (Redhat).                                                           **
#   **                                                                        **
#   ***************************************************************************/
use general;

# PROBING LOOP - LOAD ALL DRIVERS
print "\n-- Activating all network interfaces.\n\n";
chdir $IFCFGDIR;
@interfaces=`ls ifcfg* | grep -v '(ifcfg-lo|:)' | grep -v 'ifcfg-ippp[0-9]+$' | grep 'ifcfg-[a-z0-9]+$' | sed 's/^ifcfg-//g'`;

foreach (@interfaces)
{
	 `ifconfig $_ 2>&1 > /dev/null`;
}

print "-- Removing all Intel interfaces.\n\n";
print "The configuration utility could now automatically bring down ALL network\n";
print "interfaces, or let you manually select only the interfaces concerning Intel\n";
print "adapters. Would you like the configuration utility to remove all network\n";
print "interfaces automatically? ";

$auto = (options("y", "n") eq "y");
foreach (`cat /proc/net/dev`)
{
	 if (s/^\ *(.*):.*$/\1/)
	 {
		  chomp;
		  unless ($auto)
		  {
				print "Remove network interface $_? ";
				$res  = (options("y", "n") eq "y");
		  }
		  `ifconfig $_ down 2>&1 > /dev/null` if ($res || $auto);
	 }
}

print "\n-- Replacing old Intel drivers with new drivers.\n\n";

foreach (@MODS100)
{
	 remove_module($_);
}
`insmod $MODULEDIR/e100.o 2>&1 > /dev/null`;
foreach (@MODS1000)
{
	 remove_module($_);
}
`insmod $MODULEDIR/e1000.o 2>&1 > /dev/null`;

open (OUT, ">>$CONF");
print OUT "#NEXT LINES INSERTED BY IANS CONFIGURATION PROCESS\n";
foreach (`ls $PROCDIR`)
{
	 chomp;
	 next unless -d "$PROCDIR/$_";
	 if (`cat $PROCDIR/$_/Driver_Name | grep \\ PRO/100\\ `)
	 {
		  print OUT "alias $_ e100\n";
	 }
	 else
	 {
		  print OUT "alias $_ e1000\n";
	 }
}	 
close(OUT);

`insmod $MODULEDIR/ians.o 2>&1 > /dev/null`;

sub remove_module
{
	 my($mod_name) = @_;
	 my(@file);
	 `rmmod $mod_name 2>&1 > /dev/null`;
	 @file = `cat $CONF`;
	 open (OUT, ">$CONF");
	 foreach $line (@file)
	 {
		  if ($line=~/^[^#]*\b$mod_name\b/)
		  {
				print OUT "#NEXT LINE COMMENTED OUT BY IANS CONFIGURATION PROCESS\n";
				print OUT "#$line\n";
		  }
		  else
		  {
				print OUT $line;
		  }
	 }
	 close(OUT);
}







