pax_global_header00006660000000000000000000000064131072446270014520gustar00rootroot0000000000000052 comment=65469bf67f49c9811d44e04f76d7cdca4b6c8dd1 .rubocop.yml000066400000000000000000000054471310724462700133500ustar00rootroot00000000000000# Ruby 1.8 compatibility (for OS X < 10.10) Style/DotPosition: EnforcedStyle: trailing Style/HashSyntax: EnforcedStyle: hash_rockets Style/TrailingCommaInArguments: EnforcedStyleForMultiline: no_comma Metrics/AbcSize: Enabled: false Metrics/ClassLength: Enabled: false Metrics/CyclomaticComplexity: Enabled: false Metrics/LineLength: Enabled: false Metrics/MethodLength: Enabled: false Metrics/ModuleLength: CountComments: false Metrics/PerceivedComplexity: Enabled: false # favor parens-less DSL-style arguments Lint/AmbiguousOperator: Enabled: false Lint/AssignmentInCondition: Enabled: false Lint/EndAlignment: EnforcedStyleAlignWith: variable Style/Alias: EnforcedStyle: prefer_alias Style/AlignHash: Enabled: false # `system` is a special case and aligns on second argument Style/AlignParameters: Enabled: false Style/BarePercentLiterals: EnforcedStyle: percent_q Style/BlockDelimiters: EnforcedStyle: line_count_based Style/CaseIndentation: EnforcedStyle: end Style/ClassAndModuleChildren: EnforcedStyle: nested # percent-x is allowed for multiline Style/CommandLiteral: EnforcedStyle: mixed # our current conditional style is established, clear and # requiring users to change that now would be confusing. Style/ConditionalAssignment: Enabled: false Style/Documentation: Enabled: false Style/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true # dashes in filenames are typical Style/FileName: Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/ # disabled until it respects line length Style/IfUnlessModifier: Enabled: false Style/IndentArray: EnforcedStyle: special_inside_parentheses Style/IndentHeredoc: Enabled: false # only for numbers >= 1_000_000 Style/NumericLiterals: MinDigits: 7 # zero-prefixed octal literals are just too widely used (and mostly understood) Style/NumericLiteralPrefix: EnforcedOctalStyle: zero_only # consistency and readability when faced with string interpolation Style/PercentLiteralDelimiters: PreferredDelimiters: '%': '()' '%i': '()' '%q': '()' '%Q': '()' '%r': '{}' '%s': '()' '%w': '[]' '%W': '[]' '%x': '()' # we prefer Perl-style regex back references Style/PerlBackrefs: Enabled: false Style/RaiseArgs: EnforcedStyle: exploded # paths abound, easy escape Style/RegexpLiteral: EnforcedStyle: slashes # conflicts with DSL-style path concatenation with `/` Style/SpaceAroundOperators: Enabled: false # not a problem for typical shell users Style/SpecialGlobalVars: Enabled: false # ruby style guide favorite Style/StringLiterals: EnforcedStyle: double_quotes # consistency with above Style/StringLiteralsInInterpolation: EnforcedStyle: double_quotes Style/TernaryParentheses: Enabled: false Style/VariableNumber: Enabled: false Style/WordArray: Enabled: false .travis.yml000066400000000000000000000004531310724462700131770ustar00rootroot00000000000000language: ruby os: linux rvm: 2.0.0 sudo: required dist: trusty script: - gem install rubocop - rubocop - ./install --force-curl - ./uninstall -f || true - sudo rm -rf /home/linuxbrew/.linuxbrew - ./install - /home/linuxbrew/.linuxbrew/bin/brew install ack - ./uninstall -f || true LICENSE.txt000066400000000000000000000023311310724462700127060ustar00rootroot00000000000000Copyright 2009-2016 Homebrew contributors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. README.md000066400000000000000000000011151310724462700123410ustar00rootroot00000000000000# Linuxbrew (un)installer [![Build Status](https://travis-ci.org/Linuxbrew/install.svg?branch=master)](https://travis-ci.org/Linuxbrew/install) ## Install Linuxbrew ```bash /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)" ``` More installation information and options at http://linuxbrew.sh/#installation ## Uninstall Linuxbrew ```bash /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/uninstall)" ``` Download the uninstall script and run `./uninstall --help` to view more uninstall options. install000077500000000000000000000355651310724462700124760ustar00rootroot00000000000000#!/usr/bin/env ruby # This script installs only to /usr/local on Mac or ~/.linuxbrew on Linux. # To install elsewhere you can just untar # https://github.com/Homebrew/homebrew/tarball/master anywhere you like or # change the value of HOMEBREW_PREFIX. def mac? RUBY_PLATFORM[/darwin/] end def linux? RUBY_PLATFORM[/linux/] end if mac? HOMEBREW_NAME = "Homebrew".freeze HOMEBREW_PREFIX = "/usr/local".freeze HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze HOMEBREW_OLD_CACHE = "/Library/Caches/Homebrew".freeze BREW_REPO = "https://github.com/Homebrew/brew".freeze CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze else HOMEBREW_NAME = "Linuxbrew".freeze HOMEBREW_PREFIX_DEFAULT = "/home/linuxbrew/.linuxbrew".freeze HOMEBREW_CACHE = "#{ENV["HOME"]}/.cache/Homebrew".freeze HOMEBREW_OLD_CACHE = nil BREW_REPO = "https://github.com/Linuxbrew/brew".freeze CORE_TAP_REPO = "https://github.com/Linuxbrew/homebrew-core".freeze end # no analytics during installation ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1" ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"] = "1" module Tty module_function def blue bold 34 end def red bold 31 end def reset escape 0 end def bold(n = 39) escape "1;#{n}" end def underline escape "4;39" end def escape(n) "\033[#{n}m" if STDOUT.tty? end end class Array def shell_s cp = dup first = cp.shift cp.map { |arg| arg.gsub " ", "\\ " }.unshift(first).join(" ") end end def ohai(*args) puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}" end def warn(warning) puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}" end def system(*args) abort "Failed during: #{args.shell_s}" unless Kernel.system(*args) end def sudo? return @have_sudo unless @have_sudo.nil? Kernel.system "/usr/bin/sudo", "-v" @have_sudo = $? && $?.success? end def sudo(*args) if sudo? args.unshift("-A") unless ENV["SUDO_ASKPASS"].nil? ohai "/usr/bin/sudo", *args system "/usr/bin/sudo", *args else ohai *args system *args end end def getc # NOTE only tested on OS X system "/bin/stty raw -echo" if STDIN.respond_to?(:getbyte) STDIN.getbyte else STDIN.getc end ensure system "/bin/stty -raw echo" end def wait_for_user puts puts "Press RETURN to continue or any other key to abort" c = getc # we test for \r and \n because some stuff does \r instead abort unless (c == 13) || (c == 10) end class Version include Comparable attr_reader :parts def initialize(str) @parts = str.split(".").map(&:to_i) end def <=>(other) parts <=> self.class.new(other).parts end end def force_curl? ARGV.include?("--force-curl") end def macos_version return nil unless mac? @macos_version ||= Version.new(`/usr/bin/sw_vers -productVersion`.chomp[/10\.\d+/]) end def should_install_command_line_tools? return false if force_curl? return false if !mac? || macos_version < "10.9" developer_dir = `/usr/bin/xcode-select -print-path 2>/dev/null`.chomp developer_dir.empty? || !File.exist?("#{developer_dir}/usr/bin/git") end def git return false if force_curl? @git ||= if ENV["GIT"] && File.executable?(ENV["GIT"]) ENV["GIT"] elsif Kernel.system "/usr/bin/which git >/dev/null" "git" else exe = `xcrun -find git 2>/dev/null`.chomp exe if $? && $?.success? && !exe.empty? && File.executable?(exe) end return unless @git # Github only supports HTTPS fetches on 1.7.10 or later: # https://help.github.com/articles/https-cloning-errors `#{@git} --version` =~ /git version (\d\.\d+\.\d+)/ return if $1.nil? return if Version.new($1) < "1.7.10" @git end def user_only_chmod?(d) return false unless File.directory?(d) mode = File.stat(d).mode & 0777 # u = (mode >> 6) & 07 # g = (mode >> 3) & 07 # o = (mode >> 0) & 07 mode != 0755 end def chmod?(d) File.exist?(d) && !(File.readable?(d) && File.writable?(d) && File.executable?(d)) end def chown?(d) !File.owned?(d) end def chgrp?(d) !File.grpowned?(d) end # return the shell profile file based on users' preference shell def shell_profile case ENV["SHELL"] when %r{/(ba)?sh} then "~/.bash_profile" when %r{/zsh} then "~/.zshrc" when %r{/ksh} then "~/.kshrc" else "~/.bash_profile" end end # Invalidate sudo timestamp before exiting (if it wasn't active before). Kernel.system "/usr/bin/sudo -n -v 2>/dev/null" at_exit { Kernel.system "/usr/bin/sudo", "-k" } unless $?.success? # The block form of Dir.chdir fails later if Dir.CWD doesn't exist which I # guess is fair enough. Also sudo prints a warning message for no good reason Dir.chdir "/usr" ####################################################################### script abort "MacOS too old, see: https://github.com/mistydemeo/tigerbrew" if mac? && macos_version < "10.6" abort "Don't run this as root!" if Process.uid.zero? abort <<-EOABORT unless !mac? || `dsmemberutil checkmembership -U "#{ENV["USER"]}" -G admin`.include?("user is a member") This script requires the user #{ENV["USER"]} to be an Administrator. EOABORT unless mac? if File.writable?(HOMEBREW_PREFIX_DEFAULT) || File.writable?("/home/linuxbrew") || File.writable?("/home") HOMEBREW_PREFIX = HOMEBREW_PREFIX_DEFAULT.freeze else Kernel.system "/usr/bin/sudo -n -v 2>/dev/null" unless $?.success? ohai "Select the Linuxbrew installation directory" puts "- #{Tty.bold}Enter your password#{Tty.reset} to install to #{Tty.underline}#{HOMEBREW_PREFIX_DEFAULT}#{Tty.reset} (#{Tty.bold}recommended#{Tty.reset})" puts "- #{Tty.bold}Press Control-D#{Tty.reset} to install to #{Tty.underline}#{ENV["HOME"]}/.linuxbrew#{Tty.reset}" puts "- #{Tty.bold}Press Control-C#{Tty.reset} to cancel installation" end if sudo? HOMEBREW_PREFIX = HOMEBREW_PREFIX_DEFAULT.freeze else HOMEBREW_PREFIX = "#{ENV["HOME"]}/.linuxbrew".freeze end end HOMEBREW_REPOSITORY = "#{HOMEBREW_PREFIX}/Homebrew".freeze end # Tests will fail if the prefix exists, but we don't have execution # permissions. Abort in this case. abort <<-EOABORT if File.directory?(HOMEBREW_PREFIX) && (!File.executable? HOMEBREW_PREFIX) The Homebrew prefix, #{HOMEBREW_PREFIX}, exists but is not searchable. If this is not intentional, please restore the default permissions and try running the installer again: sudo chmod 775 #{HOMEBREW_PREFIX} EOABORT ohai "This script will install:" puts "#{HOMEBREW_PREFIX}/bin/brew" puts "#{HOMEBREW_PREFIX}/share/doc/homebrew" puts "#{HOMEBREW_PREFIX}/share/man/man1/brew.1" puts "#{HOMEBREW_PREFIX}/share/zsh/site-functions/_brew" puts "#{HOMEBREW_PREFIX}/etc/bash_completion.d/brew" puts "#{HOMEBREW_CACHE}/" puts HOMEBREW_REPOSITORY.to_s group_chmods = %w[ bin bin/brew etc include lib sbin share var etc/bash_completion.d lib/pkgconfig var/log share/aclocal share/doc share/info 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]. map { |d| File.join(HOMEBREW_PREFIX, d) }. select { |d| chmod?(d) } # zsh refuses to read from these directories if group writable zsh_dirs = %w[share/zsh share/zsh/site-functions]. map { |d| File.join(HOMEBREW_PREFIX, d) } user_chmods = zsh_dirs.select { |d| user_only_chmod?(d) } chmods = group_chmods + user_chmods chowns = chmods.select { |d| chown?(d) } chgrps = chmods.select { |d| chgrp?(d) } mkdirs = %w[Cellar bin etc include lib opt sbin share share/zsh share/zsh/site-functions var]. map { |d| File.join(HOMEBREW_PREFIX, d) }. reject { |d| File.directory?(d) } mkdirs << HOMEBREW_REPOSITORY unless mkdirs.include?(HOMEBREW_REPOSITORY) || File.directory?(HOMEBREW_REPOSITORY) group = `id -gn`.chomp odie "error: id -gn: failed" unless $?.success? && !group.empty? unless group_chmods.empty? ohai "The following existing directories will be made group writable:" puts(*group_chmods) end unless user_chmods.empty? ohai "The following existing directories will be made writable by user only:" puts(*user_chmods) end unless chowns.empty? ohai "The following existing directories will have their owner set to #{Tty.underline}#{ENV["USER"]}#{Tty.reset}:" puts(*chowns) end unless chgrps.empty? ohai "The following existing directories will have their group set to #{Tty.underline}#{group}#{Tty.reset}:" puts(*chgrps) end unless mkdirs.empty? ohai "The following new directories will be created:" puts(*mkdirs) end wait_for_user if STDIN.tty? && !ENV["TRAVIS"] if File.directory? HOMEBREW_PREFIX sudo "/bin/chmod", "u+rwx", *chmods unless chmods.empty? sudo "/bin/chmod", "g+rwx", *group_chmods unless group_chmods.empty? sudo "/bin/chmod", "755", *user_chmods unless user_chmods.empty? sudo "/bin/chown", ENV["USER"], *chowns unless chowns.empty? sudo "/bin/chgrp", group, *chgrps unless chgrps.empty? else sudo "/bin/mkdir", "-p", HOMEBREW_PREFIX sudo "/bin/chown", "#{ENV["USER"]}:#{group}", HOMEBREW_PREFIX end unless mkdirs.empty? sudo "/bin/mkdir", "-p", *mkdirs sudo "/bin/chmod", "g+rwx", *mkdirs sudo "/bin/chmod", "755", *zsh_dirs sudo "/bin/chown", ENV["USER"], *mkdirs sudo "/bin/chgrp", group, *mkdirs end [HOMEBREW_CACHE, HOMEBREW_OLD_CACHE].compact.each do |cache| sudo "/bin/mkdir", "-p", cache unless File.directory? cache sudo "/bin/chmod", "g+rwx", cache if chmod? cache sudo "/bin/chown", ENV["USER"], cache if chown? cache sudo "/bin/chgrp", group, cache if chgrp? cache end if should_install_command_line_tools? ohai "Searching online for the Command Line Tools" # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools clt_placeholder = "/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" sudo "/usr/bin/touch", clt_placeholder clt_label = `softwareupdate -l | grep -B 1 -E "Command Line (Developer|Tools)" | awk -F"*" '/^ +\\*/ {print $2}' | sed 's/^ *//' | tail -n1`.chomp ohai "Installing #{clt_label}" sudo "/usr/sbin/softwareupdate", "-i", clt_label sudo "/bin/rm", "-f", clt_placeholder sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools" end # Headless install may have failed, so fallback to original 'xcode-select' method if should_install_command_line_tools? && STDIN.tty? ohai "Installing the Command Line Tools (expect a GUI popup):" sudo "/usr/bin/xcode-select", "--install" puts "Press any key when the installation has completed." getc sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools" end abort <<-EOABORT if mac? && `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success? You have not agreed to the Xcode license. Before running the installer again please agree to the license by opening Xcode.app or running: sudo xcodebuild -license EOABORT ohai "Downloading and installing #{HOMEBREW_NAME}..." Dir.chdir HOMEBREW_REPOSITORY do if git # we do it in four steps to avoid merge errors when reinstalling system git, "init", "-q" # "git remote add" will fail if the remote is defined in the global config system git, "config", "remote.origin.url", BREW_REPO system git, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*" # ensure we don't munge line endings on checkout system git, "config", "core.autocrlf", "false" args = git, "fetch", "origin", "master:refs/remotes/origin/master", "--tags", "--force" args << "--depth=1" unless ARGV.include?("--full") || !ENV["HOMEBREW_DEVELOPER"].nil? system(*args) system git, "reset", "--hard", "origin/master" system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew" unless HOMEBREW_REPOSITORY == HOMEBREW_PREFIX system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force" else # -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 propagate if it fails curl_flags = "fsSL" core_tap = "#{HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core" system "/bin/bash -o pipefail -c '/usr/bin/curl -#{curl_flags} #{BREW_REPO}/tarball/master | /bin/tar xz -m --strip 1'" system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew" unless HOMEBREW_REPOSITORY == HOMEBREW_PREFIX system "/bin/mkdir", "-p", core_tap Dir.chdir core_tap do system "/bin/bash -o pipefail -c '/usr/bin/curl -#{curl_flags} #{CORE_TAP_REPO}/tarball/master | /bin/tar xz -m --strip 1'" end end end ohai "Installation successful!" puts # Use the shell's audible bell. print "\a" # Use an extra newline and bold to avoid this being missed. ohai "Homebrew has enabled anonymous aggregate user behaviour analytics." puts <<-EOS #{Tty.bold}Read the analytics documentation (and how to opt-out) here: #{Tty.underline}http://docs.brew.sh/Analytics.html#{Tty.reset} EOS if git Dir.chdir HOMEBREW_REPOSITORY do system git, "config", "--local", "--replace-all", "homebrew.analyticsmessage", "true" end end ohai "Next steps:" if !mac? puts <<-EOS - Install the Linuxbrew dependencies if you have sudo access: #{Tty.bold}Debian, Ubuntu, etc.#{Tty.reset} sudo apt-get install build-essential #{Tty.bold}Fedora, Red Hat, CentOS, etc.#{Tty.reset} sudo yum groupinstall 'Development Tools' See #{Tty.underline}http://linuxbrew.sh/#dependencies#{Tty.reset} for more information. - Add Linuxbrew to your #{Tty.underline}#{shell_profile}#{Tty.reset} by running echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >>#{shell_profile} echo 'export MANPATH="#{HOMEBREW_PREFIX}/share/man:$MANPATH"' >>#{shell_profile} echo 'export INFOPATH="#{HOMEBREW_PREFIX}/share/info:$INFOPATH"' >>#{shell_profile} - Add Linuxbrew to your #{Tty.bold}PATH#{Tty.reset} PATH="#{HOMEBREW_PREFIX}/bin:$PATH" - We recommend that you install GCC by running: brew install gcc EOS elsif macos_version < "10.9" && macos_version > "10.6" `/usr/bin/cc --version 2> /dev/null` =~ /clang-(\d{2,})/ version = $1.to_i if version < 425 puts "- Install the #{Tty.bold}Command Line Tools for Xcode:" puts " #{Tty.underline}https://developer.apple.com/downloads#{Tty.reset}" end elsif !File.exist? "/usr/bin/cc" puts "- Install #{Tty.bold}Xcode:" puts " #{Tty.underline}https://developer.apple.com/xcode#{Tty.reset}" end unless git puts "- Run `brew update --force` to complete installation by installing:" puts " #{HOMEBREW_PREFIX}/share/doc/homebrew" puts " #{HOMEBREW_PREFIX}/share/man/man1/brew.1" puts " #{HOMEBREW_PREFIX}/share/zsh/site-functions/_brew" puts " #{HOMEBREW_PREFIX}/etc/bash_completion.d/brew" puts " #{HOMEBREW_REPOSITORY}/.git" end puts "- Run `brew help` to get started" puts "- Further documentation: " puts " #{Tty.underline}http://docs.brew.sh#{Tty.reset}" warn "#{HOMEBREW_PREFIX}/bin is not in your PATH." unless ENV["PATH"].split(":").include? "#{HOMEBREW_PREFIX}/bin" uninstall000077500000000000000000000205151310724462700130260ustar00rootroot00000000000000#!/usr/bin/env ruby require "fileutils" require "optparse" require "pathname" # Default options options = { :force => false, :quiet => false, :dry_run => false, :skip_cache_and_logs => false } # global status to indicate whether there is anything wrong. @failed = false module Tty module_function def blue bold 34 end def red bold 31 end def reset escape 0 end def bold(n = 39) escape "1;#{n}" end def escape(n) "\033[#{n}m" if STDOUT.tty? end end class Array def shell_s cp = dup first = cp.shift cp.map { |arg| arg.gsub " ", "\\ " }.unshift(first).join(" ") end end class Pathname def resolved_path symlink? ? dirname+readlink : self end def /(other) self + other.to_s end def pretty_print if symlink? puts to_s + " -> " + resolved_path.to_s elsif directory? puts to_s + "/" else puts to_s end end end def ohai(*args) puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}" end def warn(warning) puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}" end def system(*args) return if Kernel.system(*args) warn "Failed during: #{args.shell_s}" @failed = true end ####################################################################### script homebrew_prefix_candidates = [] OptionParser.new do |opts| opts.banner = "Homebrew Uninstaller\nUsage: ./uninstall [options]" opts.summary_width = 16 opts.on("-pPATH", "--path=PATH", "Sets Homebrew prefix. Defaults to /usr/local.") { |p| homebrew_prefix_candidates << Pathname.new(p) } opts.on("--skip-cache-and-logs", "Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.") { |_p| options[:skip_cache_and_logs] = true } opts.on("-f", "--force", "Uninstall without prompting.") { options[:force] = true } opts.on("-q", "--quiet", "Suppress all output.") { options[:quiet] = true } opts.on("-d", "--dry-run", "Simulate uninstall but don't remove anything.") { options[:dry_run] = true } opts.on_tail("-h", "--help", "Display this message.") do puts opts exit end end.parse! if homebrew_prefix_candidates.empty? # Attempt to locate Homebrew unless `--path` is passed prefix = begin `brew --prefix` rescue "" end homebrew_prefix_candidates << Pathname.new(prefix.strip) unless prefix.empty? prefix = begin begin `command -v brew` rescue `which brew` end rescue "" end homebrew_prefix_candidates << Pathname.new(prefix.strip).dirname.parent unless prefix.empty? homebrew_prefix_candidates << Pathname.new("/usr/local") # Homebrew default path homebrew_prefix_candidates << Pathname.new("#{ENV["HOME"]}/.linuxbrew") # Linuxbrew default path end HOMEBREW_PREFIX = homebrew_prefix_candidates.detect do |p| next unless p.directory? if p.to_s == "/usr/local" && File.exist?("/usr/local/Homebrew/.git") next true end (p/".git").exist? || (p/"bin/brew").executable? end abort "Failed to locate Homebrew!" if HOMEBREW_PREFIX.nil? HOMEBREW_REPOSITORY = if (HOMEBREW_PREFIX/".git").exist? (HOMEBREW_PREFIX/".git").realpath.dirname elsif (HOMEBREW_PREFIX/"bin/brew").exist? (HOMEBREW_PREFIX/"bin/brew").realpath.dirname.parent end abort "Failed to locate Homebrew!" if HOMEBREW_REPOSITORY.nil? HOMEBREW_CELLAR = if (HOMEBREW_PREFIX/"Cellar").exist? HOMEBREW_PREFIX/"Cellar" else HOMEBREW_REPOSITORY/"Cellar" end gitignore = begin (HOMEBREW_REPOSITORY/".gitignore").read rescue Errno::ENOENT `curl -fsSL https://raw.githubusercontent.com/Homebrew/brew/master/.gitignore` end abort "Failed to fetch Homebrew .gitignore!" if gitignore.empty? homebrew_files = gitignore.split("\n"). select { |line| line.start_with? "!" }. map { |line| line.chomp("/").gsub(%r{^!?/}, "") }. reject { |line| %w[bin share share/doc].include?(line) }. map { |p| HOMEBREW_REPOSITORY/p } if HOMEBREW_PREFIX.to_s != HOMEBREW_REPOSITORY.to_s homebrew_files << HOMEBREW_REPOSITORY homebrew_files += %w[ bin/brew etc/bash_completion.d/brew share/doc/homebrew share/man/man1/brew.1 share/man/man1/brew-cask.1 share/zsh/site-functions/_brew share/zsh/site-functions/_brew_cask var/homebrew/locks/update ].map { |p| HOMEBREW_PREFIX/p } else homebrew_files << HOMEBREW_REPOSITORY/".git" homebrew_files += %w[ CHANGELOG.md lib64 ].map { |p| HOMEBREW_PREFIX/p } end homebrew_files << HOMEBREW_CELLAR homebrew_files << HOMEBREW_PREFIX/"Caskroom" unless options[:skip_cache_and_logs] homebrew_files += %W[ #{ENV["HOME"]}/Library/Caches/Homebrew #{ENV["HOME"]}/Library/Logs/Homebrew /Library/Caches/Homebrew #{ENV["HOME"]}/.cache/Homebrew #{ENV["HOMEBREW_CACHE"]} #{ENV["HOMEBREW_LOGS"]} ].map { |p| Pathname.new(p) } end if RUBY_PLATFORM.to_s.downcase.include? "darwin" homebrew_files += %W[ /Applications #{ENV["HOME"]}/Applications ].map { |p| Pathname.new(p) }.select(&:directory?).map do |p| p.children.select do |app| app.resolved_path.to_s.start_with? HOMEBREW_CELLAR.to_s end end.flatten end homebrew_files = homebrew_files.select(&:exist?).sort unless options[:quiet] warn "This script #{options[:dry_run] ? "would" : "will"} remove:" homebrew_files.each(&:pretty_print) end if STDIN.tty? && (!options[:force] && !options[:dry_run]) STDERR.print "Are you sure you want to uninstall Homebrew? [y/N] " abort unless gets.rstrip =~ /y|yes/i end ohai "Removing Homebrew installation..." unless options[:quiet] paths = %w[Frameworks bin etc include lib opt sbin share var]. map { |p| HOMEBREW_PREFIX/p }. select(&:exist?). map(&:to_s) if paths.any? args = paths + %w[-regextype egrep -regex .*/info/([^.][^/]*\.info|dir)] if options[:dry_run] args << "-print" else args += %w[-exec /bin/bash -c] args << "/usr/bin/install-info --delete --quiet {} \"$(dirname {})/dir\"" args << ";" end puts "Would delete:" if options[:dry_run] system "/usr/bin/find", *args args = paths + %w[-type l -lname */Cellar/*] if options[:dry_run] args << "-print" else args += %w[-exec unlink {} ;] end puts "Would delete:" if options[:dry_run] system "/usr/bin/find", *args end homebrew_files.each do |file| if options[:dry_run] puts "Would delete #{file}" else begin FileUtils.rm_rf(file) rescue => e warn "Failed to delete #{file}" puts e.message @failed = true end end end # Invalidate sudo timestamp before exiting at_exit { Kernel.system "/usr/bin/sudo", "-k" } def sudo? return @have_sudo unless @have_sudo.nil? Kernel.system "/usr/bin/sudo", "-v" @have_sudo = $? && $?.success? end def sudo(*args) if sudo? args.unshift("-A") unless ENV["SUDO_ASKPASS"].nil? ohai "/usr/bin/sudo", *args system "/usr/bin/sudo", *args else ohai *args system *args end end ohai "Removing empty directories..." unless options[:quiet] paths = %w[Cellar Homebrew Frameworks bin etc include lib opt sbin share var]. map { |p| HOMEBREW_PREFIX/p }. select(&:exist?). map(&:to_s) if paths.any? args = paths + %w[-name .DS_Store] if options[:dry_run] args << "-print" else args << "-delete" end puts "Would delete:" if options[:dry_run] sudo "/usr/bin/find", *args args = paths + %w[-depth -type d -empty] if options[:dry_run] args << "-print" else args += %w[-exec rmdir {} ;] end puts "Would remove directories:" if options[:dry_run] sudo "/usr/bin/find", *args end if options[:dry_run] exit else if HOMEBREW_PREFIX.to_s != "/usr/local" && HOMEBREW_PREFIX.exist? sudo "rmdir", HOMEBREW_PREFIX.to_s end if HOMEBREW_PREFIX.to_s != HOMEBREW_REPOSITORY.to_s && HOMEBREW_REPOSITORY.exist? sudo "rmdir", HOMEBREW_REPOSITORY.to_s end end unless options[:quiet] if @failed warn "Homebrew partially uninstalled (but there were steps that failed)!" puts "To finish uninstalling rerun this script with `sudo`." else ohai "Homebrew uninstalled!" end end residual_files = [] residual_files.concat(HOMEBREW_REPOSITORY.children) if HOMEBREW_REPOSITORY.exist? residual_files.concat(HOMEBREW_PREFIX.children) if HOMEBREW_PREFIX.exist? residual_files.uniq! unless residual_files.empty? || options[:quiet] puts "The following possible Homebrew files were not deleted:" residual_files.each(&:pretty_print) puts "You may wish to remove them yourself.\n" end exit 1 if @failed