Skip to content

Instantly share code, notes, and snippets.

@ivanvc
Forked from mxcl/install_homebrew.markdown
Created March 31, 2011 21:01
Show Gist options
  • Save ivanvc/897243 to your computer and use it in GitHub Desktop.
Save ivanvc/897243 to your computer and use it in GitHub Desktop.

Revisions

  1. @mxcl mxcl revised this gist Dec 7, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/ruby
    #
    # This script installs to /usr/local only. To install elsewhere you can just
    # untar http://github.com/mxcl/homebrew/tarball/master anywhere you like.
    # untar https://github.com/mxcl/homebrew/tarball/master anywhere you like.
    #
    #
    # 30th March 2010:
  2. @mxcl mxcl revised this gist Nov 3, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -126,7 +126,7 @@ def getc # NOTE only tested on OS X
    ohai "Downloading and Installing Homebrew..."
    # -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 http://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1'"
    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

    ohai "Installation successful!"
  3. @mxcl mxcl revised this gist Sep 23, 2010. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -125,7 +125,8 @@ def getc # NOTE only tested on OS X
    Dir.chdir "/usr/local" do
    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 -sSfL http://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1"
    # pipefail to cause the exit status from curl to propogate if it fails
    system "/bin/bash -o pipefail -c '/usr/bin/curl -sSfL http://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1'"
    end

    ohai "Installation successful!"
  4. @adamv adamv revised this gist Aug 16, 2010. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -88,7 +88,10 @@ def getc # NOTE only tested on OS X
    puts "/usr/local/Library/Formula/..."
    puts "/usr/local/Library/Homebrew/..."

    chmods = %w(bin etc include lib lib/pkgconfig Library sbin share var . share/locale share/man share/man/man1 share/info share/doc share/aclocal).
    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? }
  5. @adamv adamv revised this gist Aug 16, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -52,9 +52,9 @@ def system *args

    def sudo *args
    args = if args.length > 1
    args.unshift "sudo"
    args.unshift "/usr/bin/sudo"
    else
    "sudo #{args}"
    "/usr/bin/sudo #{args}"
    end
    ohai *args
    system *args
  6. @adamv adamv revised this gist Jul 1, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -88,7 +88,7 @@ def getc # NOTE only tested on OS X
    puts "/usr/local/Library/Formula/..."
    puts "/usr/local/Library/Homebrew/..."

    chmods = %w(bin etc include lib libexec Library sbin share var . share/locale share/man share/man/man1 share/info share/doc share/aclocal).
    chmods = %w(bin etc include lib lib/pkgconfig Library sbin share var . share/locale share/man share/man/man1 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? }
  7. @adamv adamv revised this gist Jun 28, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -88,7 +88,7 @@ def getc # NOTE only tested on OS X
    puts "/usr/local/Library/Formula/..."
    puts "/usr/local/Library/Homebrew/..."

    chmods = %w(bin etc include lib libexec Library sbin share var . share/locale share/man share/info share/doc share/aclocal).
    chmods = %w(bin etc include lib libexec Library sbin share var . share/locale share/man share/man/man1 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? }
  8. @mxcl mxcl revised this gist Jun 23, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -128,4 +128,4 @@ def getc # NOTE only tested on OS X
    ohai "Installation successful!"

    warn "/usr/local/bin is not in your PATH." unless ENV['PATH'].split(':').include? '/usr/local/bin'
    warn "Now install Xcode." unless Kernel.system "/usr/bin/which -s gcc"
    warn "Now install Xcode: http://developer.apple.com/technologies/xcode.html" unless Kernel.system "/usr/bin/which -s gcc"
  9. @mxcl mxcl revised this gist Jun 23, 2010. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -102,9 +102,11 @@ def getc # NOTE only tested on OS X
    puts *chgrps
    end

    puts
    puts "Press enter to continue"
    abort unless getc == 13
    if STDIN.tty?
    puts
    puts "Press enter to continue"
    abort unless getc == 13
    end

    if File.directory? "/usr/local"
    sudo "/bin/chmod", "g+w", *chmods unless chmods.empty?
  10. @mxcl mxcl revised this gist Jun 16, 2010. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -45,11 +45,9 @@ def ohai *args
    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
    abort "Failed during: #{args.shell_s}" unless Kernel.system *args
    end

    def sudo *args
    @@ -128,4 +126,4 @@ def getc # NOTE only tested on OS X
    ohai "Installation successful!"

    warn "/usr/local/bin is not in your PATH." unless ENV['PATH'].split(':').include? '/usr/local/bin'
    warn "Now install Xcode." unless system "/usr/bin/which gcc"
    warn "Now install Xcode." unless Kernel.system "/usr/bin/which -s gcc"
  11. @mxcl mxcl revised this gist Jun 16, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/ruby
    #
    # This script is for installation to /usr/local only. To install eleswhere
    # just untar http://github.com/mxcl/homebrew/tarball/master anywhere you like.
    # This script installs to /usr/local only. To install elsewhere you can just
    # untar http://github.com/mxcl/homebrew/tarball/master anywhere you like.
    #
    #
    # 30th March 2010:
  12. @mxcl mxcl revised this gist Jun 16, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -90,7 +90,7 @@ def getc # NOTE only tested on OS X
    puts "/usr/local/Library/Formula/..."
    puts "/usr/local/Library/Homebrew/..."

    chmods = %w(bin etc include lib sbin share var . share/locale share/man share/info share/doc share/aclocal).
    chmods = %w(bin etc include lib libexec Library 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? }
  13. @mxcl mxcl revised this gist Jun 15, 2010. 1 changed file with 3 additions and 11 deletions.
    14 changes: 3 additions & 11 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,8 @@
    #!/usr/bin/ruby
    #
    # Download and execute this script in one-line with no temporary files:
    # This script is for installation to /usr/local only. To install eleswhere
    # just untar http://github.com/mxcl/homebrew/tarball/master anywhere you like.
    #
    # ruby -e "$(curl http://gist.github.com/raw/323731/install_homebrew.rb)"
    #
    #
    # I deliberately didn't DRY /usr/local references into a variable as this
    # script will not "just work" if you change the destination directory. However
    # please feel free to fork it and make that possible.
    #
    # 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.
    #
    # 30th March 2010:
    # Added a check to make sure user is in the staff group. This was a problem
    @@ -130,7 +122,7 @@ def getc # NOTE only tested on OS X
    Dir.chdir "/usr/local" do
    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 -sfL http://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1"
    system "/usr/bin/curl -sSfL http://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1"
    end

    ohai "Installation successful!"
  14. @mxcl mxcl revised this gist Jun 5, 2010. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -72,7 +72,11 @@ def sudo *args

    def getc # NOTE only tested on OS X
    system "/bin/stty raw -echo"
    STDIN.getbyte
    if RUBY_VERSION >= '1.8.7'
    STDIN.getbyte
    else
    STDIN.getc
    end
    ensure
    system "/bin/stty -raw echo"
    end
  15. @mxcl mxcl revised this gist May 27, 2010. 1 changed file with 2 additions and 8 deletions.
    10 changes: 2 additions & 8 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -131,11 +131,5 @@ def getc # NOTE only tested on OS X

    ohai "Installation successful!"

    if ENV['PATH'].split(':').include? '/usr/local/bin'
    puts "Yay! Now learn to brew:"
    puts
    puts " brew help"
    puts
    else
    warn "/usr/local/bin is not in your PATH"
    end
    warn "/usr/local/bin is not in your PATH." unless ENV['PATH'].split(':').include? '/usr/local/bin'
    warn "Now install Xcode." unless system "/usr/bin/which gcc"
  16. @mxcl mxcl revised this gist May 27, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -72,7 +72,7 @@ def sudo *args

    def getc # NOTE only tested on OS X
    system "/bin/stty raw -echo"
    STDIN.getc
    STDIN.getbyte
    ensure
    system "/bin/stty -raw echo"
    end
  17. @adamv adamv revised this gist May 19, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -71,10 +71,10 @@ def sudo *args
    end

    def getc # NOTE only tested on OS X
    system "stty raw -echo"
    system "/bin/stty raw -echo"
    STDIN.getc
    ensure
    system "stty -raw echo"
    system "/bin/stty -raw echo"
    end

    ####################################################################### script
  18. @mattetti mattetti revised this gist May 18, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -72,7 +72,7 @@ def sudo *args

    def getc # NOTE only tested on OS X
    system "stty raw -echo"
    STDIN.getc
    STDIN.getbyte
    ensure
    system "stty -raw echo"
    end
  19. @mxcl mxcl revised this gist May 5, 2010. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,10 @@
    #!/usr/bin/ruby
    #
    # Download and execute this script in one-line with no temporary files:
    #
    # ruby -e "$(curl http://gist.github.com/raw/323731/install_homebrew.rb)"
    #
    #
    # I deliberately didn't DRY /usr/local references into a variable as this
    # script will not "just work" if you change the destination directory. However
    # please feel free to fork it and make that possible.
  20. @mxcl mxcl revised this gist Apr 6, 2010. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -75,10 +75,14 @@ def getc # NOTE only tested on OS X
    ####################################################################### script
    abort "/usr/local/.git already exists!" if File.directory? "/usr/local/.git"
    abort "Don't run this as root!" if Process.uid == 0
    abort <<-EOABORT unless `groups`.split.include? "staff"
    This script requires the user #{ENV['USER']} to be in the staff group. If this
    sucks for you then you can install Homebrew in your home directory or however
    you please; please refer to the website. If you still want to use this script
    the following command should work:
    unless `groups`.split.include?("staff")
    ohai "The user #{`whoami`.strip} will be added to the staff group."
    end
    dscl /Local/Default -append /Groups/staff GroupMembership $USER
    EOABORT

    ohai "This script will install:"
    puts "/usr/local/bin/brew"
    @@ -103,10 +107,6 @@ def getc # NOTE only tested on OS X
    puts "Press enter to continue"
    abort unless getc == 13

    unless `groups`.split.include?("staff")
    sudo "dscl /Local/Default -append /Groups/staff GroupMembership #{`whoami`.strip}"
    end

    if File.directory? "/usr/local"
    sudo "/bin/chmod", "g+w", *chmods unless chmods.empty?
    # all admin users are in staff
  21. @mxcl mxcl revised this gist Apr 6, 2010. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -76,6 +76,10 @@ def getc # NOTE only tested on OS X
    abort "/usr/local/.git already exists!" if File.directory? "/usr/local/.git"
    abort "Don't run this as root!" if Process.uid == 0

    unless `groups`.split.include?("staff")
    ohai "The user #{`whoami`.strip} will be added to the staff group."
    end

    ohai "This script will install:"
    puts "/usr/local/bin/brew"
    puts "/usr/local/Library/Formula/..."
    @@ -86,10 +90,6 @@ def getc # NOTE only tested on OS X
    select{ |d| File.directory? d and not File.writable? d }
    chgrps = chmods.reject{ |d| File.stat(d).grpowned? }

    unless `groups`.split.include?("staff")
    ohai "The user #{`whoami`.strip} will be added to the staff group."
    end

    unless chmods.empty?
    ohai "The following directories will be made group writable:"
    puts *chmods
  22. dbgrandi revised this gist Mar 29, 2010. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,12 @@
    # versions of OS X. I cannot verify that for sure, and it was tested on
    # 10.6.2 using the Directory Service command line utility and my laptop.
    #
    # My assumptions are:
    # - you are running OS X 10.6.x
    # - your machine is not managed as part of a group using networked
    # Directory Services
    # - you have not recently killed any baby seals or kittens
    #
    # 14th March 2010:
    # Adapted CodeButler's fork: http://gist.github.com/331512
    #
  23. dbgrandi revised this gist Mar 29, 2010. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,12 @@
    # 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.
    #
    # 30th March 2010:
    # Added a check to make sure user is in the staff group. This was a problem
    # for me, and I think it was due to me migrating my account over several
    # versions of OS X. I cannot verify that for sure, and it was tested on
    # 10.6.2 using the Directory Service command line utility and my laptop.
    #
    # 14th March 2010:
    # Adapted CodeButler's fork: http://gist.github.com/331512
    #
    @@ -74,6 +80,10 @@ def getc # NOTE only tested on OS X
    select{ |d| File.directory? d and not File.writable? d }
    chgrps = chmods.reject{ |d| File.stat(d).grpowned? }

    unless `groups`.split.include?("staff")
    ohai "The user #{`whoami`.strip} will be added to the staff group."
    end

    unless chmods.empty?
    ohai "The following directories will be made group writable:"
    puts *chmods
    @@ -87,6 +97,10 @@ def getc # NOTE only tested on OS X
    puts "Press enter to continue"
    abort unless getc == 13

    unless `groups`.split.include?("staff")
    sudo "dscl /Local/Default -append /Groups/staff GroupMembership #{`whoami`.strip}"
    end

    if File.directory? "/usr/local"
    sudo "/bin/chmod", "g+w", *chmods unless chmods.empty?
    # all admin users are in staff
  24. @mxcl mxcl revised this gist Mar 14, 2010. 1 changed file with 11 additions and 10 deletions.
    21 changes: 11 additions & 10 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -8,15 +8,14 @@
    # changes are intended to do and how well you tested them.
    #
    # 14th March 2010:
    #  Adapted CodeButler's fork: http://gist.github.com/331512
    # 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
    @@ -26,7 +25,7 @@ class Array
    def shell_s
    cp = dup
    first = cp.shift
    cp.map{ |arg| gsub " ", "\\ " }.unshift(first) * " "
    cp.map{ |arg| arg.gsub " ", "\\ " }.unshift(first) * " "
    end
    end

    @@ -73,28 +72,30 @@ def getc # NOTE only tested on OS X
    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"
    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"
    end

    unless File.stat("/usr/local").grpowned?
    warn "You are not a member of the group: %s" % `/usr/bin/stat -f%Sg /usr/local`
    puts "This is the group of /usr/local."
    puts "Type groups to see what groups you are in."
    abort "See the Homebrew wiki for alternative installation routes."
    # the group is set to wheel by default for some reason
    sudo "/usr/bin/chgrp staff /usr/local"
    end

    Dir.chdir "/usr/local" do
  25. @mxcl mxcl revised this gist Mar 14, 2010. 1 changed file with 40 additions and 17 deletions.
    57 changes: 40 additions & 17 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,9 @@
    # 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
    @@ -19,23 +22,36 @@ 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}"
    class Array
    def shell_s
    cp = dup
    first = cp.shift
    cp.map{ |arg| gsub " ", "\\ " }.unshift(first) * " "
    end
    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
    end
    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

    def opoo warning
    puts "#{Tty.red}Warning#{Tty.reset}: #{warning}"
    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 +63,7 @@ def getc # NOTE only tested on OS X

    ####################################################################### 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"
    @@ -73,11 +90,17 @@ def getc # NOTE only tested on OS X
    sudo "/bin/chmod g+w /usr/local"
    end

    unless File.stat("/usr/local").grpowned?
    warn "You are not a member of the group: %s" % `/usr/bin/stat -f%Sg /usr/local`
    puts "This is the group of /usr/local."
    puts "Type groups to see what groups you are in."
    abort "See the Homebrew wiki for alternative installation routes."
    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 +111,5 @@ def getc # NOTE only tested on OS X
    puts " brew help"
    puts
    else
    opoo "/usr/local/bin is not in your PATH"
    warn "/usr/local/bin is not in your PATH"
    end
  26. @mxcl mxcl revised this gist Mar 13, 2010. 1 changed file with 29 additions and 17 deletions.
    46 changes: 29 additions & 17 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@
    # script will not "just work" if you change the destination directory. However
    # please feel free to fork it and make that possible.
    #
    # If you do fork ensure you add a comment here that explains what the changes
    # are intended to do and how well you tested them.
    # 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.
    #

    module Tty extend self
    @@ -16,28 +16,37 @@ 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
    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
    params.unshift "sudo"
    ohai params.map{ |p| p.gsub ' ', '\\ ' } * ' '
    system *params
    if params.length == 1
    cmd = "sudo #{params.first}"
    ohai cmd
    system cmd
    else
    ohai "sudo" + params.map{ |p| p.gsub ' ', '\\ ' } * ' '
    system "sudo", *params
    end
    end

    def opoo warning
    puts "#{Tty.red}Warning#{Tty.reset}: #{warning}"
    end

    ####################################################################### script
    require 'fileutils'
    include FileUtils
    def getc # NOTE only tested on OS X
    system "stty raw -echo"
    STDIN.getc
    ensure
    system "stty -raw echo"
    end

    #abort "/usr/local/.git already exists!" if File.directory? '/usr/local/.git'
    ####################################################################### script
    abort "/usr/local/.git already exists!" if File.directory? "/usr/local/.git"

    ohai "This script will install:"
    puts "/usr/local/bin/brew"
    @@ -55,26 +64,29 @@ def opoo warning

    puts
    puts "Press enter to continue"
    abort if gets != "\n"
    abort unless getc == 13

    if File.directory? '/usr/local'
    if File.directory? "/usr/local"
    sudo "/bin/chmod", "g+w", *chmods unless chmods.empty?
    else
    sudo "/bin/mkdir", '/usr/local'
    sudo "/bin/chmod", "g+w", '/usr/local'
    sudo "/bin/mkdir /usr/local"
    sudo "/bin/chmod g+w /usr/local"
    end

    cd '/usr/local' do
    Dir.chdir "/usr/local" do
    tarball = "http://github.com/mxcl/homebrew/tarball/master"
    ohai "Extracting: #{tarball}"
    # -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"
    end

    ohai "Installation successful"
    ohai "Installation successful!"

    if ENV['PATH'].split(':').include? '/usr/local/bin'
    puts "Now try: brew help"
    puts "Yay! Now learn to brew:"
    puts
    puts " brew help"
    puts
    else
    opoo "/usr/local/bin is not in your PATH"
    end
  27. @mxcl mxcl created this gist Mar 6, 2010.
    80 changes: 80 additions & 0 deletions install_homebrew.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    #!/usr/bin/ruby
    #
    # I deliberately didn't DRY /usr/local references into a variable as this
    # script will not "just work" if you change the destination directory. However
    # please feel free to fork it and make that possible.
    #
    # If you do fork ensure you add a comment here that explains what the changes
    # are intended to do and how well you tested them.
    #

    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
    params.unshift "sudo"
    ohai params.map{ |p| p.gsub ' ', '\\ ' } * ' '
    system *params
    end

    def opoo warning
    puts "#{Tty.red}Warning#{Tty.reset}: #{warning}"
    end

    ####################################################################### script
    require 'fileutils'
    include FileUtils

    #abort "/usr/local/.git already exists!" if File.directory? '/usr/local/.git'

    ohai "This script will install:"
    puts "/usr/local/bin/brew"
    puts "/usr/local/Library/Formula/..."
    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 }

    unless chmods.empty?
    ohai "The following directories will be made group writable:"
    puts *chmods
    end

    puts
    puts "Press enter to continue"
    abort if gets != "\n"

    if File.directory? '/usr/local'
    sudo "/bin/chmod", "g+w", *chmods unless chmods.empty?
    else
    sudo "/bin/mkdir", '/usr/local'
    sudo "/bin/chmod", "g+w", '/usr/local'
    end

    cd '/usr/local' do
    tarball = "http://github.com/mxcl/homebrew/tarball/master"
    ohai "Extracting: #{tarball}"
    # -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"
    end

    ohai "Installation successful"

    if ENV['PATH'].split(':').include? '/usr/local/bin'
    puts "Now try: brew help"
    else
    opoo "/usr/local/bin is not in your PATH"
    end