merged grml-quickconfig nonblocking branch
[grml-scripts.git] / usr_sbin / ndiswrapper.sh
1 #!/bin/bash
2 # Filename:      ndiswrapper.sh
3 # Purpose:       NdisWrapper configuration script
4 # Authors:       (c) Martin Oehler 2004, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Fri Apr 21 22:22:12 CEST 2006 [mika]
8 ################################################################################
9
10 PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin"
11 export PATH
12
13 # Get root
14 if [ $UID != 0 ] ; then
15    echo Error: become root before starting $0 >& 2
16    exit 100
17 fi
18 unset SUDO_COMMAND
19
20 # XDIALOG_HIGH_DIALOG_COMPAT=1
21 # export XDIALOG_HIGH_DIALOG_COMPAT
22 # XDIALOG_FORCE_AUTOSIZE=1
23 # export XDIALOG_FORCE_AUTOSIZE
24
25 TMP=$(mktemp)
26
27 DIALOG="dialog"
28 # [ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"
29
30 BACKTITLE="GRML NDISWRAPPER TOOL"
31
32 # this error is displayed when something is wrong eith the
33 # inf file
34 inf_error() {
35   $DIALOG --title "$BACKTITLE" --backtitle "ERROR" --msgbox "The selected file is no *.inf file or the *.inf file is invalid, exiting." 12 75;
36 }
37
38
39 # at first we show the usual disclaimer that the usage of this
40 # script could simply destroy everything
41
42 # dialog doesn't knows --center
43 if [ "$DIALOG" = "dialog" ]; then
44   $DIALOG --title "$BACKTITLE" --backtitle "DISCLAIMER" --msgbox "This is the configuration tool for the ndiswrapper utilities. \n
45 Be aware that loading a windows driver file for your wlan \n
46 card using this tool could freeze your system. \n
47 \n
48 You need matching driver.inf and driver.sys files residing on \n
49 a mounted data medium. After the windows drivers have been \n
50 successfully loaded via the ndiswrapper, you have to configure \n
51 your wlan settings via iwconfig. Future releases of this script \n
52 will include this. \n
53 \n
54 Please send your feedback to <oehler@knopper.net>" 16 75;
55 else
56   $DIALOG --center --title "$BACKTITLE" --backtitle "DISCLAIMER" --msgbox "This is the configuration tool for the ndiswrapper utilities. \n
57 Be aware that loading a windows driver file for your \n
58 wlan card using this tool could freeze your system. \n
59 \n
60 You need matching driver.inf and driver.sys files residing on \n
61 a mounted data medium. After the windows drivers have been \n
62 successfully loaded via the ndiswrapper, you have to configure \n
63 your wlan settings via iwconfig. Future releases of this script \n
64 will include this. \n
65 \n
66 Please send your feedback to \n
67 <oehler@knopper.net>" 12 75;
68 fi
69
70 $DIALOG --title "$BACKTITLE" --backtitle "SELECT <DRIVER>.INF FILE" --fselect "/home/grml" 12 75 2>"$TMP"; read DRIVER_PATH <"$TMP"; rm -f "$TMP";
71
72 test -x "/usr/sbin/ndiswrapper" || { echo "NdisWrapper not found, exiting." >&2; exit 1; }
73 test -x "/sbin/modprobe" || { echo "modprobe not found, exiting." >&2; exit 1; }
74 test -e $DRIVER_PATH || { echo "$DRIVER_PATH does not exist, exiting." >&2; exit 1; }
75 case "$DRIVER_PATH" in
76   *\.inf*) NUM=`grep -c "sys" "$DRIVER_PATH"`
77            if [ "$NUM" -lt 1 ]; then
78              inf_error; exit 1;
79            fi;;
80   *) inf_error; exit 1;
81 esac
82
83 # how much lines are in /proc/net/wireless
84 LINES1=`cat /proc/net/wireless | wc -l`
85
86 ndiswrapper -i $DRIVER_PATH
87 modprobe ndiswrapper
88 ndiswrapper -m
89
90 # have we got a new device?
91 LINES2=`cat /proc/net/wireless | wc -l`
92
93 if [ "$LINES2" -gt "$LINES1" ]; then
94   $DIALOG --title "$BACKTITLE" --backtitle "RESULT" --msgbox "The ndiswrapper module has been loaded. You may configure your wlan card with iwconfig now." 12 75 2>"$TMP"; [ "$?" != "0" ] && return 1; rm -f "$TMP";
95 else
96   $DIALOG --title "$BACKTITLE" --backtitle "RESULT" --msgbox "The ndiswrapper module has been loaded but there is no new device. Perhaps NdisWrapper is not working with your driver file." 12 75 2>"$TMP"; [ "$?" != "0" ] && return 1; rm -f "$TMP";
97 fi
98
99 ## END OF FILE #################################################################