-
Notifications
You must be signed in to change notification settings - Fork 80
/
autochrome.rb
105 lines (78 loc) · 2.83 KB
/
autochrome.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env ruby
if RUBY_VERSION < '2.0'
STDERR.puts "Your version of ruby (#{RUBY_VERSION}) is crazy old, and autochrome definitely will not work; sorry."
exit 1
end
if RUBY_VERSION >= '3.2.0' # monkeypatch exists/exist method names (https://bugs.ruby-lang.org/issues/17391)
class << File
alias_method :exists?, :exist?
end
class << Dir
alias_method :exists?, :exist?
end
end
require 'optparse'
$: << File.join(File.dirname(__FILE__), 'lib')
require 'auto_chrome'
def parse_options(arg_list)
options = { profiles: [] }
OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($0)} [options] [\"profile 1\" [\"profile 2\" ...]]"
opts.separator ""
opts.on("-t", "--os-type OSTYPE", "Manually set operating system") do |t|
options[:os_type] = t
end
opts.on("-V", "--chromium-version VERSION", "Set Chromium version to download") do |v|
options[:cr_version] = v.to_i
end
opts.on("-l", "--force-download", "Download Chromium ignoring any cached versions") do |a|
options[:force_download] = a
end
opts.on("-n", "--ignore-cache", "Don't cache downloads") do
options[:ignore_cache] = true
end
opts.on("-f", "--chrome-archive FILE", "Specify a Chromium archive ZIP file") do |a|
options[:chrome_archive] = a
end
opts.on("-P", "--profiles-only", "Install Profiles (and extensions) only; do not (re-)install Chromium") do
options[:profiles_only] = true
end
opts.on("-d", "--installation-dir DIR", "Set directory to install Chromium to") do |d|
options[:install_dir] = File.expand_path(d)
end
opts.on("-D", "--data-dir DIR", "Set directory to install profiles and extensions") do |d|
options[:data_dir] = File.expand_path(d)
end
opts.on("-c", "--clobber", "Delete any existing Chromium installation") do
options[:clobber] = true
end
opts.on("-p", "--proxy-host HOST", "Proxy host") do |p|
options[:proxyhost] = p
end
opts.on("-p", "--proxy-base PORT", "Local proxy base port") do |p|
options[:proxybase] = p.to_i
end
opts.on("-e", "--extensions EXTDIR", "Directory of bundled extensions") do |e|
options[:extension_dir] = File.expand_path(e)
end
opts.on_tail("--list-themes", "List included themes") do
pathglob = File.join(ProfileBuilder::BuiltinThemeDirectory, "*.crx")
themes = Dir[pathglob].select {|f| File.file?(f)}.map do |f|
File.basename(f).gsub("\.crx", "")
end
puts "Available themes are:"
puts themes.join(", ")
exit
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
# parse arg_list in order, non-destructively, and yield non-options
end.order(arg_list) do |arg|
options[:profiles] << arg
end
options
end
a = AutoChrome.new(parse_options(ARGV))
a.go