2016-04-27 14:01:46 -07:00
|
|
|
# Migrate analytics UUID to its new home in Homebrew repo's git config and
|
|
|
|
# remove the legacy UUID file if detected.
|
2021-04-21 21:12:27 +09:00
|
|
|
# HOMEBREW_LINUX, HOMEBREW_REPOSITORY is set by bin/brew
|
|
|
|
# HOMEBREW_NO_ANALYTICS is from the user environment.
|
|
|
|
# shellcheck disable=SC2154
|
2016-04-27 14:01:46 -07:00
|
|
|
migrate-legacy-uuid-file() {
|
2018-10-04 09:31:37 +01:00
|
|
|
local legacy_uuid_file analytics_uuid
|
|
|
|
|
2021-04-21 21:12:27 +09:00
|
|
|
legacy_uuid_file="${HOME}/.homebrew_analytics_user_uuid"
|
2018-10-04 09:31:37 +01:00
|
|
|
|
2021-04-21 21:12:27 +09:00
|
|
|
if [[ -f "${legacy_uuid_file}" ]]
|
2016-04-27 14:01:46 -07:00
|
|
|
then
|
2021-09-13 20:32:20 +08:00
|
|
|
analytics_uuid="$(cat "${legacy_uuid_file}")"
|
2021-04-21 21:12:27 +09:00
|
|
|
if [[ -n "${analytics_uuid}" ]]
|
2016-04-27 14:01:46 -07:00
|
|
|
then
|
2021-04-21 21:12:27 +09:00
|
|
|
git config --file="${HOMEBREW_REPOSITORY}/.git/config" --replace-all homebrew.analyticsuuid "${analytics_uuid}" 2>/dev/null
|
2016-04-27 14:01:46 -07:00
|
|
|
fi
|
2021-04-21 21:12:27 +09:00
|
|
|
rm -f "${legacy_uuid_file}"
|
2016-04-27 14:01:46 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-04-12 11:02:22 +01:00
|
|
|
setup-analytics() {
|
2021-04-21 21:12:27 +09:00
|
|
|
local git_config_file="${HOMEBREW_REPOSITORY}/.git/config"
|
2016-04-27 14:01:46 -07:00
|
|
|
|
|
|
|
migrate-legacy-uuid-file
|
2016-04-25 18:51:00 -05:00
|
|
|
|
2021-04-21 21:12:27 +09:00
|
|
|
if [[ -n "${HOMEBREW_NO_ANALYTICS}" ]]
|
2016-04-26 04:28:38 -04:00
|
|
|
then
|
2016-05-01 22:04:46 +08:00
|
|
|
return
|
2016-04-26 04:28:38 -04:00
|
|
|
fi
|
|
|
|
|
2018-10-04 09:31:37 +01:00
|
|
|
local message_seen analytics_disabled
|
2021-04-21 21:12:27 +09:00
|
|
|
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)"
|
2021-09-13 20:32:20 +08:00
|
|
|
if [[ "${message_seen}" != "true" || "${analytics_disabled}" == "true" ]]
|
2016-04-25 18:51:00 -05:00
|
|
|
then
|
2016-04-27 14:01:46 -07:00
|
|
|
# Internal variable for brew's use, to differentiate from user-supplied setting
|
2016-04-26 04:28:38 -04:00
|
|
|
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
|
2016-04-25 18:51:00 -05:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2021-04-21 21:12:27 +09:00
|
|
|
HOMEBREW_ANALYTICS_USER_UUID="$(git config --file="${git_config_file}" --get homebrew.analyticsuuid 2>/dev/null)"
|
|
|
|
if [[ -z "${HOMEBREW_ANALYTICS_USER_UUID}" ]]
|
2016-04-12 11:02:22 +01:00
|
|
|
then
|
2017-11-22 10:58:00 -08:00
|
|
|
if [[ -x /usr/bin/uuidgen ]]
|
2016-07-24 16:35:55 -06:00
|
|
|
then
|
|
|
|
HOMEBREW_ANALYTICS_USER_UUID="$(/usr/bin/uuidgen)"
|
2017-11-22 10:58:00 -08:00
|
|
|
elif [[ -r /proc/sys/kernel/random/uuid ]]
|
|
|
|
then
|
|
|
|
HOMEBREW_ANALYTICS_USER_UUID="$(tr a-f A-F </proc/sys/kernel/random/uuid)"
|
2016-06-29 14:16:39 +02:00
|
|
|
else
|
|
|
|
HOMEBREW_ANALYTICS_USER_UUID="$(uuidgen)"
|
|
|
|
fi
|
2016-06-29 14:05:40 +02:00
|
|
|
|
2021-04-21 21:12:27 +09:00
|
|
|
if [[ -z "${HOMEBREW_ANALYTICS_USER_UUID}" ]]
|
2016-06-29 14:05:40 +02:00
|
|
|
then
|
|
|
|
# Avoid sending bogus analytics if no UUID could be generated.
|
|
|
|
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
|
|
|
|
return
|
|
|
|
fi
|
2021-04-21 21:12:27 +09:00
|
|
|
git config --file="${git_config_file}" --replace-all homebrew.analyticsuuid "${HOMEBREW_ANALYTICS_USER_UUID}" 2>/dev/null
|
2016-04-12 11:02:22 +01:00
|
|
|
fi
|
2016-04-16 11:39:57 +01:00
|
|
|
|
2021-04-21 21:12:27 +09:00
|
|
|
if [[ -n "${HOMEBREW_LINUX}" ]]
|
2016-04-16 11:39:57 +01:00
|
|
|
then
|
2019-03-12 20:13:38 +00:00
|
|
|
# For Homebrew on Linux's analytics.
|
2016-04-16 11:39:57 +01:00
|
|
|
HOMEBREW_ANALYTICS_ID="UA-76492262-1"
|
|
|
|
else
|
|
|
|
# Otherwise, fall back to Homebrew's analytics.
|
2016-04-21 08:06:12 +01:00
|
|
|
HOMEBREW_ANALYTICS_ID="UA-76679469-1"
|
2016-04-16 11:39:57 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
export HOMEBREW_ANALYTICS_ID
|
2016-04-12 11:02:22 +01:00
|
|
|
export HOMEBREW_ANALYTICS_USER_UUID
|
|
|
|
}
|