~nilsschlupp/auto-ndiswrapper/rewrite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# Auto-NDISwrapper
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; Version 2
# of the License.

import os
import commands
import sys
import string
import re


print "Auto-NDISwrapper 0.1"

#Gets the id of all the pci devices
outtext = commands.getoutput("lspci -n")

#Stores the pci ids in a list
L = outtext.split()

#Stores the ids of all the supported cards in a dictionary with the website where the driver is found
#Later on we will need something better than this as we will need to assoaciate also the preffered driver
D = {'14e4:4324':'http://www.actiontecsupport.com/files/Prism80211b2KXPDrivers.exe','0000:0000':'http://www.yahoo.com/'}

def searchcard(L,D):
	
	card = -1	
	#Looks if card is in the list of supported cards
	for item in L:
		if item in D:
			card = item
			return card

card = searchcard(L,D)

#This is thanks to mintwifi.py, GPL by the way
if card == -1:
	os.system("lspci | grep \"Network controller\" > /tmp/detected_wireless_devices")
	devices_file = open("/tmp/detected_wireless_devices")
	for device_item in devices_file.readlines():
		deviceArray = device_item.split()
		device = ' '.join(deviceArray[3:])
		pci_id_line = commands.getoutput("lspci -n | grep " + deviceArray[0]) 
		pci_id_array = pci_id_line.split()
		pci_id = ' '.join(pci_id_array[2:])	
		print "Sorry, card not yet supported by Auto-NDISwrapper but most likely there are other solutions"
		print "Save this output as it will help other people give you support"
		print "  -- " + device 
		print "      ==> PCI ID = " + pci_id

else:
	print "Card Supported"
	print "Fetching driver for card with pci id", card
	URL = D[card]
	os.system(string.join(("wget ",URL)))	
	Files = URL.split("/")
	#Will we need a elif for every compression format?
	if ".exe" in URL:
		os.system(string.join(("unzip",Files[-1])))
		Inf = os.system("ls -t")
		#This is a really ugly solution does anyone know of anything better
		if ".inf" in Inf
			for item in Inf
				if ".inf" in item
					os.system(string.join(("sudo ndiswrapper -i ",item)))
					os.system("ndiswrapper -l")
					os.system("sudo modeprobe ndiswrapper")		
					os.system("sudo ndiswrapper -m")