Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 0c9a9cf

Browse files
committed
Merge pull request #39 from mikemcquaid/homebrew-monkeypatching-cleanup
Cleanup monkeypatching bottles.
2 parents 7ec23b2 + 197b6b5 commit 0c9a9cf

File tree

7 files changed

+81
-69
lines changed

7 files changed

+81
-69
lines changed

files/boxen-bottle-hooks.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Bottle hooks for Homebrew.
2+
require "hooks/bottles"
3+
require "utils"
4+
require "net/http"
5+
require "uri"
6+
7+
# This monkeypatching sidesteps Homebrew's normal bottle support and uses our,
8+
# uh, homebrewed S3 binaries. This support is patched in instead of handled in
9+
# Puppet so that manual installs and indirect dependencies are also supported.
10+
module BoxenBottles
11+
def self.file(formula)
12+
"#{formula.name}-#{formula.version}.tar.bz2"
13+
end
14+
15+
def self.url(formula)
16+
os = MacOS.version
17+
file = self.file(formula)
18+
host = ENV['BOXEN_S3_HOST'] || 's3.amazonaws.com'
19+
bucket = ENV['BOXEN_S3_BUCKET'] || 'boxen-downloads'
20+
21+
"http://#{host}/#{bucket}/homebrew/#{os}/#{file}"
22+
end
23+
24+
def self.bottled?(formula)
25+
url = URI.parse self.url(formula)
26+
27+
Net::HTTP.start url.host do |http|
28+
http.open_timeout = 1
29+
http.read_timeout = 1
30+
31+
return Net::HTTPOK === http.head(url.path)
32+
end
33+
34+
false
35+
rescue
36+
false
37+
end
38+
39+
def self.pour(formula)
40+
url = self.url(formula)
41+
name = formula.name
42+
43+
boxen_cache = (HOMEBREW_CACHE/"boxen")
44+
boxen_cache.mkpath
45+
file = self.file(formula)
46+
cache_file = boxen_cache/file
47+
48+
ohai "Boxen: Downloading #{url}"
49+
success = system "curl", "--fail", "--progress-bar", "--output", cache_file, url
50+
raise "Boxen: Failed to download resource \"#{name}\"" unless success
51+
52+
ohai "Boxen: Pouring #{file}"
53+
system "tar", "-xf", cache_file, "-C", HOMEBREW_CELLAR
54+
55+
true
56+
end
57+
end
58+
59+
Homebrew::Hooks::Bottles.setup_formula_has_bottle do |formula|
60+
BoxenBottles.bottled?(formula)
61+
end
62+
63+
Homebrew::Hooks::Bottles.setup_pour_formula_bottle do |formula|
64+
BoxenBottles.pour(formula)
65+
end

files/boxen-install.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require "boxen-monkeypatches"
1+
require "boxen-bottle-hooks"
22
require "cmd/install"
33

4-
# A custom Homebrew command that loads our monkeypatches.
4+
# A custom Homebrew command that loads our bottle hooks.
55

66
module Homebrew
77
def self.boxen_install

files/boxen-latest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "boxen-monkeypatches"
1+
require "boxen-bottle-hooks"
22

33
# A custom Homebrew command that gives us the latest available version
44
# for a given formula. This allows us to avoid the terrifying prospect

files/boxen-monkeypatches.rb

Lines changed: 0 additions & 59 deletions
This file was deleted.

files/boxen-upgrade.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require "boxen-monkeypatches"
1+
require "boxen-bottle-hooks"
22
require "cmd/upgrade"
33

4-
# A custom Homebrew command that loads our monkeypatches.
4+
# A custom Homebrew command that loads our bottle hooks.
55

66
module Homebrew
77
def self.boxen_upgrade

manifests/init.pp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@
2727
require => Repository[$installdir]
2828
}
2929

30+
# Remove the old monkey patches, from pre #39
31+
file {
32+
"${installdir}/Library/Homebrew/boxen-monkeypatches.rb":
33+
ensure => 'absent',
34+
}
35+
3036
file {
3137
[$cachedir, $tapsdir, $cmddir, $libdir]:
3238
ensure => 'directory' ;
3339

34-
# shim for monkeypatches
35-
"${installdir}/Library/Homebrew/boxen-monkeypatches.rb":
36-
source => 'puppet:///modules/homebrew/boxen-monkeypatches.rb' ;
40+
# shim for bottle hooks
41+
"${installdir}/Library/Homebrew/boxen-bottle-hooks.rb":
42+
source => 'puppet:///modules/homebrew/boxen-bottle-hooks.rb' ;
3743
"${cmddir}/boxen-latest.rb":
3844
source => 'puppet:///modules/homebrew/boxen-latest.rb' ;
3945
"${cmddir}/boxen-install.rb":

spec/classes/homebrew_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
should contain_boxen__env_script("homebrew")
2121

22-
should contain_file("#{dir}/Library/Homebrew/boxen-monkeypatches.rb").
23-
with_source("puppet:///modules/homebrew/boxen-monkeypatches.rb")
22+
should contain_file("#{dir}/Library/Homebrew/boxen-bottle-hooks.rb").
23+
with_source("puppet:///modules/homebrew/boxen-bottle-hooks.rb")
2424

2525
["latest", "install", "upgrade"].each do |cmd|
2626
should contain_file("#{cmddir}/boxen-#{cmd}.rb").

0 commit comments

Comments
 (0)