2020-09-13 06:18:03 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use IO::Prompter;
|
|
|
|
use File::Which qw( which );
|
|
|
|
|
|
|
|
# Configurable variables
|
|
|
|
my $lang = 'en-CA';
|
|
|
|
my $install = "$ENV{HOME}/.local/bin";
|
|
|
|
my $working = "/tmp/firefox.new";
|
|
|
|
|
|
|
|
# Download link as provided by https://www.mozilla.org/$lang/firefox/developer/
|
2020-11-23 09:35:26 +00:00
|
|
|
my $url = 'https://download.mozilla.org/?product=firefox-devedition-latest-ssl'
|
2023-01-06 19:41:31 +00:00
|
|
|
. '&os=linux64&lang='.$lang;
|
2020-09-13 06:18:03 +00:00
|
|
|
|
|
|
|
# Ensure that we can unzip
|
|
|
|
unless (which("bunzip2")) {
|
2023-01-06 19:41:31 +00:00
|
|
|
die "Requires bunzip2. Try:\n"
|
|
|
|
. "sudo apt install zutils or your distro's equivalent\n";
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Only understood argument is to not bother verifying the package
|
|
|
|
my ($download_key, $verify) = (0,1);
|
|
|
|
if (defined $ARGV[0]) {
|
2023-01-06 19:41:31 +00:00
|
|
|
if ($ARGV[0] eq '--no-verify') {
|
|
|
|
$verify = 0;
|
|
|
|
} else {
|
|
|
|
die "Didn't understand argument $ARGV[0]\n";
|
|
|
|
}
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# If verification is to be done, make sure we have the key
|
|
|
|
unless ($verify) {
|
2023-01-06 19:41:31 +00:00
|
|
|
print "Checking for Mozilla GPG key in keyring...\n";
|
|
|
|
system("gpg --list-keys release\@mozillla.com 2>&1 > /dev/null");
|
|
|
|
if ($?) {
|
|
|
|
my $YN = prompt (-in => *STDIN, "You don't currently have "
|
|
|
|
. "Mozilla's GPG key in your keyring.\n"
|
|
|
|
. "Would you like to install it? If not, installation "
|
|
|
|
. "will not be verified. [y/N]: ",
|
|
|
|
-single
|
|
|
|
);
|
|
|
|
if ($YN eq 'y' || $YN eq 'Y') {
|
|
|
|
$download_key = 1;
|
|
|
|
} else {
|
|
|
|
$verify = 0;
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
2023-01-06 19:41:31 +00:00
|
|
|
}
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# If a previous download still exists remove it
|
|
|
|
if ( -e $working ) {
|
2023-01-06 19:41:31 +00:00
|
|
|
system("rm -rf $working");
|
|
|
|
if ($?) {
|
|
|
|
die "Working directory "
|
|
|
|
. $working
|
|
|
|
. "already exists and failed to remove: $!\n";
|
|
|
|
}
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get version currently installed
|
|
|
|
my $current = `$install/firefox/firefox-bin --version`;
|
|
|
|
$current =~ s/.*\s([^\s])/$1/;
|
|
|
|
chomp $current;
|
|
|
|
|
|
|
|
use WWW::Mechanize;
|
|
|
|
my $mech = WWW::Mechanize->new();
|
|
|
|
|
2020-11-23 09:35:26 +00:00
|
|
|
# $url is actually going to redirect to the proper current dowload so just get
|
|
|
|
# the redirect.
|
2020-09-13 06:18:03 +00:00
|
|
|
my $head = $mech->head($url);
|
|
|
|
|
|
|
|
my ($location, $version);
|
2020-11-23 09:35:26 +00:00
|
|
|
# This redirect will have the version id, so we can use that to determine if a
|
|
|
|
# new version actually exists
|
2020-09-13 06:18:03 +00:00
|
|
|
if ($head->{'_msg'}) {
|
2023-01-06 19:41:31 +00:00
|
|
|
$version = $location = $head->{'_previous'}->{'_headers'}->{'location'};
|
|
|
|
$version =~ s/^.*\-([^\-]*)\.tar\.bz2$/$1/;
|
|
|
|
if ($version eq $current) {
|
|
|
|
die "Current ($current) is the same as New ($version)\n";
|
|
|
|
}
|
2020-09-13 06:18:03 +00:00
|
|
|
} else {
|
2023-01-06 19:41:31 +00:00
|
|
|
print "unable to find new download\n";
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mkdir($working) || die "Couldn't make $working: $!\n";
|
|
|
|
|
|
|
|
# Download package
|
|
|
|
print "Fetching package $location...\n";
|
|
|
|
$mech->get($location);
|
2020-11-23 09:35:26 +00:00
|
|
|
$mech->save_content( $working."/firefox-".$version.".tar.bz2",
|
2023-01-06 19:41:31 +00:00
|
|
|
binmode => ':raw',
|
|
|
|
decoded_by_headers => 1
|
2020-11-23 09:35:26 +00:00
|
|
|
);
|
2020-09-13 06:18:03 +00:00
|
|
|
|
|
|
|
# If verification is required, get signature as well
|
|
|
|
if ($verify) {
|
2023-01-06 19:41:31 +00:00
|
|
|
$location .= '.asc';
|
|
|
|
print "Fetching GPG signature $location...\n";
|
|
|
|
$mech->get($location);
|
|
|
|
$mech->save_content( $working."/firefox-".$version.".tar.bz2.asc",
|
|
|
|
binmode => ':raw',
|
|
|
|
decoded_by_headers => 1
|
|
|
|
);
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# If key still needs to be fetched, get it
|
|
|
|
if ($download_key) {
|
2023-01-06 19:41:31 +00:00
|
|
|
$location =~ s/linux-x86_64.*$/KEY/;
|
|
|
|
print "Fetching GPG key $location...\n";
|
|
|
|
$mech->get($location);
|
|
|
|
$mech->save_content( $working."/mozilla.pgp",
|
|
|
|
binmode => ':raw',
|
|
|
|
decoded_by_headers => 1
|
|
|
|
);
|
|
|
|
# And install it
|
|
|
|
print "Installing Mozilla GPG key in keyring...\n";
|
|
|
|
system("gpg --import $working/mozilla.pgp 2>&1 > /dev/null");
|
|
|
|
if ($?) {
|
|
|
|
die "Warning: failed to import key. Cannot verify integrity.\n"
|
|
|
|
. "Downloaded to "
|
|
|
|
. $working
|
|
|
|
. ". You can check and install it to "
|
|
|
|
. $install
|
|
|
|
. "manually: "
|
|
|
|
. $!
|
|
|
|
. "\n";
|
|
|
|
}
|
|
|
|
unlink("$working/mozilla.pgp");
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Verify the package
|
|
|
|
if ($verify) {
|
2023-01-06 19:41:31 +00:00
|
|
|
print "Verifying download with Mozilla GPG key...\n";
|
|
|
|
system("gpg --verify $working/firefox-$version.tar.bz2.asc");
|
|
|
|
if ($?) {
|
|
|
|
die "Warning: failed to verify download. Signing failed.\n"
|
|
|
|
. "Downloaded to "
|
|
|
|
. $working
|
|
|
|
. ". You can check and install it to "
|
|
|
|
. $install
|
|
|
|
. " manually: "
|
|
|
|
. $!
|
|
|
|
. "\n";
|
|
|
|
}
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Uncompress
|
|
|
|
print "Uncompressing download with bunzip2...\n";
|
|
|
|
system("bunzip2 $working/firefox-$version.tar.bz2");
|
|
|
|
if ($?) {
|
2023-01-06 19:41:31 +00:00
|
|
|
die "Failed to uncompress: $!\n";
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Extract
|
|
|
|
print "Extracting from TAR archive...\n";
|
|
|
|
system("tar -xf $working/firefox-$version.tar -C $working");
|
|
|
|
if ($?) {
|
2023-01-06 19:41:31 +00:00
|
|
|
die "Failed to extract: $!\n";
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Bin the old backup
|
|
|
|
if (-e "$install/.firefox.old") {
|
2023-01-06 19:41:31 +00:00
|
|
|
print "Removing previous backup folder...\n";
|
|
|
|
system("rm -rf $install/.firefox.old");
|
|
|
|
if ($?) {
|
|
|
|
die "Failed to remove: $!\n";
|
|
|
|
}
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Move current to old
|
2020-11-23 09:35:26 +00:00
|
|
|
print "Backing up currently installed version ("
|
2023-01-06 19:41:31 +00:00
|
|
|
. $current
|
|
|
|
. ") to "
|
|
|
|
. $install
|
|
|
|
. "/.firefox.old...\n";
|
2020-09-13 06:18:03 +00:00
|
|
|
system("mv $install/firefox $install/.firefox.old");
|
|
|
|
if ($?) {
|
2023-01-06 19:41:31 +00:00
|
|
|
die "Failed to move: $!\n";
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Move new to current
|
|
|
|
print "Moving new version to $install for final installation...\n";
|
|
|
|
system("mv $working/firefox $install/");
|
|
|
|
if ($?) {
|
2023-01-06 19:41:31 +00:00
|
|
|
die "Failed to move: $!\n";
|
2020-09-13 06:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Hurray!
|
2020-11-23 09:35:26 +00:00
|
|
|
print "Installation of version "
|
2023-01-06 19:41:31 +00:00
|
|
|
. $version
|
|
|
|
. " complete. You should restart firefox whenever it is convenient.\n";
|
2020-09-13 06:18:03 +00:00
|
|
|
exit();
|