Skip to content

Commit

Permalink
specify a remote packages.yml on github
Browse files Browse the repository at this point in the history
  • Loading branch information
rouanw committed Nov 7, 2016
1 parent 5a9f28f commit 1fef925
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions brewpack
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
require 'yaml'
require 'optparse'
require 'set'
require 'net/http'

$filename = './packages.yml'

$default_options = { 'update' => true, 'doctor' => true, 'prune' => true, 'analytics' => true, }
$default_options = { 'update' => true, 'doctor' => true, 'prune' => true, 'analytics' => true }

$user_packages = YAML.load_file($filename) || {}

Expand All @@ -31,6 +32,18 @@ def cask_install(cask, save = false)
command "brew cask install #{cask}", "Installing cask '#{cask}'"
end

def install_formulae formulae
STDOUT.puts 'Installing packages with brew'
formulae['packages'].each do |package|
brew_install package
end

STDOUT.puts 'Installing applications with brew cask'
formulae['casks'].each do |cask|
cask_install cask
end
end

def install
options = $default_options.merge($user_packages['options'])

Expand All @@ -52,17 +65,9 @@ def install
command 'brew analytics off', 'Opting out of homebrew analytics'
end

STDOUT.puts 'Installing packages with brew'
$user_packages['packages'].each do |package|
brew_install package
end

command 'brew tap caskroom/cask', 'Setting up brew cask'

STDOUT.puts 'Installing applications with brew cask'
$user_packages['casks'].each do |cask|
cask_install cask
end
install_formulae $user_packages

STDOUT.puts 'install complete'
end
Expand All @@ -76,13 +81,24 @@ OptionParser.new do |op|
op.on('-s', '--save', 'install one formula and add to your packages.yml file') do |val|
$opts[:save] = true
end
op.on('-r', '--repo REPO', "install formula from someone's packages.yml on GitHub") do |repo|
$opts[:repo] = repo
end
end.parse!

case ARGV[0]
when 'install', 'i'
if ARGV[1]
formula = ARGV[1]
$opts[:cask] ? cask_install(formula, $opts[:save]) : brew_install(formula, $opts[:save])
elsif $opts[:repo]
uri = URI("https://raw.githubusercontent.com/#{$opts[:repo]}/master/packages.yml")
response = Net::HTTP.get_response(uri)
unless (response.code == '200')
STDOUT.puts 'Could not find packages.yml file. Specify in the format "user/repo" e.g. "rouanw/test-packages". The repo must contain a valid "packages.yml" file at its root.'
exit 1
end
install_formulae YAML.load(response.body)
else
install
end
Expand Down

0 comments on commit 1fef925

Please sign in to comment.