#!/bin/sh

set -e

case $1 in
    configure)
        # Add the "orthanc" user
        if ! getent passwd orthanc > /dev/null; then
            adduser --system --quiet \
                --home /var/lib/orthanc --no-create-home \
                --shell /bin/bash --group --gecos "Orthanc Administrator" orthanc
        fi
        if test "`id -u orthanc`" -eq 0; then
            echo "The orthanc administrative user must not be root." >&2
            false
        fi
        if test "`id -g orthanc`" -eq 0; then
            echo "The orthanc administrative group must not be root." >&2
            false
        fi

        # Create the required directories
        chown -R orthanc:orthanc /etc/orthanc
        chown -R orthanc:orthanc /var/lib/orthanc
        chmod 0775 /etc/orthanc
        chmod 0775 /var/lib/orthanc

        chmod 0664 /etc/orthanc/orthanc.json
        ;;
esac

#DEBHELPER#
