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.
|
|
|
|
migrate-legacy-uuid-file() {
|
|
|
|
local legacy_uuid_file="$HOME/.homebrew_analytics_user_uuid"
|
|
|
|
if [[ -f "$legacy_uuid_file" ]]
|
|
|
|
then
|
|
|
|
local analytics_uuid="$(<"$legacy_uuid_file")"
|
|
|
|
if [[ -n "$analytics_uuid" ]]
|
|
|
|
then
|
|
|
|
git config --file="$HOMEBREW_REPOSITORY/.git/config" --replace-all homebrew.analyticsuuid "$analytics_uuid"
|
|
|
|
fi
|
|
|
|
rm -f "$legacy_uuid_file"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-04-12 11:02:22 +01:00
|
|
|
setup-analytics() {
|
2016-04-27 14:01:46 -07:00
|
|
|
local git_config_file="$HOMEBREW_REPOSITORY/.git/config"
|
|
|
|
|
|
|
|
migrate-legacy-uuid-file
|
2016-04-25 18:51:00 -05:00
|
|
|
|
2016-04-26 04:28:38 -04:00
|
|
|
if [[ -n "$HOMEBREW_NO_ANALYTICS" ]]
|
|
|
|
then
|
2016-05-01 22:04:46 +08:00
|
|
|
return
|
2016-04-26 04:28:38 -04:00
|
|
|
fi
|
|
|
|
|
2016-04-27 14:01:46 -07:00
|
|
|
local message_seen="$(git config --file="$git_config_file" --get homebrew.analyticsmessage)"
|
|
|
|
local analytics_disabled="$(git config --file="$git_config_file" --get homebrew.analyticsdisabled)"
|
|
|
|
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
|
|
|
|
|
2016-04-27 14:01:46 -07:00
|
|
|
HOMEBREW_ANALYTICS_USER_UUID="$(git config --file="$git_config_file" --get homebrew.analyticsuuid)"
|
|
|
|
if [[ -z "$HOMEBREW_ANALYTICS_USER_UUID" ]]
|
2016-04-12 11:02:22 +01:00
|
|
|
then
|
2016-06-29 14:16:39 +02:00
|
|
|
if [[ -n "$HOMEBREW_LINUX" ]]
|
|
|
|
then
|
2016-08-07 12:55:38 +02:00
|
|
|
HOMEBREW_ANALYTICS_USER_UUID="$(tr a-f A-F </proc/sys/kernel/random/uuid)"
|
2016-07-24 16:35:55 -06:00
|
|
|
elif [[ -n "$HOMEBREW_OSX" ]]
|
|
|
|
then
|
|
|
|
HOMEBREW_ANALYTICS_USER_UUID="$(/usr/bin/uuidgen)"
|
2016-06-29 14:16:39 +02:00
|
|
|
else
|
|
|
|
HOMEBREW_ANALYTICS_USER_UUID="$(uuidgen)"
|
|
|
|
fi
|
2016-06-29 14:05:40 +02:00
|
|
|
|
|
|
|
if [[ -z "$HOMEBREW_ANALYTICS_USER_UUID" ]]
|
|
|
|
then
|
|
|
|
# Avoid sending bogus analytics if no UUID could be generated.
|
|
|
|
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
|
|
|
|
return
|
|
|
|
fi
|
2016-04-27 14:01:46 -07:00
|
|
|
git config --file="$git_config_file" --replace-all homebrew.analyticsuuid "$HOMEBREW_ANALYTICS_USER_UUID"
|
2016-04-12 11:02:22 +01:00
|
|
|
fi
|
2016-04-16 11:39:57 +01:00
|
|
|
|
|
|
|
if [[ -n "$HOMEBREW_LINUX" ]]
|
|
|
|
then
|
|
|
|
# For Linuxbrew's analytics.
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
report-analytics-screenview-command() {
|
2016-04-26 04:28:38 -04:00
|
|
|
[[ -n "$HOMEBREW_NO_ANALYTICS" || -n "$HOMEBREW_NO_ANALYTICS_THIS_RUN" ]] && return
|
2016-04-12 11:02:22 +01:00
|
|
|
|
|
|
|
# Don't report non-official commands.
|
|
|
|
if ! [[ "$HOMEBREW_COMMAND" = "bundle" ||
|
|
|
|
"$HOMEBREW_COMMAND" = "services" ||
|
|
|
|
-f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.rb" ||
|
|
|
|
-f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.sh" ||
|
|
|
|
-f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.rb" ||
|
|
|
|
-f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh" ]]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Don't report commands used mostly by our scripts and not users.
|
|
|
|
# TODO: list more e.g. shell completion things here perhaps using a single
|
|
|
|
# script as a shell-completion entry point.
|
2016-05-01 22:04:46 +08:00
|
|
|
case "$HOMEBREW_COMMAND" in
|
|
|
|
--prefix|analytics|command|commands)
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
2016-04-12 11:02:22 +01:00
|
|
|
|
|
|
|
local args=(
|
2016-08-07 12:55:38 +02:00
|
|
|
--max-time 3
|
|
|
|
--user-agent "$HOMEBREW_USER_AGENT_CURL"
|
2016-08-09 19:17:56 +01:00
|
|
|
--data v=1
|
|
|
|
--data aip=1
|
|
|
|
--data t=screenview
|
|
|
|
--data tid="$HOMEBREW_ANALYTICS_ID"
|
|
|
|
--data cid="$HOMEBREW_ANALYTICS_USER_UUID"
|
|
|
|
--data an="$HOMEBREW_PRODUCT"
|
|
|
|
--data av="$HOMEBREW_VERSION"
|
|
|
|
--data cd="$HOMEBREW_COMMAND"
|
2016-04-12 11:02:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Send analytics. Don't send or store any personally identifiable information.
|
|
|
|
# https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Analytics.md
|
|
|
|
# https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#screenView
|
|
|
|
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
|
|
|
|
if [[ -z "$HOMEBREW_ANALYTICS_DEBUG" ]]
|
|
|
|
then
|
|
|
|
"$HOMEBREW_CURL" https://www.google-analytics.com/collect \
|
|
|
|
"${args[@]}" \
|
|
|
|
--silent --output /dev/null &>/dev/null & disown
|
|
|
|
else
|
2016-08-09 21:24:39 +02:00
|
|
|
local url="https://www.google-analytics.com/debug/collect"
|
|
|
|
echo "$HOMEBREW_CURL $url ${args[*]}"
|
|
|
|
"$HOMEBREW_CURL" "$url" "${args[@]}"
|
2016-04-12 11:02:22 +01:00
|
|
|
fi
|
|
|
|
}
|