diff --git a/install.sh b/install.sh index fdc2c7480691d0a0a5eb1dbc0d4b9e4849889a39..6799f3bf55d0afcebc2df560fc80cf07e78a9901 100644 --- a/install.sh +++ b/install.sh @@ -1,42 +1,24 @@ #!/bin/bash clear set -u -echo 请输入开机密码因为需要读写权限 -# First check if the OS is Linux. -if [[ "$(uname)" = "Linux" ]]; then - HOMEBREW_ON_LINUX=1 -fi # On macOS, this script installs to /usr/local only. -# On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access -# and ~/.linuxbrew otherwise. # To install elsewhere (which is unsupported) # you can untar https://github.com/Homebrew/brew/tarball/master # anywhere you like. -if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then - HOMEBREW_PREFIX="/usr/local" - HOMEBREW_REPOSITORY="/usr/local/Homebrew" - HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew" - - STAT="stat -f" - CHOWN="/usr/sbin/chown" - CHGRP="/usr/bin/chgrp" - GROUP="admin" - TOUCH="/usr/bin/touch" -else - HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew" - HOMEBREW_CACHE="${HOME}/.cache/Homebrew" - - STAT="stat --printf" - CHOWN="/bin/chown" - CHGRP="/bin/chgrp" - GROUP="$(id -gn)" - TOUCH="/bin/touch" -fi -BREW_REPO="https://gitee.com/todungubulahe_bilibili/brew" +HOMEBREW_PREFIX="/usr/local" +HOMEBREW_REPOSITORY="/usr/local/Homebrew" +HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew" +STAT="stat -f" +CHOWN="/usr/sbin/chown" +CHGRP="/usr/bin/chgrp" +GROUP="admin" +TOUCH="/usr/bin/touch" +#默认是中科大镜像站 +BREW_REPO="https://mirrors.ustc.edu.cn/brew.git" # TODO: bump version when new macOS is released -MACOS_LATEST_SUPPORTED="10.15" +MACOS_LATEST_SUPPORTED="11.0" # TODO: bump version when new macOS is released MACOS_OLDEST_SUPPORTED="10.13" @@ -75,11 +57,6 @@ have_sudo_access() { fi HAVE_SUDO_ACCESS="$?" fi - - if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "$HAVE_SUDO_ACCESS" -ne 0 ]]; then - abort "在 macOS 上需要root(sudo)权限 (比如 将用户权限 $USER 提升为管理员权限)!" - fi - return "$HAVE_SUDO_ACCESS" } @@ -140,7 +117,6 @@ getc() { wait_for_user() { local c - echo echo "请通过按“ENTER”键进入下一个安装部分" getc c # we test for \r and \n because some stuff does \r instead @@ -153,9 +129,7 @@ major_minor() { echo "${1%%.*}.$(x="${1#*.}"; echo "${x%%.*}")" } -if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then - macos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")" -fi +macos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")" version_gt() { [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]] @@ -167,24 +141,9 @@ version_lt() { [[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]] } -should_install_git() { - if [[ $(command -v git) ]]; then - return 1 - fi -} - -should_install_curl() { - if [[ $(command -v curl) ]]; then - return 1 - fi -} should_install_command_line_tools() { - if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then - return 1 - fi - - if version_gt "$macos_version" "10.13"; then +if version_gt "$macos_version" "10.13"; then ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] else ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] || @@ -234,33 +193,14 @@ test_ruby () { no_usable_ruby() { local ruby_exec - IFS=$'\n' # Do word splitting on new lines only - for ruby_exec in $(which -a ruby); do + which -a ruby | while read -r ruby_exec; do if test_ruby "$ruby_exec"; then return 1 fi done - IFS=$' \t\n' # Restore IFS to its default value return 0 } -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 需要有 Ruby $REQUIRED_RUBY_VERSION 语言但在你的系统中找不到. - Homebrew 的便携版 Ruby 需要 Glibc $REQUIRED_GLIBC_VERSION 或其更新版. - 请看 ${tty_underline}https://docs.brew.sh/Homebrew-on-Linux 的requirements(要求)部分${tty_reset} - 安装 Ruby $REQUIRED_RUBY_VERSION 然后添加你的PATH路径. - EOFABORT - )" -fi - # USER isn't always set so provide a fall back for the installer and subprocesses. if [[ -z "${USER-}" ]]; then USER="$(chomp "$(id -un)")" @@ -277,7 +217,7 @@ fi cd "/usr" || exit 1 ####################################################################### script -if should_install_git; then +if ! command -v git >/dev/null; then abort "$(cat </dev/null; then abort "$(cat <&1) != *"mkdir"* ]]; then - ohai "选定Homebrew安装目录" - echo "- ${tty_bold}输入密码并回车${tty_reset} 去安装 去 ${tty_underline}${HOMEBREW_PREFIX_DEFAULT}${tty_reset} (${tty_bold}推荐${tty_reset})" - echo "- ${tty_bold}同时按Control和D${tty_reset} 去安装 到 ${tty_underline}$HOME/.linuxbrew${tty_reset}" - echo "- ${tty_bold}同时按 Control和C${tty_reset} 来停止安装" - 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 +have_sudo_access if [[ "$UID" == "0" ]]; then abort "Don't run this as root!" @@ -327,11 +246,10 @@ EOABORT )" fi -if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then - if version_lt "$macos_version" "10.7"; then +if version_lt "$macos_version" "10.7"; then abort "$(cat </dev/null || return + #sleep 2 + cd ~/ + export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git" + export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles" + git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install + /bin/bash -c "$(sed 's|^BREW_REPO=.*$|BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"|g' brew-install/install.sh)" + rm -rf brew-install + git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow + brew update-reset + ########################################################## + cd /usr/local/Homebrew/Library/Taps/homebrew/ + #修改源 + echo "输入你想使用源的序号:1.中科大(建议) 2.清华大学(较慢) 3.北外(比较快) " + read MY_DOWN_NUM + case $MY_DOWN_NUM in + 1) + echo "正在配置中科大源..." + sleep 2 + cd "$(brew --repo)" + sudo git remote set-url origin https://mirrors.ustc.edu.cn/brew.git + cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" + sudo git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git + cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask + sudo git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git + echo "已换源" + sleep 2 + ;; + 2) + echo "正在配置清华大学源..." + sleep 2 + cd "$(brew --repo)" + sudo git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git + cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" + sudo git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git + cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask + sudo git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git + echo "已换源" + sleep 2 + ;; + 3) + echo "正在配置北外源..." + sleep 2 + cd "$(brew --repo)" + sudo git remote set-url origin https://mirrors.bfsu.edu.cn/git/homebrew/brew.git + cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" + sudo git remote set-url origin https://mirrors.bfsu.edu.cn/git/homebrew/homebrew-core.git + cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask + git remote set-url origin https://mirrors.bfsu.edu.cn/git/homebrew/homebrew-cask.git + echo "已换源" + sleep 2 + ;; + *) + echo "未输入有效选项将不进行设置" + sleep 2 + ;; + esac + echo "正在刷新..." + brew update-reset + sleep 2 # we do it in four steps to avoid merge errors when reinstalling - execute "git" "init" "-q" + #execute "git" "init" "-q" # "git remote add" will fail if the remote is defined in the global config - execute "git" "config" "remote.origin.url" "${BREW_REPO}" - execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" + #execute "git" "config" "remote.origin.url" "${BREW_REPO}" + #execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" # ensure we don't munge line endings on checkout - execute "git" "config" "core.autocrlf" "false" + #execute "git" "config" "core.autocrlf" "false" - execute "git" "fetch" "origin" "--force" - execute "git" "fetch" "origin" "--tags" "--force" + #execute "git" "fetch" "origin" "--force" + #execute "git" "fetch" "origin" "--tags" "--force" - execute "git" "reset" "--hard" "origin/master" + #execute "git" "reset" "--hard" "origin/master" - execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew" + #execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew" + + #execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" - execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" ) || exit 1 if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]; then @@ -583,7 +550,6 @@ if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]; then fi ohai "安装完成!" -echo # Use the shell's audible bell. if [[ -t 1 ]]; then @@ -602,7 +568,8 @@ EOS ohai "Homebrew完全是非盈利的. 也可以考虑捐款:" echo "$(cat <> ${shell_profile} - eval \$(${HOMEBREW_PREFIX}/bin/brew shellenv) -- We recommend that you install GCC: - brew install gcc - -EOS -fi -cd ~/install-brew -chmod +x 换源.sh -sleep 2 -./换源.sh -exit 0 \ No newline at end of file + fi + ;; + */zsh*) + shell_profile="$HOME/.zprofile" + ;; + *) + shell_profile="$HOME/.profile" + ;; +esac +brew update diff --git a/strat-install.command b/strat-install.command index d2b3d785259c432f1b32751c5ae9ab5c19d6a3bc..f67e8713ddb2081b0097a82af84383ae0e1011d6 100644 --- a/strat-install.command +++ b/strat-install.command @@ -1,12 +1,28 @@ #!/bin/bash #yao2019xm@163.com clear +if [[ "$(uname)" = "Darwin" ]]; then + echo "安装环境支持" +else + if version_lt "$macos_version" "10.7"; then + abort "$(cat <