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