voodoojello
6/18/2010 - 3:16 AM

Super Cheesy Chromium Updater for MacOS

Super Cheesy Chromium Updater for MacOS

#!/usr/bin/perl -w
#
#          File: index.pl
#      App Name: Chromium Build-Bot URL Updater
#   App Version: 0.0.0.1a
#       Created: Tue Jun 07 22:58:50 CDT 2011
#      Modified: Thu Jun 09 07:29:43 CDT 2011
#      Authored: Mark Page [m.e.page@gmail.com]
#  File Version: 0.0.0.1a
#
#
use strict;
use warnings;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);

print header('text/plain');

my $build_id = `curl -s -L http://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/LAST_CHANGE`;

print '
{
	\'id\'  => \'' . $build_id . '\', 
	\'url\' => \'http://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/' . $build_id . '/chrome-mac.zip\',
}
';

exit;

__END__
#!/usr/bin/perl -w
#
use strict;
use warnings;
use FindBin qw($Bin);

my $global = {
	name      => 'Super Cheesy Chromium Updater for MacOS',
	version   => '0.0.2.9b',
	released  => 'Tue Sep 13 23:11:22 CDT 2011',
	contact   => 'mark.page@voodoojello.net',

	temp_dir  => $Bin . '/chromium-temp',
	restore   => $Bin . '/restore',
	vjcu_url  => 'http://voodoojello.net/chromium-updater/mac',
	loc_build => '', # Local SVNRevision build number from plist
	};

#
# Binary dependencies *should* be in $PATH but there's been 
# reported issues with MacPorts installs causing grief with 
# unzip args -- Change as needed.
#
my $curl  = '/usr/bin/curl';
my $unzip = '/usr/bin/unzip';

system('clear');

print '=' x 85 . "\n";
print " $global->{name} v$global->{version}\n";
print " Released: $global->{released}\n";
print '=' x 85 . "\n\n";

print "--> Retrieving buildbot URL and Build ID...\n";
my $bot_data = eval(`$curl -s -L $global->{vjcu_url}`);

if ($bot_data->{id}) {
	print "--> Chromium LATEST build appears to be $bot_data->{id}.\n";
	if (stat("/Applications/Chromium.app/Contents/Info.plist")) {
		print "--> Checking local Chromium build version...\n";
	
		open(PLIST,"</Applications/Chromium.app/Contents/Info.plist"); chomp(my @app_info = <PLIST>); close(PLIST);
		
		for my $l (0 .. scalar(@app_info)) {
			if ($app_info[$l] =~ m/SVNRevision/) {
				$global->{loc_build} = $app_info[($l + 1)];
				$global->{loc_build} =~ s/\t//;
				$global->{loc_build} =~ s/\<string\>//;
				$global->{loc_build} =~ s/\<\/string\>//;
				last;
				}
			}
	
		print "--> Local Chromium build version is $global->{loc_build}.\n";
		}
	else {
		print "--> Chromium does not appear to be installed... Install it now? [y/n] ";
		unless (getc(STDIN) =~ m/y/i) { print "--> Aborting!\n\n"; exit; }
		}
	
	if ($bot_data->{id} eq $global->{loc_build}) {
		print "--> Most current build already installed.\n";
		}
	else {
		print "--> Creating temporary dirs...\n";
		if (stat("$global->{temp_dir}")) { system("rm -R $global->{temp_dir}"); }
		system("mkdir $global->{temp_dir}");

		print "--> Downloading build $bot_data->{id}...\n\n";
		system("$curl -k -L $bot_data->{url} -o $global->{temp_dir}/chrome-mac.zip");
		print "\n";

		print "--> Creating restore point for build $bot_data->{id}...";
		if (!stat("$global->{restore}")) { system("mkdir -p $global->{restore}"); }
		system("mkdir -p $global->{restore}/$bot_data->{id}");
		system("cp -f $global->{temp_dir}/chrome-mac.zip $global->{restore}/$bot_data->{id}/.");
		print "\n";

		print "--> Download complete. Extracting ZIP file...\n";
		system("$unzip $global->{temp_dir}/chrome-mac.zip -d $global->{temp_dir} > /dev/null");

		if (`ps ux` =~ m/Chromium/) {
			print "--> Sending TERM signal to all running Chromium processes...\n";
			system("killall Chromium");
			}

		if (stat("/Applications/Chromium.app")) {
			print "--> Removing previously installed build...\n";
			system("rm -R /Applications/Chromium.app");
			}

		print "--> Preparing to install version $bot_data->{id}...\n";
		system("cp -f -H -R $global->{temp_dir}/chrome-mac/Chromium.app /Applications/.");
	
		print "--> Cleaning up...\n";
		system("rm -R $global->{temp_dir}");
		}
	}
else {
	print "--> Could not reach buildbot... Try again later.\n";
	}

print "--> Exiting.\n\n";
print '=' x 85 . "\n";
print ' ' x 45 . "for more info: $global->{contact}\n\n";
print ' Press [ENTER] to continue... '; my $pause = <STDIN>;

exit;

__END__