-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall.rb
146 lines (115 loc) · 3.36 KB
/
install.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Automates installing applications by category group.
#
# Note: This will require homebrew and cask. It will go ahead and install them
# if brew is missing.
#
# See: http://caskroom.io/
#
# Help: ruby install.rb -h
#
# Author:: Richard Sumilang <[email protected]>
# URL:: https://github.com/rsumilang/casks
# Homepage:: http://richardsumilang.com
# License:: http://creativecommons.org/licenses/by-sa/3.0/
require 'optparse'
require 'optparse/time'
require 'ostruct'
require 'pp'
#
# Parses out options taken in from the CLI.
#
class CaskOptionsParser
#
# Return a structure describing the options.
#
def self.parse(args)
# The options specified on the command line will be collected in *options*.
# We set default values here.
options = OpenStruct.new
options.appdir = "/Applications"
options.category = false
options.install = true
opts = OptionParser.new do |opts|
opts.banner = "Usage: install.rb [options]"
opts.separator ""
opts.separator "Specific options:"
# Application Directory
opts.on("--appdir PATH",
"Target location for Application links.",
" The default value is /Applications") do |appdir|
options.appdir << appdir
end
# Category Option
opts.on("-c", "--category [NAME]",
"Name of application category to install",
" (should reference filename in ./category)",
" All categories will be installed if not specified.") do |cat|
options.category = cat
end
# Uninstall option
opts.on("-u", "--uninstall", "Run uninstall rather than install") do |u|
options.install = false
end
opts.separator ""
opts.separator "Common options:"
# No argument, shows at tail. This will print an options summary.
# Try it and see!
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
opts.parse!(args)
options
end # parse()
end # class OptparseExample
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end
#
# Our options. Lets rock in roll
#
options = CaskOptionsParser.parse(ARGV)
#pp options
#
# Check if brew is installed, else install it.
#
if !which("brew")
puts "Installing homebrew..."
puts `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
puts "Updating brew recipes..."
puts `brew update`
puts "Installing cask..."
puts `brew install caskroom/cask/brew-cask`
end
#
# Install cmd
#
installCmd = "brew cask " << (options.install ? "install" : "uninstall") << " --appdir=#{options.appdir}"
#
# Runs either specified category of apps
# or all of them if none specified.
#
if options.category
category = "./category/#{options.category}.sh"
cmd = "#{category} \"#{installCmd}\""
puts "Processing #{category}..."
puts `#{cmd}`
else
files = Dir["./category/*.sh"]
files.each do |category|
cmd = "#{category} \"#{installCmd}\""
puts "Processing #{category}..."
puts `#{cmd}`
end
end