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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
#!/usr/bin/env /bin/bash
echo "Deprecated"
exit 0
function check_params()
{
if [ "$1" ]; then
DEST="$1"
export DEST=${DEST/%\//}/
export MAC80211=${DEST}drivers/net/wireless/mac80211/
return 0
fi
cat <<EOF
Usage: patch_kernel /PATH/TO/KERNEL
eg: patch_kernel /lib/modules/\$(uname -r)/source
EOF
}
function verify_continue()
{
cat << EOF
This will install this driver into your kernel tree located here:
${DEST}
If you would like to install to a different location, run
this as follows:
make KSRC=/path/to/kernel patch_kernel
EOF
read -p "Do you wish to continue? [Yn] " reply
case $reply in
Y|y|"")
return 0
;;
*) echo "Terminating patch prcoess."
return 1
;;
esac
if [ "$(shell whoami)" != "root" ]; then
cat << EOF
If this fails, you may need to be root to patch the kernel.
EOF
fi
}
function clean_tree()
{
cat <<EOF
Setting 'iwlwifi' entries in:
${MAC80211}Kconfig
EOF
[ -e ${MAC80211}Kconfig ] &&
grep -v "^source.*iwlwifi" ${MAC80211}Kconfig > .tmp-Kconfig
echo "source \"drivers/net/wireless/mac80211/iwlwifi/Kconfig\"" >> \
.tmp-Kconfig
cat <<EOF
Setting 'iwlwifi' entries in:
${MAC80211}Makefile
EOF
[ -e ${MAC80211}Makefile ] &&
grep -v "CONFIG_IWLWIFI" \
${MAC80211}Makefile > .tmp-Makefile
echo 'obj-$(CONFIG_IWLWIFI) += iwlwifi/' >> .tmp-Makefile
if test -f ${DEST}.config; then
cat <<EOF
Clearing 'iwlwifi' entries from:
${DEST}.config
EOF
grep -v "CONFIG_IWLWIFI" ${DEST}.config |
grep -v "CONFIG_IWL3945" |
grep -v "CONFIG_IWL4965" > .tmp-config
fi
if test -f ${DEST}include/linux/autoconf.h; then
cat <<EOF
Clearing 'iwlwifi' entries from:
${DEST}include/linux/autoconf.h
EOF
grep -v "CONFIG_IWLWIFI" ${DEST}include/linux/autoconf.h |
grep -v "CONFIG_IWL3945" |
grep -v "CONFIG_IWL4965" > .tmp-autoconf
fi
grep -q mac80211 ${DEST}drivers/net/wireless/Kconfig || {
cat <<EOF
Adding mac80211/Kconfig to:
${DEST}drivers/net/wireless
EOF
cp ${DEST}drivers/net/wireless/Kconfig .tmp-wireless-Kconfig
sed -i -e "s,endmenu,source \"drivers/net/wireless/mac80211/Kconfig\"\nendmenu,g" .tmp-wireless-Kconfig
}
grep -q mac80211 ${DEST}drivers/net/wireless/Makefile || {
cat <<EOF
Adding mac80211/Makefile to:
${DEST}drivers/net/wireless
EOF
cp ${DEST}drivers/net/wireless/Makefile .tmp-wireless-Makefile
echo 'obj-y += mac80211/' >> .tmp-wireless-Makefile
}
return 0
}
function check_perms()
{
[ -d ${MAC80211}iwlwifi ] && [ -w ${MAC80211}iwlwifi ] && return 0
[ -d ${MAC80211} ] && [ -w ${MAC80211} ] && return 0
[ -d ${DEST}drivers/net/wireless/ ] &&
[ -w ${DEST}drivers/net/wireless/ ] && return 0
cat <<EOF
Insufficient permissions to write to:
${MAC80211}iwlwifi
Aborting. Perhaps try running as root?
EOF
return 1
}
function copy_files()
{
echo "Copying files..."
cp README.iwlwifi ${DEST}Documentation/networking
mkdir -p ${MAC80211}iwlwifi
cp compatible/{Kconfig,Makefile} ${MAC80211}iwlwifi/
cp compatible/*.{c,h} ${MAC80211}iwlwifi/
}
function add_to_tree()
{
echo "Installing potentially modified files..."
[ -e ${MAC80211}Kconfig ] && cp ${MAC80211}Kconfig ${MAC80211}Kconfig.bk
[ -e ${MAC80211}Makefile ] && cp ${MAC80211}Makefile ${MAC80211}Makefile.bk
if test -f ${DEST}include/linux/autoconf.h; then
cp ${DEST}include/linux/autoconf.h \
${DEST}include/linux/autoconf.h.bk
mv -f .tmp-autoconf ${DEST}include/linux/autoconf.h
fi
if test -f ${DEST}.config; then
cp ${DEST}.config ${DEST}.config.bk
mv -f .tmp-config ${DEST}.config
fi
mv -f .tmp-Kconfig ${MAC80211}Kconfig
mv -f .tmp-Makefile ${MAC80211}Makefile
[ -e .tmp-wireless-Kconfig ] &&
mv -f .tmp-wireless-Kconfig ${DEST}drivers/net/wireless/Kconfig
[ -e .tmp-wireless-Makefile ] &&
mv -f .tmp-wireless-Makefile ${DEST}drivers/net/wireless/Makefile
return 0
}
function show_results()
{
cat <<EOF
Kernel has been updated to include:
iwlwifi drivers for Linux
you can now edit your kernel's configuration via 'make menuconfig' and
build as you would any kernel image and set of modules.
EOF
}
check_params $@ &&
scripts/check_kernel "${DEST}" &&
verify_continue &&
check_perms &&
clean_tree &&
copy_files &&
add_to_tree &&
show_results
|