Skip to content

Commit

Permalink
fix(multi-user): fix multi-user support (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordigg authored and TheKevJames committed Dec 10, 2017
1 parent b06c0ce commit 343d4e8
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 30 deletions.
3 changes: 2 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
$command_line_tools_package = undef,
$command_line_tools_source = undef,
$github_token = undef,
$group = 'admin'
$group = 'admin',
$multiuser = false,
) {

if $::operatingsystem != 'Darwin' {
Expand Down
106 changes: 77 additions & 29 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,39 +1,88 @@
class homebrew::install {

$brew_root = '/usr/local'
$brew_subfolders = [
'/usr/local/bin',
'/usr/local/Cellar',
'/usr/local/etc',
'/usr/local/Frameworks',
'/usr/local/include',
'/usr/local/lib',
'/usr/local/lib/pkgconfig',
'/usr/local/opt',
'/usr/local/share',
'/usr/local/share/doc',
'/usr/local/share/man',
'/usr/local/var',
]

# High Sierra no longer allows us to set perms on /usr/local
if $facts['os']['macosx']['version']['major'] == '10.13' {
$brew_folders = $brew_subfolders
} else {
$brew_folders = concat([$brew_root], $brew_subfolders)
$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_sys_folders.each | String $brew_sys_folder | {
if !defined(File[$brew_sys_folder]) {
file { $brew_sys_folder:
ensure => directory,
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_sys_chmod_folders.each | String $brew_sys_chmod_folder | {
exec { "brew-chmod-sys-${brew_sys_chmod_folder}":
command => "/bin/chmod -R 775 ${brew_sys_chmod_folder}",
unless => "/usr/bin/stat -f '%OLp' ${brew_sys_chmod_folder} | /usr/bin/grep -w '775'",
notify => Exec["set-${brew_sys_chmod_folder}-directory-inherit"],
}
exec { "set-${brew_sys_chmod_folder}-directory-inherit":
command => "/bin/chmod -R +a '${homebrew::group}:allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit' ${brew_sys_chmod_folder}",
refreshonly => true,
}
}

$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',
]

file { $brew_folders:
ensure => directory,
group => $homebrew::group,
mode => '0775',
} ->
file { '/usr/local/Homebrew':
ensure => directory,
owner => $homebrew::user,
group => $homebrew::group,
mode => '0775',
} ->
}

if $homebrew::multiuser == true {
$brew_folders.each | String $brew_folder | {
exec { "chmod-${brew_folder}":
command => "/bin/chmod -R 775 ${brew_folder}",
unless => "/usr/bin/stat -f '%OLp' '${brew_folder}' | /usr/bin/grep -w '775'",
notify => Exec["set-${brew_folder}-directory-inherit"]
}
exec { "chown-${brew_folder}":
command => "/usr/sbin/chown -R :${homebrew::group} ${brew_folder}'",
unless => "/usr/bin/stat -f '%Sg' '${brew_folder}' | /usr/bin/grep -w '${homebrew::group}'",
}
exec { "set-${brew_folder}-directory-inherit":
command => "/bin/chmod -R +a '${homebrew::group}:allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit' ${brew_folder}",
refreshonly => true,
}
}
}

exec { 'install-homebrew':
cwd => '/usr/local/Homebrew',
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\"'",
Expand All @@ -46,7 +95,6 @@
target => '/usr/local/Homebrew/bin/brew',
owner => $homebrew::user,
group => $homebrew::group,
mode => '0775',
}

}

0 comments on commit 343d4e8

Please sign in to comment.