#!/bin/bash
#
# NAME
#   debian/postinst -- Debian postinst for netrek-server-vanilla
#
# DESCRIPTION
#   Place holder for post-installation maintainer scripts
#
# COPYRIGHT
#   Copyright (c) 2008 Bob Tanner <tanner@real-time.com>
#
# LICENSE
#   This program is free software; you can redistribute it and/or modify it
#   under the terms of the GNU General Public License as published by the Free
#   Software Foundation; either version 2, or (at your option) any later
#   version.
#
#   This program is distributed in the hope that it will be useful, but WITHOUT
#   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#   more details.
#
#   You should have received a copy of the GNU General Public License along
#   with this program; if not, write to the Free Software Foundation, Inc., 59
#   Temple Place, Suite 330, Boston, MA 02111-1307 USA.

# Source debconf library.
. /usr/share/debconf/confmodule

CONFIGFILE=/etc/default/netrek-server-vanilla

if [ ! -e $CONFIGFILE ]; then
    (
        echo "# Config file for netrek-vanilla-server"
        echo "ENABLED="
    ) >> $CONFIGFILE
fi

# Check user's answer
db_get netrek-server-vanilla/start_on_boot
ENABLED="$RET"

db_stop

# If the admin deleted or commented some variables, (re-)add 
# them to the conffile.
grep -Eq "^ *ENABLED=" $CONFIGFILE || echo "ENABLED=" >> $CONFIGFILE

invoke-rc.d netrek-server-vanilla stop

sed -e "s/^ *ENABLED=.*/ENABLED=\"$ENABLED\"/" \
  < $CONFIGFILE > $CONFIGFILE.tmp
mv -f $CONFIGFILE.tmp $CONFIGFILE

# fix permissions.
if ! id netrek >/dev/null 2>/dev/null; then
    addgroup --system netrek
    adduser --system --home /var/lib/netrek-server-vanilla \
	--no-create-home --disabled-password --ingroup netrek netrek
fi
chgrp -R netrek /var/lib/netrek-server-vanilla
chown -R netrek /var/lib/netrek-server-vanilla
chmod 2755 /var/lib/netrek-server-vanilla

#DEBHELPER#