This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
portail-citoyen2/debian/portail-citoyen2.postinst

85 lines
2.8 KiB
Bash

#!/bin/sh
#
# Postinst script for portail-citoyen
#
set -e
NAME=portail-citoyen
USER=portail-citoyen
GROUP=portail-citoyen
HOME=/var/lib/${NAME}2
# source debconf stuff
. /usr/share/debconf/confmodule
case "$1" in
configure)
if ! getent group $GROUP > /dev/null 2>&1; then
echo -n "Adding group $GROUP.." >&2
addgroup --quiet --system $GROUP
echo "..done" >&2
fi
if ! getent passwd $USER > /dev/null 2>&1; then
echo -n "Adding user $USER.." >&2
adduser --quiet --system --gecos "$NAME daemon" \
--ingroup $GROUP \
--no-create-home --home $HOME \
$USER
echo "..done" >&2
fi
if [ ! -f "/etc/$NAME/secret" ]; then
echo -n "Generating Django secret.." >&2
echo "export SECRET_KEY='`</dev/urandom tr -dc [:alnum:]-_\!\%\^:\; | head -c70`'" > /etc/$NAME/secret
chmod 0640 /etc/$NAME/secret
chown root:$GROUP /etc/$NAME/secret
echo "..done" >&2
fi
if [ ! -f "/etc/$NAME/saml-certs.conf" ]; then
echo -n "Generating SAML certificates.." >&2
openssl genrsa -out /tmp/saml.key 2048 >&2
openssl rsa -in /tmp/saml.key -pubout -out /tmp/saml.pub >&2
echo SAML_SIGNATURE_PRIVATE_KEY=\"`cat /tmp/saml.key`\" > /etc/$NAME/saml-certs.conf
echo SAML_SIGNATURE_PUBLIC_KEY=\"`cat /tmp/saml.pub`\" >> /etc/$NAME/saml-certs.conf
rm /tmp/saml.key /tmp/saml.pub
echo "..done" >&2
fi
chown $USER:$GROUP /var/lib/portail-citoyen2 \
/var/lib/portail-citoyen2/collectstatic \
/var/lib/portail-citoyen2/media \
/var/lib/portail-citoyen2/static \
/var/lib/portail-citoyen2/templates \
/var/run/portail-citoyen \
/var/log/portail-citoyen
# 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/portail-citoyen/db.conf"
dbc_generate_include_args="-o template_infile=/etc/portail-citoyen/db.conf -U"
dbc_generate_include_owner="root:portail-citoyen"
dbc_generate_include_perms="640"
dbc_pgsql_createdb_encoding="UTF8"
dbc_go portail-citoyen $@
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