Skip to content

Instantly share code, notes, and snippets.

@zerok
Created January 10, 2010 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerok/273605 to your computer and use it in GitHub Desktop.
Save zerok/273605 to your computer and use it in GitHub Desktop.
use strict;
use File::Temp qw/tempdir/;
use File::Path qw/rmtree/;
my $baseurl = "http://build.chromium.org/buildbot/snapshots/chromium-rel-mac/";
my $download_format = "$baseurl%s/chrome-mac.zip";
my $default_installation_dir = "/Applications";
my @search_dirs = ('/Applications', '~/Applications');
sub get_version {
my $path = shift;
my $infofile = "$path/Contents/Info.plist";
open(FP, "< $infofile") or die "Couldn't open $infofile";
my $check_next = 0;
my $rev = undef;
while(<FP>){
if ($check_next) {
if (/<string>(.*)<\/string>/) {
$rev = $1;
last;
}
} else {
if (/<key>SVNRevision<\/key>/) {
$check_next = 1;
next;
}
}
}
close(FP);
return $rev;
}
sub find_latest_revision {
my $rev = undef;
foreach my $line (`curl $baseurl 2> /dev/null`){
if ($line =~ /<a href="(\d+)\/">.*<\/a>/){
$rev = $1;
}
}
return $rev;
}
# Find out what version is currently installed
my $chromium_app = undef;;
my $current_rev = undef;
my $latest_rev = undef;
my $chromium_dir = undef;
foreach my $dir (@search_dirs){
my $path = "$dir/Chromium.app";
if (-e $path){
$chromium_app = $path;
$chromium_dir = $dir;
last;
}
}
if (defined($chromium_app)){
print "Found previous installation in $chromium_app\n";
$current_rev = get_version($chromium_app);
print "Currently installed revision: $current_rev\n";
} else {
$chromium_dir = $default_installation_dir;
}
$latest_rev = find_latest_revision();
if (!defined($current_rev) or $latest_rev gt $current_rev){
print "Downloading new build: $latest_rev\n";
my $dl = sprintf($download_format, $latest_rev);
my $tempdir = tempdir();
# Download the file into the tempfolder
`curl $dl > $tempdir/chrome-mac.zip && cd $tempdir && unzip chrome-mac.zip`;
if (defined($chromium_app)){
`rm -rf $chromium_app`;
}
`mv $tempdir/chrome-mac/Chromium.app $chromium_dir`;
rmtree($tempdir);
} else {
print "Your Chromium installation is up-to-date\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment