From 983cf90f787984cc4dfef5f9774e295392c85eb4 Mon Sep 17 00:00:00 2001 From: neo Date: Thu, 27 Oct 2022 17:33:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 89 +++++++++++++++++++++++----------------------------- uninstall.sh | 16 ---------- 2 files changed, 40 insertions(+), 65 deletions(-) diff --git a/install.sh b/install.sh index 8291b46..56efcb0 100755 --- a/install.sh +++ b/install.sh @@ -112,15 +112,17 @@ OS="$(uname)" if [[ "${OS}" == "Linux" ]] then HOMEBREW_ON_LINUX=1 -elif [[ "${OS}" != "Darwin" ]] +elif [[ "${OS}" == "Darwin" ]] then + HOMEBREW_ON_MACOS=1 +else abort "Homebrew is only supported on macOS and Linux." fi # Required installation paths. To install elsewhere (which is unsupported) # you can untar https://github.com/Homebrew/brew/tarball/master # anywhere you like. -if [[ -z "${HOMEBREW_ON_LINUX-}" ]] +if [[ -n "${HOMEBREW_ON_MACOS-}" ]] then UNAME_MACHINE="$(/usr/bin/uname -m)" @@ -146,9 +148,9 @@ then else UNAME_MACHINE="$(uname -m)" - # On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access - # and ~/.linuxbrew (which is unsupported) if run interactively. - HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew" + # On Linux, this script installs to /home/linuxbrew/.linuxbrew only + HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew" + HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew" HOMEBREW_CACHE="${HOME}/.cache/Homebrew" STAT_PRINTF=("stat" "--printf") @@ -183,9 +185,9 @@ fi export HOMEBREW_{BREW,CORE}_GIT_REMOTE # TODO: bump version when new macOS is released or announced -MACOS_NEWEST_UNSUPPORTED="13.0" +MACOS_NEWEST_UNSUPPORTED="14.0" # TODO: bump version when new macOS is released -MACOS_OLDEST_SUPPORTED="10.15" +MACOS_OLDEST_SUPPORTED="11.0" # For Homebrew on Linux REQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556 @@ -225,7 +227,7 @@ have_sudo_access() { HAVE_SUDO_ACCESS="$?" fi - if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "${HAVE_SUDO_ACCESS}" -ne 0 ]] + if [[ -n "${HOMEBREW_ON_MACOS-}" ]] && [[ "${HAVE_SUDO_ACCESS}" -ne 0 ]] then abort "Need sudo access on macOS (e.g. the user ${USER} needs to be an Administrator)!" fi @@ -511,41 +513,25 @@ fi # shellcheck disable=SC2016 ohai 'Checking for `sudo` access (which may request your password)...' -if [[ -z "${HOMEBREW_ON_LINUX-}" ]] +if [[ -n "${HOMEBREW_ON_MACOS-}" ]] then have_sudo_access -else - if [[ -w "${HOMEBREW_PREFIX_DEFAULT}" ]] || - [[ -w "/home/linuxbrew" ]] || - [[ -w "/home" ]] - then - HOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}" - elif [[ -n "${NONINTERACTIVE-}" ]] - then - if have_sudo_access - then - HOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}" - else - abort "Insufficient permissions to install Homebrew to \"${HOMEBREW_PREFIX_DEFAULT}\"." - fi - else - trap exit SIGINT - if ! /usr/bin/sudo -n -v &>/dev/null - then - ohai "Select a Homebrew installation directory:" - echo "- ${tty_bold}Enter your password${tty_reset} to install to ${tty_underline}${HOMEBREW_PREFIX_DEFAULT}${tty_reset} (${tty_bold}recommended${tty_reset})" - echo "- ${tty_bold}Press Control-D${tty_reset} to install to ${tty_underline}${HOME}/.linuxbrew${tty_reset}" - echo "- ${tty_bold}Press Control-C${tty_reset} to cancel installation" - fi - if have_sudo_access - then - HOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}" - else - HOMEBREW_PREFIX="${HOME}/.linuxbrew" - fi - trap - SIGINT - fi - HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew" +elif ! [[ -w "${HOMEBREW_PREFIX}" ]] && + ! [[ -w "/home/linuxbrew" ]] && + ! [[ -w "/home" ]] && + ! have_sudo_access +then + abort "$( + cat </dev/null execute "git" "reset" "--hard" "origin/master" @@ -1070,8 +1060,9 @@ then then plural="s" fi - echo "- Run these commands in your terminal to add the non-default Git remote${plural} for ${non_default_repos}:" - printf " echo '%s' >> ${shell_profile}\n" "${additional_shellenv_commands[@]}" + printf "- Run these commands in your terminal to add the non-default Git remote%s for %s:" "${plural}" "${non_default_repos}" + printf " echo '# Set PATH, MANPATH, etc., for Homebrew.' >> %s" "${shell_profile}" + printf " echo '%s' >> %s\n" "${additional_shellenv_commands[@]}" "${shell_profile}" printf " %s\n" "${additional_shellenv_commands[@]}" fi diff --git a/uninstall.sh b/uninstall.sh index 373bdbe..8e0c3c0 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -373,22 +373,6 @@ do 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