home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- ###################################
- #Name : isa-detect.pl
- #
- #Description: Program that detects isa network cards.
- #
- #Copyright (C) 1999 Corel Corporation
- #
- # EXHIBIT A -Corel Public License.
- #
- # The contents of this file are subject to the Corel Public License
- # Version 1.0 (the "License"); you may not use this file except in
- # compliance with the License. You may obtain a copy of the License at
- # linux.corel.com/linuxproducts/corellinux/license.htm.
- # Software distributed under the License is distributed on an "AS IS"
- # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- # License for the specific language governing rights and limitations
- # under the License.
- # The Original Code is isa-detect.pl.
- # The Initial Developer of the Original Code is Corel Corporation.
- # Portions created by Corel are Copyright (C) 1999 All Rights Reserved.
- # Contributor(s): ______________________________________.
- ##############################################################
- use strict;
-
- my (@modules, $elem, $dmesg_outp, $fline, $file_modules, $file_conf_modules, $card_num, $probe_driver_path) = ((), "", "", "", "", "", 1);
- my ($irq, $ioaddr) = ("", "");
- my ($kernel_ver) = ("");
-
- # set the essential filenames (with full path)
- $file_modules="/etc/modules";
- $file_conf_modules="/etc/conf.modules";
- $kernel_ver=`uname -r`;
- chomp $kernel_ver;
- $probe_driver_path="/lib/modules/$kernel_ver/.isaprobe";
-
- $card_num=1;
-
- @modules = ("3c509", "ne");
-
- # load 8390.o since some modules depend on it. This module can safely
- # be loaded since it does not initialize any specfic card; it only
- # provides a set of functions for other modules
- `insmod $probe_driver_path/8390.o`;
-
- # go through all the module names in above list
- foreach $elem (@modules)
- {
- $ioaddr=0;
- $irq=0;
-
- `dmesg -c>/dev/null`;
- `insmod $probe_driver_path/$elem.o`;
- $dmesg_outp = `dmesg |grep 'cdl:$elem.o'`;
-
- # if card probed successfully add the proper options line to
- # conf.modules
- if( $dmesg_outp ne "" ) {
- $dmesg_outp =~ /^.+(0x[0-9a-z]+).+IRQ (\d+)/;
- $ioaddr = $1;
- $irq = $2;
- # remove any existing lines relating to this module
- # so we don't have duplicates
- rm_line("$file_modules", "$elem");
-
- # we do not give the 3c509 module any io or irq arguments
- if ( $elem ne "3c509" )
- {
- rm_line("$file_conf_modules", "options $elem");
- `echo options $elem io=$ioaddr irq=$irq >> $file_conf_modules`;
- }
- rm_line("$file_modules", "$elem");
- `echo $elem >> $file_modules`;
- print "[network.";
- print $card_num;
- print "]\n";
- print " driver = $elem.o\n\n";
- $card_num++;
- # if card probe was not successful then remove any related lines
- # from conf.modules and modules
- } else {
- rm_line("$file_conf_modules", "options $elem");
- rm_line("$file_modules", "$elem");
- }
- }
-
- `rmmod 8390`;
-
- # removes lines in $_[0] that start with $_[1]
- sub rm_line
- {
- open(FIN, "<$_[0]");
-
- open(FOUT, ">$_[0].tmp") or die "rm_line: error opening $_[0].tmp for output $!";
-
- while($fline=<FIN>) {
- unless( $fline =~ /^$_[1]/ ) {
- print FOUT $fline;
- }
- }
- close FIN;
- close FOUT;
- `mv $_[0].tmp $_[0]`;
- }
-