sample: eliminate clever code to determine which proc file is accessed
[madwifi/.git] / scripts / find-madwifi-modules.sh
1 #!/bin/sh
2
3 if [ -z "${1}" ] ; then
4         echo "Purpose:"
5         echo "Locate all madwifi-related kernel modules for a given kernel"
6         echo "(including all its subdirectories)."
7         echo
8         echo "Usage:"
9         echo "$0 [-l] [-r] <kernelrelease> [destdir]"
10         echo
11         echo "<kernelrelease>: the kernel release that madwifi has been compiled for"
12         echo "[destdir]: destination directory for the compiled madwifi modules (optional)"
13         echo "-l list the modules we find."
14         echo "-r remove the modules we find."
15         echo "If neither -l or -r is specified, the user will be prompted."
16         echo
17         exit 1
18 fi
19
20 LIST_CMD=0
21 REMOVE_CMD=0
22 while [ 1 ]; do
23         case $1 in
24                 -l)
25                         LIST_CMD=1
26                         shift;
27                         ;;
28                 -r)
29                         REMOVE_CMD=1
30                         shift;
31                         ;;
32                 *)      
33                         break;
34                         ;;
35         esac;
36 done;
37
38 KVERS="${1}"
39
40 if [ -n "${2}" ]; then
41         KDEST="${2}"
42 else
43         KDEST=""
44 fi
45
46 SEARCH="${KDEST}/lib/modules/${KVERS}"
47
48 PATTERN="^.*\/(ath_(hal|pci|rate_[^.]*)\.k?o)|(wlan(_(acl|ccmp|scan_(ap|sta)|tkip|wep|xauth))?\.k?o)$"
49 OLD_MODULES=$(find ${SEARCH} -type f -regex '.*\.k?o' 2>/dev/null | grep -w -E "${PATTERN}")
50
51
52
53 if [ -n "${OLD_MODULES}" ]; then
54         if [ "$LIST_CMD" -eq 1 ] || [ "$REMOVE_CMD" -eq 1 ]; then
55                 if [ "$LIST_CMD" -eq 1 ]; then
56                         for m in ${OLD_MODULES}; do echo ${m}; done
57                 fi;
58                 if [ "$REMOVE_CMD" -eq 1 ]; then
59                         rm -f ${OLD_MODULES}
60                 fi;
61         else
62                 echo ""
63                 echo "WARNING:"
64                 echo "It seems that there are modules left from previous MadWifi installations."
65                 echo "If you are unistalling the MadWifi modules please press \"r\" to remove them."
66                 echo "If you are installing new MadWifi modules, you should consider removing those"
67                 echo "already installed, or else you may experience problems during operation."
68                 echo "Remove old modules?"
69                 
70                 while true; do
71                         echo
72                         echo -n "[l]ist, [r]emove, [i]gnore or e[x]it (l,r,i,[x]) ? "
73                         echo
74                         read REPLY
75                         case ${REPLY} in
76                                 l|L)
77                                         for m in ${OLD_MODULES}; do echo ${m}; done
78                                         continue
79                                         ;;
80                                 
81                                 r|R)
82                                         rm -f ${OLD_MODULES}
83                                         exit
84                                         ;;
85                         
86                                 i|I)
87                                         exit 0
88                                         ;;
89                 
90                                 x|X)
91                                         exit 1
92                                         ;;
93         
94                                 *)
95                                         continue
96                                         ;;
97                         esac
98                 done
99         fi;
100 fi
101
102 exit 0