]> the.earth.li Git - onak.git/blob - debian/postinst
Cleanup postinst to avoid recursive chown of database
[onak.git] / debian / postinst
1 #! /bin/sh
2
3 set -e
4
5 if [ "$1" = "configure" ]; then
6     if dpkg --compare-versions -- "$2" le "0.4.6-1"; then
7         echo "Upgrading from old onak.conf version"
8         if [ -e /etc/onak.conf.dpkg-backup -a ! -e /etc/onak.conf ]; then
9                 echo "Migrating onak.conf to onak.ini"
10                 # Old config file was modified; generate a new style
11                 # file. onak will use the file extension to determine it's
12                 # an old style config, so we need the symlink.
13                 ln -s /etc/onak.conf.dpkg-backup /etc/onak.conf
14                 onak -c /etc/onak.conf dumpconfig /etc/onak.ini
15                 rm /etc/onak.conf
16         fi
17     fi
18
19     # Add the onak user
20     adduser --system --home /var/lib/onak --no-create-home --disabled-login onak
21
22     # Take ownership of the database and spool directory
23     chown onak /var/lib/onak
24     chown onak /var/spool/onak
25
26     # Create our logfile
27     touch /var/log/onak.log
28     chown onak /var/log/onak.log
29
30     #
31     # If we're using a default config and there's no onak database, create it
32     # by adding my key.
33     #
34     if grep -q "^backend=defaultdb4" /etc/onak.ini &&
35             grep -q "^location=/var/lib/onak" /etc/onak.ini &&
36             [ ! -e /var/lib/onak/num_keydb -a \
37                 -e /usr/share/doc/onak/noodles.key.gz ]; then
38         zcat /usr/share/doc/onak/noodles.key | runuser -u onak -- onak -b add
39     fi
40
41     # Make the CGI tools setuid onak
42     for i in /usr/lib/cgi-bin/pks/*
43     do
44         if ! dpkg-statoverride --list $i >/dev/null
45         then
46             dpkg-statoverride --update --add onak root 4755 $i
47         fi
48     done
49 fi
50
51 #DEBHELPER#
52
53 #
54 # With the move to systemd this will force systemd to start keyd even if it's
55 # disabled in the onak config file; the systemd service file can't check the
56 # way the init script does. Work around this by doing the check here and
57 # only calling invoke-rc.d if it's actually enabled.
58 #
59 if grep -q -E '^use_keyd=*(true|yes|1)$' /etc/onak.ini; then
60     invoke-rc.d onak start || exit $?
61 fi