Last active
July 28, 2022 21:43
-
-
Save h0tw1r3/204869126ccbae1d3121520b62655cce to your computer and use it in GitHub Desktop.
Deploy shared homebrew on Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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