#! /bin/sh

set -e

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

    # Add the onak user
    adduser --system --home /var/lib/onak --no-create-home --disabled-login onak

    # 
    # If there's no onak database, create it by adding my key.
    #
    if [ ! -e /var/lib/onak/num_keydb ]; then
        zcat /usr/share/doc/onak/noodles.key | onak -b add
    fi

    # Take ownership of the database directory
    chown -R onak /var/lib/onak

    # Create our logfile
    touch /var/log/onak.log
    chown onak /var/log/onak.log

    # Make the CGI tools setuid onak
    for i in /usr/lib/cgi-bin/pks/*
    do
        if ! dpkg-statoverride --list $i >/dev/null
        then
            dpkg-statoverride --update --add onak root 4755 $i
        fi
    done
fi