#!/bin/sh
set -e

. /usr/share/debconf/confmodule

db_version 2.0

# Configure the client cell.  Default to the current ThisCell file and,
# failing that, the lowercased local domain name, if available.  Ignore errors
# on read, since it may fail if there's no newline in the file.
if [ -r /etc/openafs/ThisCell ] ; then
    read cell < /etc/openafs/ThisCell
    db_set openafs-client/thiscell "$cell"
fi
db_get openafs-client/thiscell || true
if [ "x$RET" = "x" ] ; then
    domain=`dnsdomainname 2>/dev/null || true`
    if [ -n "$domain" ] ; then
        db_set openafs-client/thiscell `echo "$domain" | tr 'A-Z' 'a-z'`
    fi
fi
db_input high openafs-client/thiscell || true

# Configure the cache size.  Default to the current value in the cacheinfo
# configuration file.
if [ -r /etc/openafs/cacheinfo ] ; then
    IFS=: read mountpoint cachedir cachesize < /etc/openafs/cacheinfo
    db_set openafs-client/cachesize "$cachesize"
fi
db_input high openafs-client/cachesize || true
db_go

# Configure the AFS client parameters set in /etc/openafs/afs.conf, taking
# defaults from the current file.
test -f /etc/openafs/afs.conf && . /etc/openafs/afs.conf
if [ "x$AFS_CLIENT" != "x" ] ; then
    db_set openafs-client/run-client "$AFS_CLIENT"
fi
db_input low openafs-client/run-client || true
if [ "x$AFS_AFSDB" != "x" ] ; then
    db_set openafs-client/afsdb "$AFS_AFSDB"
fi
if [ "x$AFS_CRYPT" != "x" ] ; then
    db_set openafs-client/crypt "$AFS_CRYPT"
fi
if [ "x$AFS_DYNROOT" != "x" ] ; then
    db_set openafs-client/dynroot "$AFS_DYNROOT"
fi
if [ "x$AFS_FAKESTAT" != "x" ] ; then
    db_set openafs-client/fakestat "$AFS_FAKESTAT"
fi
db_beginblock
db_input low openafs-client/afsdb || true
db_input low openafs-client/crypt || true
db_input medium openafs-client/dynroot || true
db_input low openafs-client/fakestat || true
db_endblock
db_go
