2024-08-31 01:36:53 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
set -e
|
|
|
|
|
|
2024-10-17 18:50:07 +00:00
|
|
|
echo -e "\e[34m[Info] Sourcebot version: $SOURCEBOT_VERSION\e[0m"
|
|
|
|
|
|
2024-09-28 23:47:07 +00:00
|
|
|
# Issue a info message about telemetry
|
|
|
|
|
if [ ! -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then
|
|
|
|
|
echo -e "\e[34m[Info] Disabling telemetry since SOURCEBOT_TELEMETRY_DISABLED was set.\e[0m"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check if DATA_CACHE_DIR exists, if not create it
|
|
|
|
|
if [ ! -d "$DATA_CACHE_DIR" ]; then
|
|
|
|
|
mkdir -p "$DATA_CACHE_DIR"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# In order to detect if this is the first run, we create a `.installed` file in
|
|
|
|
|
# the cache directory.
|
|
|
|
|
FIRST_RUN_FILE="$DATA_CACHE_DIR/.installed"
|
|
|
|
|
if [ ! -f "$FIRST_RUN_FILE" ]; then
|
|
|
|
|
touch "$FIRST_RUN_FILE"
|
|
|
|
|
|
|
|
|
|
# If this is our first run, send a `install` event to PostHog
|
|
|
|
|
# (if telemetry is enabled)
|
|
|
|
|
if [ -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then
|
|
|
|
|
curl -L -s --header "Content-Type: application/json" -d '{
|
|
|
|
|
"api_key": "'"$NEXT_PUBLIC_POSTHOG_KEY"'",
|
|
|
|
|
"event": "install",
|
2024-10-17 18:50:07 +00:00
|
|
|
"distinct_id": "'"$(uuidgen)"'",
|
|
|
|
|
"properties": {
|
|
|
|
|
"sourcebot_version": "'"$SOURCEBOT_VERSION"'"
|
|
|
|
|
}
|
2024-09-28 23:47:07 +00:00
|
|
|
}' https://us.i.posthog.com/capture/ > /dev/null
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2024-09-28 06:38:32 +00:00
|
|
|
# Fallback to sample config if a config does not exist
|
2024-09-29 20:27:30 +00:00
|
|
|
if echo "$CONFIG_PATH" | grep -qE '^https?://'; then
|
|
|
|
|
if ! curl --output /dev/null --silent --head --fail "$CONFIG_PATH"; then
|
|
|
|
|
echo -e "\e[33m[Warning] Remote config file at '$CONFIG_PATH' not found. Falling back on sample config.\e[0m"
|
2024-09-29 21:17:43 +00:00
|
|
|
CONFIG_PATH="./default-config.json"
|
2024-09-29 20:27:30 +00:00
|
|
|
fi
|
|
|
|
|
elif [ ! -f "$CONFIG_PATH" ]; then
|
|
|
|
|
echo -e "\e[33m[Warning] Config file at '$CONFIG_PATH' not found. Falling back on sample config.\e[0m"
|
2024-09-29 21:17:43 +00:00
|
|
|
CONFIG_PATH="./default-config.json"
|
2024-09-05 20:00:27 +00:00
|
|
|
fi
|
|
|
|
|
|
2024-09-28 06:38:32 +00:00
|
|
|
echo -e "\e[34m[Info] Using config file at: '$CONFIG_PATH'.\e[0m"
|
|
|
|
|
|
2024-09-17 04:37:34 +00:00
|
|
|
# Update nextjs public env variables w/o requiring a rebuild.
|
|
|
|
|
# @see: https://phase.dev/blog/nextjs-public-runtime-variables/
|
|
|
|
|
|
|
|
|
|
# Infer NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED if it is not set
|
|
|
|
|
if [ -z "$NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED" ] && [ ! -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then
|
|
|
|
|
export NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED="$SOURCEBOT_TELEMETRY_DISABLED"
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-17 18:50:07 +00:00
|
|
|
# Infer NEXT_PUBLIC_SOURCEBOT_VERSION if it is not set
|
|
|
|
|
if [ -z "$NEXT_PUBLIC_SOURCEBOT_VERSION" ] && [ ! -z "$SOURCEBOT_VERSION" ]; then
|
|
|
|
|
export NEXT_PUBLIC_SOURCEBOT_VERSION="$SOURCEBOT_VERSION"
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-17 20:31:18 +00:00
|
|
|
find /app/packages/web/public /app/packages/web/.next -type f -name "*.js" |
|
2024-09-17 04:37:34 +00:00
|
|
|
while read file; do
|
|
|
|
|
sed -i "s|BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED|${NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED}|g" "$file"
|
2024-10-17 18:50:07 +00:00
|
|
|
sed -i "s|BAKED_NEXT_PUBLIC_SOURCEBOT_VERSION|${NEXT_PUBLIC_SOURCEBOT_VERSION}|g" "$file"
|
2024-09-17 04:37:34 +00:00
|
|
|
done
|
|
|
|
|
|
2024-09-05 20:00:27 +00:00
|
|
|
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
|