brewmaster 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
@@ -0,0 +1 @@
1
+ 1.9.3-p362
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brewmaster.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tony Pitale
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # Brewmaster
2
+
3
+ Given a configuration, it will install homebrew/brew-cask/ruby-build/chruby and use them to install brews, casks, and rubies.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'brewmaster'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install brewmaster
18
+
19
+ ## Usage ##
20
+
21
+ ### Create ~/.bootstrap.yml ###
22
+
23
+ ---
24
+ brews:
25
+ - jq
26
+ - chruby
27
+ - ruby-build
28
+ casks:
29
+ - handbrake
30
+ rubies:
31
+ - 2.0.0-p195
32
+
33
+ `brewmaster --bootstrap`
34
+
35
+ ## This will: ##
36
+
37
+ ### Install homebrew ###
38
+
39
+ `ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"`
40
+
41
+ ### Tap brew-cask ###
42
+
43
+ `brew tap phinze/homebrew-cask`
44
+ `brew install brew-cask`
45
+
46
+ ### Installs ruby-build and chruby ###
47
+
48
+ `brew install ruby-build chruby`
49
+
50
+ ### Then it will: ###
51
+
52
+ * Install any listed brews
53
+ * Upgrade any listed outdated brews
54
+ * Install any listed casks
55
+ * Install any listed rubies with ruby-build into `~/.rubies/{{version}}`
56
+
57
+ ## Contributing ##
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby -Ilib
2
+
3
+ require 'brewmaster'
4
+
5
+ Brewmaster::CLI.new(ARGV).run
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'brewmaster/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "brewmaster"
8
+ gem.version = Brewmaster::VERSION
9
+ gem.authors = ["Tony Pitale"]
10
+ gem.email = ["tpitale@gmail.com"]
11
+ gem.description = %q{Configuration driven installation and updating of homebrew/brew-casks/rubies.}
12
+ gem.summary = %q{Given a configuration, it will install homebrew/brew-cask/ruby-build/chruby and use them to install brews, casks, and rubies.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rspec"
21
+ end
@@ -0,0 +1,75 @@
1
+ require 'optparse'
2
+ require 'yaml'
3
+
4
+ module Brewmaster
5
+ BOOTSTRAP_CONFIG_PATH = File.expand_path('~/.bootstrap.yml')
6
+
7
+ def self.bootstrap!
8
+ install_homebrew
9
+ install_brew_cask
10
+ setup_load_paths
11
+ install_ruby_tools
12
+ end
13
+
14
+ def self.install_homebrew
15
+ `ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"`
16
+ end
17
+
18
+ def self.update_homebrew
19
+ `brew update`
20
+ end
21
+
22
+ def self.install_brew_cask
23
+ `brew tap phinze/homebrew-cask`
24
+ `brew install brew-cask`
25
+ end
26
+
27
+ def self.install_ruby_tools
28
+ BrewCollection.new(['chruby', 'ruby-build']).install_missing
29
+ end
30
+
31
+ def self.setup_load_paths
32
+ setup_homebrew_load_path
33
+ setup_brew_cask_load_path
34
+ end
35
+
36
+ def self.setup_homebrew_load_path
37
+ begin
38
+ # build homebrew into loadpath
39
+ $: << File.join(`brew --prefix`.strip, 'Library', 'Homebrew')
40
+
41
+ require 'global'
42
+ require 'formula'
43
+ require 'keg'
44
+ require 'cmd/install'
45
+ require 'cmd/outdated'
46
+ require 'cmd/upgrade'
47
+ rescue
48
+ puts 'You seem to be missing homebrew'
49
+ end
50
+ end
51
+
52
+ def self.setup_brew_cask_load_path
53
+ begin
54
+ # build brew-cask into loadpath
55
+ cask_bin = `which brew-cask.rb`.strip
56
+ cask_bin_path = `dirname #{cask_bin}`.strip
57
+ cask_bin_link = `readlink #{cask_bin}`.strip
58
+ cask_real_path = Pathname.new(File.join(cask_bin_path,cask_bin_link)).realpath
59
+
60
+ $: << File.expand_path('../../rubylib', cask_real_path)
61
+
62
+ require 'cask'
63
+ rescue => e
64
+ puts 'You seem to be missing brew-cask'
65
+ end
66
+ end
67
+ end
68
+
69
+ require "brewmaster/version"
70
+ require 'brewmaster/brew_collection'
71
+ require 'brewmaster/cask_collection'
72
+ require 'brewmaster/ruby_collection'
73
+ require 'brewmaster/configuration'
74
+ require 'brewmaster/coordinator'
75
+ require 'brewmaster/cli'
@@ -0,0 +1,48 @@
1
+ module Brewmaster
2
+ class BrewCollection
3
+ def initialize(names)
4
+ @names = names
5
+ @formulae = names.map {|name| Formula.factory(name)}
6
+ end
7
+
8
+ def install_missing
9
+ Homebrew.perform_preinstall_checks
10
+
11
+ missing.each {|f| Homebrew.install_formula(f)}
12
+ end
13
+
14
+ def install_updates
15
+ Homebrew.perform_preinstall_checks
16
+
17
+ outdated.each {|f| Homebrew.upgrade_formula(f)}
18
+ end
19
+
20
+ # def remove_extras
21
+ # p extras
22
+ # end
23
+
24
+ # anything not installed, excluding the outdated
25
+ def missing
26
+ @missing ||= @formulae.select {|f| !f.installed?} - self.class.outdated
27
+ end
28
+
29
+ # anything outdated that we want installed that is not pinned
30
+ def outdated
31
+ @outdated ||= @formulae & self.class.outdated.select {|f| !f.pinned?}
32
+ end
33
+
34
+ # anything installed, that's not in our list anymore
35
+ # def extras
36
+ # @extras ||= self.class.installed - @formulae
37
+ # end
38
+
39
+ def self.installed
40
+ # `ls #{HOMEBREW_CELLAR}`.split
41
+ Formula.installed
42
+ end
43
+
44
+ def self.outdated
45
+ Homebrew.outdated_brews
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ module Brewmaster
2
+ class CaskCollection
3
+ def initialize(names)
4
+ @names = names
5
+ end
6
+
7
+ def install_missing
8
+ Cask::CLI::Install.run(*missing)
9
+ end
10
+
11
+ # anything not installed, excluding the outdated
12
+ def missing
13
+ @missing ||= @names - self.class.installed
14
+ end
15
+
16
+ def self.installed
17
+ Cask.installed.map {|c| (c.split("/").last)}
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ module Brewmaster
2
+ class CLI
3
+ attr_accessor :configuration, :coordinator
4
+
5
+ def initialize(args)
6
+ options = {}
7
+
8
+ @name = 'brewmaster'
9
+
10
+ OptionParser.new do |parser|
11
+ parser.banner = [
12
+ "Usage: #{@name} [--bootstrap] [-c config_file]\n",
13
+ " #{@name} --help\n"
14
+ ].compact.join
15
+
16
+ parser.on('-c', '--config FILE') do |path|
17
+ options[:config_path] = path
18
+ end
19
+
20
+ parser.on('--bootstrap') do
21
+ options[:bootstrap] = true
22
+ end
23
+
24
+ # parser.on("-l", "--log FILE") do |path|
25
+ # options[:log_path] = path
26
+ # end
27
+
28
+ parser.on_tail("-?", "--help", "Display this usage information.") do
29
+ puts "#{parser}\n"
30
+ exit
31
+ end
32
+ end.parse!(args)
33
+
34
+ self.configuration = Configuration.new(options)
35
+ self.coordinator = Coordinator.new(configuration)
36
+ end
37
+
38
+ def run
39
+ coordinator.run
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ module Brewmaster
2
+ class Configuration
3
+ def initialize(options={})
4
+ @bootstrap = options.fetch(:bootstrap, false)
5
+ @config_file = YAML.load_file(options.fetch(:config_path, Brewmaster::BOOTSTRAP_CONFIG_PATH))
6
+ end
7
+
8
+ def bootstrap?
9
+ @bootstrap
10
+ end
11
+
12
+ def brews
13
+ @brews ||= @config_file['brews']
14
+ end
15
+
16
+ def casks
17
+ @casks ||= @config_file['casks']
18
+ end
19
+
20
+ def rubies
21
+ @rubies ||= @config_file['rubies']
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ module Brewmaster
2
+ class Coordinator
3
+ attr_accessor :configuration
4
+
5
+ def initialize(configuration)
6
+ self.configuration = configuration
7
+ end
8
+
9
+ def run
10
+ if configuration.bootstrap?
11
+ Brewmaster.bootstrap!
12
+ else
13
+ Brewmaster.setup_load_paths
14
+ end
15
+
16
+ run_brews
17
+ run_casks
18
+ run_rubies
19
+ end
20
+
21
+ def run_brews
22
+ c = BrewCollection.new(configuration.brews)
23
+ c.install_missing
24
+ c.install_updates
25
+ end
26
+
27
+ def run_casks
28
+ c = CaskCollection.new(configuration.casks)
29
+ c.install_missing
30
+ end
31
+
32
+ def run_rubies
33
+ c = RubyCollection.new(configuration.rubies)
34
+ c.install_missing
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ module Brewmaster
2
+ class RubyCollection
3
+ def initialize(rubies)
4
+ @rubies = rubies
5
+ end
6
+
7
+ def install_missing
8
+ missing.each {|v| install_version(v)}
9
+ end
10
+
11
+ def missing
12
+ (@rubies - self.class.installed).select {|v| available?(v)}
13
+ end
14
+
15
+ def available?(version)
16
+ self.class.available_versions.include?(version)
17
+ end
18
+
19
+ def install_version(v)
20
+ `ruby-build #{v} ~/.rubies/#{v}`
21
+ end
22
+
23
+ def self.installed
24
+ `ls ~/.rubies/`.split
25
+ end
26
+
27
+ def self.available_versions
28
+ `ruby-build --definitions`.split
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Brewmaster
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'rspec'
4
+
5
+ require File.expand_path('../../lib/brewmaster', __FILE__)
6
+
7
+ # Dir["./spec/support/**/*.rb"].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ # config.mock_with :mocha
11
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brewmaster
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tony Pitale
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Configuration driven installation and updating of homebrew/brew-casks/rubies.
31
+ email:
32
+ - tpitale@gmail.com
33
+ executables:
34
+ - brewmaster
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - .rspec
40
+ - .ruby-version
41
+ - .travis.yml
42
+ - Gemfile
43
+ - LICENSE.txt
44
+ - README.md
45
+ - Rakefile
46
+ - bin/brewmaster
47
+ - brewmaster.gemspec
48
+ - lib/brewmaster.rb
49
+ - lib/brewmaster/brew_collection.rb
50
+ - lib/brewmaster/cask_collection.rb
51
+ - lib/brewmaster/cli.rb
52
+ - lib/brewmaster/configuration.rb
53
+ - lib/brewmaster/coordinator.rb
54
+ - lib/brewmaster/ruby_collection.rb
55
+ - lib/brewmaster/version.rb
56
+ - spec/spec_helper.rb
57
+ homepage: ''
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.23
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Given a configuration, it will install homebrew/brew-cask/ruby-build/chruby
81
+ and use them to install brews, casks, and rubies.
82
+ test_files:
83
+ - spec/spec_helper.rb