feat: 更新脚本

This commit is contained in:
neo 2021-01-03 20:24:10 +08:00
parent 0b60dd95d5
commit e615dc5bc1
4 changed files with 49 additions and 36 deletions

View File

@ -1,8 +1,8 @@
#!/usr/bin/ruby #!/usr/bin/ruby
STDERR.print <<EOS STDERR.print <<EOS
Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in Warning: Ruby版本Homebrew安装脚本已被废弃新版脚本使用Bash重写。
Bash. Please migrate to the following command: 请使用以下命令:
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)" /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
EOS EOS

View File

@ -7,20 +7,34 @@ if [[ ! -t 0 || -n "${CI-}" ]]; then
NONINTERACTIVE=1 NONINTERACTIVE=1
fi fi
# First check if the OS is Linux. abort() {
if [[ "$(uname)" = "Linux" ]]; then printf "%s\n" "$1"
exit 1
}
# First check OS.
OS="$(uname)"
if [[ "$OS" == "Linux" ]]; then
HOMEBREW_ON_LINUX=1 HOMEBREW_ON_LINUX=1
elif [[ "$OS" != "Darwin" ]]; then
abort "Homebrew is only supported on macOS and Linux."
fi fi
# On macOS, this script installs to /usr/local only. UNAME_MACHINE="$(uname -m)"
# On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access
# and ~/.linuxbrew otherwise. # Required installation paths. To install elsewhere (which is unsupported)
# 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-}" ]]; then if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
if [[ "$UNAME_MACHINE" == "arm64" ]]; then
# On ARM macOS, this script installs to /opt/homebrew only
HOMEBREW_PREFIX="/opt/homebrew"
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}"
else
# On Intel macOS, this script installs to /usr/local only
HOMEBREW_PREFIX="/usr/local" HOMEBREW_PREFIX="/usr/local"
HOMEBREW_REPOSITORY="/usr/local/Homebrew" HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
fi
HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew" HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"
STAT="stat -f" STAT="stat -f"
@ -29,6 +43,8 @@ if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
GROUP="admin" GROUP="admin"
TOUCH="/usr/bin/touch" TOUCH="/usr/bin/touch"
else else
# 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_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew"
HOMEBREW_CACHE="${HOME}/.cache/Homebrew" HOMEBREW_CACHE="${HOME}/.cache/Homebrew"
@ -117,11 +133,6 @@ warn() {
printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")"
} }
abort() {
printf "%s\n" "$1"
exit 1
}
execute() { execute() {
if ! "$@"; then if ! "$@"; then
abort "$(printf "Failed during: %s" "$(shell_join "$@")")" abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
@ -333,21 +344,16 @@ EOABORT
)" )"
fi fi
UNAME_MACHINE="$(uname -m)" if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
# On macOS, support 64-bit Intel and ARM
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "$UNAME_MACHINE" == "arm64" ]]; then if [[ "$UNAME_MACHINE" != "arm64" ]] && [[ "$UNAME_MACHINE" != "x86_64" ]]; then
abort "$(cat <<EOABORT abort "Homebrew is only supported on Intel and ARM processors!"
Homebrew is not (yet) supported on ARM processors! fi
Rerun the Homebrew installer under Rosetta 2. else
If you really know what you are doing and are prepared for a very broken # On Linux, support only 64-bit Intel
experience you can use another installation option for installing on ARM: if [[ "$UNAME_MACHINE" != "x86_64" ]]; then
${tty_underline}https://docs.brew.sh/Installation${tty_reset}
EOABORT
)"
fi
if [[ "$UNAME_MACHINE" != "x86_64" ]]; then
abort "Homebrew is only supported on Intel processors!" abort "Homebrew is only supported on Intel processors!"
fi
fi fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
@ -419,7 +425,7 @@ done
directories=(bin etc include lib sbin share var opt directories=(bin etc include lib sbin share var opt
share/zsh share/zsh/site-functions share/zsh share/zsh/site-functions
var/homebrew var/homebrew/linked var/homebrew var/homebrew/linked
Cellar Caskroom Homebrew Frameworks) Cellar Caskroom Frameworks)
mkdirs=() mkdirs=()
for dir in "${directories[@]}"; do for dir in "${directories[@]}"; do
if ! [[ -d "${HOMEBREW_PREFIX}/${dir}" ]]; then if ! [[ -d "${HOMEBREW_PREFIX}/${dir}" ]]; then
@ -518,6 +524,11 @@ if [[ "${#mkdirs[@]}" -gt 0 ]]; then
execute_sudo "$CHGRP" "$GROUP" "${mkdirs[@]}" execute_sudo "$CHGRP" "$GROUP" "${mkdirs[@]}"
fi fi
if ! [[ -d "${HOMEBREW_REPOSITORY}" ]]; then
execute_sudo "/bin/mkdir" "-p" "${HOMEBREW_REPOSITORY}"
fi
execute_sudo "$CHOWN" "$USER:$GROUP" "${HOMEBREW_REPOSITORY}"
if ! [[ -d "${HOMEBREW_CACHE}" ]]; then if ! [[ -d "${HOMEBREW_CACHE}" ]]; then
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
execute_sudo "/bin/mkdir" "-p" "${HOMEBREW_CACHE}" execute_sudo "/bin/mkdir" "-p" "${HOMEBREW_CACHE}"
@ -598,7 +609,9 @@ ohai "Downloading and installing Homebrew..."
execute "git" "reset" "--hard" "origin/master" execute "git" "reset" "--hard" "origin/master"
if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_PREFIX}" ]]; then
execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew" execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew"
fi
execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force"
) || exit 1 ) || exit 1

View File

@ -1,8 +1,8 @@
#!/usr/bin/ruby #!/usr/bin/ruby
STDERR.print <<EOS STDERR.print <<EOS
Warning: The Ruby Homebrew uninstaller is now deprecated and has been rewritten in Warning: Ruby版本Homebrew安装脚本已被废弃新版脚本使用Bash重写。
Bash. Please migrate to the following command: 请使用以下命令:
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)" /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)"
EOS EOS

View File

@ -170,7 +170,7 @@ Usage: $0 [options]
Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS. Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.
-f, --force Uninstall without prompting. -f, --force Uninstall without prompting.
-q, --quiet Suppress all output. -q, --quiet Suppress all output.
-d, --dry-run Simulate uninstall but don't remove anything. -n, --dry-run Simulate uninstall but don't remove anything.
-h, --help Display this message. -h, --help Display this message.
EOS EOS
exit "${1:-0}" exit "${1:-0}"
@ -183,7 +183,7 @@ while [[ $# -gt 0 ]]; do
--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|--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