2 # rt2870-firmware-update v0.2.2
3 ## Copyright 2011 Simone Sclavi 'Ito'
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 use Getopt
::Long
qw(:config no_ignore_case);
26 use Term
::ANSIColor
qw(:constants);
27 $Term::ANSIColor
::AUTORESET
= 1;
30 my $res = GetOptions
("probe|p" => \
$probe);
31 die ":: usage: $0 [ --probe | -p ]\n" unless $res and (scalar @ARGV == 0);
35 my $LSUSB = qx(which lsusb
2> /dev/null
);
37 die ":: install 'usbutils' package first!\n" unless $LSUSB;
38 my $lsusb_out = qx($LSUSB -d
1737:0079);
41 say BLUE
":: device 'ID 1737:0079 Linksys WUSB600N v2' found!";
45 say RED
qq{:: WARNING
: I cannot find the Linksys WUSB600N v2 device
!
46 :: If your wireless adapter is connected
, probably the
47 :: 'rt3572sta' driver is NOT what you need
...};
51 die ":: root privileges required!\n" unless ($> == 0 or $< == 0) ;
53 my $ralink_url = URI
->new('http://mirror.thebasementserver.com');
54 $ralink_url->path('/soft/ralink/linux/');
56 my $browser = LWP
::UserAgent
->new();
57 $browser->env_proxy( ); # in case we're behind a firewall
58 $browser->timeout(30);
59 my $resp = $browser->get($ralink_url);
60 die ':: oops, got error #', $resp->status_line, "#, exiting ...\n" unless $resp->is_success;
61 ## looking for latest firmware
62 if ($resp->content !~ /(?<fw_name>RT2870_Firmware_V\d+\.zip)/)
64 die ":: cannot find a suitable firmware to download\n";
67 #add firmware name to url path
68 my @segments = $ralink_url->path_segments();
69 push @segments, $+{fw_name
};
70 $ralink_url->path_segments(@segments);
72 $resp = $browser->get($ralink_url, ':content_file' => '/tmp/rt2870-firmware.zip');
73 die ':: oops, got error #', $resp->status_line, "#, exiting ...\n" unless $resp->is_success;
75 my $ae = Archive
::Extract
->new( archive
=> '/tmp/rt2870-firmware.zip' );
76 $ae->extract( to
=> '/tmp') or die ':: ', $ae->error, "\n";
78 my $new_firmware = $ae->extract_path . '/rt2870.bin';
79 my $old_firmware = '/lib/firmware/rt2870.bin';
80 die ":: you already have the latest firmware\n" if (compare
($new_firmware, $old_firmware) == 0);
81 copy
($new_firmware, $old_firmware) or die ":: copy failed: $!\n";
82 say ':: firmware updated successfully!';