解决Mac安装不了brew,切换国内站点超速安装

更新时间:2023-05-17 12:12:39 阅读: 评论:0

解决Mac安装不了brew,切换国内站点超速安装#!/bin/bash
配置要求t -u
abort() {
printf "%s\n" "$@"
exit 1
}
if [ -z "${BASH_VERSION:-}" ]; then
abort "Bash is required to interpret this script."
fi
# Check if script is run non-interactively (e.g. CI)
# If it is run non-interactively we should not prompt for passwords.
if [[ ! -t 0 || -n "${CI-}" ]]; then
NONINTERACTIVE=1
fi
# First check OS.
OS="$(uname)"
if [[ "$OS" == "Linux" ]]; then
HOMEBREW_ON_LINUX=1
elif [[ "$OS" != "Darwin" ]]; then
abort "Homebrew is only supported on macOS and Linux."
fi
# Required installation paths. To install elwhere (which is unsupported)
# you can untar /Homebrew/brew/tarball/master
# anywhere you like.
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
UNAME_MACHINE="$(/usr/bin/uname -m)"
if [[ "$UNAME_MACHINE" == "arm64" ]]; then
# On ARM macOS, this script installs to /opt/homebrew only
HOMEBREW_PREFIX="/opt/homebrew"
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}"
el
# On Intel macOS, this script installs to /usr/local only
HOMEBREW_PREFIX="/usr/local"
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
fi
HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"
HOMEBREW_CORE_DEFAULT_GIT_REMOTE="/Homebrew/homebrew-core"
STAT="stat -f"
PERMISSION_FORMAT="%A"
CHOWN="/usr/sbin/chown"
CHGRP="/usr/bin/chgrp"
GROUP="admin"
TOUCH="/usr/bin/touch"
el
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"
HOMEBREW_CACHE="${HOME}/.cache/Homebrew"
HOMEBREW_CORE_DEFAULT_GIT_REMOTE="/Homebrew/linuxbrew-core"
STAT="stat --printf"
PERMISSION_FORMAT="%a"
CHOWN="/bin/chown"
CHGRP="/bin/chgrp"
GROUP="$(id -gn)"
TOUCH="/bin/touch"
fi
HOMEBREW_BREW_DEFAULT_GIT_REMOTE="/Homebrew/brew"
# U remote URLs of Homebrew repositories from environment if t.
HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_GIT_REMOTE:-"${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}"}" HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_GIT_REMOTE:-"${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}"}" # The URLs with and without the '.git' suffix are the same Git remote. Do not prompt.
if [[ "$HOMEBREW_BREW_GIT_REMOTE" == "${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}.git" ]]; then
HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}"
fi
if [[ "$HOMEBREW_CORE_GIT_REMOTE" == "${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}.git" ]]; then
HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}"
fi
export HOMEBREW_{BREW,CORE}_GIT_REMOTE
# TODO: bump version when new macOS is relead or announced
MACOS_NEWEST_UNSUPPORTED="12.0"
# TODO: bump version when new macOS is relead
MACOS_OLDEST_SUPPORTED="10.14"
# For Homebrew on Linux
REQUIRED_RUBY_VERSION=2.6  # /Homebrew/brew/pull/6556
REQUIRED_GLIBC_VERSION=2.13  # docs.brew.sh/Homebrew-on-Linux#requirements
REQUIRED_CURL_VERSION=7.41.0 # HOMEBREW_MINIMUM_CURL_VERSION in brew.sh in Homebrew/brew
REQUIRED_GIT_VERSION=2.7.0 # HOMEBREW_MINIMUM_GIT_VERSION in brew.sh in Homebrew/brew
# no analytics during installation
export HOMEBREW_NO_ANALYTICS_THIS_RUN=1
export HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT=1
# string formatters
if [[ -t 1 ]]; then
tty_escape() { printf "\033[%sm" "$1"; }
el
tty_escape() { :; }
fi
tty_mkbold() { tty_escape "1;$1"; }
tty_underline="$(tty_escape "4;39")"
tty_blue="$(tty_mkbold 34)"
tty_red="$(tty_mkbold 31)"
tty_bold="$(tty_mkbold 39)"
tty_ret="$(tty_escape 0)"
have_sudo_access() {
if [[ ! -x "/usr/bin/sudo" ]]; then
return 1
fi
local -a args
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A")
elif [[ -n "${NONINTERACTIVE-}" ]]; then
args=("-n")
fi
if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
if [[ -n "${args[*]-}" ]]; then
SUDO="/usr/bin/sudo ${args[*]}"
el
SUDO="/usr/bin/sudo"
fi
if [[ -n "${NONINTERACTIVE-}" ]]; then
${SUDO} -l mkdir &>/dev/null
el
${SUDO} -v && ${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 ur $USER needs to be an Administrator)!"
御泥坊好不好fi
return "$HAVE_SUDO_ACCESS"
}
搜狗怎么打繁体字shell_join() {
shell_join() {
local arg
printf "%s" "$1"
shift
for arg in "$@"; do
printf " "
printf "%s" "${arg// /\ }"
done
}
chomp() {
printf "%s" "${1/"$'\n'"/}"
}
ohai() {
printf "${tty_blue}==>${tty_bold} %s${tty_ret}\n" "$(shell_join "$@")"
}
warn() {菜花黄
printf "${tty_red}Warning${tty_ret}: %s\n" "$(chomp "$1")"
}
execute() {
if ! "$@"; then
abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
fi
}
execute_sudo() {
local -a args=("$@")
if have_sudo_access; then
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A" "${args[@]}")
fi
ohai "/usr/bin/sudo" "${args[@]}"
execute "/usr/bin/sudo" "${args[@]}"
el
ohai "${args[@]}"
execute "${args[@]}"
fi
}
车间英文getc() {
local save_state
save_state=$(/bin/stty -g)
日落半林中打一字/bin/stty raw -echo
IFS= read -r -n 1 -d '' "$@"
/
bin/stty "$save_state"
}
ring_bell() {
# U the shell's audible bell.
if [[ -t 1 ]]; then
printf "\a"
fi
}
wait_for_ur() {
local c
echo
最美逆行
echo "Press RETURN to continue or any other key to abort"
getc c
# we test for \r and \n becau some stuff does \r instead
if ! [[ "$c" == $'\r' || "$c" == $'\n' ]]; then
exit 1
fi
}
major_minor() {
echo "${1%%.*}.$(x="${1#*.}"; echo "${x%%.*}")"
}
version_gt() {
[[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]]
[[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]]
}
version_ge() {
[[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -ge "${2#*.}" ]]
}
version_lt() {
[[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]]
}
should_install_command_line_tools() {
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then
return 1
fi
if version_gt "$macos_version" "10.13"; then
! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]
el
! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] ||
! [[ -e "/usr/include/iconv.h" ]]
fi
}
get_permission() {
$STAT "${PERMISSION_FORMAT}" "$1"
}
ur_only_chmod() {
[[ -d "$1" ]] && [[ "$(get_permission "$1")" != 75[0145] ]]
}
exists_but_not_writable() {
[[ -e "$1" ]] && ! [[ -r "$1" && -w "$1" && -x "$1" ]]
}
get_owner() {
$STAT "%u" "$1"
}
file_not_owned() {
[[ "$(get_owner "$1")" != "$(id -u)" ]]
}
get_group() {
$STAT "%g" "$1"
}
file_not_grpowned() {
[[ " $(id -G "$USER") " != *" $(get_group "$1") "* ]]
}
# Plea sync with 'test_ruby()' in 'Library/Homebrew/utils/ruby.sh' from Homebrew/brew repository.
test_ruby() {
if [[ ! -x "$1" ]]
then
return 1
fi
"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \
"abort if Gem::w(_s.dup).to_s.split('.').first(2) != \
Gem::w('$REQUIRED_RUBY_VERSION').to_s.split('.').first(2)" 2>/dev/null
}
test_curl() {
if [[ ! -x "$1" ]]
then
return 1
fi
local curl_version_output curl_name_and_version
curl_version_output=$("$1" --version 2>/dev/null)
curl_name_and_version="${curl_version_output%% (*}"
version_ge "$(major_minor "${curl_name_and_version##* }")" "$(major_minor "$REQUIRED_CURL_VERSION")" }
test_git() {
if [[ ! -x "$1" ]]
then
return 1
fi
local git_version_output
git_version_output=$("$1" --version 2>/dev/null)
version_ge "$(major_minor "${git_version_output##* }")" "$(major_minor "$REQUIRED_GIT_VERSION")" }
# Search given executable in all PATH entries (remove dependency for `which` command)
which_all() {
if [[ $# -ne 1 ]]
then
return 1
fi
local executable entries entry retcode=1
IFS=':' read -r -a entries <<< "${PATH}"  # `readarray -d ':' -t` ems not applicable on WSL Bash
for entry in "${entries[@]}"
do
executable="${entry}/$1"
if [[ -x "${executable}" ]]
then
echo "${executable}"
retcode=0  # prent
fi
done
return "${retcode}"
}
# Search PATH for the specified program that satisfies Homebrew requirements
find_tool() {
if [[ $# -ne 1 ]]
then
return 1
轻罗小扇白兰花fi
local executable
while read -r executable
do
if "test_$1" "${executable}"
then
echo "${executable}"
break
fi
done < <(which_all "$1")
}
no_usable_ruby() {
[[ -z $(find_tool ruby) ]]
}
outdated_glibc() {
local glibc_version
glibc_version=$(ldd --version | head -n1 | grep -o '[0-9.]*$' | grep -o '^[0-9]\+\.[0-9]\+')
version_lt "$glibc_version" "$REQUIRED_GLIBC_VERSION"
}
if [[ -n "${HOMEBREW_ON_LINUX-}" ]] && no_usable_ruby && outdated_glibc
then
abort "$(cat <<-EOFABORT
Homebrew requires Ruby $REQUIRED_RUBY_VERSION which was not found on your system.
Homebrew portable Ruby requires Glibc version $REQUIRED_GLIBC_VERSION or newer,
and your Glibc version is too old.
See ${tty_underline}docs.brew.sh/Homebrew-on-Linux#requirements${tty_ret}
Install Ruby $REQUIRED_RUBY_VERSION and add its location to your PATH.
EOFABORT
)"
fi

本文发布于:2023-05-17 12:12:39,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/667487.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:安装   切换   配置   要求   不了   超速   站点
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图