diff options
| author | Zhiming Wang | 2016-04-27 14:01:46 -0700 |
|---|---|---|
| committer | Martin Afanasjew | 2016-04-30 22:40:55 +0200 |
| commit | c63400d56baaa36f111c2e2d7e709c9ea7b8b992 (patch) | |
| tree | 87c71ebf34a52cd472fc648769f76e8476a134eb /Library/Homebrew/utils | |
| parent | b0d906f0f8d90c08b0b799d5cf0fd18bf78c30da (diff) | |
| download | brew-c63400d56baaa36f111c2e2d7e709c9ea7b8b992.tar.bz2 | |
analytics: relocate UUID to homebrew.analyticsuuid in .git/config
This way analytics related settings and parameters (currently
analyticsdisabled, analyticsmessage and analyticsuuid) are all kept in
the same place.
Note that in this commit we offer a path of migration: if
~/.homebrew_analytics_user_uuid already exists, read the UUID from it,
write to homebrew.analyticsuuid, and remove it.
See more detailed discussions in #145.
Closes #162.
Signed-off-by: Martin Afanasjew <martin@afanasjew.de>
Diffstat (limited to 'Library/Homebrew/utils')
| -rw-r--r-- | Library/Homebrew/utils/analytics.sh | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/Library/Homebrew/utils/analytics.sh b/Library/Homebrew/utils/analytics.sh index 3c6fc59a0..47716e5e5 100644 --- a/Library/Homebrew/utils/analytics.sh +++ b/Library/Homebrew/utils/analytics.sh @@ -1,30 +1,44 @@ +# 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 +} + setup-analytics() { - # User UUID file. Used for Homebrew user counting. Can be deleted and - # recreated with no adverse effect (beyond our user counts being inflated). - HOMEBREW_ANALYTICS_USER_UUID_FILE="$HOME/.homebrew_analytics_user_uuid" + local git_config_file="$HOMEBREW_REPOSITORY/.git/config" + + migrate-legacy-uuid-file # Make disabling anlytics sticky if [[ -n "$HOMEBREW_NO_ANALYTICS" ]] then - git config --file="$HOMEBREW_REPOSITORY/.git/config" --replace-all homebrew.analyticsdisabled true - # Internal variable for brew's use, to differentiate from user-supplied setting - export HOMEBREW_NO_ANALYTICS_THIS_RUN="1" + git config --file="$git_config_file" --replace-all homebrew.analyticsdisabled true + git config --file="$git_config_file" --unset-all homebrew.analyticsuuid fi - if [[ "$(git config --file="$HOMEBREW_REPOSITORY/.git/config" --get homebrew.analyticsmessage)" != "true" || - "$(git config --file="$HOMEBREW_REPOSITORY/.git/config" --get homebrew.analyticsdisabled)" = "true" ]] + 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" ]] then - [[ -f "$HOMEBREW_ANALYTICS_USER_UUID_FILE" ]] && rm -f "$HOMEBREW_ANALYTICS_USER_UUID_FILE" + # Internal variable for brew's use, to differentiate from user-supplied setting export HOMEBREW_NO_ANALYTICS_THIS_RUN="1" return fi - if [[ -r "$HOMEBREW_ANALYTICS_USER_UUID_FILE" ]] + HOMEBREW_ANALYTICS_USER_UUID="$(git config --file="$git_config_file" --get homebrew.analyticsuuid)" + if [[ -z "$HOMEBREW_ANALYTICS_USER_UUID" ]] then - HOMEBREW_ANALYTICS_USER_UUID="$(<"$HOMEBREW_ANALYTICS_USER_UUID_FILE")" - else HOMEBREW_ANALYTICS_USER_UUID="$(uuidgen)" - echo "$HOMEBREW_ANALYTICS_USER_UUID" > "$HOMEBREW_ANALYTICS_USER_UUID_FILE" + git config --file="$git_config_file" --replace-all homebrew.analyticsuuid "$HOMEBREW_ANALYTICS_USER_UUID" fi if [[ -n "$HOMEBREW_LINUX" ]] |
