Skip to content

Instantly share code, notes, and snippets.

@newtonapple
Created August 14, 2009 05:51
Show Gist options
  • Save newtonapple/167668 to your computer and use it in GitHub Desktop.
Save newtonapple/167668 to your computer and use it in GitHub Desktop.
An automated Ruby script for grabbing the latest Mac Chromium build
#!/usr/bin/env ruby
# A simple Ruby script to update Chromium from dev build.
# Currently only works on Mac. You should be able extend it to Linux and Windows without much fuzz.
# If you want progress bar, sudo gem install ruby-progressbar
# Usage:
# ruby chromium_updater.rb
require 'fileutils'
require 'open-uri'
require 'tmpdir'
module ChromiumBuild
BUILD_SNAPSHOT_URL = 'http://build.chromium.org/f/chromium/snapshots.old'
class Updater
attr_accessor :install_path, :build_dir, :platform
def initialize( install_path, build_dir, platform )
self.install_path = install_path
self.build_dir = build_dir
self.platform = platform.to_s
puts "#{BUILD_SNAPSHOT_URL}/#{@platform}/LATEST"
@latest_revision_uri = URI.parse("#{BUILD_SNAPSHOT_URL}/#{@platform}/LATEST")
end
def update
build
unpack
cleanup
end
def unpack
## platform specific
end
def cleanup
## platform specific
end
def build
@build ||= get_build
end
begin
# sudo gem install ruby-progressbar
require 'rubygems'
require 'progressbar'
def get_build
@build = File.open(File.join(build_dir, build_filename), 'w')
progress_bar = nil
Net::HTTP.start(latest_build_uri.host) do |http|
progress_bar = ProgressBar.new('progress', http.head(latest_build_uri.path).content_length)
progress_bar.file_transfer_mode
http.get(latest_build_uri.path) do |data|
@build.write(data)
progress_bar.inc(data.size)
end
end
ensure
@build.close
progress_bar && progress_bar.finish
return @build
end
rescue LoadError => e
def get_build
@build = File.open(File.join(build_dir, build_filename), 'w')
@build.write(latest_build_uri.read)
ensure
@build.close
return @build
end
end
def latest_revision
@latest_revision ||= get_latest_revision
end
protected
def latest_build_uri
URI.parse "#{BUILD_SNAPSHOT_URL}/#{@platform}/#{latest_revision}/#{build_filename}"
end
def get_latest_revision
@latest_revision = @latest_revision_uri.read
end
def build_filename
"#{build_basename}.zip"
end
def build_basename
"chrome-#{@platform.downcase}"
end
end
class MacUpdater < Updater
def initialize( install_path='/Applications/Chromium.app', build_dir=Dir.tmpdir )
super(install_path, build_dir, 'Mac')
end
def unpack
`unzip #{build.path} -d #{build_dir}`
FileUtils.rm_rf install_path
FileUtils.cp_r extracted_app_path, install_path, :verbose => true
end
def cleanup
FileUtils.rm_rf Dir.glob(File.join(build_dir, "#{build_basename}*")), :verbose => true
end
private
def extracted_app_path
File.join build_dir, build_basename, 'Chromium.app'
end
end
end
if __FILE__ == $0
updater = ChromiumBuild::MacUpdater.new
puts "Downloading rev ##{updater.latest_revision}..."
updater.get_build
puts "Unpacking..."
updater.unpack
puts "Cleaning up..."
updater.cleanup
puts "All done!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment