diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-10-11 11:49:20 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-10 18:17:41 +0200 |
commit | fe8d95e177621f71b8c61cab203b44d5eb8f3b2c (patch) | |
tree | 1bcbfd7edf6096b2552ea348cfa1c35bcf054472 /debian/python3-django-ishtar.postinst | |
parent | 10fdb26623fd0f42f5a4fb65a41cd17350b6f24a (diff) | |
download | Ishtar-fe8d95e177621f71b8c61cab203b44d5eb8f3b2c.tar.bz2 Ishtar-fe8d95e177621f71b8c61cab203b44d5eb8f3b2c.zip |
🚀 Debian package: python-django-ishtar
Diffstat (limited to 'debian/python3-django-ishtar.postinst')
-rw-r--r-- | debian/python3-django-ishtar.postinst | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/debian/python3-django-ishtar.postinst b/debian/python3-django-ishtar.postinst new file mode 100644 index 000000000..e6543eb21 --- /dev/null +++ b/debian/python3-django-ishtar.postinst @@ -0,0 +1,103 @@ +#!/bin/bash + +set -e +#set -x + +cecho() { + local code="\033[" + case "$1" in + black | bk) color="${code}0;30m";; + red | r) color="${code}1;31m";; + green | g) color="${code}1;32m";; + yellow | y) color="${code}1;33m";; + blue | b) color="${code}1;34m";; + purple | p) color="${code}1;35m";; + cyan | c) color="${code}1;36m";; + gray | gr) color="${code}0;37m";; + *) local text="$1" + esac + [ -z "$text" ] && local text="$color$2${code}0m" + echo -e "$text" +} + +DATA_DIR=/srv/ishtar +CONFIG_PATH=/etc/ishtar +INSTANCES_FILE=$CONFIG_PATH/instances + +case "$1" in + configure) + mkdir -p $CONFIG_PATH 2> /dev/null + if [ ! -f $CONFIG_PATH/config ]; then + cp /usr/share/python3-django-ishtar/install/config.template $CONFIG_PATH/config ; + fi + source $CONFIG_PATH/config + export LANG=$ISHTAR_LOCALE.UTF-8 + if [ "$(locale 2>&1 >/dev/null|wc -l)" != 0 ]; then + cecho r "Unable to set LANG=$LANG properly" + cecho y "Try: 'dpkg-reconfigure locales' or install the 'locales-all' package." + cecho y "If you want to use another locale, modify /etc/ishtar/config properly." + exit 1 + fi + instances="$( (cat $INSTANCES_FILE 2>/dev/null || true) | xargs )" + if [ -n "$instances" ]; then + if [ -f /usr/sbin/rabbitmqctl ]; then # assume queues are configured + cecho c "Verify rabbitmq queues are empty" + for instance in $instances; do + for res in `/usr/sbin/rabbitmqctl list_queues -p /ishtar$instance -q messages`; do + if [ $res != 0 ] && [ $res != 'messages' ]; then + cecho r "The queue for $instance is not empty ($res messages)." + cecho y "Wait a few minutes (hours?) for update." + exit 1 + fi; + done + done + fi + messages_compiled=""; + for instance in $instances; do + if [ ! $messages_compiled ]; then + cecho c "Compile i18n messages" + (cd $DATA_DIR; python3 $DATA_DIR/$instance/manage.py compilemessages); + messages_compiled="ok"; + cecho c "Updating instances found in $INSTANCES_FILE: $instances" + fi + # The upgrade procedure below was built from the "update" + # target and its dependencies in the upstream Makefile: + cecho c "* Updating $instance" + cd $DATA_DIR/$instance + # migrate + python3 manage.py migrate + # "collectstatic" + python3 manage.py collectstatic --noinput + cecho g "Updating $instance: OK" + done + cecho g "Updating all instances: OK" + + # the assumption is that nginx and uwsgi were configured + # through ishtar-prepare-instance, so let's restart them + # unconditionally: + cecho c "Restarting uwsgi and nginx" + invoke-rc.d uwsgi restart + invoke-rc.d nginx restart + cecho g "Restarting uwsgi and nginx: OK" + SUPERVISOR=/usr/bin/supervisorctl + if [ -f "$SUPERVISOR" ]; then + cecho c "Restarting supervisor service" + $SUPERVISOR restart all + cecho g "Restarting supervisor service: OK" + fi + else + cecho g "Found no instances to update in $INSTANCES_FILE" + cecho y "To create a new instance:" + cecho y " ishtar-prepare-instance" + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac |