Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Last active July 28, 2022 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h0tw1r3/204869126ccbae1d3121520b62655cce to your computer and use it in GitHub Desktop.
Save h0tw1r3/204869126ccbae1d3121520b62655cce to your computer and use it in GitHub Desktop.
Deploy shared homebrew on Linux
class homebrew (
Array[String] $packages = ['procps-ng', 'curl', 'file', 'git'],
) {
yum::group { 'Development Tools':
ensure => present,
}
-> package { $packages:
ensure => present
}
-> user { 'linuxbrew':
ensure => present,
home => '/home/linuxbrew',
managehome => true,
}
-> file { [
'/home/linuxbrew',
'/home/linuxbrew/.linuxbrew',
]:
ensure => directory,
owner => 'linuxbrew',
mode => '0755',
}
-> archive { '/var/tmp/homebrew.tar.gz':
source => 'https://github.com/Homebrew/brew/tarball/master',
extract => true,
extract_path => '/home/linuxbrew/.linuxbrew',
extract_command => 'tar --strip-components=1 -xzf %s',
creates => '/home/linuxbrew/.linuxbrew/bin/brew',
user => 'linuxbrew',
}
-> exec { 'homebrew-update':
cwd => '/home/linuxbrew/.linuxbrew',
command => '/home/linuxbrew/.linuxbrew/bin/brew update --force --quiet',
user => 'linuxbrew',
provider => shell,
creates => '/home/linuxbrew/.linuxbrew/Library/Taps/homebrew/homebrew-core',
environment => [ 'HOME=/home/linuxbrew' ],
timeout => 1800,
require => Package[$packages],
}
file { '/etc/profile.d/brew.sh':
ensure => present,
mode => '0755',
content => @(EOD)
# never add brew to a system users path
if [[ $(id -ru) -ge 1000 ]] || [[ ${SUDO_UID:-0} -ge 1000 ]] ; then
if [ -x /home/linuxbrew/.linuxbrew/bin/brew ] ; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
if [[ "$(id -un)" != "linuxbrew" ]] ; then
alias brew='sudo -iu linuxbrew /home/linuxbrew/.linuxbrew/bin/brew'
fi
fi
fi
| EOD
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment