feat: 更新脚本

This commit is contained in:
neo 2022-10-27 17:33:25 +08:00
parent 8fde5826ad
commit 983cf90f78
2 changed files with 40 additions and 65 deletions

View File

@ -112,15 +112,17 @@ OS="$(uname)"
if [[ "${OS}" == "Linux" ]] if [[ "${OS}" == "Linux" ]]
then then
HOMEBREW_ON_LINUX=1 HOMEBREW_ON_LINUX=1
elif [[ "${OS}" != "Darwin" ]] elif [[ "${OS}" == "Darwin" ]]
then then
HOMEBREW_ON_MACOS=1
else
abort "Homebrew is only supported on macOS and Linux." abort "Homebrew is only supported on macOS and Linux."
fi fi
# Required installation paths. To install elsewhere (which is unsupported) # Required installation paths. To install elsewhere (which is unsupported)
# you can untar https://github.com/Homebrew/brew/tarball/master # you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like. # anywhere you like.
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] if [[ -n "${HOMEBREW_ON_MACOS-}" ]]
then then
UNAME_MACHINE="$(/usr/bin/uname -m)" UNAME_MACHINE="$(/usr/bin/uname -m)"
@ -146,9 +148,9 @@ then
else else
UNAME_MACHINE="$(uname -m)" UNAME_MACHINE="$(uname -m)"
# On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access # On Linux, this script installs to /home/linuxbrew/.linuxbrew only
# and ~/.linuxbrew (which is unsupported) if run interactively. HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew"
HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew" HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
HOMEBREW_CACHE="${HOME}/.cache/Homebrew" HOMEBREW_CACHE="${HOME}/.cache/Homebrew"
STAT_PRINTF=("stat" "--printf") STAT_PRINTF=("stat" "--printf")
@ -183,9 +185,9 @@ fi
export HOMEBREW_{BREW,CORE}_GIT_REMOTE export HOMEBREW_{BREW,CORE}_GIT_REMOTE
# TODO: bump version when new macOS is released or announced # 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 # TODO: bump version when new macOS is released
MACOS_OLDEST_SUPPORTED="10.15" MACOS_OLDEST_SUPPORTED="11.0"
# For Homebrew on Linux # For Homebrew on Linux
REQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556 REQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556
@ -225,7 +227,7 @@ have_sudo_access() {
HAVE_SUDO_ACCESS="$?" HAVE_SUDO_ACCESS="$?"
fi fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "${HAVE_SUDO_ACCESS}" -ne 0 ]] if [[ -n "${HOMEBREW_ON_MACOS-}" ]] && [[ "${HAVE_SUDO_ACCESS}" -ne 0 ]]
then then
abort "Need sudo access on macOS (e.g. the user ${USER} needs to be an Administrator)!" abort "Need sudo access on macOS (e.g. the user ${USER} needs to be an Administrator)!"
fi fi
@ -511,41 +513,25 @@ fi
# shellcheck disable=SC2016 # shellcheck disable=SC2016
ohai 'Checking for `sudo` access (which may request your password)...' ohai 'Checking for `sudo` access (which may request your password)...'
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] if [[ -n "${HOMEBREW_ON_MACOS-}" ]]
then then
have_sudo_access have_sudo_access
else elif ! [[ -w "${HOMEBREW_PREFIX}" ]] &&
if [[ -w "${HOMEBREW_PREFIX_DEFAULT}" ]] || ! [[ -w "/home/linuxbrew" ]] &&
[[ -w "/home/linuxbrew" ]] || ! [[ -w "/home" ]] &&
[[ -w "/home" ]] ! have_sudo_access
then then
HOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}" abort "$(
elif [[ -n "${NONINTERACTIVE-}" ]] cat <<EOABORT
then Insufficient permissions to install Homebrew to \"${HOMEBREW_PREFIX}\" (the default prefix).
if have_sudo_access
then Alternative (unsupported) installation methods are available at:
HOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}" https://docs.brew.sh/Installation#alternative-installs
else
abort "Insufficient permissions to install Homebrew to \"${HOMEBREW_PREFIX_DEFAULT}\"." Please note this will require most formula to build from source, a buggy, slow and energy-inefficient experience.
fi We will close any issues without response for these unsupported configurations.
else EOABORT
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"
fi fi
HOMEBREW_CORE="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core" HOMEBREW_CORE="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core"
@ -563,7 +549,7 @@ EOABORT
)" )"
fi fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] if [[ -n "${HOMEBREW_ON_MACOS-}" ]]
then then
# On macOS, support 64-bit Intel and ARM # On macOS, support 64-bit Intel and ARM
if [[ "${UNAME_MACHINE}" != "arm64" ]] && [[ "${UNAME_MACHINE}" != "x86_64" ]] if [[ "${UNAME_MACHINE}" != "arm64" ]] && [[ "${UNAME_MACHINE}" != "x86_64" ]]
@ -587,7 +573,7 @@ EOABORT
fi fi
fi fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] if [[ -n "${HOMEBREW_ON_MACOS-}" ]]
then then
macos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")" macos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")"
if version_lt "${macos_version}" "10.7" if version_lt "${macos_version}" "10.7"
@ -865,7 +851,7 @@ execute_sudo "${CHOWN[@]}" "-R" "${USER}:${GROUP}" "${HOMEBREW_REPOSITORY}"
if ! [[ -d "${HOMEBREW_CACHE}" ]] if ! [[ -d "${HOMEBREW_CACHE}" ]]
then then
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] if [[ -n "${HOMEBREW_ON_MACOS-}" ]]
then then
execute_sudo "${MKDIR[@]}" "${HOMEBREW_CACHE}" execute_sudo "${MKDIR[@]}" "${HOMEBREW_CACHE}"
else else
@ -923,7 +909,7 @@ then
execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools" execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
fi fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && ! output="$(/usr/bin/xcrun clang 2>&1)" && [[ "${output}" == *"license"* ]] if [[ -n "${HOMEBREW_ON_MACOS-}" ]] && ! output="$(/usr/bin/xcrun clang 2>&1)" && [[ "${output}" == *"license"* ]]
then then
abort "$( abort "$(
cat <<EOABORT cat <<EOABORT
@ -947,7 +933,10 @@ ohai "Downloading and installing Homebrew..."
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
# ensure we don't munge line endings on checkout # ensure we don't munge line endings on checkout
execute "git" "config" "core.autocrlf" "false" execute "git" "config" "--bool" "core.autocrlf" "false"
# make sure symlinks are saved as-is
execute "git" "config" "--bool" "core.symlinks" "true"
execute "git" "fetch" "--force" "origin" execute "git" "fetch" "--force" "origin"
execute "git" "fetch" "--force" "--tags" "origin" execute "git" "fetch" "--force" "--tags" "origin"
@ -983,7 +972,8 @@ ohai "Downloading and installing Homebrew..."
execute "git" "init" "-q" execute "git" "init" "-q"
execute "git" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}" execute "git" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
execute "git" "config" "core.autocrlf" "false" execute "git" "config" "--bool" "core.autocrlf" "false"
execute "git" "config" "--bool" "core.symlinks" "true"
execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master" execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master"
execute "git" "remote" "set-head" "origin" "--auto" >/dev/null execute "git" "remote" "set-head" "origin" "--auto" >/dev/null
execute "git" "reset" "--hard" "origin/master" execute "git" "reset" "--hard" "origin/master"
@ -1070,8 +1060,9 @@ then
then then
plural="s" plural="s"
fi fi
echo "- Run these commands in your terminal to add the non-default Git remote${plural} for ${non_default_repos}:" printf "- Run these commands in your terminal to add the non-default Git remote%s for %s:" "${plural}" "${non_default_repos}"
printf " echo '%s' >> ${shell_profile}\n" "${additional_shellenv_commands[@]}" 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[@]}" printf " %s\n" "${additional_shellenv_commands[@]}"
fi fi

View File

@ -373,22 +373,6 @@ do
done done
if [[ "${#paths[@]}" -gt 0 ]] if [[ "${#paths[@]}" -gt 0 ]]
then 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/*') args=("${paths[@]}" -type l -lname '*/Cellar/*')
if [[ -n "${opt_dry_run}" ]] if [[ -n "${opt_dry_run}" ]]
then then