feat: 更新最新脚本

This commit is contained in:
neo 2021-11-01 16:35:41 +08:00
parent f0b3645986
commit 87cb590f4c
3 changed files with 597 additions and 403 deletions

View File

@ -1,4 +1,4 @@
name: GitHub Actions CI name: CI
on: on:
push: push:
branches: branches:
@ -30,7 +30,6 @@ jobs:
run: | run: |
git config --global core.autocrlf false git config --global core.autocrlf false
git config --global core.eol lf git config --global core.eol lf
- name: Set up Git repository - name: Set up Git repository
uses: actions/checkout@main uses: actions/checkout@main
@ -40,7 +39,6 @@ jobs:
sudo rm -rf /Applications/Xcode.app \ sudo rm -rf /Applications/Xcode.app \
/Library/Developer/CommandLineTools /Library/Developer/CommandLineTools
sudo xcode-select --reset sudo xcode-select --reset
- name: Install WSL - name: Install WSL
if: runner.os == 'windows' if: runner.os == 'windows'
# https://github.com/Vampire/setup-wsl/releases/tag/v1.1.0 # https://github.com/Vampire/setup-wsl/releases/tag/v1.1.0
@ -53,19 +51,19 @@ jobs:
- name: Set up Homebrew PATH - name: Set up Homebrew PATH
if: runner.os != 'windows' if: runner.os != 'windows'
run: | run: |
if [ "${{ runner.os }}" = "macOS" ]; then if [[ "${{ runner.os }}" = "macOS" ]]
echo "/usr/local/bin:/usr/bin:/bin" >> ${GITHUB_PATH} then
echo "/usr/local/bin:/usr/bin:/bin" >> "${GITHUB_PATH}"
else else
echo "/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin" >> ${GITHUB_PATH} echo "/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin" >> "${GITHUB_PATH}"
fi fi
- name: Uninstall GitHub Actions Homebrew - name: Uninstall GitHub Actions Homebrew
run: | run: |
if which brew &>/dev/null; then if which brew &>/dev/null
then
/bin/bash uninstall.sh -n >/dev/null /bin/bash uninstall.sh -n >/dev/null
/bin/bash uninstall.sh -f >/dev/null /bin/bash uninstall.sh -f >/dev/null
fi fi
- name: Set up WSL environment - name: Set up WSL environment
if: runner.os == 'windows' if: runner.os == 'windows'
shell: "wsl-bash -u root {0}" shell: "wsl-bash -u root {0}"
@ -74,7 +72,6 @@ jobs:
chmod 644 /etc/sudoers.d/runner chmod 644 /etc/sudoers.d/runner
echo -e "#!/bin/bash\nexec /home/linuxbrew/.linuxbrew/bin/brew \"\$@\"" | tee /usr/local/bin/brew echo -e "#!/bin/bash\nexec /home/linuxbrew/.linuxbrew/bin/brew \"\$@\"" | tee /usr/local/bin/brew
chmod 755 /usr/local/bin/brew chmod 755 /usr/local/bin/brew
- run: /bin/bash -c "$(cat install.sh)" - run: /bin/bash -c "$(cat install.sh)"
- run: brew config - run: brew config
@ -83,39 +80,32 @@ jobs:
- run: /bin/bash uninstall.sh -f >/dev/null - run: /bin/bash uninstall.sh -f >/dev/null
- name: Install Homebrew with mirror remotes - name: Install Homebrew with non-default remotes
# Use the default remotes but with Git Protocol # Use the default remotes but with Git Protocol
run: | run: |
HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/brew" HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/brew"
if [ "${{ runner.os }}" = "macOS" ]; then HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/homebrew-core"
HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/homebrew-core" export HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_DEFAULT_GIT_REMOTE/#https/git}"
else export HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_DEFAULT_GIT_REMOTE/#https/git}"
HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/linuxbrew-core"
fi
export HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_DEFAULT_GIT_REMOTE/%https/git}"
export HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_DEFAULT_GIT_REMOTE/%https/git}"
/bin/bash -c "$(cat install.sh)" /bin/bash -c "$(cat install.sh)"
- run: brew config - run: brew config
- run: | - run: |
/bin/bash uninstall.sh -f >/dev/null /bin/bash uninstall.sh -f >/dev/null
unset HOMEBREW_{BREW,CORE}{,_DEFAULT}_GIT_REMOTE unset HOMEBREW_{BREW,CORE}{,_DEFAULT}_GIT_REMOTE
- run: /bin/bash -c "$(cat install.sh)" - run: /bin/bash -c "$(cat install.sh)"
- name: Uninstall and reinstall with sudo NOPASSWD - name: Uninstall and reinstall with sudo NOPASSWD
if: runner.os == 'linux' if: runner.os == 'linux'
run: | run: |
echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee "/etc/sudoers.d/$USER" echo "${USER} ALL=(ALL) NOPASSWD:ALL" | sudo tee "/etc/sudoers.d/${USER}"
/bin/bash uninstall.sh -f >/dev/null /bin/bash uninstall.sh -f >/dev/null
/bin/bash -c "$(cat install.sh)" /bin/bash -c "$(cat install.sh)"
- name: Check code styles
- run: brew install shellcheck
- run: shellcheck *.sh
if: runner.os != 'windows' if: runner.os != 'windows'
run: |
brew install shellcheck shfmt diffutils
brew style *.sh
- run: /bin/bash uninstall.sh -n >/dev/null - run: /bin/bash uninstall.sh -n >/dev/null
- run: /bin/bash uninstall.sh -f >/dev/null - run: /bin/bash uninstall.sh -f >/dev/null

File diff suppressed because it is too large Load Diff

View File

@ -9,25 +9,27 @@ abort() {
strip_s() { strip_s() {
local s local s
for s in "$@"; do for s in "$@"
s=${s## } do
s="${s## }"
echo "${s%% }" echo "${s%% }"
done done
} }
dir_children() { dir_children() {
local p local p
for p in "$@"; do for p in "$@"
[[ -d $p ]] || continue do
find "$p" -mindepth 1 -maxdepth 1 [[ -d "${p}" ]] || continue
find "${p}" -mindepth 1 -maxdepth 1
done done
} }
# Set up temp dir # Set up temp dir
tmpdir=/tmp/uninstall.$$ tmpdir="/tmp/uninstall.$$"
mkdir -p "$tmpdir" || abort "Unable to create temp dir '$tmpdir'" mkdir -p "${tmpdir}" || abort "Unable to create temp dir '${tmpdir}'"
trap ' trap '
rm -fr "$tmpdir" rm -fr "${tmpdir}"
# Invalidate sudo timestamp before exiting # Invalidate sudo timestamp before exiting
/usr/bin/sudo -k /usr/bin/sudo -k
' EXIT ' EXIT
@ -41,15 +43,16 @@ opt_skip_cache_and_logs=""
# global status to indicate whether there is anything wrong. # global status to indicate whether there is anything wrong.
failed=false failed=false
un=$(uname) un="$(uname)"
case "$un" in case "${un}" in
Linux) Linux)
ostype=linux ostype=linux
homebrew_prefix_default=/home/linuxbrew/.linuxbrew homebrew_prefix_default=/home/linuxbrew/.linuxbrew
;; ;;
Darwin) Darwin)
ostype=macos ostype=macos
if [[ "$(uname -m)" == "arm64" ]]; then if [[ "$(uname -m)" == "arm64" ]]
then
homebrew_prefix_default=/opt/homebrew homebrew_prefix_default=/opt/homebrew
else else
homebrew_prefix_default=/usr/local homebrew_prefix_default=/usr/local
@ -57,32 +60,36 @@ case "$un" in
realpath() { realpath() {
cd "$(dirname "$1")" && echo "$(pwd -P)/$(basename "$1")" cd "$(dirname "$1")" && echo "$(pwd -P)/$(basename "$1")"
} }
;; ;;
*) *)
abort "Unsupported system type '$un'" abort "Unsupported system type '${un}'"
;; ;;
esac esac
# string formatters # string formatters
if [[ -t 1 ]]; then if [[ -t 1 ]]
then
tty_escape() { printf "\033[%sm" "$1"; } tty_escape() { printf "\033[%sm" "$1"; }
else else
tty_escape() { :; } tty_escape() { :; }
fi fi
tty_mkbold() { tty_escape "1;${1:-39}"; } tty_mkbold() { tty_escape "1;${1:-39}"; }
tty_blue=$(tty_mkbold 34) tty_blue="$(tty_mkbold 34)"
tty_red=$(tty_mkbold 31) tty_red="$(tty_mkbold 31)"
tty_bold=$(tty_mkbold 39) tty_bold="$(tty_mkbold 39)"
tty_reset=$(tty_escape 0) tty_reset="$(tty_escape 0)"
have_sudo_access() { have_sudo_access() {
local -a args local -a args
if [[ -n "${SUDO_ASKPASS-}" ]]; then if [[ -n "${SUDO_ASKPASS-}" ]]
then
args=("-A") args=("-A")
fi fi
if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then if [[ -z "${HAVE_SUDO_ACCESS-}" ]]
if [[ -n "${args[*]-}" ]]; then then
if [[ -n "${args[*]-}" ]]
then
/usr/bin/sudo "${args[@]}" -l mkdir &>/dev/null /usr/bin/sudo "${args[@]}" -l mkdir &>/dev/null
else else
/usr/bin/sudo -l mkdir &>/dev/null /usr/bin/sudo -l mkdir &>/dev/null
@ -90,18 +97,20 @@ have_sudo_access() {
HAVE_SUDO_ACCESS="$?" HAVE_SUDO_ACCESS="$?"
fi fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "$HAVE_SUDO_ACCESS" -ne 0 ]]; then if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "${HAVE_SUDO_ACCESS}" -ne 0 ]]
abort "Need sudo access on macOS (e.g. the user $USER to be an Administrator)!" then
abort "Need sudo access on macOS (e.g. the user ${USER} to be an Administrator)!"
fi fi
return "$HAVE_SUDO_ACCESS" return "${HAVE_SUDO_ACCESS}"
} }
shell_join() { shell_join() {
local arg local arg
printf "%s" "$1" printf "%s" "$1"
shift shift
for arg in "$@"; do for arg in "$@"
do
printf " " printf " "
printf "%s" "${arg// /\ }" printf "%s" "${arg// /\ }"
done done
@ -111,13 +120,16 @@ resolved_pathname() { realpath "$1"; }
pretty_print_pathnames() { pretty_print_pathnames() {
local p local p
for p in "$@"; do for p in "$@"
if [[ -h $p ]]; then do
printf '%s -> %s\n' "$p" "$(resolved_pathname "$p")" if [[ -L "${p}" ]]
elif [[ -d $p ]]; then then
echo "$p/" printf '%s -> %s\n' "${p}" "$(resolved_pathname "${p}")"
elif [[ -d "${p}" ]]
then
echo "${p}/"
else else
echo "$p" echo "${p}"
fi fi
done done
} }
@ -135,17 +147,20 @@ warn() {
} }
execute() { execute() {
if ! "$@"; then if ! "$@"
then
abort "$(printf "Failed during: %s" "$(shell_join "$@")")" abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
fi fi
} }
execute_sudo() { execute_sudo() {
local -a args=("$@") local -a args=("$@")
if [[ -n "${SUDO_ASKPASS-}" ]]; then if [[ -n "${SUDO_ASKPASS-}" ]]
then
args=("-A" "${args[@]}") args=("-A" "${args[@]}")
fi fi
if have_sudo_access; then if have_sudo_access
then
ohai "/usr/bin/sudo" "${args[@]}" ohai "/usr/bin/sudo" "${args[@]}"
system "/usr/bin/sudo" "${args[@]}" system "/usr/bin/sudo" "${args[@]}"
else else
@ -155,7 +170,8 @@ execute_sudo() {
} }
system() { system() {
if ! "$@"; then if ! "$@"
then
warn "Failed during: $(shell_join "$@")" warn "Failed during: $(shell_join "$@")"
failed=true failed=true
fi fi
@ -180,132 +196,159 @@ EOS
exit "${1:-0}" exit "${1:-0}"
} }
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]
do
case "$1" in case "$1" in
-p*) homebrew_prefix_candidates+=("${1#-p}");; -p*) homebrew_prefix_candidates+=("${1#-p}") ;;
--path=*) homebrew_prefix_candidates+=("${1#--path=}");; --path=*) homebrew_prefix_candidates+=("${1#--path=}") ;;
--skip-cache-and-logs) opt_skip_cache_and_logs=1;; --skip-cache-and-logs) opt_skip_cache_and_logs=1 ;;
-f|--force) opt_force=1;; -f | --force) opt_force=1 ;;
-q|--quiet) opt_quiet=1;; -q | --quiet) opt_quiet=1 ;;
-d|-n|--dry-run) opt_dry_run=1;; -d | -n | --dry-run) opt_dry_run=1 ;;
-h|--help) usage;; -h | --help) usage ;;
*) warn "Unrecognized option: '$1'"; usage 1;; *)
warn "Unrecognized option: '$1'"
usage 1
;;
esac esac
shift shift
done done
if [[ ${#homebrew_prefix_candidates[@]} -eq 0 ]]; then # Attempt to locate Homebrew unless `--path` is passed # Attempt to locate Homebrew unless `--path` is passed
prefix=$(brew --prefix) if [[ "${#homebrew_prefix_candidates[@]}" -eq 0 ]]
[[ -n $prefix ]] && homebrew_prefix_candidates+=("$prefix") then
prefix=$(command -v brew) || prefix="" prefix="$(brew --prefix)"
[[ -n $prefix ]] && homebrew_prefix_candidates+=("$(dirname "$(dirname "$(strip_s "$prefix")")")") [[ -n "${prefix}" ]] && homebrew_prefix_candidates+=("${prefix}")
homebrew_prefix_candidates+=("$homebrew_prefix_default") # Homebrew default path prefix="$(command -v brew)" || prefix=""
homebrew_prefix_candidates+=("$HOME/.linuxbrew") # Linuxbrew default path [[ -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 fi
HOMEBREW_PREFIX=$(for p in "${homebrew_prefix_candidates[@]}"; do HOMEBREW_PREFIX="$(
[[ -d $p ]] || continue for p in "${homebrew_prefix_candidates[@]}"
[[ $p == "$homebrew_prefix_default" && -d $p/Homebrew/.git ]] && echo "$p" && break do
[[ -d $p/.git || -x $p/bin/brew ]] && echo "$p" && break [[ -d "${p}" ]] || continue
done) [[ ${p} == "${homebrew_prefix_default}" && -d "${p}/Homebrew/.git" ]] && echo "${p}" && break
[[ -n $HOMEBREW_PREFIX ]] || abort "Failed to locate Homebrew!" [[ -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 if [[ -d "${HOMEBREW_PREFIX}/.git" ]]
HOMEBREW_REPOSITORY=$(dirname "$(realpath "$HOMEBREW_PREFIX/.git")") then
elif [[ -x $HOMEBREW_PREFIX/bin/brew ]]; then HOMEBREW_REPOSITORY="$(dirname "$(realpath "${HOMEBREW_PREFIX}/.git")")"
HOMEBREW_REPOSITORY=$(dirname "$(dirname "$(realpath "$HOMEBREW_PREFIX/bin/brew")")") elif [[ -x "${HOMEBREW_PREFIX}/bin/brew" ]]
then
HOMEBREW_REPOSITORY="$(dirname "$(dirname "$(realpath "${HOMEBREW_PREFIX}/bin/brew")")")"
else else
abort "Failed to locate Homebrew!" abort "Failed to locate Homebrew!"
fi fi
if [[ -d $HOMEBREW_PREFIX/Cellar ]]; then if [[ -d "${HOMEBREW_PREFIX}/Cellar" ]]
HOMEBREW_CELLAR=$HOMEBREW_PREFIX/Cellar then
HOMEBREW_CELLAR="${HOMEBREW_PREFIX}/Cellar"
else else
HOMEBREW_CELLAR=$HOMEBREW_REPOSITORY/Cellar HOMEBREW_CELLAR="${HOMEBREW_REPOSITORY}/Cellar"
fi fi
if [[ -s $HOMEBREW_REPOSITORY/.gitignore ]]; then if [[ -s "${HOMEBREW_REPOSITORY}/.gitignore" ]]
gitignore=$(<"$HOMEBREW_REPOSITORY/.gitignore") then
gitignore="$(<"${HOMEBREW_REPOSITORY}/.gitignore")"
else else
gitignore=$(curl -fsSL https://cdn.jsdelivr.net/gh/Homebrew/brew/.gitignore) gitignore=$(curl -fsSL https://cdn.jsdelivr.net/gh/Homebrew/brew/.gitignore)
fi fi
[[ -n $gitignore ]] || abort "Failed to fetch Homebrew .gitignore!" [[ -n "${gitignore}" ]] || abort "Failed to fetch Homebrew .gitignore!"
{ {
while read -r l; do while read -r l
[[ $l == \!* ]] || continue do
l=${l#\!} [[ "${l}" == \!* ]] || continue
l=${l#/} l="${l#\!}"
[[ $l == @(bin|share|share/doc) ]] && echo "REJECT: $l" >&2 && continue l="${l#/}"
echo "$HOMEBREW_REPOSITORY/$l" [[ "${l}" == @(bin|share|share/doc) ]] && echo "REJECT: ${l}" >&2 && continue
done <<<"$gitignore" echo "${HOMEBREW_REPOSITORY}/${l}"
done <<<"${gitignore}"
if [[ $HOMEBREW_PREFIX != "$HOMEBREW_REPOSITORY" ]]; then if [[ "${HOMEBREW_PREFIX}" != "${HOMEBREW_REPOSITORY}" ]]
echo "$HOMEBREW_REPOSITORY" then
for p in \ echo "${HOMEBREW_REPOSITORY}"
bin/brew \ directories=(
etc/bash_completion.d/brew \ bin/brew
share/doc/homebrew \ etc/bash_completion.d/brew
share/man/man1/brew.1 \ share/doc/homebrew
share/man/man1/brew-cask.1 \ share/man/man1/brew.1
share/zsh/site-functions/_brew \ share/man/man1/brew-cask.1
share/zsh/site-functions/_brew_cask \ share/man/man1/README.md
var/homebrew \ share/zsh/site-functions/_brew
; do share/zsh/site-functions/_brew_cask
echo "$HOMEBREW_PREFIX/$p" share/fish/vendor_completions.d/brew.fish
var/homebrew
)
for p in "${directories[@]}"
do
echo "${HOMEBREW_PREFIX}/${p}"
done done
else else
echo "$HOMEBREW_REPOSITORY/.git" echo "${HOMEBREW_REPOSITORY}/.git"
fi fi
echo "$HOMEBREW_CELLAR" echo "${HOMEBREW_CELLAR}"
echo "$HOMEBREW_PREFIX/Caskroom" echo "${HOMEBREW_PREFIX}/Caskroom"
[[ -n $opt_skip_cache_and_logs ]] || cat <<-EOS [[ -n ${opt_skip_cache_and_logs} ]] || cat <<-EOS
$HOME/Library/Caches/Homebrew ${HOME}/Library/Caches/Homebrew
$HOME/Library/Logs/Homebrew ${HOME}/Library/Logs/Homebrew
/Library/Caches/Homebrew /Library/Caches/Homebrew
$HOME/.cache/Homebrew ${HOME}/.cache/Homebrew
${HOMEBREW_CACHE:-} ${HOMEBREW_CACHE:-}
${HOMEBREW_LOGS:-} ${HOMEBREW_LOGS:-}
EOS EOS
if [[ $ostype == macos ]]; then if [[ "${ostype}" == macos ]]
dir_children "/Applications" "$HOME/Applications" | while read -r p2; do then
[[ $(resolved_pathname "$p2") == $HOMEBREW_CELLAR/* ]] && echo "$p2" dir_children "/Applications" "${HOME}/Applications" | while read -r p2; do
[[ $(resolved_pathname "${p2}") == "${HOMEBREW_CELLAR}"/* ]] && echo "${p2}"
done done
fi fi
} | while read -r l; do } | while read -r l; do
[[ -e $l ]] && echo "$l" [[ -e "${l}" ]] && echo "${l}"
done | sort -u > "$tmpdir/homebrew_files" done | sort -u >"${tmpdir}/homebrew_files"
homebrew_files=() homebrew_files=()
while read -r l; do while read -r l
homebrew_files+=("$l") do
done < "$tmpdir/homebrew_files" homebrew_files+=("${l}")
done <"${tmpdir}/homebrew_files"
if [[ -z $opt_quiet ]]; then if [[ -z "${opt_quiet}" ]]
dry_str=${opt_dry_run:+would} then
dry_str="${opt_dry_run:+would}"
warn "This script ${dry_str:-will} remove:" warn "This script ${dry_str:-will} remove:"
pretty_print_pathnames "${homebrew_files[@]}" pretty_print_pathnames "${homebrew_files[@]}"
fi fi
if [[ -t 0 && -z $opt_force && -z $opt_dry_run ]]; then 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] " read -rp "Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] "
[[ $REPLY == [yY]* ]] || abort [[ "${REPLY}" == [yY]* ]] || abort
fi fi
[[ -n $opt_quiet ]] || ohai "Removing Homebrew installation..." [[ -n "${opt_quiet}" ]] || ohai "Removing Homebrew installation..."
paths=() paths=()
for p in Frameworks bin etc include lib opt sbin share var; do for p in Frameworks bin etc include lib opt sbin share var
p=$HOMEBREW_PREFIX/$p do
[[ -e $p ]] && paths+=("$p") p="${HOMEBREW_PREFIX}/${p}"
[[ -e "${p}" ]] && paths+=("${p}")
done done
if [[ ${#paths[@]} -gt 0 ]]; then if [[ "${#paths[@]}" -gt 0 ]]
if [[ $ostype == macos ]]; then then
if [[ "${ostype}" == macos ]]
then
args=(-E "${paths[@]}" -regex '.*/info/([^.][^/]*\.info|dir)') args=(-E "${paths[@]}" -regex '.*/info/([^.][^/]*\.info|dir)')
else else
args=("${paths[@]}" -regextype posix-extended -regex '.*/info/([^.][^/]*\.info|dir)') args=("${paths[@]}" -regextype posix-extended -regex '.*/info/([^.][^/]*\.info|dir)')
fi fi
if [[ -n $opt_dry_run ]]; then if [[ -n "${opt_dry_run}" ]]
then
args+=(-print) args+=(-print)
echo "Would delete:" echo "Would delete:"
else else
@ -315,22 +358,26 @@ if [[ ${#paths[@]} -gt 0 ]]; then
fi fi
system /usr/bin/find "${args[@]}" system /usr/bin/find "${args[@]}"
args=("${paths[@]}" -type l -lname '*/Cellar/*') args=("${paths[@]}" -type l -lname '*/Cellar/*')
if [[ -n $opt_dry_run ]]; then if [[ -n "${opt_dry_run}" ]]
then
args+=(-print) args+=(-print)
else else
args+=(-exec unlink '{}' ';') args+=(-exec unlink '{}' ';')
fi fi
[[ -n $opt_dry_run ]] && echo "Would delete:" [[ -n "${opt_dry_run}" ]] && echo "Would delete:"
system /usr/bin/find "${args[@]}" system /usr/bin/find "${args[@]}"
fi fi
for file in "${homebrew_files[@]}"; do for file in "${homebrew_files[@]}"
if [[ -n $opt_dry_run ]]; then do
if [[ -n "${opt_dry_run}" ]]
then
echo "Would delete ${file}" echo "Would delete ${file}"
else else
if ! err=$(rm -fr "$file" 2>&1); then if ! err="$(rm -fr "${file}" 2>&1)"
then
warn "Failed to delete ${file}" warn "Failed to delete ${file}"
echo "$err" echo "${err}"
fi fi
fi fi
done done
@ -340,17 +387,20 @@ sudo() {
system /usr/bin/sudo "$@" system /usr/bin/sudo "$@"
} }
[[ -n $opt_quiet ]] || ohai "Removing empty directories..." [[ -n "${opt_quiet}" ]] || ohai "Removing empty directories..."
paths=() paths=()
for p in bin etc include lib opt sbin share var \ for p in bin etc include lib opt sbin share var Caskroom Cellar Homebrew Frameworks
Caskroom Cellar Homebrew Frameworks; do do
p=$HOMEBREW_PREFIX/$p p="${HOMEBREW_PREFIX}/${p}"
[[ -e $p ]] && paths+=("$p") [[ -e "${p}" ]] && paths+=("${p}")
done done
if [[ ${#paths[@]} -gt 0 ]]; then if [[ "${#paths[@]}" -gt 0 ]]
if [[ $ostype == macos ]]; then then
if [[ "${ostype}" == macos ]]
then
args=("${paths[@]}" -name .DS_Store) args=("${paths[@]}" -name .DS_Store)
if [[ -n $opt_dry_run ]]; then if [[ -n "${opt_dry_run}" ]]
then
args+=(-print) args+=(-print)
echo "Would delete:" echo "Would delete:"
else else
@ -359,7 +409,8 @@ if [[ ${#paths[@]} -gt 0 ]]; then
execute_sudo /usr/bin/find "${args[@]}" execute_sudo /usr/bin/find "${args[@]}"
fi fi
args=("${paths[@]}" -depth -type d -empty) args=("${paths[@]}" -depth -type d -empty)
if [[ -n $opt_dry_run ]]; then if [[ -n "${opt_dry_run}" ]]
then
args+=(-print) args+=(-print)
echo "Would remove directories:" echo "Would remove directories:"
else else
@ -368,16 +419,20 @@ if [[ ${#paths[@]} -gt 0 ]]; then
execute_sudo /usr/bin/find "${args[@]}" execute_sudo /usr/bin/find "${args[@]}"
fi fi
[[ -n $opt_dry_run ]] && exit [[ -n "${opt_dry_run}" ]] && exit
if [[ $HOMEBREW_PREFIX != "$homebrew_prefix_default" && -e $HOMEBREW_PREFIX ]]; then if [[ "${HOMEBREW_PREFIX}" != "${homebrew_prefix_default}" && -e "${HOMEBREW_PREFIX}" ]]
execute_sudo rmdir "$HOMEBREW_PREFIX" then
execute_sudo rmdir "${HOMEBREW_PREFIX}"
fi fi
if [[ $HOMEBREW_PREFIX != "$HOMEBREW_REPOSITORY" && -e $HOMEBREW_REPOSITORY ]]; then if [[ "${HOMEBREW_PREFIX}" != "${HOMEBREW_REPOSITORY}" && -e "${HOMEBREW_REPOSITORY}" ]]
execute_sudo rmdir "$HOMEBREW_REPOSITORY" then
execute_sudo rmdir "${HOMEBREW_REPOSITORY}"
fi fi
if [[ -z $opt_quiet ]]; then if [[ -z "${opt_quiet}" ]]
if [[ $failed == true ]]; then then
if [[ "${failed}" == true ]]
then
warn "Homebrew partially uninstalled (but there were steps that failed)!" warn "Homebrew partially uninstalled (but there were steps that failed)!"
echo "To finish uninstalling rerun this script with \`sudo\`." echo "To finish uninstalling rerun this script with \`sudo\`."
else else
@ -385,15 +440,17 @@ if [[ -z $opt_quiet ]]; then
fi fi
fi fi
dir_children "$HOMEBREW_REPOSITORY" "$HOMEBREW_PREFIX" \ dir_children "${HOMEBREW_REPOSITORY}" "${HOMEBREW_PREFIX}" |
| sort -u > "$tmpdir/residual_files" sort -u >"${tmpdir}/residual_files"
if [[ -s $tmpdir/residual_files && -z $opt_quiet ]]; then if [[ -s "${tmpdir}/residual_files" && -z "${opt_quiet}" ]]
then
echo "The following possible Homebrew files were not deleted:" echo "The following possible Homebrew files were not deleted:"
while read -r f; do while read -r f
pretty_print_pathnames "$f" do
done <"$tmpdir/residual_files" pretty_print_pathnames "${f}"
done <"${tmpdir}/residual_files"
echo -e "You may wish to remove them yourself.\n" echo -e "You may wish to remove them yourself.\n"
fi fi
[[ $failed != true ]] [[ "${failed}" != true ]]