#!/bin/sh # postinst script for slm. # # See: dh_installdeb(1). set -e if [ -e /usr/share/debconf/confmodule ]; then . /usr/share/debconf/confmodule db_get slm/debug || true DEBUG="$RET" db_get slm/servername || true SERVERNAME="$RET" CSRF_TRUSTED_ORIGINS="https://$SERVERNAME" ALLOWED_HOSTS="$SERVERNAME" db_get slm/adminmail || true ADMIN_E_MAIL="$RET" db_get slm/adminpass || true ADMIN_PASS="$RET" db_get slm/lang || true SLM_LANG="$RET" fi case "$1" in configure) ######## prepare a subdirectory to speed up matplotlib ############ for d in /var/www/.config/matplotlib /var/www/.cache/matplotlib; do mkdir -p $d; find $d | xargs chown www-data done ################# configuration of settings.py #################### # choose between debug or production settings if [ "$DEBUG" = "false" ]; then SETTINGS=/var/lib/slm/manuels/settings-production.py else SETTINGS=/var/lib/slm/manuels/settings-debug.py fi cat $SETTINGS | sed -e "s/__ALLOWED_HOSTS__/$ALLOWED_HOSTS/" \ -e "s%__CSRF_TRUSTED_ORIGINS__%$CSRF_TRUSTED_ORIGINS%" \ -e "s/^LANGUAGE_CODE.*/LANGUAGE_CODE = '$SLM_LANG'/" \ > /var/lib/slm/manuels/settings.py # modify the secret key to have an original key (to keep it secret) echo "Changing the secret key in settings.py" sed -i "s/SECRET_KEY = .*/SECRET_KEY = '$(pwgen 64 1)'/" \ /var/lib/slm/manuels/settings.py a2enmod rewrite a2enmod ssl # in case of a missing package node-svgdotjs-svg.js, # create a fake directory if [ ! -e /usr/share/nodejs/@svgdotjs/svg.js ]; then mkdir -p /usr/share/nodejs/@svgdotjs/svg.js fi # and the same for package node-svgdotjs-svg.draggable.js if [ ! -e /usr/share/javascript/svg.draggable.js ]; then mkdir -p /usr/share/javascript/svg.draggable.js fi cd /var/lib/slm; echo 'yes' | python3 manage.py collectstatic cd /var/lib/slm; python3 manage.py makemigrations cd /var/lib/slm; python3 manage.py makemigrations gestion cd /var/lib/slm; python3 manage.py migrate # create a superuser if it does not yet exist cd /var/lib/slm; cat createSuperUserIfNone | \ sed -e "s/__ADMIN_E_MAIL__/$ADMIN_E_MAIL/" \ -e "s/__ADMIN_PASS__/$ADMIN_PASS/" | \ python3 manage.py shell # let www-data write to the database setfacl -m u:www-data:rwx /var/lib/slm setfacl -m u:www-data:rw /var/lib/slm/db.sqlite3 # let www-data write to media mkdir -p /var/lib/slm/media/sauvegarde find /var/lib/slm/media -type d | xargs setfacl -m u:www-data:rwx find /var/lib/slm/media -type f | xargs setfacl -m u:www-data:rw # symlink /srv/$SERVERNAME => /var/lib/slm # when necessary [ -e /srv/$SERVERNAME ] || ln -s /var/lib/slm /srv/$SERVERNAME ############### prepare apache2's configuration ################## ############### when it does not yet exist ################## if [ ! -e /etc/apache2/sites-available/slm.conf ]; then cat /usr/share/doc/slm/apache.conf | \ sed "s/__SERVERNAME__/$SERVERNAME/g" > \ /etc/apache2/sites-available/slm.conf; cat <&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. exit 0