#!/bin/sh

set -e

case "$1" in
configure)
    . /usr/share/debconf/confmodule
    db_version 2.0

    db_get openafs-fileserver/thiscell
    echo $RET >/etc/openafs/server/ThisCell

    if [ ! -f /etc/openafs/server/CellServDB ] ; then
        sed -n "/^>$RET/,/^>/p" /etc/openafs/CellServDB | sed '$d' \
            >/etc/openafs/server/CellServDB
        if [ ! -s /etc/openafs/server/CellServDB ] ; then
            echo ">$RET" >/etc/openafs/server/CellServDB
        fi
    fi

    # Move the contents of the old /etc/openafs/server-local directory into
    # /var/lib/openafs/local.  Most of the files in this directory are
    # automatically generated, so it didn't belong in /etc.
    #
    # Change the paths to upserver and upclient in BosConfig from older
    # versions that had the binaries in /usr/sbin.
    if [ "x$2" != "x" ] && dpkg --compare-versions $2 lt 1.4.4.dfsg1-4 ; then
        for f in sysid sysid.old NetInfo NetRestrict ; do
            if [ -e "/etc/openafs/server-local/$f" ] ; then
                cp "/etc/openafs/server-local/$f" "/var/lib/openafs/local/$f"
            fi
        done
        if [ -e /etc/openafs/BosConfig ] ; then
            sed -i -e 's,/usr/sbin/upserver,/usr/lib/openafs/upserver,' \
                   -e 's,/usr/sbin/upclient,/usr/lib/openafs/upclient,' \
                       /etc/openafs/BosConfig
        fi
    fi
    db_stop
    ;;

abort-upgrade|abort-remove|abort-deconfigure)
    ;;

*)
    echo "postinst called with unknown argument \`$1'" >&2
    exit 0
    ;;
esac

# dh_installdeb will replace this with shell code automatically generated by
# other debhelper scripts.
#DEBHELPER#

exit 0
