Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew: install correctly on apple silicon #155

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/facter/has_brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
Facter.add(:has_brew) do
confine :operatingsystem => 'Darwin'
setcode do
File.exists?('/usr/local/bin/brew') or system('brew --version >/dev/null 2>&1')
File.exists?('/usr/local/bin/brew') or File.exists?('/opt/homebrew/bin/brew') or system('brew --version >/dev/null 2>&1')
end
end
13 changes: 10 additions & 3 deletions lib/puppet/provider/package/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@

has_feature :install_options

commands :brew => '/usr/local/bin/brew'
if (File.exist?('/usr/local/bin/brew')) then
@brewbin = '/usr/local/bin/brew'
true
elsif (File.exist?('/opt/homebrew/bin/brew')) then
@brewbin = '/opt/homebrew/bin/brew'
end

commands :brew => @brewbin
commands :stat => '/usr/bin/stat'

def self.execute(cmd, failonfail = false, combine = false)
owner = stat('-nf', '%Uu', '/usr/local/bin/brew').to_i
group = stat('-nf', '%Ug', '/usr/local/bin/brew').to_i
owner = stat('-nf', '%Uu', "#{@brewbin}").to_i
group = stat('-nf', '%Ug', "#{@brewbin}").to_i
home = Etc.getpwuid(owner).dir

if owner == 0
Expand Down
13 changes: 10 additions & 3 deletions lib/puppet/provider/package/brewcask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@

has_feature :install_options

commands :brew => '/usr/local/bin/brew'
if (File.exist?('/usr/local/bin/brew')) then
@brewbin = '/usr/local/bin/brew'
true
elsif (File.exist?('/opt/homebrew/bin/brew')) then
@brewbin = '/opt/homebrew/bin/brew'
end

commands :brew => @brewbin
commands :stat => '/usr/bin/stat'

def self.execute(cmd, failonfail = false, combine = false)
owner = stat('-nf', '%Uu', '/usr/local/bin/brew').to_i
group = stat('-nf', '%Ug', '/usr/local/bin/brew').to_i
owner = stat('-nf', '%Uu', "#{@brewbin}").to_i
group = stat('-nf', '%Ug', "#{@brewbin}").to_i
home = Etc.getpwuid(owner).dir

if owner == 0
Expand Down
13 changes: 10 additions & 3 deletions lib/puppet/provider/package/homebrew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@

has_feature :install_options

commands :brew => '/usr/local/bin/brew'
if (File.exist?('/usr/local/bin/brew')) then
@brewbin = '/usr/local/bin/brew'
true
elsif (File.exist?('/opt/homebrew/bin/brew')) then
@brewbin = '/opt/homebrew/bin/brew'
end

commands :brew => @brewbin
commands :stat => '/usr/bin/stat'

def self.execute(cmd, failonfail = false, combine = false)
owner = stat('-nf', '%Uu', '/usr/local/bin/brew').to_i
group = stat('-nf', '%Ug', '/usr/local/bin/brew').to_i
owner = stat('-nf', '%Uu', "#{@brewbin}").to_i
group = stat('-nf', '%Ug', "#{@brewbin}").to_i
home = Etc.getpwuid(owner).dir

if owner == 0
Expand Down
13 changes: 10 additions & 3 deletions lib/puppet/provider/package/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@

has_feature :install_options

commands :brew => '/usr/local/bin/brew'
if (File.exist?('/usr/local/bin/brew')) then
@brewbin = '/usr/local/bin/brew'
true
elsif (File.exist?('/opt/homebrew/bin/brew')) then
@brewbin = '/opt/homebrew/bin/brew'
end

commands :brew => @brewbin
commands :stat => '/usr/bin/stat'

def self.execute(cmd, failonfail = false, combine = false)
owner = stat('-nf', '%Uu', '/usr/local/bin/brew').to_i
group = stat('-nf', '%Ug', '/usr/local/bin/brew').to_i
owner = stat('-nf', '%Uu', "#{@brewbin}").to_i
group = stat('-nf', '%Ug', "#{@brewbin}").to_i
home = Etc.getpwuid(owner).dir

if owner == 0
Expand Down
100 changes: 60 additions & 40 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
class homebrew::install {

case $::facts[processors][models][0] {
# brew complains if it finds its bin in /usr/local/bin on Apple Silicon
# so we should put brew where it expects to be
/^Apple*/: {
$brew_root = '/opt/homebrew'
$inst_dir = $brew_root
$link_bin = false
$brew_folders_extra = []
}
/^Intel*/: {
$brew_root = '/usr/local'
$inst_dir = "${brew_root}/Homebrew"
$link_bin = true
$brew_folders_extra = ["${brew_root}/Homebrew",]
}
default: { fail("unknown arch for processor ${::facts[processors][models][0]}") }
}
$brew_sys_folders = [
'/usr/local/bin',
'/usr/local/etc',
'/usr/local/Frameworks',
'/usr/local/include',
'/usr/local/lib',
'/usr/local/lib/pkgconfig',
'/usr/local/var',
"${brew_root}/bin",
"${brew_root}/etc",
"${brew_root}/Frameworks",
"${brew_root}/include",
"${brew_root}/lib",
"${brew_root}/lib/pkgconfig",
"${brew_root}/var",
]
$brew_sys_folders.each | String $brew_sys_folder | {
if !defined(File[$brew_sys_folder]) {
file { $brew_sys_folder:
ensure => directory,
owner => $homebrew::user,
group => $homebrew::group,
}
}
}

$brew_sys_chmod_folders = [
'/usr/local/bin',
'/usr/local/include',
'/usr/local/lib',
'/usr/local/etc',
'/usr/local/Frameworks',
'/usr/local/var',

"${brew_root}/bin",
"${brew_root}/include",
"${brew_root}/lib",
"${brew_root}/etc",
"${brew_root}/Frameworks",
"${brew_root}/var",
]
$brew_sys_chmod_folders.each | String $brew_sys_chmod_folder | {
exec { "brew-chmod-sys-${brew_sys_chmod_folder}":
Expand All @@ -39,25 +56,26 @@
}
}

$brew_folders = [
'/usr/local/opt',
'/usr/local/Homebrew',
'/usr/local/Caskroom',
'/usr/local/Cellar',
'/usr/local/var/homebrew',
'/usr/local/share',
'/usr/local/share/doc',
'/usr/local/share/info',
'/usr/local/share/man',
'/usr/local/share/man1',
'/usr/local/share/man2',
'/usr/local/share/man3',
'/usr/local/share/man4',
'/usr/local/share/man5',
'/usr/local/share/man6',
'/usr/local/share/man7',
'/usr/local/share/man8',
]
$brew_folders = flatten(
$brew_folders_extra,
[
"${brew_root}/opt",
"${brew_root}/Caskroom",
"${brew_root}/Cellar",
"${brew_root}/var/homebrew",
"${brew_root}/share",
"${brew_root}/share/doc",
"${brew_root}/share/info",
"${brew_root}/share/man",
"${brew_root}/share/man1",
"${brew_root}/share/man2",
"${brew_root}/share/man3",
"${brew_root}/share/man4",
"${brew_root}/share/man5",
"${brew_root}/share/man6",
"${brew_root}/share/man7",
"${brew_root}/share/man8",
])

file { $brew_folders:
ensure => directory,
Expand All @@ -84,17 +102,19 @@
}

exec { 'install-homebrew':
cwd => '/usr/local/Homebrew',
cwd => $inst_dir,
command => "/usr/bin/su ${homebrew::user} -c '/bin/bash -o pipefail -c \"/usr/bin/curl -skSfL https://github.com/homebrew/brew/tarball/master | /usr/bin/tar xz -m --strip 1\"'",
creates => '/usr/local/Homebrew/bin/brew',
creates => "${inst_dir}/bin/brew",
logoutput => on_failure,
timeout => 0,
}
~> file { '/usr/local/bin/brew':
ensure => 'link',
target => '/usr/local/Homebrew/bin/brew',
owner => $homebrew::user,
group => $homebrew::group,
if $link_bin {
file { "${brew_root}/bin/brew":
ensure => 'link',
target => "${inst_dir}/bin/brew",
owner => $homebrew::user,
group => $homebrew::group,
}
}

}