Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 13th, 2012  |  syntax: None  |  size: 4.21 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/ruby
  2. #
  3. # This script installs to /usr/local only. To install elsewhere you can just
  4. # untar https://github.com/mxcl/homebrew/tarball/master anywhere you like.
  5. #
  6. #
  7. # 30th March 2010:
  8. #   Added a check to make sure user is in the staff group. This was a problem
  9. #   for me, and I think it was due to me migrating my account over several
  10. #   versions of OS X. I cannot verify that for sure, and it was tested on
  11. #   10.6.2 using the Directory Service command line utility and my laptop.
  12. #
  13. #   My assumptions are:
  14. #     - you are running OS X 10.6.x
  15. #     - your machine is not managed as part of a group using networked
  16. #       Directory Services
  17. #     - you have not recently killed any baby seals or kittens
  18. #
  19. # 14th March 2010:
  20. #   Adapted CodeButler's fork: http://gist.github.com/331512
  21. #
  22.  
  23. module Tty extend self
  24.   def blue; bold 34; end
  25.   def white; bold 39; end
  26.   def red; underline 31; end
  27.   def reset; escape 0; end
  28.   def bold n; escape "1;#{n}" end
  29.   def underline n; escape "4;#{n}" end
  30.   def escape n; "\033[#{n}m" if STDOUT.tty? end
  31. end
  32.  
  33. class Array
  34.   def shell_s
  35.     cp = dup
  36.     first = cp.shift
  37.     cp.map{ |arg| arg.gsub " ", "\\ " }.unshift(first) * " "
  38.   end
  39. end
  40.  
  41. def ohai *args
  42.   puts "#{Tty.blue}==>#{Tty.white} #{args.shell_s}#{Tty.reset}"
  43. end
  44.  
  45. def warn warning
  46.   puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}"
  47. end
  48.  
  49. def system *args
  50.   abort "Failed during: #{args.shell_s}" unless Kernel.system *args
  51. end
  52.  
  53. def sudo *args
  54.   args = if args.length > 1
  55.     args.unshift "/usr/bin/sudo"
  56.   else
  57.     "/usr/bin/sudo #{args}"
  58.   end
  59.   ohai *args
  60.   system *args
  61. end
  62.  
  63. def getc  # NOTE only tested on OS X
  64.   system "/bin/stty raw -echo"
  65.   if RUBY_VERSION >= '1.8.7'
  66.     STDIN.getbyte
  67.   else
  68.     STDIN.getc
  69.   end
  70. ensure
  71.   system "/bin/stty -raw echo"
  72. end
  73.  
  74. ####################################################################### script
  75. abort "/usr/local/.git already exists!" if File.directory? "/usr/local/.git"
  76. abort "Don't run this as root!" if Process.uid == 0
  77. abort <<-EOABORT unless `groups`.split.include? "staff"
  78. This script requires the user #{ENV['USER']} to be in the staff group. If this
  79. sucks for you then you can install Homebrew in your home directory or however
  80. you please; please refer to the website. If you still want to use this script
  81. the following command should work:
  82.  
  83.     dscl /Local/Default -append /Groups/staff GroupMembership $USER
  84. EOABORT
  85.  
  86. ohai "This script will install:"
  87. puts "/usr/local/bin/brew"
  88. puts "/usr/local/Library/Formula/..."
  89. puts "/usr/local/Library/Homebrew/..."
  90.  
  91. chmods = %w( . bin etc include lib lib/pkgconfig Library sbin share var share/locale share/man
  92.              share/man/man1 share/man/man2 share/man/man3 share/man/man4
  93.              share/man/man5 share/man/man6 share/man/man7 share/man/man8
  94.              share/info share/doc share/aclocal ).
  95.             map{ |d| "/usr/local/#{d}" }.
  96.             select{ |d| File.directory? d and not File.writable? d }
  97. chgrps = chmods.reject{ |d| File.stat(d).grpowned? }
  98.  
  99. unless chmods.empty?
  100.   ohai "The following directories will be made group writable:"
  101.   puts *chmods
  102. end
  103. unless chgrps.empty?
  104.   ohai "The following directories will have their group set to #{Tty.underline 39}staff#{Tty.reset}:"
  105.   puts *chgrps
  106. end
  107.  
  108. if STDIN.tty?
  109.   puts
  110.   puts "Press enter to continue"
  111.   abort unless getc == 13
  112. end
  113.  
  114. if File.directory? "/usr/local"
  115.   sudo "/bin/chmod", "g+w", *chmods unless chmods.empty?
  116.   # all admin users are in staff
  117.   sudo "/usr/bin/chgrp", "staff", *chgrps unless chgrps.empty?
  118. else
  119.   sudo "/bin/mkdir /usr/local"
  120.   sudo "/bin/chmod g+w /usr/local"
  121.   # the group is set to wheel by default for some reason
  122.   sudo "/usr/bin/chgrp staff /usr/local"
  123. end
  124.  
  125. Dir.chdir "/usr/local" do
  126.   ohai "Downloading and Installing Homebrew..."
  127.   # -m to stop tar erroring out if it can't modify the mtime for root owned directories
  128.   # pipefail to cause the exit status from curl to propogate if it fails
  129.   system "/bin/bash -o pipefail -c '/usr/bin/curl -sSfL https://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1'"
  130. end
  131.  
  132. ohai "Installation successful!"
  133.  
  134. warn "/usr/local/bin is not in your PATH." unless ENV['PATH'].split(':').include? '/usr/local/bin'
  135. warn "Now install Xcode: http://developer.apple.com/technologies/xcode.html" unless Kernel.system "/usr/bin/which -s gcc"