#!/bin/bash

set -e

if [[ "$1" == "configure" ]]; then

    if ! getent group prometheus2influxdb >/dev/null; then
        groupadd --system prometheus2influxdb
    fi

    if ! getent passwd prometheus2influxdb >/dev/null; then
        useradd --system --gid prometheus2influxdb --home-dir /nonexistent --shell /sbin/nologin prometheus2influxdb
    fi

    chown root:prometheus2influxdb /etc/prometheus2influxdb.yaml
    chmod 0640 /etc/prometheus2influxdb.yaml

    deb-systemd-helper enable prometheus2influxdb.timer
    deb-systemd-invoke restart prometheus2influxdb.timer

fi