mirror of
https://gitee.com/ineo6/homebrew-install.git
synced 2025-09-26 13:59:58 +08:00
feat: 更新脚本
This commit is contained in:
parent
815732c78d
commit
8fde5826ad
@ -7,7 +7,7 @@
|
||||
set -u
|
||||
|
||||
abort() {
|
||||
printf "%s\n" "$@"
|
||||
printf "%s\n" "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -33,6 +33,12 @@ then
|
||||
abort 'Both `$INTERACTIVE` and `$NONINTERACTIVE` are set. Please unset at least one variable and try again.'
|
||||
fi
|
||||
|
||||
# Check if script is run in POSIX mode
|
||||
if [[ -n "${POSIXLY_CORRECT+1}" ]]
|
||||
then
|
||||
abort 'Bash must not run in POSIX mode. Please unset POSIXLY_CORRECT and try again.'
|
||||
fi
|
||||
|
||||
# string formatters
|
||||
if [[ -t 1 ]]
|
||||
then
|
||||
@ -94,6 +100,13 @@ else
|
||||
ohai 'Running in non-interactive mode because `$NONINTERACTIVE` is set.'
|
||||
fi
|
||||
|
||||
# USER isn't always set so provide a fall back for the installer and subprocesses.
|
||||
if [[ -z "${USER-}" ]]
|
||||
then
|
||||
USER="$(chomp "$(id -un)")"
|
||||
export USER
|
||||
fi
|
||||
|
||||
# First check OS.
|
||||
OS="$(uname)"
|
||||
if [[ "${OS}" == "Linux" ]]
|
||||
@ -129,6 +142,7 @@ then
|
||||
CHGRP=("/usr/bin/chgrp")
|
||||
GROUP="admin"
|
||||
TOUCH=("/usr/bin/touch")
|
||||
INSTALL=("/usr/bin/install" -d -o "root" -g "wheel" -m "0755")
|
||||
else
|
||||
UNAME_MACHINE="$(uname -m)"
|
||||
|
||||
@ -143,6 +157,7 @@ else
|
||||
CHGRP=("/bin/chgrp")
|
||||
GROUP="$(id -gn)"
|
||||
TOUCH=("/bin/touch")
|
||||
INSTALL=("/usr/bin/install" -d -o "${USER}" -g "${GROUP}" -m "0755")
|
||||
fi
|
||||
CHMOD=("/bin/chmod")
|
||||
MKDIR=("/bin/mkdir" "-p")
|
||||
@ -256,7 +271,7 @@ ring_bell() {
|
||||
wait_for_user() {
|
||||
local c
|
||||
echo
|
||||
echo "Press ${tty_bold}RETURN${tty_reset} to continue or any other key to abort:"
|
||||
echo "Press ${tty_bold}RETURN${tty_reset}/${tty_bold}ENTER${tty_reset} to continue or any other key to abort:"
|
||||
getc c
|
||||
# we test for \r and \n because some stuff does \r instead
|
||||
if ! [[ "${c}" == $'\r' || "${c}" == $'\n' ]]
|
||||
@ -282,6 +297,16 @@ version_lt() {
|
||||
[[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]]
|
||||
}
|
||||
|
||||
check_run_command_as_root() {
|
||||
[[ "${EUID:-${UID}}" == "0" ]] || return
|
||||
|
||||
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
|
||||
[[ -f /.dockerenv ]] && return
|
||||
[[ -f /proc/1/cgroup ]] && grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup && return
|
||||
|
||||
abort "Don't run this as root!"
|
||||
}
|
||||
|
||||
should_install_command_line_tools() {
|
||||
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]
|
||||
then
|
||||
@ -409,13 +434,6 @@ EOABORT
|
||||
)"
|
||||
fi
|
||||
|
||||
# USER isn't always set so provide a fall back for the installer and subprocesses.
|
||||
if [[ -z "${USER-}" ]]
|
||||
then
|
||||
USER="$(chomp "$(id -un)")"
|
||||
export USER
|
||||
fi
|
||||
|
||||
# Invalidate sudo timestamp before exiting (if it wasn't active before).
|
||||
if [[ -x /usr/bin/sudo ]] && ! /usr/bin/sudo -n -v 2>/dev/null
|
||||
then
|
||||
@ -527,15 +545,7 @@ else
|
||||
fi
|
||||
HOMEBREW_CORE="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core"
|
||||
|
||||
if [[ "${EUID:-${UID}}" == "0" ]]
|
||||
then
|
||||
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
|
||||
if ! [[ -f /proc/1/cgroup ]] ||
|
||||
! grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup
|
||||
then
|
||||
abort "Don't run this as root!"
|
||||
fi
|
||||
fi
|
||||
check_run_command_as_root
|
||||
|
||||
if [[ -d "${HOMEBREW_PREFIX}" && ! -x "${HOMEBREW_PREFIX}" ]]
|
||||
then
|
||||
@ -584,7 +594,7 @@ Your Mac OS X version is too old. See:
|
||||
${tty_underline}https://github.com/mistydemeo/tigerbrew${tty_reset}
|
||||
EOABORT
|
||||
)"
|
||||
elif version_lt "${macos_version}" "10.10"
|
||||
elif version_lt "${macos_version}" "10.11"
|
||||
then
|
||||
abort "Your OS X version is too old."
|
||||
elif version_ge "${macos_version}" "${MACOS_NEWEST_UNSUPPORTED}" ||
|
||||
@ -759,6 +769,12 @@ then
|
||||
additional_shellenv_commands+=("export HOMEBREW_CORE_GIT_REMOTE=\"${HOMEBREW_CORE_GIT_REMOTE}\"")
|
||||
fi
|
||||
|
||||
if [[ -n "${HOMEBREW_INSTALL_FROM_API-}" ]]
|
||||
then
|
||||
ohai "HOMEBREW_INSTALL_FROM_API is set."
|
||||
echo "Homebrew/homebrew-core will not be tapped during this ${tty_bold}install${tty_reset} run."
|
||||
fi
|
||||
|
||||
if [[ -z "${NONINTERACTIVE-}" ]]
|
||||
then
|
||||
ring_bell
|
||||
@ -788,13 +804,7 @@ then
|
||||
execute_sudo "${CHGRP[@]}" "${GROUP}" "${chgrps[@]}"
|
||||
fi
|
||||
else
|
||||
execute_sudo "${MKDIR[@]}" "${HOMEBREW_PREFIX}"
|
||||
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]
|
||||
then
|
||||
execute_sudo "${CHOWN[@]}" "root:wheel" "${HOMEBREW_PREFIX}"
|
||||
else
|
||||
execute_sudo "${CHOWN[@]}" "${USER}:${GROUP}" "${HOMEBREW_PREFIX}"
|
||||
fi
|
||||
execute_sudo "${INSTALL[@]}" "${HOMEBREW_PREFIX}"
|
||||
fi
|
||||
|
||||
if [[ "${#mkdirs[@]}" -gt 0 ]]
|
||||
@ -916,7 +926,16 @@ ohai "Downloading and installing Homebrew..."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -d "${HOMEBREW_CORE}" ]]
|
||||
if [[ -n "${HOMEBREW_INSTALL_FROM_API-}" ]]
|
||||
then
|
||||
# shellcheck disable=SC2016
|
||||
ohai 'Skip tapping homebrew/core because `$HOMEBREW_INSTALL_FROM_API` is set.'
|
||||
# Unset HOMEBREW_DEVELOPER since it is no longer needed and causes warnings during brew update below
|
||||
if [[ -n "${HOMEBREW_ON_LINUX-}" && (-n "${HOMEBREW_CURL_PATH-}" || -n "${HOMEBREW_GIT_PATH-}") ]]
|
||||
then
|
||||
export -n HOMEBREW_DEVELOPER
|
||||
fi
|
||||
elif [[ ! -d "${HOMEBREW_CORE}" ]]
|
||||
then
|
||||
ohai "Tapping homebrew/core"
|
||||
(
|
||||
@ -992,7 +1011,10 @@ case "${SHELL}" in
|
||||
shell_profile="${HOME}/.profile"
|
||||
;;
|
||||
esac
|
||||
if [[ "${UNAME_MACHINE}" == "arm64" ]] || [[ -n "${HOMEBREW_ON_LINUX-}" ]]
|
||||
|
||||
# `which` is a shell function defined above.
|
||||
# shellcheck disable=SC2230
|
||||
if [[ "$(which brew)" != "${HOMEBREW_PREFIX}/bin/brew" ]]
|
||||
then
|
||||
cat <<EOS
|
||||
- Run these two commands in your terminal to add Homebrew to your ${tty_bold}PATH${tty_reset}:
|
||||
|
78
install.sh
78
install.sh
@ -7,7 +7,7 @@
|
||||
set -u
|
||||
|
||||
abort() {
|
||||
printf "%s\n" "$@"
|
||||
printf "%s\n" "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -33,6 +33,12 @@ then
|
||||
abort 'Both `$INTERACTIVE` and `$NONINTERACTIVE` are set. Please unset at least one variable and try again.'
|
||||
fi
|
||||
|
||||
# Check if script is run in POSIX mode
|
||||
if [[ -n "${POSIXLY_CORRECT+1}" ]]
|
||||
then
|
||||
abort 'Bash must not run in POSIX mode. Please unset POSIXLY_CORRECT and try again.'
|
||||
fi
|
||||
|
||||
# string formatters
|
||||
if [[ -t 1 ]]
|
||||
then
|
||||
@ -94,6 +100,13 @@ else
|
||||
ohai 'Running in non-interactive mode because `$NONINTERACTIVE` is set.'
|
||||
fi
|
||||
|
||||
# USER isn't always set so provide a fall back for the installer and subprocesses.
|
||||
if [[ -z "${USER-}" ]]
|
||||
then
|
||||
USER="$(chomp "$(id -un)")"
|
||||
export USER
|
||||
fi
|
||||
|
||||
# First check OS.
|
||||
OS="$(uname)"
|
||||
if [[ "${OS}" == "Linux" ]]
|
||||
@ -129,6 +142,7 @@ then
|
||||
CHGRP=("/usr/bin/chgrp")
|
||||
GROUP="admin"
|
||||
TOUCH=("/usr/bin/touch")
|
||||
INSTALL=("/usr/bin/install" -d -o "root" -g "wheel" -m "0755")
|
||||
else
|
||||
UNAME_MACHINE="$(uname -m)"
|
||||
|
||||
@ -143,6 +157,7 @@ else
|
||||
CHGRP=("/bin/chgrp")
|
||||
GROUP="$(id -gn)"
|
||||
TOUCH=("/bin/touch")
|
||||
INSTALL=("/usr/bin/install" -d -o "${USER}" -g "${GROUP}" -m "0755")
|
||||
fi
|
||||
CHMOD=("/bin/chmod")
|
||||
MKDIR=("/bin/mkdir" "-p")
|
||||
@ -286,6 +301,16 @@ version_lt() {
|
||||
[[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]]
|
||||
}
|
||||
|
||||
check_run_command_as_root() {
|
||||
[[ "${EUID:-${UID}}" == "0" ]] || return
|
||||
|
||||
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
|
||||
[[ -f /.dockerenv ]] && return
|
||||
[[ -f /proc/1/cgroup ]] && grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup && return
|
||||
|
||||
abort "Don't run this as root!"
|
||||
}
|
||||
|
||||
should_install_command_line_tools() {
|
||||
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]
|
||||
then
|
||||
@ -413,13 +438,6 @@ EOABORT
|
||||
)"
|
||||
fi
|
||||
|
||||
# USER isn't always set so provide a fall back for the installer and subprocesses.
|
||||
if [[ -z "${USER-}" ]]
|
||||
then
|
||||
USER="$(chomp "$(id -un)")"
|
||||
export USER
|
||||
fi
|
||||
|
||||
# Invalidate sudo timestamp before exiting (if it wasn't active before).
|
||||
if [[ -x /usr/bin/sudo ]] && ! /usr/bin/sudo -n -v 2>/dev/null
|
||||
then
|
||||
@ -531,15 +549,7 @@ else
|
||||
fi
|
||||
HOMEBREW_CORE="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core"
|
||||
|
||||
if [[ "${EUID:-${UID}}" == "0" ]]
|
||||
then
|
||||
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
|
||||
if ! [[ -f /proc/1/cgroup ]] ||
|
||||
! grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup
|
||||
then
|
||||
abort "Don't run this as root!"
|
||||
fi
|
||||
fi
|
||||
check_run_command_as_root
|
||||
|
||||
if [[ -d "${HOMEBREW_PREFIX}" && ! -x "${HOMEBREW_PREFIX}" ]]
|
||||
then
|
||||
@ -588,7 +598,7 @@ Your Mac OS X version is too old. See:
|
||||
${tty_underline}https://github.com/mistydemeo/tigerbrew${tty_reset}
|
||||
EOABORT
|
||||
)"
|
||||
elif version_lt "${macos_version}" "10.10"
|
||||
elif version_lt "${macos_version}" "10.11"
|
||||
then
|
||||
abort "Your OS X version is too old."
|
||||
elif version_ge "${macos_version}" "${MACOS_NEWEST_UNSUPPORTED}" ||
|
||||
@ -763,6 +773,12 @@ then
|
||||
additional_shellenv_commands+=("export HOMEBREW_CORE_GIT_REMOTE=\"${HOMEBREW_CORE_GIT_REMOTE}\"")
|
||||
fi
|
||||
|
||||
if [[ -n "${HOMEBREW_INSTALL_FROM_API-}" ]]
|
||||
then
|
||||
ohai "HOMEBREW_INSTALL_FROM_API is set."
|
||||
echo "Homebrew/homebrew-core will not be tapped during this ${tty_bold}install${tty_reset} run."
|
||||
fi
|
||||
|
||||
ohai "安装提示"
|
||||
|
||||
echo "中文安装教程(建议收藏):https://brew.idayer.com/"
|
||||
@ -826,13 +842,7 @@ then
|
||||
execute_sudo "${CHGRP[@]}" "${GROUP}" "${chgrps[@]}"
|
||||
fi
|
||||
else
|
||||
execute_sudo "${MKDIR[@]}" "${HOMEBREW_PREFIX}"
|
||||
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]
|
||||
then
|
||||
execute_sudo "${CHOWN[@]}" "root:wheel" "${HOMEBREW_PREFIX}"
|
||||
else
|
||||
execute_sudo "${CHOWN[@]}" "${USER}:${GROUP}" "${HOMEBREW_PREFIX}"
|
||||
fi
|
||||
execute_sudo "${INSTALL[@]}" "${HOMEBREW_PREFIX}"
|
||||
fi
|
||||
|
||||
if [[ "${#mkdirs[@]}" -gt 0 ]]
|
||||
@ -954,7 +964,16 @@ ohai "Downloading and installing Homebrew..."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -d "${HOMEBREW_CORE}" ]]
|
||||
if [[ -n "${HOMEBREW_INSTALL_FROM_API-}" ]]
|
||||
then
|
||||
# shellcheck disable=SC2016
|
||||
ohai 'Skip tapping homebrew/core because `$HOMEBREW_INSTALL_FROM_API` is set.'
|
||||
# Unset HOMEBREW_DEVELOPER since it is no longer needed and causes warnings during brew update below
|
||||
if [[ -n "${HOMEBREW_ON_LINUX-}" && (-n "${HOMEBREW_CURL_PATH-}" || -n "${HOMEBREW_GIT_PATH-}") ]]
|
||||
then
|
||||
export -n HOMEBREW_DEVELOPER
|
||||
fi
|
||||
elif [[ ! -d "${HOMEBREW_CORE}" ]]
|
||||
then
|
||||
ohai "Tapping homebrew/core"
|
||||
(
|
||||
@ -1030,10 +1049,13 @@ case "${SHELL}" in
|
||||
shell_profile="${HOME}/.profile"
|
||||
;;
|
||||
esac
|
||||
if [[ "${UNAME_MACHINE}" == "arm64" ]] || [[ -n "${HOMEBREW_ON_LINUX-}" ]]
|
||||
|
||||
# `which` is a shell function defined above.
|
||||
# shellcheck disable=SC2230
|
||||
if [[ "$(which brew)" != "${HOMEBREW_PREFIX}/bin/brew" ]]
|
||||
then
|
||||
warn "!!!!!!!!!!! 重要 !!!!!!!!!!!!!!!"
|
||||
echo "切记执行环境变量设置!,如已执行过请忽略。"
|
||||
echo "切记在终端执行环境变量设置!,如已执行过请忽略。"
|
||||
cat <<EOS
|
||||
- 执行下面命令将 Homebrew 到 ${tty_bold}PATH${tty_reset} 中:
|
||||
echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"' >> ${shell_profile}
|
||||
|
26
uninstall.sh
26
uninstall.sh
@ -7,7 +7,7 @@
|
||||
set -u
|
||||
|
||||
abort() {
|
||||
printf "%s\n" "$@"
|
||||
printf "%s\n" "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -19,6 +19,12 @@ then
|
||||
abort "Bash is required to interpret this script."
|
||||
fi
|
||||
|
||||
# Check if script is run in POSIX mode
|
||||
if [[ -n "${POSIXLY_CORRECT+1}" ]]
|
||||
then
|
||||
abort 'Bash must not run in POSIX mode. Please unset POSIXLY_CORRECT and try again.'
|
||||
fi
|
||||
|
||||
shopt -s extglob
|
||||
|
||||
strip_s() {
|
||||
@ -200,7 +206,7 @@ homebrew_prefix_candidates=()
|
||||
usage() {
|
||||
cat <<EOS
|
||||
Homebrew Uninstaller
|
||||
Usage: $0 [options]
|
||||
Usage: [NONINTERACTIVE=1] $0 [options]
|
||||
-p, --path=PATH Sets Homebrew prefix. Defaults to ${homebrew_prefix_default}.
|
||||
--skip-cache-and-logs
|
||||
Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.
|
||||
@ -208,6 +214,7 @@ Usage: $0 [options]
|
||||
-q, --quiet Suppress all output.
|
||||
-n, --dry-run Simulate uninstall but don't remove anything.
|
||||
-h, --help Display this message.
|
||||
NONINTERACTIVE Imply --force if NONINTERACTIVE is non-empty.
|
||||
EOS
|
||||
exit "${1:-0}"
|
||||
}
|
||||
@ -233,12 +240,13 @@ done
|
||||
# Attempt to locate Homebrew unless `--path` is passed
|
||||
if [[ "${#homebrew_prefix_candidates[@]}" -eq 0 ]]
|
||||
then
|
||||
prefix="$(brew --prefix)"
|
||||
prefix="$("${homebrew_prefix_default}"/bin/brew --prefix)"
|
||||
[[ -n "${prefix}" ]] && homebrew_prefix_candidates+=("${prefix}")
|
||||
prefix="$(command -v brew)" || prefix=""
|
||||
prefix="$(command -v "${homebrew_prefix_default}"/bin/brew)" || prefix=""
|
||||
[[ -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
|
||||
[[ "$(uname -m)" == "arm64" ]] && homebrew_prefix_candidates+=("/usr/local") # If migrated from Intel to ARM old path will remain
|
||||
fi
|
||||
|
||||
HOMEBREW_PREFIX="$(
|
||||
@ -272,7 +280,7 @@ if [[ -s "${HOMEBREW_REPOSITORY}/.gitignore" ]]
|
||||
then
|
||||
gitignore="$(<"${HOMEBREW_REPOSITORY}/.gitignore")"
|
||||
else
|
||||
gitignore=$(curl -fsSL https://cdn.jsdelivr.net/gh/Homebrew/brew/.gitignore)
|
||||
gitignore=$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/.gitignore)
|
||||
fi
|
||||
[[ -n "${gitignore}" ]] || abort "Failed to fetch Homebrew .gitignore!"
|
||||
|
||||
@ -342,6 +350,14 @@ then
|
||||
pretty_print_pathnames "${homebrew_files[@]}"
|
||||
fi
|
||||
|
||||
# Always use single-quoted strings with `exp` expressions
|
||||
# shellcheck disable=SC2016
|
||||
if [[ -n "${NONINTERACTIVE-}" ]]
|
||||
then
|
||||
ohai 'Running in non-interactive mode because `$NONINTERACTIVE` is set.'
|
||||
opt_force=1
|
||||
fi
|
||||
|
||||
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] "
|
||||
|
Loading…
x
Reference in New Issue
Block a user