Merge pull request #11214 from hyuraku/utils_repair_style
Utils repair style
This commit is contained in:
commit
5d67709cb6
@ -1,43 +1,46 @@
|
|||||||
# Migrate analytics UUID to its new home in Homebrew repo's git config and
|
# Migrate analytics UUID to its new home in Homebrew repo's git config and
|
||||||
# remove the legacy UUID file if detected.
|
# remove the legacy UUID file if detected.
|
||||||
|
# HOMEBREW_LINUX, HOMEBREW_REPOSITORY is set by bin/brew
|
||||||
|
# HOMEBREW_NO_ANALYTICS is from the user environment.
|
||||||
|
# shellcheck disable=SC2154
|
||||||
migrate-legacy-uuid-file() {
|
migrate-legacy-uuid-file() {
|
||||||
local legacy_uuid_file analytics_uuid
|
local legacy_uuid_file analytics_uuid
|
||||||
|
|
||||||
legacy_uuid_file="$HOME/.homebrew_analytics_user_uuid"
|
legacy_uuid_file="${HOME}/.homebrew_analytics_user_uuid"
|
||||||
|
|
||||||
if [[ -f "$legacy_uuid_file" ]]
|
if [[ -f "${legacy_uuid_file}" ]]
|
||||||
then
|
then
|
||||||
analytics_uuid="$(<"$legacy_uuid_file")"
|
analytics_uuid="$(<"${legacy_uuid_file}")"
|
||||||
if [[ -n "$analytics_uuid" ]]
|
if [[ -n "${analytics_uuid}" ]]
|
||||||
then
|
then
|
||||||
git config --file="$HOMEBREW_REPOSITORY/.git/config" --replace-all homebrew.analyticsuuid "$analytics_uuid" 2>/dev/null
|
git config --file="${HOMEBREW_REPOSITORY}/.git/config" --replace-all homebrew.analyticsuuid "${analytics_uuid}" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
rm -f "$legacy_uuid_file"
|
rm -f "${legacy_uuid_file}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
setup-analytics() {
|
setup-analytics() {
|
||||||
local git_config_file="$HOMEBREW_REPOSITORY/.git/config"
|
local git_config_file="${HOMEBREW_REPOSITORY}/.git/config"
|
||||||
|
|
||||||
migrate-legacy-uuid-file
|
migrate-legacy-uuid-file
|
||||||
|
|
||||||
if [[ -n "$HOMEBREW_NO_ANALYTICS" ]]
|
if [[ -n "${HOMEBREW_NO_ANALYTICS}" ]]
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local message_seen analytics_disabled
|
local message_seen analytics_disabled
|
||||||
message_seen="$(git config --file="$git_config_file" --get homebrew.analyticsmessage 2>/dev/null)"
|
message_seen="$(git config --file="${git_config_file}" --get homebrew.analyticsmessage 2>/dev/null)"
|
||||||
analytics_disabled="$(git config --file="$git_config_file" --get homebrew.analyticsdisabled 2>/dev/null)"
|
analytics_disabled="$(git config --file="${git_config_file}" --get homebrew.analyticsdisabled 2>/dev/null)"
|
||||||
if [[ "$message_seen" != "true" || "$analytics_disabled" = "true" ]]
|
if [[ "${message_seen}" != "true" || "${analytics_disabled}" = "true" ]]
|
||||||
then
|
then
|
||||||
# Internal variable for brew's use, to differentiate from user-supplied setting
|
# Internal variable for brew's use, to differentiate from user-supplied setting
|
||||||
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
|
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HOMEBREW_ANALYTICS_USER_UUID="$(git config --file="$git_config_file" --get homebrew.analyticsuuid 2>/dev/null)"
|
HOMEBREW_ANALYTICS_USER_UUID="$(git config --file="${git_config_file}" --get homebrew.analyticsuuid 2>/dev/null)"
|
||||||
if [[ -z "$HOMEBREW_ANALYTICS_USER_UUID" ]]
|
if [[ -z "${HOMEBREW_ANALYTICS_USER_UUID}" ]]
|
||||||
then
|
then
|
||||||
if [[ -x /usr/bin/uuidgen ]]
|
if [[ -x /usr/bin/uuidgen ]]
|
||||||
then
|
then
|
||||||
@ -49,16 +52,16 @@ setup-analytics() {
|
|||||||
HOMEBREW_ANALYTICS_USER_UUID="$(uuidgen)"
|
HOMEBREW_ANALYTICS_USER_UUID="$(uuidgen)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$HOMEBREW_ANALYTICS_USER_UUID" ]]
|
if [[ -z "${HOMEBREW_ANALYTICS_USER_UUID}" ]]
|
||||||
then
|
then
|
||||||
# Avoid sending bogus analytics if no UUID could be generated.
|
# Avoid sending bogus analytics if no UUID could be generated.
|
||||||
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
|
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
git config --file="$git_config_file" --replace-all homebrew.analyticsuuid "$HOMEBREW_ANALYTICS_USER_UUID" 2>/dev/null
|
git config --file="${git_config_file}" --replace-all homebrew.analyticsuuid "${HOMEBREW_ANALYTICS_USER_UUID}" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$HOMEBREW_LINUX" ]]
|
if [[ -n "${HOMEBREW_LINUX}" ]]
|
||||||
then
|
then
|
||||||
# For Homebrew on Linux's analytics.
|
# For Homebrew on Linux's analytics.
|
||||||
HOMEBREW_ANALYTICS_ID="UA-76492262-1"
|
HOMEBREW_ANALYTICS_ID="UA-76492262-1"
|
||||||
|
|||||||
@ -1,17 +1,19 @@
|
|||||||
# create a lock using `flock(2)`. A name is required as first argument.
|
# create a lock using `flock(2)`. A name is required as first argument.
|
||||||
# the lock will be automatically unlocked when the shell process quits.
|
# the lock will be automatically unlocked when the shell process quits.
|
||||||
# Noted due to the fixed FD, a shell process can only create one lock.
|
# Noted due to the fixed FD, a shell process can only create one lock.
|
||||||
|
# HOMEBREW_PREFIX is set by extend/ENV/super.rb
|
||||||
|
# shellcheck disable=SC2154
|
||||||
lock() {
|
lock() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local lock_dir="$HOMEBREW_PREFIX/var/homebrew/locks"
|
local lock_dir="${HOMEBREW_PREFIX}/var/homebrew/locks"
|
||||||
local lock_file="$lock_dir/$name"
|
local lock_file="${lock_dir}/${name}"
|
||||||
[[ -d "$lock_dir" ]] || mkdir -p "$lock_dir"
|
[[ -d "${lock_dir}" ]] || mkdir -p "${lock_dir}"
|
||||||
if ! [[ -w "$lock_dir" ]]
|
if ! [[ -w "${lock_dir}" ]]
|
||||||
then
|
then
|
||||||
odie <<EOS
|
odie <<EOS
|
||||||
Can't create $name lock in $lock_dir!
|
Can't create ${name} lock in ${lock_dir}!
|
||||||
Fix permissions by running:
|
Fix permissions by running:
|
||||||
sudo chown -R \$(whoami) $HOMEBREW_PREFIX/var/homebrew
|
sudo chown -R \$(whoami) ${HOMEBREW_PREFIX}/var/homebrew
|
||||||
EOS
|
EOS
|
||||||
fi
|
fi
|
||||||
# 200 is the file descriptor used in the lock.
|
# 200 is the file descriptor used in the lock.
|
||||||
@ -24,11 +26,11 @@ EOS
|
|||||||
# close FD first, this is required if parent process holds a different lock.
|
# close FD first, this is required if parent process holds a different lock.
|
||||||
exec 200>&-
|
exec 200>&-
|
||||||
# open the lock file to FD, so the shell process can hold the lock.
|
# open the lock file to FD, so the shell process can hold the lock.
|
||||||
exec 200>"$lock_file"
|
exec 200>"${lock_file}"
|
||||||
if ! _create_lock 200 "$name"
|
if ! _create_lock 200 "${name}"
|
||||||
then
|
then
|
||||||
odie <<EOS
|
odie <<EOS
|
||||||
Another active Homebrew $name process is already in progress.
|
Another active Homebrew ${name} process is already in progress.
|
||||||
Please wait for it to finish or terminate it to continue.
|
Please wait for it to finish or terminate it to continue.
|
||||||
EOS
|
EOS
|
||||||
fi
|
fi
|
||||||
@ -39,19 +41,19 @@ _create_lock() {
|
|||||||
local name="$2"
|
local name="$2"
|
||||||
local ruby="/usr/bin/ruby"
|
local ruby="/usr/bin/ruby"
|
||||||
local python="/usr/bin/python"
|
local python="/usr/bin/python"
|
||||||
[[ -x "$ruby" ]] || ruby="$(type -P ruby)"
|
[[ -x "${ruby}" ]] || ruby="$(type -P ruby)"
|
||||||
[[ -x "$python" ]] || python="$(type -P python)"
|
[[ -x "${python}" ]] || python="$(type -P python)"
|
||||||
|
|
||||||
if [[ -x "$ruby" ]] && "$ruby" -e "exit(RUBY_VERSION >= '1.8.7')"
|
if [[ -x "${ruby}" ]] && "${ruby}" -e "exit(RUBY_VERSION >= '1.8.7')"
|
||||||
then
|
then
|
||||||
"$ruby" -e "File.new($lock_fd).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)"
|
"${ruby}" -e "File.new(${lock_fd}).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)"
|
||||||
elif [[ -x "$python" ]]
|
elif [[ -x "${python}" ]]
|
||||||
then
|
then
|
||||||
"$python" -c "import fcntl; fcntl.flock($lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)"
|
"${python}" -c "import fcntl; fcntl.flock(${lock_fd}, fcntl.LOCK_EX | fcntl.LOCK_NB)"
|
||||||
elif [[ -x "$(type -P flock)" ]]
|
elif [[ -x "$(type -P flock)" ]]
|
||||||
then
|
then
|
||||||
flock -n "$lock_fd"
|
flock -n "${lock_fd}"
|
||||||
else
|
else
|
||||||
onoe "Cannot create $name lock, please avoid running Homebrew in parallel."
|
onoe "Cannot create ${name} lock, please avoid running Homebrew in parallel."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
export HOMEBREW_REQUIRED_RUBY_VERSION=2.6.3
|
export HOMEBREW_REQUIRED_RUBY_VERSION=2.6.3
|
||||||
|
|
||||||
|
# HOMEBREW_LIBRARY is from the user environment
|
||||||
|
# shellcheck disable=SC2154
|
||||||
test_ruby() {
|
test_ruby() {
|
||||||
if [[ ! -x $1 ]]
|
if [[ ! -x $1 ]]
|
||||||
then
|
then
|
||||||
@ -7,20 +9,23 @@ test_ruby() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt \
|
"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt \
|
||||||
"$HOMEBREW_LIBRARY/Homebrew/utils/ruby_check_version_script.rb" \
|
"${HOMEBREW_LIBRARY}/Homebrew/utils/ruby_check_version_script.rb" \
|
||||||
"$HOMEBREW_REQUIRED_RUBY_VERSION" 2>/dev/null
|
"${HOMEBREW_REQUIRED_RUBY_VERSION}" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# HOMEBREW_MACOS is set by brew.sh
|
||||||
|
# HOMEBREW_PATH is set by global.rb
|
||||||
|
# shellcheck disable=SC2154
|
||||||
find_ruby() {
|
find_ruby() {
|
||||||
if [[ -n "$HOMEBREW_MACOS" ]]
|
if [[ -n "${HOMEBREW_MACOS}" ]]
|
||||||
then
|
then
|
||||||
echo "/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
|
echo "/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
|
||||||
else
|
else
|
||||||
IFS=$'\n' # Do word splitting on new lines only
|
IFS=$'\n' # Do word splitting on new lines only
|
||||||
for ruby_exec in $(which -a ruby 2>/dev/null) $(PATH=$HOMEBREW_PATH which -a ruby 2>/dev/null)
|
for ruby_exec in $(command -v -a ruby 2>/dev/null) $(PATH=${HOMEBREW_PATH} command -v -a ruby 2>/dev/null)
|
||||||
do
|
do
|
||||||
if test_ruby "$ruby_exec"; then
|
if test_ruby "${ruby_exec}"; then
|
||||||
echo "$ruby_exec"
|
echo "${ruby_exec}"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -28,14 +33,17 @@ find_ruby() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# HOMEBREW_FORCE_VENDOR_RUBY is from the user environment
|
||||||
|
# HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH are set by brew.sh
|
||||||
|
# shellcheck disable=SC2154
|
||||||
need_vendored_ruby() {
|
need_vendored_ruby() {
|
||||||
if [[ -n "$HOMEBREW_FORCE_VENDOR_RUBY" ]]
|
if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" ]]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
elif [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]]
|
elif [[ -n "${HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH}" ]]
|
||||||
then
|
then
|
||||||
return 1
|
return 1
|
||||||
elif [[ -z "$HOMEBREW_MACOS" ]] && test_ruby "$HOMEBREW_RUBY_PATH"
|
elif [[ -z "${HOMEBREW_MACOS}" ]] && test_ruby "${HOMEBREW_RUBY_PATH}"
|
||||||
then
|
then
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
@ -43,6 +51,8 @@ need_vendored_ruby() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# HOMEBREW_LINUX is set by brew.sh
|
||||||
|
# shellcheck disable=SC2154
|
||||||
setup-ruby-path() {
|
setup-ruby-path() {
|
||||||
local vendor_dir
|
local vendor_dir
|
||||||
local vendor_ruby_root
|
local vendor_ruby_root
|
||||||
@ -56,53 +66,53 @@ setup-ruby-path() {
|
|||||||
local upgrade_fail
|
local upgrade_fail
|
||||||
local install_fail
|
local install_fail
|
||||||
|
|
||||||
if [[ -n $HOMEBREW_MACOS ]]
|
if [[ -n ${HOMEBREW_MACOS} ]]
|
||||||
then
|
then
|
||||||
upgrade_fail="Failed to upgrade Homebrew Portable Ruby!"
|
upgrade_fail="Failed to upgrade Homebrew Portable Ruby!"
|
||||||
install_fail="Failed to install Homebrew Portable Ruby (and your system version is too old)!"
|
install_fail="Failed to install Homebrew Portable Ruby (and your system version is too old)!"
|
||||||
else
|
else
|
||||||
local advice="
|
local advice="
|
||||||
If there's no Homebrew Portable Ruby available for your processor:
|
If there's no Homebrew Portable Ruby available for your processor:
|
||||||
- install Ruby $HOMEBREW_REQUIRED_RUBY_VERSION with your system package manager (or rbenv/ruby-build)
|
- install Ruby ${HOMEBREW_REQUIRED_RUBY_VERSION} with your system package manager (or rbenv/ruby-build)
|
||||||
- make it first in your PATH
|
- make it first in your PATH
|
||||||
- try again
|
- try again
|
||||||
"
|
"
|
||||||
upgrade_fail="Failed to upgrade Homebrew Portable Ruby!$advice"
|
upgrade_fail="Failed to upgrade Homebrew Portable Ruby!${advice}"
|
||||||
install_fail="Failed to install Homebrew Portable Ruby and cannot find another Ruby $HOMEBREW_REQUIRED_RUBY_VERSION!$advice"
|
install_fail="Failed to install Homebrew Portable Ruby and cannot find another Ruby ${HOMEBREW_REQUIRED_RUBY_VERSION}!${advice}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor"
|
vendor_dir="${HOMEBREW_LIBRARY}/Homebrew/vendor"
|
||||||
vendor_ruby_root="$vendor_dir/portable-ruby/current"
|
vendor_ruby_root="${vendor_dir}/portable-ruby/current"
|
||||||
vendor_ruby_path="$vendor_ruby_root/bin/ruby"
|
vendor_ruby_path="${vendor_ruby_root}/bin/ruby"
|
||||||
vendor_ruby_terminfo="$vendor_ruby_root/share/terminfo"
|
vendor_ruby_terminfo="${vendor_ruby_root}/share/terminfo"
|
||||||
vendor_ruby_latest_version=$(<"$vendor_dir/portable-ruby-version")
|
vendor_ruby_latest_version=$(<"${vendor_dir}/portable-ruby-version")
|
||||||
vendor_ruby_current_version=$(readlink "$vendor_ruby_root")
|
vendor_ruby_current_version=$(readlink "${vendor_ruby_root}")
|
||||||
|
|
||||||
unset HOMEBREW_RUBY_PATH
|
unset HOMEBREW_RUBY_PATH
|
||||||
|
|
||||||
if [[ "$HOMEBREW_COMMAND" == "vendor-install" ]]
|
if [[ "${HOMEBREW_COMMAND}" == "vendor-install" ]]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -x "$vendor_ruby_path" ]]
|
if [[ -x "${vendor_ruby_path}" ]]
|
||||||
then
|
then
|
||||||
HOMEBREW_RUBY_PATH="$vendor_ruby_path"
|
HOMEBREW_RUBY_PATH="${vendor_ruby_path}"
|
||||||
TERMINFO_DIRS="$vendor_ruby_terminfo"
|
TERMINFO_DIRS="${vendor_ruby_terminfo}"
|
||||||
if [[ $vendor_ruby_current_version != "$vendor_ruby_latest_version" ]]
|
if [[ ${vendor_ruby_current_version} != "${vendor_ruby_latest_version}" ]]
|
||||||
then
|
then
|
||||||
brew vendor-install ruby || odie "$upgrade_fail"
|
brew vendor-install ruby || odie "${upgrade_fail}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
HOMEBREW_RUBY_PATH=$(find_ruby)
|
HOMEBREW_RUBY_PATH=$(find_ruby)
|
||||||
if need_vendored_ruby
|
if need_vendored_ruby
|
||||||
then
|
then
|
||||||
brew vendor-install ruby || odie "$install_fail"
|
brew vendor-install ruby || odie "${install_fail}"
|
||||||
HOMEBREW_RUBY_PATH="$vendor_ruby_path"
|
HOMEBREW_RUBY_PATH="${vendor_ruby_path}"
|
||||||
TERMINFO_DIRS="$vendor_ruby_terminfo"
|
TERMINFO_DIRS="${vendor_ruby_terminfo}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export HOMEBREW_RUBY_PATH
|
export HOMEBREW_RUBY_PATH
|
||||||
[[ -n "$HOMEBREW_LINUX" && -n "$TERMINFO_DIRS" ]] && export TERMINFO_DIRS
|
[[ -n "${HOMEBREW_LINUX}" && -n "${TERMINFO_DIRS}" ]] && export TERMINFO_DIRS
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user