fwcutter/make: Avoid _DEFAULT_SOURCE warning
[b43-tools.git] / DEBIAN / postinst
1 #!/bin/sh
2
3 set -e
4
5 . /usr/share/debconf/confmodule
6
7 tmp=`mktemp -q -d`
8
9 latest_firmware ()
10 {
11 cd $tmp
12 export FIRMWARE_INSTALL_DIR="/lib/firmware"
13
14 # use apt proxy
15 APT_PROXIES=$(apt-config shell \
16 http_proxy Acquire::http::Proxy \
17 https_proxy Acquire::https::Proxy \
18 ftp_proxy Acquire::ftp::Proxy \
19 )
20
21 if [ -n "$APT_PROXIES" ]; then
22         eval export $APT_PROXIES
23 fi
24
25 wget --timeout=60 http://downloads.openwrt.org/sources/wl_apsta-3.130.20.0.o
26 if [ $? -ne 0 ]; then
27         echo "Some problem occurred during the firmware download. Please check your internet connection."
28         exit 0
29     else
30         if [ -d /lib/firmware/b43legacy ]; then
31            echo "Deleting old extracted firmware..."
32            rm -rf /lib/firmware/b43legacy
33         fi
34 fi
35 b43-fwcutter -w "$FIRMWARE_INSTALL_DIR" wl_apsta-3.130.20.0.o
36 rm -rf $tmp
37 }
38
39 # check environment
40 if [ "$(stat -c %d/%i /)" != "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ];
41  then
42     echo "A chroot environment has been detected."
43     echo "Remember this firmware needs kernel >= 2.6.25."
44     latest_firmware
45     exit 0
46  else
47     echo "No chroot environment found. Starting normal installation"
48 fi
49
50 # install firmware unconditional if the corresponding debconf value is true
51 # this is usefull for live-systems or similar systems that should work on
52 # changing hardware
53 db_get b43-fwcutter/install-unconditional
54 if [ "$RET" = "true" ] ; then
55     latest_firmware
56     exit 0
57 fi
58
59 # Fix for BCM4306 [14e4:4320] (rev 02)
60 chip=`lspci -n | grep -o "14e4:4320 (rev 02)"` || true
61 if [ "$chip" ] ; then
62    echo "Your card is BCM4306 [14e4:4320] (rev 02), using b43legacy firmware"
63    latest_firmware
64    exit 0
65 fi
66
67 # check chip
68 supported=0
69 pci=`lspci -n | grep -o "14e4:[1234567890abcdef]\+"` || true
70
71 if [ -n "$pci" ]; then
72         for device in $pci; do
73                 device_id=`echo $device | cut -d: -f2`
74                 case $device_id in
75                 4301 | 4306 | 4320 | 4324 |  4325)
76                         supported=1
77                         break
78                 ;;
79                 esac
80         done
81 fi
82
83 if [ "$supported" = 0 ]; then
84         echo "No supported card found."
85         echo "Use b43 firmware. This is just for the b43legacy driver."
86         echo "Aborting."
87         exit 0
88 fi
89
90 latest_firmware
91
92