#!/bin/bash
#
# Post-installation script for the GRR server deb.
#
# Installs GRR in a virtualenv, sets it up as a systemd service, starts
# the service, then runs 'grr_config_updater initialize'.

set -e

# The token below is replaced with shellscript snippets generated
# by debhelper commands. See http://manpages.ubuntu.com/dh_installdeb

#DEBHELPER#

case "$1" in
    configure)
      adduser --system fleetspeak
      groupadd --system -f fleetspeak
      if [ "$DEBIAN_FRONTEND" != noninteractive ]; then

        echo "#################################################################"
        echo "Running grr_config_updater initialize"
        echo "To avoid this prompting, set DEBIAN_FRONTEND=noninteractive"
        echo "#################################################################"

        grr_config_updater initialize
      fi
esac

echo "#################################################################"
echo "Install complete."
echo "If upgrading, make sure you read the release notes:"
echo "https://grr-doc.readthedocs.io/en/latest/release-notes.html"
echo "#################################################################"
