utils/analytics.sh: repair style

This commit is contained in:
hyuraku 2021-04-21 21:12:27 +09:00
parent 05260f4565
commit d3b07d078f

View File

@ -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"