em…… homebrew 卸载问题解决
2020-06-27 本文已影响0人
杨大魔王
卸载homebrew的时候提示raw.githubusercontent.com:443不通...
当然最简单办法,翻墙 … …
奈何手上没翻墙工具,于是… …
1.首先,先搞到shell脚本gayhub中 homebrew/install工程中的 uninstall.sh
2.去github homebrew/brew这个工程找到.gitignore文件,保存内容到本地文本
3.然后修改sh脚本中 curl balabala生不出小孩不许来大姨妈.com
为 cat 刚刚保存ignore文件的完整路径
ps:相对路径也行,需要cd到gitignore文件所在文件夹再继续
4.打开终端chmod +x 本地的uninstall.sh 加个开心的运行权限
5.好了!万事俱备,执行吧,后浪
操作是mac上.. windows同理,各位大佬看个乐呵就完了。
最后祝您,身体健康!
想起来,你们甚至懒得打开gayhub,
卸载的shell文件
#!/bin/bash
set -u
shopt -s extglob
abort() {
printf "%s\n" "$@"
exit 1
}
strip_s() {
local s
for s in "$@"; do
s=${s## }
echo "${s%% }"
done
}
dir_children() {
local p
for p in "$@"; do
[[ -d $p ]] || continue
find "$p" -mindepth 1 -maxdepth 1
done
}
# Set up temp dir
tmpdir=/tmp/uninstall.$$
mkdir -p "$tmpdir" || abort "Unable to create temp dir '$tmpdir'"
trap '
rm -fr "$tmpdir"
# Invalidate sudo timestamp before exiting
/usr/bin/sudo -k
' EXIT
# Default options
opt_force=""
opt_quiet=""
opt_dry_run=""
opt_skip_cache_and_logs=""
# global status to indicate whether there is anything wrong.
failed=false
un=$(uname)
case "$un" in
Linux)
ostype=linux
homebrew_prefix_default=/home/linuxbrew/.linuxbrew
;;
Darwin)
ostype=macos
homebrew_prefix_default=/usr/local
realpath() {
cd "$(dirname "$1")" && echo "$(pwd -P)/$(basename "$1")"
}
;;
*)
abort "Unsupported system type '$un'"
;;
esac
# string formatters
if [[ -t 1 ]]; then
tty_escape() { printf "\033[%sm" "$1"; }
else
tty_escape() { :; }
fi
tty_mkbold() { tty_escape "1;${1:-39}"; }
tty_blue=$(tty_mkbold 34)
tty_red=$(tty_mkbold 31)
tty_bold=$(tty_mkbold 39)
tty_reset=$(tty_escape 0)
have_sudo_access() {
local -a args
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A")
fi
if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
if [[ -n "${args[*]-}" ]]; then
/usr/bin/sudo "${args[@]}" -l mkdir &>/dev/null
else
/usr/bin/sudo -l mkdir &>/dev/null
fi
HAVE_SUDO_ACCESS="$?"
fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "$HAVE_SUDO_ACCESS" -ne 0 ]]; then
abort "Need sudo access on macOS (e.g. the user $USER to be an Administrator)!"
fi
return "$HAVE_SUDO_ACCESS"
}
shell_join() {
local arg
printf "%s" "$1"
shift
for arg in "$@"; do
printf " "
printf "%s" "${arg// /\ }"
done
}
resolved_pathname() { realpath "$1"; }
pretty_print_pathnames() {
local p
for p in "$@"; do
if [[ -h $p ]]; then
printf '%s -> %s\n' "$p" "$(resolved_pathname "$p")"
elif [[ -d $p ]]; then
echo "$p/"
else
echo "$p"
fi
done
}
chomp() {
printf "%s" "${1/"$'\n'"/}"
}
ohai() {
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
}
warn() {
printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")"
}
execute() {
if ! "$@"; then
abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
fi
}
execute_sudo() {
local -a args=("$@")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A" "${args[@]}")
fi
if have_sudo_access; then
ohai "/usr/bin/sudo" "${args[@]}"
system "/usr/bin/sudo" "${args[@]}"
else
ohai "${args[@]}"
system "${args[@]}"
fi
}
system() {
if ! "$@"; then
warn "Failed during: $(shell_join "$@")"
failed=true
fi
}
####################################################################### script
homebrew_prefix_candidates=()
usage() {
cat <<EOS
Homebrew Uninstaller
Usage: $0 [options]
-p, --path=PATH Sets Homebrew prefix. Defaults to /usr/local.
--skip-cache-and-logs
Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.
-f, --force Uninstall without prompting.
-q, --quiet Suppress all output.
-d, --dry-run Simulate uninstall but don't remove anything.
-h, --help Display this message.
EOS
exit "${1:-0}"
}
while [[ $# -gt 0 ]]; do
case "$1" in
-p*) homebrew_prefix_candidates+=("${1#-p}");;
--path=*) homebrew_prefix_candidates+=("${1#--path=}");;
--skip-cache-and-logs) opt_skip_cache_and_logs=1;;
-f|--force) opt_force=1;;
-q|--quiet) opt_quiet=1;;
-d|--dry-run) opt_dry_run=1;;
-h|--help) usage;;
*) warn "Unrecognized option: '$1'"; usage 1;;
esac
shift
done
if [[ ${#homebrew_prefix_candidates[@]} -eq 0 ]]; then # Attempt to locate Homebrew unless `--path` is passed
prefix=$(brew --prefix)
[[ -n $prefix ]] && homebrew_prefix_candidates+=("$prefix")
prefix=$(command -v brew) || prefix=""
[[ -n $prefix ]] && homebrew_prefix_candidates+=("$(dirname "$(dirname "$(strip_s "$prefix")")")")
homebrew_prefix_candidates+=("$homebrew_prefix_default") # Homebrew default path
homebrew_prefix_candidates+=("$HOME/.linuxbrew") # Linuxbrew default path
fi
HOMEBREW_PREFIX=$(for p in "${homebrew_prefix_candidates[@]}"; do
[[ -d $p ]] || continue
[[ $p == "$homebrew_prefix_default" && -d $p/Homebrew/.git ]] && echo "$p" && break
[[ -d $p/.git || -x $p/bin/brew ]] && echo "$p" && break
done)
[[ -n $HOMEBREW_PREFIX ]] || abort "Failed to locate Homebrew!"
if [[ -d $HOMEBREW_PREFIX/.git ]]; then
HOMEBREW_REPOSITORY=$(dirname "$(realpath "$HOMEBREW_PREFIX/.git")")
elif [[ -x $HOMEBREW_PREFIX/bin/brew ]]; then
HOMEBREW_REPOSITORY=$(dirname "$(dirname "$(realpath "$HOMEBREW_PREFIX/bin/brew")")")
else
abort "Failed to locate Homebrew!"
fi
if [[ -d $HOMEBREW_PREFIX/Cellar ]]; then
HOMEBREW_CELLAR=$HOMEBREW_PREFIX/Cellar
else
HOMEBREW_CELLAR=$HOMEBREW_REPOSITORY/Cellar
fi
if [[ -s $HOMEBREW_REPOSITORY/.gitignore ]]; then
gitignore=$(<"$HOMEBREW_REPOSITORY/.gitignore")
else
gitignore=$(cat ./ignore)
fi
[[ -n $gitignore ]] || abort "Failed to fetch Homebrew .gitignore!"
{
while read -r l; do
[[ $l == \!* ]] || continue
l=${l#\!}
l=${l#/}
[[ $l == @(bin|share|share/doc) ]] && echo "REJECT: $l" >&2 && continue
echo "$HOMEBREW_REPOSITORY/$l"
done <<<"$gitignore"
if [[ $HOMEBREW_PREFIX != "$HOMEBREW_REPOSITORY" ]]; then
echo "$HOMEBREW_REPOSITORY"
for p in \
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 \
; do
echo "$HOMEBREW_PREFIX/$p"
done
else
echo "$HOMEBREW_REPOSITORY/.git"
fi
echo "$HOMEBREW_CELLAR"
echo "$HOMEBREW_PREFIX/Caskroom"
[[ -n $opt_skip_cache_and_logs ]] || cat <<-EOS
$HOME/Library/Caches/Homebrew
$HOME/Library/Logs/Homebrew
/Library/Caches/Homebrew
$HOME/.cache/Homebrew
${HOMEBREW_CACHE:-}
${HOMEBREW_LOGS:-}
EOS
if [[ $ostype == macos ]]; then
dir_children "/Applications" "$HOME/Applications" | while read -r p2; do
[[ $(resolved_pathname "$p2") == $HOMEBREW_CELLAR/* ]] && echo "$p2"
done
fi
} | while read -r l; do
[[ -e $l ]] && echo "$l"
done | sort -u > "$tmpdir/homebrew_files"
homebrew_files=()
while read -r l; do
homebrew_files+=("$l")
done < "$tmpdir/homebrew_files"
if [[ -z $opt_quiet ]]; then
dry_str=${opt_dry_run:+would}
warn "This script ${dry_str:-will} remove:"
pretty_print_pathnames "${homebrew_files[@]}"
fi
if [[ -t 0 && -z $opt_force && -z $opt_dry_run ]]; then
read -rp "Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] "
[[ $REPLY == [yY]* ]] || abort
fi
[[ -n $opt_quiet ]] || ohai "Removing Homebrew installation..."
paths=()
for p in Frameworks bin etc include lib opt sbin share var; do
p=$HOMEBREW_PREFIX/$p
[[ -e $p ]] && paths+=("$p")
done
if [[ ${#paths[@]} -gt 0 ]]; then
if [[ $ostype == macos ]]; then
args=(-E "${paths[@]}" -regex '.*/info/([^.][^/]*\.info|dir)')
else
args=("${paths[@]}" -regextype posix-extended -regex '.*/info/([^.][^/]*\.info|dir)')
fi
if [[ -n $opt_dry_run ]]; then
args+=(-print)
echo "Would delete:"
else
args+=(-exec /bin/bash -c)
args+=("/usr/bin/install-info --delete --quiet {} \"\$(dirname {})/dir\"")
args+=(';')
fi
system /usr/bin/find "${args[@]}"
args=("${paths[@]}" -type l -lname '*/Cellar/*')
if [[ -n $opt_dry_run ]]; then
args+=(-print)
else
args+=(-exec unlink '{}' ';')
fi
[[ -n $opt_dry_run ]] && echo "Would delete:"
system /usr/bin/find "${args[@]}"
fi
for file in "${homebrew_files[@]}"; do
if [[ -n $opt_dry_run ]]; then
echo "Would delete ${file}"
else
if ! err=$(rm -fr "$file" 2>&1); then
warn "Failed to delete ${file}"
echo "$err"
fi
fi
done
sudo() {
ohai "/usr/bin/sudo" "$@"
system /usr/bin/sudo "$@"
}
[[ -n $opt_quiet ]] || ohai "Removing empty directories..."
paths=()
for p in bin etc include lib opt sbin share var \
Caskroom Cellar Homebrew Frameworks; do
p=$HOMEBREW_PREFIX/$p
[[ -e $p ]] && paths+=("$p")
done
if [[ ${#paths[@]} -gt 0 ]]; then
if [[ $ostype == macos ]]; then
args=("${paths[@]}" -name .DS_Store)
if [[ -n $opt_dry_run ]]; then
args+=(-print)
echo "Would delete:"
else
args+=(-delete)
fi
execute_sudo /usr/bin/find "${args[@]}"
fi
args=("${paths[@]}" -depth -type d -empty)
if [[ -n $opt_dry_run ]]; then
args+=(-print)
echo "Would remove directories:"
else
args+=(-exec rmdir '{}' ';')
fi
execute_sudo /usr/bin/find "${args[@]}"
fi
[[ -n $opt_dry_run ]] && exit
if [[ $HOMEBREW_PREFIX != "$homebrew_prefix_default" && -e $HOMEBREW_PREFIX ]]; then
execute_sudo rmdir "$HOMEBREW_PREFIX"
fi
if [[ $HOMEBREW_PREFIX != "$HOMEBREW_REPOSITORY" && -e $HOMEBREW_REPOSITORY ]]; then
execute_sudo rmdir "$HOMEBREW_REPOSITORY"
fi
if [[ -z $opt_quiet ]]; then
if [[ $failed == true ]]; then
warn "Homebrew partially uninstalled (but there were steps that failed)!"
echo "To finish uninstalling rerun this script with \`sudo\`."
else
ohai "Homebrew uninstalled!"
fi
fi
dir_children "$HOMEBREW_REPOSITORY" "$HOMEBREW_PREFIX" \
| sort -u > "$tmpdir/residual_files"
if [[ -s $tmpdir/residual_files && -z $opt_quiet ]]; then
echo "The following possible Homebrew files were not deleted:"
while read -r f; do
pretty_print_pathnames "$f"
done <"$tmpdir/residual_files"
echo -e "You may wish to remove them yourself.\n"
fi
[[ $failed != true ]]
.gitignore
# First, ignore everything.
/*
# Explicitly ignore OS X Finder thumbnail files.
.DS_Store
# Unignore the contents of `Library` as that's where our code lives.
!/Library/
# Ignore files within `Library` (again).
/Library/Homebrew/.npmignore
/Library/Homebrew/bin
/Library/Homebrew/doc
/Library/Homebrew/test/.gem
/Library/Homebrew/test/.subversion
/Library/Homebrew/test/coverage
/Library/Homebrew/test/fs_leak_log
/Library/Homebrew/vendor/portable-ruby
/Library/Taps
/Library/PinnedTaps
/Library/Homebrew/.byebug_history
/Library/Homebrew/sorbet/rbi/hidden-definitions/errors.txt
# Ignore Bundler files
**/.bundle/bin
**/.bundle/cache
**/vendor/bundle/ruby/*/bin
**/vendor/bundle/ruby/*/build_info/
**/vendor/bundle/ruby/*/cache
**/vendor/bundle/ruby/*/extensions
**/vendor/bundle/ruby/*/gems/*/*
**/vendor/bundle/ruby/*/specifications
# Unignore vendored gems
!**/vendor/bundle/ruby/*/gems/*/lib
!**/vendor/bundle/ruby/*/gems/rubocop-performance-*/config
!**/vendor/bundle/ruby/*/gems/rubocop-rspec-*/config
# Ignore partially included gems where we don't need all files
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support.rb
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/all.rb
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/cache.rb
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/cache/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/concurrency/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/dependencies.rb
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/dependencies/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/duration/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/json.rb
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/json/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/log_subscriber.rb
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/log_subscriber/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/messages/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/multibyte/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/number_helper.rb
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/number_helper/
**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/testing/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/atomic/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/atomic_reference/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/collection/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/concern/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/executor/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/synchronization/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/thread_safe/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/utility/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/lib/*/*.jar
**/vendor/bundle/ruby/*/gems/i18n-*/lib/i18n/tests*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/*.rb
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/http/agent.rb
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/http/*auth*.rb
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/c*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/d*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/e*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/f*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/h*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/i*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/p*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/r*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/t*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/u*
**/vendor/bundle/ruby/*/gems/mechanize-*/lib/mechanize/x*
**/vendor/bundle/ruby/*/gems/thread_safe-*/lib/thread_safe/util
# Ignore dependencies we don't wish to vendor
**/vendor/bundle/ruby/*/gems/ast-*/
**/vendor/bundle/ruby/*/gems/bundler-*/
**/vendor/bundle/ruby/*/gems/byebug-*/
**/vendor/bundle/ruby/*/gems/coderay-*/
**/vendor/bundle/ruby/*/gems/connection_pool-*/
**/vendor/bundle/ruby/*/gems/coveralls-*/
**/vendor/bundle/ruby/*/gems/diff-lcs-*/
**/vendor/bundle/ruby/*/gems/docile-*/
**/vendor/bundle/ruby/*/gems/domain_name-*/
**/vendor/bundle/ruby/*/gems/http-cookie-*/
**/vendor/bundle/ruby/*/gems/hpricot-*/
**/vendor/bundle/ruby/*/gems/jaro_winkler-*/
**/vendor/bundle/ruby/*/gems/json-*/
**/vendor/bundle/ruby/*/gems/method_source-*/
**/vendor/bundle/ruby/*/gems/mime-types-data-*/
**/vendor/bundle/ruby/*/gems/mime-types-*/
**/vendor/bundle/ruby/*/gems/mini_portile2-*/
**/vendor/bundle/ruby/*/gems/minitest-*/
**/vendor/bundle/ruby/*/gems/mustache-*/
**/vendor/bundle/ruby/*/gems/net-http-digest_auth-*/
**/vendor/bundle/ruby/*/gems/net-http-persistent-*/
**/vendor/bundle/ruby/*/gems/nokogiri-*/
**/vendor/bundle/ruby/*/gems/ntlm-http-*/
**/vendor/bundle/ruby/*/gems/parallel-*/
**/vendor/bundle/ruby/*/gems/parallel_tests-*/
**/vendor/bundle/ruby/*/gems/parser-*/
**/vendor/bundle/ruby/*/gems/powerpack-*/
**/vendor/bundle/ruby/*/gems/psych-*/
**/vendor/bundle/ruby/*/gems/pry-*/
**/vendor/bundle/ruby/*/gems/rainbow-*/
**/vendor/bundle/ruby/*/gems/rdiscount-*/
**/vendor/bundle/ruby/*/gems/regexp_parser-*/
**/vendor/bundle/ruby/*/gems/ronn-*/
**/vendor/bundle/ruby/*/gems/rspec-*/
**/vendor/bundle/ruby/*/gems/rspec-core-*/
**/vendor/bundle/ruby/*/gems/rspec-expectations-*/
**/vendor/bundle/ruby/*/gems/rspec-its-*/
**/vendor/bundle/ruby/*/gems/rspec-mocks-*/
**/vendor/bundle/ruby/*/gems/rspec-retry-*/
**/vendor/bundle/ruby/*/gems/rspec-support-*/
**/vendor/bundle/ruby/*/gems/rspec-wait-*/
**/vendor/bundle/ruby/*/gems/rubocop-0*/
**/vendor/bundle/ruby/*/gems/rubocop-ast-*/
**/vendor/bundle/ruby/*/gems/ruby-prof-*/
**/vendor/bundle/ruby/*/gems/ruby-progressbar-*/
**/vendor/bundle/ruby/*/gems/simplecov-*/
**/vendor/bundle/ruby/*/gems/simplecov-cobertura-*/
**/vendor/bundle/ruby/*/gems/simplecov-html-*/
**/vendor/bundle/ruby/*/gems/term-ansicolor-*/
**/vendor/bundle/ruby/*/gems/thor-*/
**/vendor/bundle/ruby/*/gems/tins-*/
**/vendor/bundle/ruby/*/gems/unf_ext-*/
**/vendor/bundle/ruby/*/gems/unf-*/
**/vendor/bundle/ruby/*/gems/unicode-display_width-*/
**/vendor/bundle/ruby/*/gems/webrobots-*/
# Ignore conditional dependencies we don't wish to vendor
**/vendor/bundle/ruby/*/gems/bindata-*/
**/vendor/bundle/ruby/*/gems/elftools-*/
**/vendor/bundle/ruby/*/gems/patchelf-*/
**/vendor/bundle/ruby/*/gems/sorbet-*/
**/vendor/bundle/ruby/*/gems/sorbet-runtime-*/
**/vendor/bundle/ruby/*/gems/tapioca-*/
# Ignore `bin` contents (again).
/bin
# Unignore our `brew` script.
!/bin/brew
# Unignore our documentation/completions.
!/.github
!/completions
!/docs
!/manpages
# Ignore generated documentation site
/docs/_site
/docs/bin
/docs/.jekyll-metadata
/docs/vendor
# Unignore our root-level metadata files.
!/.dockerignore
!/.editorconfig
!/.gitignore
!/.yardopts
!/.vale.ini
!/CHANGELOG.md
!/CONTRIBUTING.md
!/Dockerfile
!/Dockerfile.test.yml
!/LICENSE.txt
!/README.md
# Unignore tests' bundle config
!/Library/Homebrew/test/.bundle/config