#!/bin/sh

#   enter the SKS run-time directory as all
#   other SKS commands work relatively to it
cd @l_prefix@/var/sks || exit $?

#   create an initial SKS key database (KGB)
echo "++ creating initial SKS key database"
@l_prefix@/sbin/sks fastbuild -n 4 -cache 100

#   import at least the OpenPKG OpenPGP keys
#   into the key database as SKS cleandb and
#   pbuild commands require some content anyway
echo "++ load OpenPKG OpenPGP keys into SKS key database"
( HOME=`pwd`
  rm -rf $HOME/.gnupg
  @l_prefix@/bin/gpg --import @l_prefix@/etc/openpkg/openpkg.*.pgp
  @l_prefix@/bin/gpg --export -o openpkg.pgp
  rm -rf $HOME/.gnupg
) >/dev/null 2>&1 || exit $?
@l_prefix@/sbin/sks merge openpkg.pgp
rm -f openpkg.pgp

#   finalize the key database
echo "++ cleaning up SKS key database"
@l_prefix@/sbin/sks cleandb

#   generate prefix-tree index
echo "++ generating SKS prefix-tree index"
@l_prefix@/sbin/sks pbuild -cache 20 -ptree_cache 70

#   cleanup
rm -f fastbuild.log merge.log clean.log pbuild.log

#   generate top-level web page
echo "++ generating SKS top-level web form symlink"
mkdir web
ln -s ../../../etc/sks/sks.html web/index.html

#   generate initial configuration files
echo "++ generating SKS configuration file symlinks"
for file in sksconf mailsync membership; do
    ln -s ../../etc/sks/$file $file
done

