From e399d0463af4e01bb513d779e44340dad497318a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?yao2019=EF=BC=88=E9=A1=BF=E8=B0=B7=E5=B8=83=E6=8B=89?= =?UTF-8?q?=E8=B5=AB=EF=BC=89?= <7496100+yao2019ss@user.noreply.gitee.com> Date: Tue, 25 Aug 2020 09:49:01 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20stra?= =?UTF-8?q?t-install.command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- strat-install.command | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 strat-install.command diff --git a/strat-install.command b/strat-install.command deleted file mode 100644 index 30264f0..0000000 --- a/strat-install.command +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -clear -echo "你是mac用户吗请输入y/n" -read MY_DOWN_NUM -case $MY_DOWN_NUM in -yes) - cd ~ - git clone https://gitee.com/yao2019ss/install-brew.git - if [ ! -d "install-brew.git" ];then - mv install-brew.git install-brew - cd install-brew - fi -chmod +x install.sh -./install.sh -;; -y) - cd ~ - git clone https://gitee.com/yao2019ss/install-brew.git - if [ ! -d "install-brew.git" ];then - mv install-brew.git install-brew - cd install-brew - fi -chmod +x install.sh -./install.sh -;; -*) - echo 抱歉此脚本只支持mac用户Linux版正在开发 - read -p "请按任意退出" -;; -esac -exit 0 -- Gitee From fcb23d3c2ab8a3267994f5693d986cce05c472aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?yao2019=EF=BC=88=E9=A1=BF=E8=B0=B7=E5=B8=83=E6=8B=89?= =?UTF-8?q?=E8=B5=AB=EF=BC=89?= <7496100+yao2019ss@user.noreply.gitee.com> Date: Tue, 25 Aug 2020 09:49:09 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20inst?= =?UTF-8?q?all.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 683 ----------------------------------------------------- 1 file changed, 683 deletions(-) delete mode 100644 install.sh diff --git a/install.sh b/install.sh deleted file mode 100644 index c18b5bb..0000000 --- a/install.sh +++ /dev/null @@ -1,683 +0,0 @@ -#!/bin/bash -set -u - -# 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" - -# TODO: bump version when new macOS is released -MACOS_LATEST_SUPPORTED="10.15" -# TODO: bump version when new macOS is released -MACOS_OLDEST_SUPPORTED="10.13" - -# For Homebrew on Linux -REQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556 -REQUIRED_GLIBC_VERSION=2.13 # https://docs.brew.sh/Homebrew-on-Linux#requirements - -# 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"; } -else - 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_reset="$(tty_escape 0)" - -have_sudo_access() { - local -a args - if [[ -n "${SUDO_ASKPASS-}" ]]; then - args=("-A") - fi - - if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then - if [[ -n "${args[*]-}" ]]; then - /usr/bin/sudo "${args[@]}" -l mkdir &>/dev/null - else - /usr/bin/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 user $USER to be an Administrator)!" - fi - - return "$HAVE_SUDO_ACCESS" -} - -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_reset}\n" "$(shell_join "$@")" -} - -warn() { - printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" -} - -abort() { - printf "%s\n" "$1" - exit 1 -} - -execute() { - if ! "$@"; then - abort "$(printf "Failed during: %s" "$(shell_join "$@")")" - fi -} - -execute_sudo() { - local -a args=("$@") - if [[ -n "${SUDO_ASKPASS-}" ]]; then - args=("-A" "${args[@]}") - fi - if have_sudo_access; then - ohai "/usr/bin/sudo" "${args[@]}" - execute "/usr/bin/sudo" "${args[@]}" - else - 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" -} - -wait_for_user() { - local c - echo - echo "Press RETURN 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' ]]; then - exit 1 - fi -} - -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#*.}" ]] -} -version_ge() { - [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -ge "${2#*.}" ]] -} -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 - ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] - else - ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] || - ! [[ -e "/usr/include/iconv.h" ]] - fi -} - -get_permission() { - $STAT "%A" "$1" -} - -user_only_chmod() { - [[ -d "$1" ]] && [[ "$(get_permission "$1")" != "755" ]] -} - -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") "* ]] -} - -# Please 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::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) != \ - Gem::Version.new('$REQUIRED_RUBY_VERSION').to_s.split('.').first(2)" 2>/dev/null -} - -no_usable_ruby() { - local ruby_exec - IFS=$'\n' # Do word splitting on new lines only - for ruby_exec in $(which -a ruby); 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 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}https://docs.brew.sh/Homebrew-on-Linux#requirements${tty_reset} - Install Ruby $REQUIRED_RUBY_VERSION and add its location to your 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)")" - export USER -fi - -# Invalidate sudo timestamp before exiting (if it wasn't active before). -if ! /usr/bin/sudo -n -v 2>/dev/null; then - trap '/usr/bin/sudo -k' EXIT -fi - -# Things can fail later if `pwd` doesn't exist. -# Also sudo prints a warning message for no good reason -cd "/usr" || exit 1 - -####################################################################### script -if should_install_git; then - abort "$(cat <&1) != *"mkdir"* ]]; then - ohai "Select the Homebrew installation directory" - echo "- ${tty_bold}Enter your password${tty_reset} to install to ${tty_underline}${HOMEBREW_PREFIX_DEFAULT}${tty_reset} (${tty_bold}recommended${tty_reset})" - echo "- ${tty_bold}Press Control-D${tty_reset} to install to ${tty_underline}$HOME/.linuxbrew${tty_reset}" - echo "- ${tty_bold}Press Control-C${tty_reset} to cancel installation" - 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 - -if [[ "$UID" == "0" ]]; then - abort "Don't run this as root!" -elif [[ -d "$HOMEBREW_PREFIX" && ! -x "$HOMEBREW_PREFIX" ]]; then - abort "$(cat </dev/null || return - - # we do it in four steps to avoid merge errors when reinstalling - 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/*" - - # ensure we don't munge line endings on checkout - execute "git" "config" "core.autocrlf" "false" - - execute "git" "fetch" "origin" "--force" - execute "git" "fetch" "origin" "--tags" "--force" - - execute "git" "reset" "--hard" "origin/master" - - execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew" - - execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" -) || exit 1 - -if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]; then - warn "${HOMEBREW_PREFIX}/bin is not in your PATH." -fi - -ohai "Installation successful!" -echo - -# Use the shell's audible bell. -if [[ -t 1 ]]; then - printf "\a" -fi - -# Use an extra newline and bold to avoid this being missed. -ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics." -echo "$(cat </dev/null || return - execute "git" "config" "--replace-all" "homebrew.analyticsmessage" "true" - execute "git" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true" -) || 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 - case "$SHELL" in - */bash*) - if [[ -r "$HOME/.bash_profile" ]]; then - shell_profile="$HOME/.bash_profile" - else - shell_profile="$HOME/.profile" - fi - ;; - */zsh*) - shell_profile="$HOME/.zprofile" - ;; - *) - shell_profile="$HOME/.profile" - ;; - esac - - echo "- Install the Homebrew dependencies if you have sudo access:" - - if [[ $(command -v apt-get) ]]; then - echo " sudo apt-get install build-essential" - elif [[ $(command -v yum) ]]; then - echo " sudo yum groupinstall 'Development Tools'" - elif [[ $(command -v pacman) ]]; then - echo " sudo pacman -S base-devel" - elif [[ $(command -v apk) ]]; then - echo " sudo apk add build-base" - fi - - cat <> ${shell_profile} - eval \$(${HOMEBREW_PREFIX}/bin/brew shellenv) -- We recommend that you install GCC: - brew install gcc - -EOS -fi -echo 你需要换源[n/y]吗?可以使下载更快! -read MY_DOWN_NUM -case $MY_DOWN_NUM in -yes) - chmod +x install.sh - ./install.sh -;; -y) - echo 你需要换源[n/y]吗?可以使下载更快! - read MY_DOWN_NUM - case $MY_DOWN_NUM in -yes/y) - chmod +x install.sh - ./install.sh -;; -*) - echo 已为您跳过换源 -;; -esac -read -p "按任意退出" -exit 0 \ No newline at end of file -- Gitee From aa0832d13f1479f370314f2fbf2316c99caf9b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?yao2019=EF=BC=88=E9=A1=BF=E8=B0=B7=E5=B8=83=E6=8B=89?= =?UTF-8?q?=E8=B5=AB=EF=BC=89?= <7496100+yao2019ss@user.noreply.gitee.com> Date: Tue, 25 Aug 2020 09:49:16 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E6=8D=A2=E6=BA=90.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\346\215\242\346\272\220.sh" | 102 ---------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 "\346\215\242\346\272\220.sh" diff --git "a/\346\215\242\346\272\220.sh" "b/\346\215\242\346\272\220.sh" deleted file mode 100644 index 0ec0b65..0000000 --- "a/\346\215\242\346\272\220.sh" +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -clear -cd /usr/local/Homebrew/Library/Taps/homebrew/ -echo "正在检测安装进度..." -sleep 2 -#克隆到本地并修改名称linux不需要 -if [ ! -d "brew" ];then - git clone --mirror https://gitee.com/yao2019ss/brew.git - cd /usr/local/Homebrew/Library/Taps/homebrew/brew.git - git pull - cd /usr/local/Homebrew/Library/Taps/homebrew - mv brew.git brew - echo 已为您下载brew - sleep 2 -else - echo 您已下载brew - sleep 2 -fi -########################################################## -cd /usr/local/Homebrew/Library/Taps/homebrew -if [ ! -d "homebrew-core" ];then - git clone --mirror https://gitee.com/yao2019ss/homebrew-core.git - cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core.git - git pull - cd /usr/local/Homebrew/Library/Taps/homebrew - mv homebrew-core.git homebrew-core - echo 已为您下载homebrew-core - sleep 2 -else - echo 您已下载homebrew-core - sleep 2 -fi - -########################################################## -cd /usr/local/Homebrew/Library/Taps/homebrew/ -if [ ! -d "homebrew-cask" ];then - git clone --mirror https://gitee.com/yao2019ss/homebrew-cask.git - cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask.git/ - git pull - cd /usr/local/Homebrew/Library/Taps/homebrew - mv homebrew-cask.git homebrew-cask - echo 已为您下载homebrew-cask - - sleep 2 -else - echo 您已下载homebrew-cask - sleep 2 -fi -clear -#修改源 -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 - brew update -;; -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 - brew update -;; -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 - brew update -;; -*) - echo "未输入有效选项将不进行设置" - sleep 2 -;; -esac -echo "已换源谢谢食用" -sleep 2 -clear -read -p "按任意退出" -exit 0 \ No newline at end of file -- Gitee From 39bdc22fc615928a9bd060218e2a1fbdef8d7efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?yao2019=EF=BC=88=E9=A1=BF=E8=B0=B7=E5=B8=83=E6=8B=89?= =?UTF-8?q?=E8=B5=AB=EF=BC=89?= <7496100+yao2019ss@user.noreply.gitee.com> Date: Tue, 25 Aug 2020 09:50:54 +0800 Subject: [PATCH 4/4] install Homebrew shell --- install.sh | 664 ++++++++++++++++++++++++++++++++++ strat-install.command | 37 ++ "\346\215\242\346\272\220.sh" | 113 ++++++ 3 files changed, 814 insertions(+) create mode 100644 install.sh create mode 100644 strat-install.command create mode 100644 "\346\215\242\346\272\220.sh" diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..fdc2c74 --- /dev/null +++ b/install.sh @@ -0,0 +1,664 @@ +#!/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" + +# TODO: bump version when new macOS is released +MACOS_LATEST_SUPPORTED="10.15" +# TODO: bump version when new macOS is released +MACOS_OLDEST_SUPPORTED="10.13" + +# For Homebrew on Linux +REQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556 +REQUIRED_GLIBC_VERSION=2.13 # https://docs.brew.sh/Homebrew-on-Linux#requirements + +# 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"; } +else + 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_reset="$(tty_escape 0)" + +have_sudo_access() { + local -a args + if [[ -n "${SUDO_ASKPASS-}" ]]; then + args=("-A") + fi + + if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then + if [[ -n "${args[*]-}" ]]; then + /usr/bin/sudo "${args[@]}" -l mkdir &>/dev/null + else + /usr/bin/sudo -l mkdir &>/dev/null + 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" +} + +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_reset}\n" "$(shell_join "$@")" +} + +warn() { + printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" +} + +abort() { + printf "%s\n" "$1" + exit 1 +} + +execute() { + if ! "$@"; then + abort "$(printf "Failed during: %s" "$(shell_join "$@")")" + fi +} + +execute_sudo() { + local -a args=("$@") + if [[ -n "${SUDO_ASKPASS-}" ]]; then + args=("-A" "${args[@]}") + fi + if have_sudo_access; then + ohai "/usr/bin/sudo" "${args[@]}" + execute "/usr/bin/sudo" "${args[@]}" + else + 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" +} + +wait_for_user() { + local c + echo + echo "请通过按“ENTER”键进入下一个安装部分" + getc c + # we test for \r and \n because some stuff does \r instead + if ! [[ "$c" == $'\r' || "$c" == $'\n' ]]; then + exit 1 + fi +} + +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#*.}" ]] +} +version_ge() { + [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -ge "${2#*.}" ]] +} +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 + ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] + else + ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] || + ! [[ -e "/usr/include/iconv.h" ]] + fi +} + +get_permission() { + $STAT "%A" "$1" +} + +user_only_chmod() { + [[ -d "$1" ]] && [[ "$(get_permission "$1")" != "755" ]] +} + +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") "* ]] +} + +# Please 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::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) != \ + Gem::Version.new('$REQUIRED_RUBY_VERSION').to_s.split('.').first(2)" 2>/dev/null +} + +no_usable_ruby() { + local ruby_exec + IFS=$'\n' # Do word splitting on new lines only + for ruby_exec in $(which -a ruby); 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)")" + export USER +fi + +# Invalidate sudo timestamp before exiting (if it wasn't active before). +if ! /usr/bin/sudo -n -v 2>/dev/null; then + trap '/usr/bin/sudo -k' EXIT +fi + +# Things can fail later if `pwd` doesn't exist. +# Also sudo prints a warning message for no good reason +cd "/usr" || exit 1 + +####################################################################### script +if should_install_git; 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 + +if [[ "$UID" == "0" ]]; then + abort "Don't run this as root!" +elif [[ -d "$HOMEBREW_PREFIX" && ! -x "$HOMEBREW_PREFIX" ]]; then + abort "$(cat </dev/null || return + + # we do it in four steps to avoid merge errors when reinstalling + 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/*" + + # ensure we don't munge line endings on checkout + execute "git" "config" "core.autocrlf" "false" + + execute "git" "fetch" "origin" "--force" + execute "git" "fetch" "origin" "--tags" "--force" + + execute "git" "reset" "--hard" "origin/master" + + execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew" + + execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" +) || exit 1 + +if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]; then + warn "${HOMEBREW_PREFIX}/bin is not in your PATH." +fi + +ohai "安装完成!" +echo + +# Use the shell's audible bell. +if [[ -t 1 ]]; then + printf "\a" +fi + +# Use an extra newline and bold to avoid this being missed. +ohai "Homebrew是一个匿名者聚集一起分析的组织." +echo "$(cat </dev/null || return + execute "git" "config" "--replace-all" "homebrew.analyticsmessage" "true" + execute "git" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true" +) || exit 1 + +ohai "下一部分:" +echo "- 执行 \`brew help\` " +echo "- 进一步获取帮助: " +echo " ${tty_underline}https://docs.brew.sh${tty_reset}" + +if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then + case "$SHELL" in + */bash*) + if [[ -r "$HOME/.bash_profile" ]]; then + shell_profile="$HOME/.bash_profile" + else + shell_profile="$HOME/.profile" + fi + ;; + */zsh*) + shell_profile="$HOME/.zprofile" + ;; + *) + shell_profile="$HOME/.profile" + ;; + esac + + echo "- 安装Homebrew需要root(sudo)权限:" + + if [[ $(command -v apt-get) ]]; then + echo " sudo apt-get install build-essential" + elif [[ $(command -v yum) ]]; then + echo " sudo yum groupinstall 'Development Tools'" + elif [[ $(command -v pacman) ]]; then + echo " sudo pacman -S base-devel" + elif [[ $(command -v apk) ]]; then + echo " sudo apk add build-base" + fi + + 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 diff --git a/strat-install.command b/strat-install.command new file mode 100644 index 0000000..d2b3d78 --- /dev/null +++ b/strat-install.command @@ -0,0 +1,37 @@ +#!/bin/bash +#yao2019xm@163.com +clear +echo "尊敬的用户使用此脚本请遵守 GNU General Public License v3.0开源许可证[y/n]" +read MY_DOWN_NUM +case $MY_DOWN_NUM in +yes) + cd ~ + git clone https://gitee.com/yao2019ss/install-brew.git + if [ ! -d "install-brew.git" ];then + mv install-brew.git install-brew + cd install-brew + fi + chmod +x install.sh + ./install.sh +;; +y) + cd ~ + git clone https://gitee.com/yao2019ss/install-brew.git + if [ ! -d "install-brew.git" ];then + mv install-brew.git install-brew + cd install-brew + fi + chmod +x install.sh + ./install.sh +;; +n) + read -p "抱歉由于您无法遵守GNU-General-Public-License-v3.0请按任意退出" +;; +no) + read -p "抱歉由于您无法遵守GNU-General-Public-License-v3.0请按任意退出" +;; +*) + read -p "输入无效请重新打开此脚本" +;; +esac +exit 0 diff --git "a/\346\215\242\346\272\220.sh" "b/\346\215\242\346\272\220.sh" new file mode 100644 index 0000000..1ca973c --- /dev/null +++ "b/\346\215\242\346\272\220.sh" @@ -0,0 +1,113 @@ +#!/bin/bash +clear +echo 你需要换源[y/n]吗?可以使下载更快! +read MY_DOWN_NUM +case $MY_DOWN_NUM in +yes) + #进入换源 +;; +y) + #进入换源 +;; +*) + echo 已为您跳过换源 + sleep 2 + read -p "按任意建进入清理下载的安装脚本等;不想清理请直接关闭窗口即可" + cd ~ + rm -rf install-brew + exit 0 +;; +esac +cd /usr/local/Homebrew/Library/Taps/homebrew/ +echo "正在检测安装进度..." +sleep 2 +#克隆到本地并修改名称linux不需要 +if [ ! -d "brew" ];then + git clone --mirror https://gitee.com/yao2019ss/brew.git + mv brew.git brew + echo 已为您下载brew + sleep 2 +else + echo 您已下载brew + sleep 2 +fi +########################################################## +cd /usr/local/Homebrew/Library/Taps/homebrew +if [ ! -d "homebrew-core" ];then + git clone --mirror https://gitee.com/yao2019ss/homebrew-core.git + mv homebrew-core.git homebrew-core + echo 已为您下载homebrew-core + sleep 2 +else + echo 您已下载homebrew-core + sleep 2 +fi + +########################################################## +cd /usr/local/Homebrew/Library/Taps/homebrew/ +if [ ! -d "homebrew-cask" ];then + git clone --mirror https://gitee.com/yao2019ss/homebrew-cask.git + mv homebrew-cask.git homebrew-cask + echo 已为您下载homebrew-cask + + sleep 2 +else + echo 您已下载homebrew-cask + sleep 2 +fi +clear +#修改源 +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 "正在刷新..." +sleep 2 +brew update +clear +sleep 2 +read -p "按任意建进入清理下载的安装脚本等;不想清理请直接关闭窗口即可" +cd ~ +rm -rf install-brew +read -p "清理完成按任意键退出" +exit 0 -- Gitee