diff --git a/install.sh b/install.sh index be83ffa..fed2b80 100755 --- a/install.sh +++ b/install.sh @@ -36,6 +36,8 @@ if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew" fi HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew" + #changed HOMEBREW_CORE_GIT_REMOTE="https://github.com/Homebrew/homebrew-core" + HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git/" STAT="stat -f" CHOWN="/usr/sbin/chown" @@ -47,6 +49,8 @@ else # and ~/.linuxbrew (which is unsupported) if run interactively. HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew" HOMEBREW_CACHE="${HOME}/.cache/Homebrew" + #changed HOMEBREW_CORE_GIT_REMOTE="https://github.com/Homebrew/linuxbrew-core" + HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git/" STAT="stat --printf" CHOWN="/bin/chown" @@ -54,7 +58,8 @@ else GROUP="$(id -gn)" TOUCH="/bin/touch" fi -BREW_REPO="https://mirrors.ustc.edu.cn/brew.git" +#changed HOMEBREW_BREW_GIT_REMOTE="https://github.com/Homebrew/brew" +HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git" # TODO: bump version when new macOS is released or announced MACOS_NEWEST_UNSUPPORTED="12.0" @@ -176,10 +181,6 @@ major_minor() { echo "${1%%.*}.$(x="${1#*.}"; echo "${x%%.*}")" } -if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then - macos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")" -fi - version_gt() { [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]] } @@ -232,7 +233,7 @@ file_not_grpowned() { } # Please sync with 'test_ruby()' in 'Library/Homebrew/utils/ruby.sh' from Homebrew/brew repository. -test_ruby () { +test_ruby() { if [[ ! -x $1 ]] then return 1 @@ -307,10 +308,10 @@ EOABORT fi if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then - have_sudo_access + have_sudo_access else if [[ -n "${NONINTERACTIVE-}" ]] || - [[ -w "$HOMEBREW_PREFIX_DEFAULT" ]] || + [[ -w "${HOMEBREW_PREFIX_DEFAULT}" ]] || [[ -w "/home/linuxbrew" ]] || [[ -w "/home" ]]; then HOMEBREW_PREFIX="$HOMEBREW_PREFIX_DEFAULT" @@ -331,10 +332,11 @@ else fi HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew" fi +HOMEBREW_CORE="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core" if [[ "${EUID:-${UID}}" == "0" ]]; then abort "Don't run this as root!" -elif [[ -d "$HOMEBREW_PREFIX" && ! -x "$HOMEBREW_PREFIX" ]]; then +elif [[ -d "${HOMEBREW_PREFIX}" && ! -x "${HOMEBREW_PREFIX}" ]]; then abort "$(cat </dev/null || return + + execute "git" "init" "-q" + execute "git" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}" + execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" + execute "git" "config" "core.autocrlf" "false" + execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master" + execute "git" "remote" "set-head" "origin" "--auto" >/dev/null + execute "git" "reset" "--hard" "origin/master" + + cd "${HOMEBREW_REPOSITORY}" >/dev/null || return + ) || exit 1 + fi + + execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" "--quiet" ) || exit 1 if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]; then @@ -652,11 +680,7 @@ EOS ) || exit 1 ohai "Next steps:" -echo "- Run \`brew help\` to get started" -echo "- Further documentation: " -echo " ${tty_underline}https://docs.brew.sh${tty_reset}" - -if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then +if [[ "$UNAME_MACHINE" == "arm64" ]] || [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then case "$SHELL" in */bash*) if [[ -r "$HOME/.bash_profile" ]]; then @@ -673,6 +697,18 @@ if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then ;; esac + cat <> ${shell_profile} + eval \$(${HOMEBREW_PREFIX}/bin/brew shellenv) +EOS +fi + +echo "- Run \`brew help\` to get started" +echo "- Further documentation: " +echo " ${tty_underline}https://docs.brew.sh${tty_reset}" + +if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then echo "- Install the Homebrew dependencies if you have sudo access:" if [[ $(command -v apt-get) ]]; then @@ -687,9 +723,6 @@ if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then cat <> ${shell_profile} - eval \$(${HOMEBREW_PREFIX}/bin/brew shellenv) - We recommend that you install GCC: brew install gcc