#!/bin/sh

# Perform necessary post-installation steps

capture () {
  if type curl > /dev/null; then
    if [ -e /var/opt/firezone/cache/telemetry_id ]; then
      telemetry_id=`cat /var/opt/firezone/cache/telemetry_id`
      if [ ! -z "$telemetry_id" ]; then
        curl -s -XPOST \
          -m 5 \
          -H 'Content-Type: application/json' \
          -d "{
            \"api_key\": \"phc_ubuPhiqqjMdedpmbWpG2Ak3axqv5eMVhFDNBaXl9UZK\",
            \"event\": \"postinst\",
            \"properties\": {
              \"distinct_id\": \"$telemetry_id\"
            }
          }" \
          https://t.firez.one/capture/ > /dev/null
      fi
    fi
  fi
}
if [ ! -e /var/opt/firezone/.disable_telemetry ]; then
  capture || true
fi

# Symlink ctl commands
DEST_DIR=/opt/firezone

if [ -e ${DEST_DIR}/embedded/bin/symlink_ctl_cmds ]; then
    ${DEST_DIR}/embedded/bin/symlink_ctl_cmds
fi

if tput bold; then
  bold=$(tput bold)
else
  bold=''
fi
if tput sgr0; then
  normal=$(tput sgr0)
else
  normal=''
fi

echo $bold
echo "Please see our upgrade guide for any version notes that apply:"
echo
echo "=> https://docs.firezone.dev/administer/upgrade/?utm_source=product"
echo
echo
echo "Heads up! Firezone 0.7.x will be the last release to support Omnibus."
echo "Firezone 0.8 and above will support containerized deployments only."
echo "Read more about the transition in our migration guide:"
echo
echo "=> https://docs.firezone.dev/administer/migrate/?utm_source=product"
echo $normal
