-
-
Save niwo/1090685 to your computer and use it in GitHub Desktop.
An automated Ruby script for grabbing the latest Mac Chromium build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# A simple Ruby script to update Chromium from dev build. | |
# Currently only works on Mac and Win32. | |
# If you want progress bar, sudo gem install ruby-progressbar | |
# Read more about progress bar here: http://github.com/nex3/ruby-progressbar/tree/master | |
# Usage: | |
# ruby chromium_updater.rb | |
require 'fileutils' | |
require 'open-uri' | |
require 'tmpdir' | |
module ChromiumBuild | |
BUILD_SNAPSHOT_URL = 'http://commondatastorage.googleapis.com/chromium-browser-snapshots' | |
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 | |
@latest_revision_uri = URI.parse("#{BUILD_SNAPSHOT_URL}/#{@platform.capitalize}/LAST_CHANGE") | |
end | |
def update | |
build | |
unpack | |
cleanup | |
end | |
def unpack | |
## platform specific | |
end | |
def cleanup | |
## platform specific | |
end | |
def build | |
@build ||= get_build | |
end | |
begin | |
# Use http://github.com/nex3/ruby-progressbar/tree/master | |
# sudo gem install nex3-ruby-progressbar | |
require 'rubygems' | |
require 'progressbar' | |
def get_build | |
@build = File.open(File.join(build_dir, build_filename), 'wb') | |
pbar = nil | |
open(latest_build_uri, | |
:content_length_proc => lambda {|t| | |
if t && 0 < t | |
pbar = ProgressBar.new("Downloading #{latest_build_uri}", t) | |
pbar.file_transfer_mode | |
end | |
}, | |
:progress_proc => lambda {|s| | |
pbar.set s if pbar | |
}) {|f| @build.write(f.read) } | |
ensure | |
@build.close | |
pbar && pbar.finish | |
return @build | |
end | |
# start download w/o using progress bar | |
rescue LoadError => e | |
def get_build | |
@build = File.open(File.join(build_dir, build_filename), 'w') | |
puts latest_build_uri | |
@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.capitalize}/#{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}" | |
end | |
end | |
class Win32Updater < Updater | |
def initialize( install_path="C:/Program Files/Google/Chromium", build_dir=Dir.tmpdir ) | |
super(install_path, build_dir, 'win') | |
end | |
def unpack | |
begin | |
puts %x["C:/Program Files/7-Zip/7z.exe" e #{build.path} -o#{File.join(build_dir, build_basename)} -y] | |
rescue | |
puts 'Error: Please install 7-zip under C:\Program Files\7-Zip\\' | |
exit | |
end | |
begin | |
FileUtils.cp_r Dir.glob(extracted_app_path + "/*"), install_path, :verbose => true, :preserve => true | |
rescue | |
puts "Error: Please close Chromium before updating" | |
exit | |
end | |
end | |
def build_basename | |
"chrome-#{@platform}32" | |
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 | |
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, :preserve => 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 | |
module Platform | |
def self.is_mac? | |
RUBY_PLATFORM.downcase.include?("darwin") | |
end | |
def self.is_windows? | |
RUBY_PLATFORM.downcase.include?("w32") | |
end | |
def self.is_linux? | |
RUBY_PLATFORM.downcase.include?("linux") | |
end | |
end | |
if __FILE__ == $0 | |
if Platform.is_mac? | |
updater = ChromiumBuild::MacUpdater.new | |
elsif Platform.is_windows? | |
updater = ChromiumBuild::Win32Updater.new | |
end | |
unless updater | |
puts "unsupported platform #{RUBY_PLATFORM}" | |
exit | |
end | |
puts "Downloading rev ##{updater.latest_revision}..." | |
updater.get_build | |
puts "Unpacking..." | |
updater.unpack | |
puts "Cleaning up..." | |
updater.cleanup | |
puts "All done!" | |
end |
Author
niwo
commented
Jul 18, 2011
- updated with new paths of chromium builds
- MacUpdater: added the option "preserve" to cp_r in order to make Chromium.app executable
- using the new google api for downloads (commondatastorage.googleapis.com/chromium-browser-snapshots)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment