diff --git a/install_homebrew.rb b/install_homebrew.rb index a0a9b33bbc..8c5caaf928 100644 --- a/install_homebrew.rb +++ b/install_homebrew.rb @@ -7,35 +7,50 @@ # If you do fork, please ensure you add a comment here that explains what the # changes are intended to do and how well you tested them. # +# 14th March 2010: +# Adapted CodeButler's fork: http://gist.github.com/331512 +# module Tty extend self def blue; bold 34; end def white; bold 39; end def red; underline 31; end def reset; escape 0; end - def underline; underline 39; end def bold n; escape "1;#{n}" end def underline n; escape "4;#{n}" end def escape n; "\033[#{n}m" if STDOUT.tty? end end -def ohai s - puts "#{Tty.blue}==>#{Tty.white} #{s}#{Tty.reset}" -end - -def sudo *params - if params.length == 1 - cmd = "sudo #{params.first}" - ohai cmd - system cmd - else - ohai "sudo" + params.map{ |p| p.gsub ' ', '\\ ' } * ' ' - system "sudo", *params +class Array + def shell_s + cp = dup + first = cp.shift + cp.map{ |arg| arg.gsub " ", "\\ " }.unshift(first) * " " end end -def opoo warning - puts "#{Tty.red}Warning#{Tty.reset}: #{warning}" +def ohai *args + puts "#{Tty.blue}==>#{Tty.white} #{args.shell_s}#{Tty.reset}" +end + +def warn warning + puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}" +end + +alias :system_orig :system + +def system *args + abort "Failed during: #{args.shell_s}" unless system_orig *args +end + +def sudo *args + args = if args.length > 1 + args.unshift "sudo" + else + "sudo #{args}" + end + ohai *args + system *args end def getc # NOTE only tested on OS X @@ -47,6 +62,7 @@ end ####################################################################### script abort "/usr/local/.git already exists!" if File.directory? "/usr/local/.git" +abort "Don't run this as root!" if Process.uid == 0 ohai "This script will install:" puts "/usr/local/bin/brew" @@ -56,11 +72,16 @@ puts "/usr/local/Library/Homebrew/..." chmods = %w(bin etc include lib sbin share var . share/locale share/man 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? } unless chmods.empty? ohai "The following directories will be made group writable:" puts *chmods end +unless chgrps.empty? + ohai "The following directories will have their group set to #{Tty.underline 39}staff#{Tty.reset}:" + puts *chgrps +end puts puts "Press enter to continue" @@ -68,16 +89,19 @@ abort unless getc == 13 if File.directory? "/usr/local" sudo "/bin/chmod", "g+w", *chmods unless chmods.empty? + # all admin users are in staff + sudo "/usr/bin/chgrp", "staff", *chgrps unless chgrps.empty? else sudo "/bin/mkdir /usr/local" sudo "/bin/chmod g+w /usr/local" + # the group is set to wheel by default for some reason + sudo "/usr/bin/chgrp staff /usr/local" end Dir.chdir "/usr/local" do - tarball = "http://github.com/mxcl/homebrew/tarball/master" - ohai "Extracting: #{tarball}" + ohai "Downloading and Installing Homebrew..." # -m to stop tar erroring out if it can't modify the mtime for root owned directories - system "/usr/bin/curl -#L #{tarball} | /usr/bin/tar xz -m --strip 1" + system "/usr/bin/curl -sfL http://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1" end ohai "Installation successful!" @@ -88,5 +112,5 @@ if ENV['PATH'].split(':').include? '/usr/local/bin' puts " brew help" puts else - opoo "/usr/local/bin is not in your PATH" + warn "/usr/local/bin is not in your PATH" end