home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / findhostbridge < prev    next >
Encoding:
Text File  |  2006-05-09  |  3.7 KB  |  150 lines

  1. #!/usr/bin/puppybasic
  2.  
  3. include "/usr/lib/wxbasicscript/basefunctions.inc"
  4.  
  5.  
  6. shell("lspci >/tmp/findhostbridge.tmp")
  7. pci = readfiletolist("/tmp/findhostbridge.tmp")
  8. removefile("/tmp/findhostbridge.tmp")
  9.  
  10. pcihash = {}
  11.  
  12.  
  13. for i=0 to count(pci)-1
  14.   'print pci[i]
  15.  
  16.   pci[i]= ucase(pci[i])
  17.  
  18.   if instr( pci[i] , ":") then
  19.     id = cutleft( pci[i] , ": ")
  20.     id = trim(id)
  21.  
  22.   // check for integrated chipsets
  23.  
  24.     if left( id , 4 ) = "10B9" then
  25.       hostbridge = "ali-agp"
  26.       lsmod = "ali_agp"
  27.       shell("modprobe " & hostbridge)
  28.       shell( "lsmod | grep \"^" & lsmod & "\" >/tmp/findhostbridge.tmp")
  29.       isused = readfile("/tmp/findhostbridge.tmp")
  30.       removefile("/tmp/findhostbridge.tmp")
  31.       if right(isused , 1) = "1" then
  32.         print hostbridge
  33.         end
  34.       else
  35.         shell("rmmod " & hostbridge )
  36.       end if
  37.     end if
  38.     if left( id , 4 ) = "1002" then
  39.       hostbridge = "ati-agp"
  40.       lsmod = "ati_agp"
  41.       shell("modprobe " & hostbridge)
  42.       shell( "lsmod | grep \"^" & lsmod & "\" >/tmp/findhostbridge.tmp")
  43.       isused = readfile("/tmp/findhostbridge.tmp")
  44.       removefile("/tmp/findhostbridge.tmp")
  45.       if right(isused , 1) = "1" then
  46.         print hostbridge
  47.         end
  48.       else
  49.         shell("rmmod " & hostbridge )
  50.       end if
  51.     end if
  52.     if left( id , 4 ) = "1039" then
  53.       hostbridge = "sis-agp"
  54.       lsmod = "sis_agp"
  55.       shell("modprobe " & hostbridge)
  56.       shell( "lsmod | grep \"^" & lsmod & "\" >/tmp/findhostbridge.tmp")
  57.       isused = readfile("/tmp/findhostbridge.tmp")
  58.       removefile("/tmp/findhostbridge.tmp")
  59.       if right(isused , 1) = "1" then
  60.         print hostbridge
  61.         end
  62.       else
  63.         shell("rmmod " & hostbridge )
  64.       end if
  65.     end if
  66.     if left( id , 4 ) = "1166" then
  67.       hostbridge = "sworks-agp"
  68.       lsmod = "sworks_agp"
  69.       shell("modprobe " & hostbridge)
  70.       shell( "lsmod | grep \"^" & lsmod & "\" >/tmp/findhostbridge.tmp")
  71.       isused = readfile("/tmp/findhostbridge.tmp")
  72.       removefile("/tmp/findhostbridge.tmp")
  73.       if right(isused , 1) = "1" then
  74.         print hostbridge
  75.         end
  76.       else
  77.         shell("rmmod " & hostbridge )
  78.       end if
  79.     end if
  80.  
  81.   // check for single chipsets
  82.     if instr(id , "(") then
  83.       id = cutright( id , "(" )
  84.     end if
  85.     id = trim(id)
  86. '    id = replace( id , "8086:" ,"" )
  87.      id = cutleft( id , ":")
  88.     if len(id) = 4 then
  89.       pcihash[id] = id
  90.       'print pcihash[id]
  91.     end if
  92.   end if
  93. next
  94.  
  95. hostbridge = ""
  96.  
  97. shell("ls /lib/modules/2.6/char/agp/*.ko>/tmp/findhostbridge.tmp")
  98. modules = readfiletolist("/tmp/findhostbridge.tmp")
  99. removefile("/tmp/findhostbridge.tmp")
  100.  
  101. for each module in modules
  102. if instr(module , "-") then
  103. if instr(module , "/") then
  104.   module = mycutleftfromright(module , "/")
  105.   module = replace(module , ".ko" , "")
  106.  
  107.   shell("modinfo " & module & " >/tmp/findhostbridge.tmp")
  108.   agp = readfiletolist("/tmp/findhostbridge.tmp")
  109.   removefile("/tmp/findhostbridge.tmp")
  110.  
  111.   for i=0 to count(agp)-1
  112.  
  113.       id = cutleft( agp[i] , "d0000")
  114.       id = left(id , 4)
  115.       if pcihash[id] then
  116.         'print module & " hostbridge found"
  117.         hostbridge = module
  118.       end if
  119.       'print id
  120.  
  121.   next
  122. end if
  123. end if
  124. next
  125.  
  126.  
  127. if hostbridge = "" then
  128.   'print "no hostbridge found, exiting..."
  129. else
  130.   'print "hostbridge found: " & hostbridge
  131.    shell("modprobe " & hostbridge)
  132.    print hostbridge
  133. end if
  134.  
  135.  
  136.   ////////////////////////////////////////////////////////////////////////////////////
  137.  // 
  138. //    return right part of a string, counting the seperator from left
  139.  
  140. function mycutleftfromright( thestring , splitter )
  141.  
  142.     x = rinstr( thestring , splitter )
  143.     thepath = right( thestring , len(thestring)-x-len(splitter)+1 )
  144.     'print "---" & thepath
  145.  
  146.     return thepath
  147.  
  148. end function
  149.  
  150.