2010-03-06 08:14:26 -07:00
|
|
|
|
#!/usr/bin/ruby
|
2010-06-15 12:00:51 +01:00
|
|
|
|
# This script installs to /usr/local only. To install elsewhere you can just
|
2012-03-09 11:57:53 +00:00
|
|
|
|
# untar https://github.com/mxcl/homebrew/tarball/master anywhere you like.
|
2010-03-06 08:14:26 -07:00
|
|
|
|
|
|
|
|
|
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 bold n; escape "1;#{n}" end
|
|
|
|
|
def underline n; escape "4;#{n}" end
|
2010-03-13 06:24:44 -07:00
|
|
|
|
def escape n; "\033[#{n}m" if STDOUT.tty? end
|
2010-03-06 08:14:26 -07:00
|
|
|
|
end
|
|
|
|
|
|
2010-03-14 05:20:27 -07:00
|
|
|
|
class Array
|
|
|
|
|
def shell_s
|
|
|
|
|
cp = dup
|
|
|
|
|
first = cp.shift
|
|
|
|
|
cp.map{ |arg| arg.gsub " ", "\\ " }.unshift(first) * " "
|
|
|
|
|
end
|
2010-03-06 08:14:26 -07:00
|
|
|
|
end
|
|
|
|
|
|
2010-03-14 05:20:27 -07:00
|
|
|
|
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}"
|
2010-03-06 08:14:26 -07:00
|
|
|
|
end
|
2010-03-14 05:20:27 -07:00
|
|
|
|
|
|
|
|
|
def system *args
|
2010-06-16 13:17:54 +01:00
|
|
|
|
abort "Failed during: #{args.shell_s}" unless Kernel.system *args
|
2010-03-14 05:20:27 -07:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def sudo *args
|
|
|
|
|
args = if args.length > 1
|
2012-03-09 11:57:10 +00:00
|
|
|
|
args.unshift "/usr/bin/sudo"
|
2010-03-14 05:20:27 -07:00
|
|
|
|
else
|
2011-08-06 12:02:55 +01:00
|
|
|
|
"/usr/bin/sudo #{args.first}"
|
2010-03-14 05:20:27 -07:00
|
|
|
|
end
|
|
|
|
|
ohai *args
|
|
|
|
|
system *args
|
2010-03-06 08:14:26 -07:00
|
|
|
|
end
|
|
|
|
|
|
2010-03-13 06:24:44 -07:00
|
|
|
|
def getc # NOTE only tested on OS X
|
2012-03-09 12:04:01 +00:00
|
|
|
|
system "/bin/stty raw -echo"
|
2010-06-05 12:29:37 +01:00
|
|
|
|
if RUBY_VERSION >= '1.8.7'
|
|
|
|
|
STDIN.getbyte
|
|
|
|
|
else
|
|
|
|
|
STDIN.getc
|
|
|
|
|
end
|
2010-03-13 06:24:44 -07:00
|
|
|
|
ensure
|
2012-03-09 12:04:01 +00:00
|
|
|
|
system "/bin/stty -raw echo"
|
2010-03-13 06:24:44 -07:00
|
|
|
|
end
|
2010-03-06 08:14:26 -07:00
|
|
|
|
|
2011-07-29 15:20:32 +01:00
|
|
|
|
def badlibs
|
|
|
|
|
@badlibs ||= begin
|
|
|
|
|
Dir['/usr/local/lib/*.dylib'].select do |dylib|
|
|
|
|
|
ENV['dylib'] = dylib
|
|
|
|
|
File.file? dylib and not File.symlink? dylib and `/usr/bin/file "$dylib"` =~ /shared library/
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-03-13 06:24:44 -07:00
|
|
|
|
####################################################################### script
|
2011-07-29 15:17:35 +01:00
|
|
|
|
abort "/usr/local/.git already exists!" unless Dir["/usr/local/.git/*"].empty?
|
2010-03-14 05:20:27 -07:00
|
|
|
|
abort "Don't run this as root!" if Process.uid == 0
|
2010-04-06 13:58:56 +01:00
|
|
|
|
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:
|
2010-03-06 08:14:26 -07:00
|
|
|
|
|
2010-04-06 13:58:56 +01:00
|
|
|
|
dscl /Local/Default -append /Groups/staff GroupMembership $USER
|
|
|
|
|
EOABORT
|
2010-04-06 13:45:16 +01:00
|
|
|
|
|
2010-03-06 08:14:26 -07:00
|
|
|
|
ohai "This script will install:"
|
|
|
|
|
puts "/usr/local/bin/brew"
|
|
|
|
|
puts "/usr/local/Library/Formula/..."
|
|
|
|
|
puts "/usr/local/Library/Homebrew/..."
|
|
|
|
|
|
2011-07-29 15:20:00 +01:00
|
|
|
|
chmods = %w( share/man lib/pkgconfig var/log share/locale
|
2012-03-09 11:57:33 +00:00
|
|
|
|
share/man/man1 share/man/man2 share/man/man3 share/man/man4
|
|
|
|
|
share/man/man5 share/man/man6 share/man/man7 share/man/man8
|
2011-07-29 15:20:00 +01:00
|
|
|
|
share/info share/doc share/aclocal ).map{ |d| "/usr/local/#{d}" }
|
|
|
|
|
root_dirs = []
|
|
|
|
|
%w(bin Cellar etc include lib Library sbin share var .git).each do |d|
|
|
|
|
|
d = "/usr/local/#{d}"
|
|
|
|
|
if File.directory? d then chmods else root_dirs end << d
|
|
|
|
|
end
|
|
|
|
|
chmods = chmods.select{ |d| File.directory? d and not File.writable? d }
|
2010-03-14 05:20:27 -07:00
|
|
|
|
chgrps = chmods.reject{ |d| File.stat(d).grpowned? }
|
2010-03-06 08:14:26 -07:00
|
|
|
|
|
|
|
|
|
unless chmods.empty?
|
|
|
|
|
ohai "The following directories will be made group writable:"
|
|
|
|
|
puts *chmods
|
|
|
|
|
end
|
2010-03-14 05:20:27 -07:00
|
|
|
|
unless chgrps.empty?
|
|
|
|
|
ohai "The following directories will have their group set to #{Tty.underline 39}staff#{Tty.reset}:"
|
|
|
|
|
puts *chgrps
|
|
|
|
|
end
|
2010-03-06 08:14:26 -07:00
|
|
|
|
|
2011-07-29 15:20:00 +01:00
|
|
|
|
|
2010-06-23 16:25:53 +01:00
|
|
|
|
if STDIN.tty?
|
|
|
|
|
puts
|
|
|
|
|
puts "Press enter to continue"
|
|
|
|
|
abort unless getc == 13
|
|
|
|
|
end
|
2010-03-06 08:14:26 -07:00
|
|
|
|
|
2011-07-29 15:20:00 +01:00
|
|
|
|
sudo "/bin/mkdir /usr/local" unless File.directory? "/usr/local"
|
|
|
|
|
sudo "/bin/chmod o+w /usr/local"
|
2011-08-06 11:28:07 +01:00
|
|
|
|
begin
|
|
|
|
|
sudo "/bin/chmod", "g+w", *chmods unless chmods.empty?
|
|
|
|
|
sudo "/usr/bin/chgrp", "staff", *chgrps unless chgrps.empty?
|
|
|
|
|
system "/bin/mkdir", *root_dirs unless root_dirs.empty?
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
# 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
|
|
|
|
|
ensure
|
|
|
|
|
# we reset the permissions of /usr/local because we want to minimise the
|
|
|
|
|
# amount of fiddling we do to the system. Some tools require /usr/local to
|
|
|
|
|
# be by non-writable for non-root users.
|
|
|
|
|
sudo "/bin/chmod o-w /usr/local"
|
2010-03-06 08:14:26 -07:00
|
|
|
|
end
|
|
|
|
|
|
2010-05-28 00:54:53 +01:00
|
|
|
|
warn "/usr/local/bin is not in your PATH." unless ENV['PATH'].split(':').include? '/usr/local/bin'
|
2010-06-23 16:26:02 +01:00
|
|
|
|
warn "Now install Xcode: http://developer.apple.com/technologies/xcode.html" unless Kernel.system "/usr/bin/which -s gcc"
|
2011-07-29 15:20:32 +01:00
|
|
|
|
|
|
|
|
|
unless badlibs.empty?
|
|
|
|
|
warn "The following *evil* dylibs exist in /usr/local/lib"
|
|
|
|
|
puts "They may break builds or worse. You should consider deleting them:"
|
|
|
|
|
puts *badlibs
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ohai "Installation successful!"
|
|
|
|
|
puts "Now type: brew help"
|