wok-current view get-wifi-firmware/stuff/get-wifi-firmware @ rev 20892
Remove ashism ==
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Feb 26 09:14:07 2019 +0100 (2019-02-26) |
parents | a13a6c5b176e |
children | c07aaa614a02 |
line source
1 #!/bin/sh
2 # install linux-wireless, wireless_tools and b43-fwcutter if needed.
4 MODULE=$(echo $0 | sed 's/.*get-\(.*\)-firmware/\1/')
5 ROOT="$2"
6 PKG=$MODULE-firmware
7 DEPENDS=""
9 MODULE_LIST=""
10 while read module desc ; do
11 [ "$MODULE" = "$module" ] && desc="$SHORT_DESC"
12 MODULE_LIST="$MODULE_LIST $module"
13 done <<EOT
14 b43 Broadcom $MODULE firmware.
15 b43legacy Broadcom $MODULE firmware (BCM4306 rev2 or 802.11b chips).
16 ipw2100 Intel PRO/Wireless 2100 firmware.
17 ipw2200 Intel PRO/Wireless 2200BG firmware.
18 iwlwifi-3945 Intel PRO/Wireless 3945ABG/BG firmware.
19 iwlwifi-4965 Intel WiFi Link 4965AGN firmware.
20 iwlwifi-5000 Intel Wireless WiFi Link 5000AGN firmware.
21 iwlwifi-5150 Intel Wireless WiFi Link 5150AGN firmware.
22 iwlwifi-1000 Intel Wireless WiFi Link 1000BGN firmware.
23 iwlwifi-6000 Intel Wireless WiFi Link 6000 Series Wi-fi Adapters.
24 rt61 new RT2x00 RT61 Wireless Lan firmware.
25 rt61pci new RT2x00 RT61 Wireless Lan firmware.
26 rt73 new RT2x00 RT73(RT2571W) Wireless Lan firmware.
27 rt73usb new RT2x00 RT73(RT2571W) Wireless Lan firmware.
28 rt2870usb RaLink RT2870USB (RT2870/RT2770) WiFi adapter.
29 zd1211 zd1211/zd1211rw Wireless Lan firmware.
30 zd1211rw zd1211/zd1211rw Wireless Lan firmware.
31 EOT
33 case "$MODULE" in
34 b43)
35 WEB_SITE="http://www.linuxwireless.org/en/users/Drivers/b43"
36 WGET_URL="http://mirror2.openwrt.org/sources"
37 VERSION=$(wget -O - $WGET_URL | sed \
38 '/broadcom-wl-[0-9\.]*.tar/!d;s/.*com-wl-\([0-9\.]*\).tar.*/\1/' | \
39 tail -n 1)
40 SUBDIR="broadcom-wl-$VERSION"
41 WGET_URL="$WGET_URL/$SUBDIR.tar.bz2"
42 DEPENDS="b43-fwcutter"
43 FWSET=wl_apsta_mimo.o
44 ;;
45 b43legacy)
46 WEB_SITE="http://downloads.openwrt.org/"
47 VERSION=$(wget -O - ${WEB_SITE}sources | sed \
48 '/wl_apsta/!d;s/.*>wl_apsta-\(.*\).o.*/\1/')
49 WGET_URL="${WEB_SITE}sources/wl_apsta-$VERSION.o"
50 DEPENDS="b43-fwcutter"
51 FWSET=wl_apsta-$VERSION.o
52 ;;
53 ipw2100)
54 VERSION=$(wget -O - http://$MODULE.sourceforge.net/firmware.php?fid=2 |\
55 sed "/$MODULE-fw/!d;s/.*fw-\(.*\).tgz.*/\1/")
56 WEB_SITE="http://$MODULE.sourceforge.net/"
57 WGET_URL="http://bughost.org/firmware/${MODULE}-fw-${VERSION}.tgz"
58 ;;
59 ipw2200)
60 VERSION=$(wget -O - http://$MODULE.sourceforge.net/firmware.php?fid=8 |\
61 sed "/$MODULE-fw/!d;s/.*fw-\(.*\).tgz.*/\1/")
62 WEB_SITE="http://$MODULE.sourceforge.net/"
63 WGET_URL="http://bughost.org/firmware/${MODULE}-fw-${VERSION}.tgz"
64 ;;
65 iwlwifi-*)
66 WEB_SITE="http://www.intellinuxwireless.org/?n=Downloads"
67 VERSION=$(wget -O - $WEB_SITE | sed -e "/$MODULE-/!d" -e \
68 's/.*-ucode-\([0-9\.-]*\).t.*/\1/;q')
69 WGET_URL="http://www.intellinuxwireless.org/iwlwifi/downloads/$MODULE-ucode-$VERSION.tgz"
70 ;;
71 rt61*)
72 WGET_URL="http://archlinux.c3sl.ufpr.br/other/rt2x00-rt61-fw"
73 VERSION=$(wget -O - $WGET_URL | sed '/Firmware/!d;s/.*_V\(.*\).zip.*/\1/')
74 WEB_SITE="http://www.ralinktech.com/"
75 WGET_URL="$WGET_URL/RT61_Firmware_V${VERSION}.zip"
76 ;;
77 rt73*)
78 WGET_URL="http://archlinux.c3sl.ufpr.br/other/rt2x00-rt71w-fw"
79 VERSION=$(wget -O - $WGET_URL | sed '/Firmware/!d;s/.*_V\(.*\).zip.*/\1/')
80 WEB_SITE="http://www.ralinktech.com/"
81 WGET_URL="$WGET_URL/RT71W_Firmware_V${VERSION}.zip"
82 ;;
83 rt2870usb)
84 WGET_URL="http://archlinux.c3sl.ufpr.br/other/${MODULE}-fw"
85 VERSION=$(wget -O - $WGET_URL | sed '/Firmware/!d;s/.*_V\(.*\).zip.*/\1/')
86 WEB_SITE="http://www.ralinktech.com/"
87 WGET_URL="$WGET_URL/RT2870_Firmware_V${VERSION}.zip"
88 ;;
89 zd1211*)
90 WGET_URL="http://mirrors.kernel.org/debian/pool/non-free/z/zd1211-firmware"
91 VERSION=$(wget -O - $WGET_URL | sed -e '/zd1211-firmware/!d' \
92 -e '/all.deb/!d' -e 's/.*>zd1211-firmware_\(.*\)_all.deb.*/\1/')
93 SHORT_DESC="zd1211/zd1211rw Wireless Lan firmware."
94 WEB_SITE="http://packages.debian.org/etch/zd1211-firmware"
95 WGET_URL="$WGET_URL/zd1211-firmware_${VERSION}_all.deb"
96 ;;
97 *)
98 case "$1" in
99 --install)
100 cd $(dirname $0)
101 for i in $MODULE_LIST ; do
102 ln -s get-wifi-firmware get-$i-firmware
103 done
104 exit 0 ;;
105 --get-free-firmware)
106 for i in $MODULE_LIST ; do
107 case "$i" in
108 iwlwifi*|rt*) get-$i-firmware
109 esac
110 done
111 exit 0 ;;
112 esac
113 echo "Unknown wifi driver. Please run one of the following commands:"
114 for i in $(cd $(dirname $0); ls get-*-firmware); do
115 [ -L $i ] || continue
116 [ "$(readlink $i)" = "get-wifi-firmware" ] || continue
117 echo " $i"
118 done
119 exit 1;;
120 esac
122 # Check if user is root to install.
123 if test $(id -u) != 0 ; then
124 echo -e "\nYou must be root to run `basename $0`."
125 echo -e "Please use 'su' and root password to become super-user.\n"
126 exit 0
127 fi
129 # Avoid reinstall
130 if [ -d $ROOT/var/lib/tazpkg/installed/$PKG ]; then
131 echo -e "\n$PKG package is already installed.\n"
132 exit 0
133 fi
135 # We need drivers, the extractor and tools.
136 for pkg in linux-wireless wireless_tools $DEPENDS
137 do
138 if [ ! -d $ROOT/var/lib/tazpkg/installed/$pkg ]; then
139 tazpkg get-install $pkg --root=$ROOT
140 fi
141 done
143 # Get files
144 TMP=/tmp/$(basename $0)$$
145 mkdir $TMP
146 TOP=$PWD
147 cd $TMP
148 wget $WGET_URL
149 TARBALL="$(basename $WGET_URL)"
150 if [ ! -s $TARBALL ]; then
151 cd $TOP
152 rm -rf $DIR
153 echo "Could not download $TARBALL. Exiting."
154 exit 1
155 fi
157 case "$WGET_URL" in
158 *rpm) rpm2cpio < $TARBALL | cpio -id;;
159 *deb) dpkg-deb -x $TARBALL . ;;
160 *bz2) tar xjf $TARBALL
161 cd $SUBDIR/driver;;
162 *tar.gz|*tgz) tar xzf $TARBALL;;
163 *zip) unzip $TARBALL;;
164 *o) ;;
165 esac
167 # Create pseudo package
168 mkdir -p $PKG-$VERSION/fs/lib/firmware $PKG-$VERSION/fs/usr/share/licenses
169 case "$MODULE" in
170 b43*) b43-fwcutter -w "$PKG-$VERSION/fs/lib/firmware" $FWSET;;
171 ipw2200) cp ${MODULE}-fw-$VERSION/*LICENSE* $PKG-$VERSION/fs/usr/share/licenses/intel-$MODULE-LICENSE.txt
172 mv ${MODULE}-fw-$VERSION/* $PKG-$VERSION/fs/lib/firmware;;
173 ipw2100) cp *LICENSE* $PKG-$VERSION/fs/usr/share/licenses/intel-$MODULE-LICENSE.txt
174 mv *.fw* *LICENSE* $PKG-$VERSION/fs/lib/firmware;;
175 rt*)
176 mv RT*_Firmware_V$VERSION/*.bin $PKG-$VERSION/fs/lib/firmware
177 mv RT*_Firmware_V$VERSION/*LICENSE* $PKG-$VERSION/fs/usr/share/licenses/ralink-rt61-LICENSE.txt;;
178 iwlwifi*) mv iwlwifi*/iwlwifi*.ucode $PKG-$VERSION/fs/lib/firmware
179 mv iwlwifi*/*LICENSE* $PKG-$VERSION/fs/usr/share/licenses/intel-iwlwifi-LICENSE.txt ;;
180 zd1211*)
181 mv lib/firmware/zd1211 $PKG-$VERSION/fs/lib/firmware
182 for i in $(cd usr/lib/hotplug/firmware; ls); do
183 target=$(readlink usr/lib/hotplug/firmware/$i)
184 ln -s $(basename $target) $PKG-$VERSION/fs/lib/firmware/zd1211/$i
185 done;;
186 esac
188 # Creat receipt
189 cat > $PKG-$VERSION/receipt <<EOT
190 PACKAGE="$PKG"
191 VERSION="$VERSION"
192 CATEGORY="non-free"
193 SHORT_DESC="$SHORT_DESC."
194 WEB_SITE="$WEB_SITE"
195 DEPENDS="linux-wireless wireless_tools $DEPENDS"
196 EOT
198 # Pack
199 tazpkg pack $PKG-$VERSION
201 # Install pseudo package
202 tazpkg install $PKG-$VERSION.tazpkg --root=$ROOT
204 # Clean
205 cd $TOP
206 rm -rf $TMP
208 if [ "$1" = "--firmware" ] ; then
209 echo "just install firmare: yes"
210 JUST_INSTALL_FIRMWARE="yes"
211 fi
213 if [ ! "$JUST_INSTALL_FIRMWARE" = "yes" ]; then
214 echo "configuring and loading module ..."
215 # Check if we need wpa_supplicant
216 . $ROOT/etc/network.conf
217 if [ $WIFI_KEY_TYPE = "wpa" ] || [ $WIFI_KEY_TYPE = "WPA" ]; then
218 if [ ! -d $ROOT/var/lib/tazpkg/installed/wpa_supplicant ]; then
219 tazpkg get-install wpa_supplicant --root=$ROOT
220 fi
221 fi
223 # Configure /etc/network.conf and start connexion
224 sed -i s/'WIFI="no"'/'WIFI="yes"'/ $ROOT/etc/network.conf
226 # Load module
227 if [ -z "$ROOT" -a -n "$(modprobe -l $MODULE)" ]; then
228 echo "Loading module: $MODULE..."
229 if modprobe $MODULE ; then
230 sleep 2
231 /etc/init.d/network.sh restart
232 fi
233 fi
234 fi