summaryrefslogtreecommitdiff
path: root/debian/python-django-ishtar.postinst
diff options
context:
space:
mode:
authorCyril Brulebois <cyril@debamax.com>2016-04-22 10:43:19 +0200
committerCyril Brulebois <cyril@debamax.com>2016-04-22 11:52:54 +0200
commitabb9db59a556162a4be80058d52a907761fd076e (patch)
treebbe7c3bed41ca45492c13b8c10f342dec5b19820 /debian/python-django-ishtar.postinst
parent2eb28d46b0d5c2ae5c7dd614db8e7800baeb0756 (diff)
downloadIshtar-abb9db59a556162a4be80058d52a907761fd076e.tar.bz2
Ishtar-abb9db59a556162a4be80058d52a907761fd076e.zip
Add postinst script to update all created instances.
The update procedure is inspired by the "update" target in upstream Makefile, except for the hardcoding of the localized applications. Keeping this postinst script "set -x" would be a bit too verbose on the long run, so it would probably be a good idea to remove that line once initial testing has happened. Signed-off-by: Cyril Brulebois <cyril@debamax.com>
Diffstat (limited to 'debian/python-django-ishtar.postinst')
-rw-r--r--debian/python-django-ishtar.postinst63
1 files changed, 63 insertions, 0 deletions
diff --git a/debian/python-django-ishtar.postinst b/debian/python-django-ishtar.postinst
new file mode 100644
index 000000000..a92b034ed
--- /dev/null
+++ b/debian/python-django-ishtar.postinst
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+set -e
+set -x
+
+DATA_DIR=/var/lib/python-django-ishtar
+INSTANCES_FILE=$DATA_DIR/INSTANCES
+
+case "$1" in
+ configure)
+ instances="$( (cat $INSTANCES_FILE 2>/dev/null || true) | xargs )"
+ if [ -n "$instances" ]; then
+ echo "updading instances found in $INSTANCES_FILE: $instances"
+ for instance in $instances; do
+ # The upgrade procedure below was built from the "update"
+ # target and its dependencies in the upstream Makefile:
+ echo "updating $instance"
+ cd $DATA_DIR/$instance
+
+ # from "syncdb" target:
+ python manage.py syncdb --noinput
+ python manage.py migrate
+
+ # from "compilemessages" target:
+ #
+ # NOTE: Instead of hardcoding an "apps" variable here, let's
+ # look at candidates with find, and check whether each of
+ # them indeed contains PO files as a second check:
+ maybe_localized=$(cd $DATA_DIR; find -maxdepth 2 -name 'locale')
+ for candidate in $maybe_localized; do
+ if find $DATA_DIR/$candidate -name '*.po' >/dev/null 2>&1; then
+ # Really looks like a valid app, let's strip the last
+ # directory, cd into it, and compile messages using
+ # the instance's manage.py script:
+ app=${candidate%%/locale}
+ (cd $DATA_DIR/$app; python $DATA_DIR/$instance/manage.py compilemessages)
+ fi
+ done
+ # XXX: Doing this only once is likely sufficient, so
+ # we could remember having performed that update while
+ # taking care of the first instance, to avoid
+ # extraneous reruns?
+
+ # from "collectstatic" target:
+ python manage.py collectstatic --noinput
+
+ echo "updating $instance: OK"
+ done
+ echo "updating all instances: OK"
+ else
+ echo "found no instances to upgrade in $INSTANCES_FILE"
+ fi
+ ;;
+
+ abort-upgrade|abort-remove|abort-deconfigure)
+
+ ;;
+
+ *)
+ echo "postinst called with unknown argument \`$1'" >&2
+ exit 1
+ ;;
+esac