# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee module RightConf class BrewInstaller include ProgressReporter # Check whether brew is already installed and install it if not # # === Return # true:: Always return true def self.check_and_install installed = Command.execute('brew', '--version').success? return true if installed new.install end # Actually install brew # # === Return # true:: Always return true def install report_check('Installing Homebrew') chmods = %w( . bin etc include lib lib/pkgconfig Library sbin share var share/locale share/man share/man/man1 share/man/man2 share/man/man3 share/man/man4 share/man/man5 share/man/man6 share/man/man7 share/man/man8 share/info share/doc share/aclocal ). map{ |d| "/usr/local/#{d}" }. select{ |d| File.directory? d and not File.writable? d } chgrps = chmods.reject{ |d| File.stat(d).grpowned? } if File.directory?('/usr/local') Command.sudo('/bin/chmod', 'g+w', *chmods) unless chmods.empty? # all admin users are in staff Command.sudo('/usr/bin/chgrp', 'staff', *chgrps) unless chgrps.empty? else Command.sudo('/bin/mkdir', '/usr/local') Command.sudo('/bin/chmod', 'g+w', '/usr/local') # the group is set to wheel by default for some reason Command.sudo('/usr/bin/chgrp', 'staff', '/usr/local') end Dir.chdir('/usr/local') do # -m to stop tar erroring out if it can't modify the mtime for root owned directories # pipefail to cause the exit status from curl to propogate if it fails system("/bin/bash -o pipefail -c '/usr/bin/curl -sSfL https://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1'") end report_success unless chmods.empty? report("The following directories had to be made group writable: #{chmods.join(', ')}") end unless chgrps.empty? report("The following directories had their group set to staff: #{chgrps.join(', ')}") end unless ENV['PATH'].split(':').include? '/usr/local/bin' report('/usr/local/bin is not in your PATH.') end end end end