aboutsummaryrefslogtreecommitdiff
path: root/debian/postinst
blob: a1e461aa44680fd0933031ebe0a36d90a60f8b68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
# Reference: https://salsa.debian.org/sssd-team/sssd/-/blob/experimental/debian/sssd-common.postinst
set -e

#DEBHELPER#

OUT=/dev/null
USERNAME=hex-zero
HOME=/var/www/hex-zero

case "$1" in
    configure)
        update-rc.d hex-zero defaults
        if ! getent passwd ${USERNAME} 1>${OUT} 2>&1 ;
        then
            echo "Creating ${USERNAME} system user & group..."
            adduser --quiet --system --home $HOME \
                --disabled-password --group \
                --gecos "0x0 system user" \
                ${USERNAME} > ${OUT} 2>&1
        fi
        chown ${USERNAME}:${USERNAME} \
            ${HOME} ${HOME}/* \
            /var/log/hex-zero /var/log/hex-zero/*log 1>/${OUT} 2>&1 || :
        if ! test -r /var/www/hex-zero/db.sqlite || test $( stat -c "%s" /var/www/hex-zero/db.sqlite 2>/dev/null ) -lt 50 ;
        then
            # detect if short_url exists for the user
            result="$( sh /var/www/hex-zero/check-for-short_url.sh 1>/dev/null 2>&1 && echo good || echo bad )"
            if test "${result}" = "bad" ;
            then
               echo "Please install python3 module short_url with \`/usr/libexec/hex-zero/install-short_url-for-hex-zero.sh\` and then dpkg-reconfigure hex-zero."
            else
               echo "Initializing sqlite database for hex-zero"
               su ${USERNAME} -c 'cd /var/www/hex-zero ; /var/www/hex-zero/hex_zero.py db init' 2>/dev/null || :
               su ${USERNAME} -c 'cd /var/www/hex-zero ; /var/www/hex-zero/hex_zero.py db upgrade'
            fi
        fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

exit 0
bgstack15