|
15 | 15 |
|
16 | 16 | # In order to detect if this is the first run, we create a `.installed` file in |
17 | 17 | # the cache directory. |
18 | | -FIRST_RUN_FILE="$DATA_CACHE_DIR/.installed" |
| 18 | +FIRST_RUN_FILE="$DATA_CACHE_DIR/.installedv2" |
| 19 | + |
19 | 20 | if [ ! -f "$FIRST_RUN_FILE" ]; then |
20 | 21 | touch "$FIRST_RUN_FILE" |
21 | | - |
| 22 | + export SOURCEBOT_INSTALL_ID=$(uuidgen) |
| 23 | + |
22 | 24 | # If this is our first run, send a `install` event to PostHog |
23 | 25 | # (if telemetry is enabled) |
24 | 26 | if [ -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then |
25 | 27 | curl -L -s --header "Content-Type: application/json" -d '{ |
26 | | - "api_key": "'"$NEXT_PUBLIC_POSTHOG_KEY"'", |
| 28 | + "api_key": "'"$POSTHOG_KEY"'", |
27 | 29 | "event": "install", |
28 | | - "distinct_id": "'"$(uuidgen)"'", |
| 30 | + "distinct_id": "'"$SOURCEBOT_INSTALL_ID"'", |
29 | 31 | "properties": { |
30 | 32 | "sourcebot_version": "'"$SOURCEBOT_VERSION"'" |
31 | 33 | } |
32 | 34 | }' https://us.i.posthog.com/capture/ > /dev/null |
33 | 35 | fi |
| 36 | +else |
| 37 | + export SOURCEBOT_INSTALL_ID=$(cat "$FIRST_RUN_FILE" | jq -r '.install_id') |
| 38 | + PREVIOUS_VERSION=$(cat "$FIRST_RUN_FILE" | jq -r '.version') |
| 39 | + |
| 40 | + # If the version has changed, we assume an upgrade has occurred. |
| 41 | + if [ "$PREVIOUS_VERSION" != "$SOURCEBOT_VERSION" ]; then |
| 42 | + echo -e "\e[34m[Info] Upgraded from version $PREVIOUS_VERSION to $SOURCEBOT_VERSION\e[0m" |
| 43 | + |
| 44 | + if [ -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then |
| 45 | + curl -L -s --header "Content-Type: application/json" -d '{ |
| 46 | + "api_key": "'"$POSTHOG_KEY"'", |
| 47 | + "event": "upgrade", |
| 48 | + "distinct_id": "'"$SOURCEBOT_INSTALL_ID"'", |
| 49 | + "properties": { |
| 50 | + "from_version": "'"$PREVIOUS_VERSION"'", |
| 51 | + "to_version": "'"$SOURCEBOT_VERSION"'" |
| 52 | + } |
| 53 | + }' https://us.i.posthog.com/capture/ > /dev/null |
| 54 | + fi |
| 55 | + fi |
34 | 56 | fi |
35 | 57 |
|
| 58 | +echo "{\"version\": \"$SOURCEBOT_VERSION\", \"install_id\": \"$SOURCEBOT_INSTALL_ID\"}" > "$FIRST_RUN_FILE" |
| 59 | + |
36 | 60 | # Fallback to sample config if a config does not exist |
37 | 61 | if echo "$CONFIG_PATH" | grep -qE '^https?://'; then |
38 | 62 | if ! curl --output /dev/null --silent --head --fail "$CONFIG_PATH"; then |
|
0 commit comments