feat: 优化mx环境变量

This commit is contained in:
neo 2023-03-06 14:43:27 +08:00
parent 71b5abec17
commit 40828fec78
2 changed files with 82 additions and 56 deletions

View File

@ -447,7 +447,8 @@ fi
cd "/usr" || exit 1 cd "/usr" || exit 1
####################################################################### script ####################################################################### script
if ! command -v git >/dev/null USABLE_GIT="$(command -v git)"
if [[ -z "${USABLE_GIT}" ]]
then then
abort "$( abort "$(
cat <<EOABORT cat <<EOABORT
@ -887,22 +888,22 @@ ohai "Downloading and installing Homebrew..."
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
# we do it in four steps to avoid merge errors when reinstalling # we do it in four steps to avoid merge errors when reinstalling
execute "git" "-c" "init.defaultBranch=master" "init" "--quiet" execute "${USABLE_GIT}" "-c" "init.defaultBranch=master" "init" "--quiet"
# "git remote add" will fail if the remote is defined in the global config # "git remote add" will fail if the remote is defined in the global config
execute "git" "config" "remote.origin.url" "${HOMEBREW_BREW_GIT_REMOTE}" execute "${USABLE_GIT}" "config" "remote.origin.url" "${HOMEBREW_BREW_GIT_REMOTE}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" execute "${USABLE_GIT}" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
# ensure we don't munge line endings on checkout # ensure we don't munge line endings on checkout
execute "git" "config" "--bool" "core.autocrlf" "false" execute "${USABLE_GIT}" "config" "--bool" "core.autocrlf" "false"
# make sure symlinks are saved as-is # make sure symlinks are saved as-is
execute "git" "config" "--bool" "core.symlinks" "true" execute "${USABLE_GIT}" "config" "--bool" "core.symlinks" "true"
execute "git" "fetch" "--force" "origin" execute "${USABLE_GIT}" "fetch" "--force" "origin"
execute "git" "fetch" "--force" "--tags" "origin" execute "${USABLE_GIT}" "fetch" "--force" "--tags" "origin"
execute "git" "reset" "--hard" "origin/master" execute "${USABLE_GIT}" "reset" "--hard" "origin/master"
if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_PREFIX}" ]] if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_PREFIX}" ]]
then then
@ -923,14 +924,14 @@ ohai "Downloading and installing Homebrew..."
execute "${MKDIR[@]}" "${HOMEBREW_CORE}" execute "${MKDIR[@]}" "${HOMEBREW_CORE}"
cd "${HOMEBREW_CORE}" >/dev/null || return cd "${HOMEBREW_CORE}" >/dev/null || return
execute "git" "-c" "init.defaultBranch=master" "init" "--quiet" execute "${USABLE_GIT}" "-c" "init.defaultBranch=master" "init" "--quiet"
execute "git" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}" execute "${USABLE_GIT}" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" execute "${USABLE_GIT}" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
execute "git" "config" "--bool" "core.autocrlf" "false" execute "${USABLE_GIT}" "config" "--bool" "core.autocrlf" "false"
execute "git" "config" "--bool" "core.symlinks" "true" execute "${USABLE_GIT}" "config" "--bool" "core.symlinks" "true"
execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master" execute "${USABLE_GIT}" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master"
execute "git" "remote" "set-head" "origin" "--auto" >/dev/null execute "${USABLE_GIT}" "remote" "set-head" "origin" "--auto" >/dev/null
execute "git" "reset" "--hard" "origin/master" execute "${USABLE_GIT}" "reset" "--hard" "origin/master"
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
) || exit 1 ) || exit 1
@ -972,8 +973,8 @@ EOS
( (
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
execute "git" "config" "--replace-all" "homebrew.analyticsmessage" "true" execute "${USABLE_GIT}" "config" "--replace-all" "homebrew.analyticsmessage" "true"
execute "git" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true" execute "${USABLE_GIT}" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true"
) || exit 1 ) || exit 1
ohai "Next steps:" ohai "Next steps:"
@ -994,11 +995,23 @@ case "${SHELL}" in
;; ;;
esac esac
if grep -qs "eval \"\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"" "${shell_profile}"
then
if ! [[ -x "$(command -v brew)" ]]
then
cat <<EOS
- Run this command in your terminal to add Homebrew to your ${tty_bold}PATH${tty_reset}:
eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
EOS
fi
else
cat <<EOS cat <<EOS
- Run these two commands in your terminal to add Homebrew to your ${tty_bold}PATH${tty_reset}: - Run these two commands in your terminal to add Homebrew to your ${tty_bold}PATH${tty_reset}:
(echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ${shell_profile} (echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ${shell_profile}
eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)" eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
EOS EOS
fi
if [[ -n "${non_default_repos}" ]] if [[ -n "${non_default_repos}" ]]
then then
plural="" plural=""

View File

@ -479,7 +479,8 @@ fi
cd "/usr" || exit 1 cd "/usr" || exit 1
####################################################################### script ####################################################################### script
if ! command -v git >/dev/null USABLE_GIT="$(command -v git)"
if [[ -z "${USABLE_GIT}" ]]
then then
abort "$( abort "$(
cat <<EOABORT cat <<EOABORT
@ -953,22 +954,22 @@ ohai "Downloading and installing Homebrew..."
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
# we do it in four steps to avoid merge errors when reinstalling # we do it in four steps to avoid merge errors when reinstalling
execute "git" "init" "-q" execute "${USABLE_GIT}" "-c" "init.defaultBranch=master" "init" "--quiet"
# "git remote add" will fail if the remote is defined in the global config # "git remote add" will fail if the remote is defined in the global config
execute "git" "config" "remote.origin.url" "${HOMEBREW_BREW_GIT_REMOTE}" execute "${USABLE_GIT}" "config" "remote.origin.url" "${HOMEBREW_BREW_GIT_REMOTE}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" execute "${USABLE_GIT}" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
# ensure we don't munge line endings on checkout # ensure we don't munge line endings on checkout
execute "git" "config" "--bool" "core.autocrlf" "false" execute "${USABLE_GIT}" "config" "--bool" "core.autocrlf" "false"
# make sure symlinks are saved as-is # make sure symlinks are saved as-is
execute "git" "config" "--bool" "core.symlinks" "true" execute "${USABLE_GIT}" "config" "--bool" "core.symlinks" "true"
execute "git" "fetch" "--force" "origin" execute "${USABLE_GIT}" "fetch" "--force" "origin"
execute "git" "fetch" "--force" "--tags" "origin" execute "${USABLE_GIT}" "fetch" "--force" "--tags" "origin"
execute "git" "reset" "--hard" "origin/master" execute "${USABLE_GIT}" "reset" "--hard" "origin/master"
if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_PREFIX}" ]] if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_PREFIX}" ]]
then then
@ -989,14 +990,14 @@ ohai "Downloading and installing Homebrew..."
execute "${MKDIR[@]}" "${HOMEBREW_CORE}" execute "${MKDIR[@]}" "${HOMEBREW_CORE}"
cd "${HOMEBREW_CORE}" >/dev/null || return cd "${HOMEBREW_CORE}" >/dev/null || return
execute "git" "-c" "init.defaultBranch=master" "init" "--quiet" execute "${USABLE_GIT}" "-c" "init.defaultBranch=master" "init" "--quiet"
execute "git" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}" execute "${USABLE_GIT}" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" execute "${USABLE_GIT}" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
execute "git" "config" "--bool" "core.autocrlf" "false" execute "${USABLE_GIT}" "config" "--bool" "core.autocrlf" "false"
execute "git" "config" "--bool" "core.symlinks" "true" execute "${USABLE_GIT}" "config" "--bool" "core.symlinks" "true"
execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master" execute "${USABLE_GIT}" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master"
execute "git" "remote" "set-head" "origin" "--auto" >/dev/null execute "${USABLE_GIT}" "remote" "set-head" "origin" "--auto" >/dev/null
execute "git" "reset" "--hard" "origin/master" execute "${USABLE_GIT}" "reset" "--hard" "origin/master"
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
) || exit 1 ) || exit 1
@ -1011,14 +1012,14 @@ ohai "Downloading and installing Homebrew..."
execute "${MKDIR[@]}" "${HOMEBREW_CASK}" execute "${MKDIR[@]}" "${HOMEBREW_CASK}"
cd "${HOMEBREW_CASK}" >/dev/null || return cd "${HOMEBREW_CASK}" >/dev/null || return
execute "git" "-c" "init.defaultBranch=master" "init" "--quiet" execute "${USABLE_GIT}" "-c" "init.defaultBranch=master" "init" "--quiet"
execute "git" "config" "remote.origin.url" "${HOMEBREW_CASK_GIT_REMOTE}" execute "${USABLE_GIT}" "config" "remote.origin.url" "${HOMEBREW_CASK_GIT_REMOTE}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" execute "${USABLE_GIT}" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
execute "git" "config" "--bool" "core.autocrlf" "false" execute "${USABLE_GIT}" "config" "--bool" "core.autocrlf" "false"
execute "git" "config" "--bool" "core.symlinks" "true" execute "${USABLE_GIT}" "config" "--bool" "core.symlinks" "true"
execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master" execute "${USABLE_GIT}" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master"
execute "git" "remote" "set-head" "origin" "--auto" >/dev/null execute "${USABLE_GIT}" "remote" "set-head" "origin" "--auto" >/dev/null
execute "git" "reset" "--hard" "origin/master" execute "${USABLE_GIT}" "reset" "--hard" "origin/master"
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
) || exit 1 ) || exit 1
@ -1033,14 +1034,14 @@ ohai "Downloading and installing Homebrew..."
execute "${MKDIR[@]}" "${HOMEBREW_SERVICES}" execute "${MKDIR[@]}" "${HOMEBREW_SERVICES}"
cd "${HOMEBREW_SERVICES}" >/dev/null || return cd "${HOMEBREW_SERVICES}" >/dev/null || return
execute "git" "-c" "init.defaultBranch=master" "init" "--quiet" execute "${USABLE_GIT}" "-c" "init.defaultBranch=master" "init" "--quiet"
execute "git" "config" "remote.origin.url" "${HOMEBREW_SERVICES_DEFAULT_GIT_REMOTE}" execute "${USABLE_GIT}" "config" "remote.origin.url" "${HOMEBREW_SERVICES_DEFAULT_GIT_REMOTE}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*" execute "${USABLE_GIT}" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
execute "git" "config" "--bool" "core.autocrlf" "false" execute "${USABLE_GIT}" "config" "--bool" "core.autocrlf" "false"
execute "git" "config" "--bool" "core.symlinks" "true" execute "${USABLE_GIT}" "config" "--bool" "core.symlinks" "true"
execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master" execute "${USABLE_GIT}" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master"
execute "git" "remote" "set-head" "origin" "--auto" >/dev/null execute "${USABLE_GIT}" "remote" "set-head" "origin" "--auto" >/dev/null
execute "git" "reset" "--hard" "origin/master" execute "${USABLE_GIT}" "reset" "--hard" "origin/master"
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
) || exit 1 ) || exit 1
@ -1063,8 +1064,8 @@ EOS
( (
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
execute "git" "config" "--replace-all" "homebrew.analyticsmessage" "true" execute "${USABLE_GIT}" "config" "--replace-all" "homebrew.analyticsmessage" "true"
execute "git" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true" execute "${USABLE_GIT}" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true"
) || exit 1 ) || exit 1
ohai "Next steps:" ohai "Next steps:"
@ -1126,6 +1127,18 @@ EOS
" "
fi fi
if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]
then
eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
echo ""
warn " 重要 "
cat <<EOS
如果遇到 command not found brew请执行下面脚本完成安装:
eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
EOS
fi
if [[ -n "${HOMEBREW_ON_LINUX-}" ]] if [[ -n "${HOMEBREW_ON_LINUX-}" ]]
then then
echo "- Install Homebrew's dependencies if you have sudo access:" echo "- Install Homebrew's dependencies if you have sudo access:"