authentic/debian-jessie/authentic2.postinst

108 lines
3.9 KiB
Bash

#!/bin/sh
#
# Postinst script for authentic2
#
set -e
NAME=authentic2
AUTHENTIC_USER=authentic
AUTHENTIC_GROUP=authentic
AUTHENTIC_HOME=/var/lib/authentic2
AUTHENTIC_SECRET_KEY="$AUTHENTIC_HOME/secret_key"
# source debconf stuff
. /usr/share/debconf/confmodule
case "$1" in
configure)
if ! getent group $AUTHENTIC_GROUP > /dev/null 2>&1; then
echo -n "Adding group $AUTHENTIC_GROUP.." >&2
addgroup --quiet --system $AUTHENTIC_GROUP
echo "..done" >&2
fi
if ! getent passwd $AUTHENTIC_USER > /dev/null 2>&1; then
echo -n "Adding user $AUTHENTIC_USER.." >&2
adduser --quiet --system --gecos "Authentic2 daemon" \
--ingroup $AUTHENTIC_GROUP \
--no-create-home --home $AUTHENTIC_HOME \
$AUTHENTIC_USER
echo "..done" >&2
fi
if [ ! -f $AUTHENTIC_SECRET_KEY ]; then
if [ -f /etc/$NAME/secret ]; then
echo -n "Converting storage of the secret key.." >&2
. /etc/$NAME/secret
echo -n "$SECRET_KEY" >"$AUTHENTIC_SECRET_KEY"
rm /etc/$NAME/secret
echo "..done" >&2
else
echo -n "Generating a secret key.." >&2
echo -n "`</dev/urandom tr -dc [:alnum:]-_\!\%\^:\; | head -c70`" > "$AUTHENTIC_SECRET_KEY"
chmod 0600 $AUTHENTIC_SECRET_KEY
echo "..done" >&2
fi
fi
if [ -d $AUTHENTIC_HOME/extra-static ]; then
if [ -d $AUTHENTIC_HOME/static ]; then
mv $AUTHENTIC_HOME/static $AUTHENTIC_HOME/static.dpkg_old
fi
mkdir -p $AUTHENTIC_HOME/static
echo -n "Migrate old extra-static/ to static/.." >&2
mv $AUTHENTIC_HOME/extra-static/* $AUTHENTIC_HOME/static/
mv $AUTHENTIC_HOME/extra-static $AUTHENTIC_HOME/extra-static.dpkg_old
echo "..done" >&2
fi
if [ -f /etc/authentic2/authentic.conf ]; then
# Fix old configuration file
sed -i -e '/^\. \/etc\/authentic2\/secret$/d' \
-e '/^export *STATIC_ROOT *=/d' \
-e '/^. \/etc\/authentic2\/db.conf$/d' \
-e '/^# do not remove this line, it imports/d' \
/etc/authentic2/authentic.conf >&2
fi
chown -R $AUTHENTIC_USER:$AUTHENTIC_GROUP /var/lib/authentic2/
# source dbconfig-common shell library, and call the hook function
if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql ]; then
. /usr/share/dbconfig-common/dpkg/postinst.pgsql
dbc_generate_include="template:/etc/authentic2/db.conf"
dbc_generate_include_args="-o template_infile=/usr/share/authentic2/templates/db.conf -U"
dbc_generate_include_owner="root:authentic"
dbc_generate_include_perms="640"
dbc_pgsql_createdb_encoding="UTF8"
dbc_go authentic2 $@
fi
if [ ! -f /etc/authentic2/cert.pem -a ! -f /etc/authentic2/key.pem ]; then
echo -n "Generating key material..." >&2
openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:2048 -out /etc/authentic2/key.pem >&2
openssl req -x509 -new -out /etc/authentic2/cert.pem -subj '/CN=whocares' -key /etc/authentic2/key.pem -days 3650 >&2
chown $AUTHENTIC_USER.$AUTHENTIC_GROUP /etc/authentic2/cert.pem /etc/authentic2/key.pem
chmod 640 /etc/authentic2/cert.pem /etc/authentic2/key.pem
echo "..done" >&2
fi
;;
reconfigure|abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
db_stop
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0