home *** CD-ROM | disk | FTP | other *** search
/ Chip: Linux Special / CorelLinux_CHIP.iso / live / sbin / isa-detect.pl < prev    next >
Encoding:
Perl Script  |  1999-11-12  |  3.1 KB  |  105 lines

  1. #!/usr/bin/perl
  2. ###################################
  3. #Name : isa-detect.pl
  4. #
  5. #Description: Program that detects isa network cards. 
  6. #            
  7. #Copyright (C) 1999 Corel Corporation 
  8. # EXHIBIT A -Corel Public License. 
  9. # The contents of this file are subject to the Corel Public License 
  10. # Version 1.0 (the "License"); you may not use this file except in 
  11. # compliance  with the License. You may obtain a copy of the License at 
  12. # linux.corel.com/linuxproducts/corellinux/license.htm. 
  13. # Software distributed under the License is distributed on an "AS IS" 
  14. # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
  15. # License for the specific language governing rights and limitations 
  16. # under the License. 
  17. # The Original Code is isa-detect.pl. 
  18. # The Initial Developer of the Original Code is Corel Corporation. 
  19. # Portions created by Corel are Copyright (C) 1999  All Rights Reserved. 
  20. # Contributor(s): ______________________________________. 
  21. ##############################################################
  22. use strict;
  23.  
  24. my (@modules, $elem, $dmesg_outp, $fline, $file_modules, $file_conf_modules, $card_num, $probe_driver_path) = ((), "", "", "", "", "", 1);
  25. my ($irq, $ioaddr) = ("", "");
  26. my ($kernel_ver) = ("");
  27.  
  28. # set the essential filenames (with full path)
  29. $file_modules="/etc/modules";
  30. $file_conf_modules="/etc/conf.modules";
  31. $kernel_ver=`uname -r`;
  32. chomp $kernel_ver;
  33. $probe_driver_path="/lib/modules/$kernel_ver/.isaprobe";
  34.  
  35. $card_num=1;
  36.  
  37. @modules = ("3c509", "ne");
  38.  
  39. # load 8390.o since some modules depend on it.  This module can safely
  40. # be loaded since it does not initialize any specfic card; it only
  41. # provides a set of functions for other modules
  42. `insmod $probe_driver_path/8390.o`;
  43.  
  44. # go through all the module names in above list
  45. foreach $elem (@modules)
  46. {
  47.     $ioaddr=0;
  48.     $irq=0;
  49.  
  50.     `dmesg -c>/dev/null`;
  51.     `insmod $probe_driver_path/$elem.o`;
  52.     $dmesg_outp = `dmesg |grep 'cdl:$elem.o'`;
  53.  
  54.     # if card probed successfully add the proper options line to
  55.     # conf.modules
  56.     if( $dmesg_outp ne "" ) {
  57.         $dmesg_outp =~ /^.+(0x[0-9a-z]+).+IRQ (\d+)/;
  58.         $ioaddr = $1;
  59.         $irq = $2;
  60.         # remove any existing lines relating to this module
  61.         # so we don't have duplicates
  62.         rm_line("$file_modules", "$elem");
  63.  
  64.         # we do not give the 3c509 module any io or irq arguments
  65.         if ( $elem ne "3c509" )
  66.         {
  67.             rm_line("$file_conf_modules", "options $elem");
  68.             `echo options $elem io=$ioaddr irq=$irq >> $file_conf_modules`;
  69.         }
  70.         rm_line("$file_modules", "$elem");
  71.         `echo $elem >> $file_modules`;
  72.         print "[network.";
  73.         print $card_num;
  74.         print "]\n";
  75.         print "        driver = $elem.o\n\n";
  76.         $card_num++;
  77.     # if card probe was not successful then remove any related lines
  78.     # from conf.modules and modules
  79.     } else {
  80.         rm_line("$file_conf_modules", "options $elem");
  81.         rm_line("$file_modules", "$elem");
  82.     }
  83. }
  84.  
  85. `rmmod 8390`;
  86.  
  87. # removes lines in $_[0] that start with $_[1]
  88. sub rm_line
  89. {
  90.     open(FIN, "<$_[0]");
  91.  
  92.     open(FOUT, ">$_[0].tmp") or die "rm_line: error opening $_[0].tmp for output $!";
  93.  
  94.     while($fline=<FIN>) {
  95.         unless( $fline =~ /^$_[1]/ ) {
  96.             print FOUT $fline;
  97.         }
  98.     }
  99.     close FIN;
  100.     close FOUT;
  101.     `mv $_[0].tmp $_[0]`;
  102. }
  103.