Only seed initial Debian package database if key file is available.
[onak.git] / debian / postinst
1 #! /bin/sh
2
3 set -e
4
5 if [ "$1" = "configure" ]; then
6
7     # Add the onak user
8     adduser --system --home /var/lib/onak --no-create-home --disabled-login onak
9
10     #
11     # If we're using a default config and there's no onak database, create it
12     # by adding my key.
13     #
14     if grep -q "^db_dir /var/lib/onak" /etc/onak.conf &&
15             grep -q "^db_backend db4" /etc/onak.conf &&
16             [ ! -e /var/lib/onak/num_keydb -a \
17                 -e /usr/share/doc/onak/noodles.key ]; then
18         zcat /usr/share/doc/onak/noodles.key | onak -b add
19     fi
20
21     # Take ownership of the database and spool directory
22     chown -R onak /var/lib/onak
23     chown -R onak /var/spool/onak
24
25     # Create our logfile
26     touch /var/log/onak.log
27     chown onak /var/log/onak.log
28
29     # Make the CGI tools setuid onak
30     for i in /usr/lib/cgi-bin/pks/*
31     do
32         if ! dpkg-statoverride --list $i >/dev/null
33         then
34             dpkg-statoverride --update --add onak root 4755 $i
35         fi
36     done
37
38     # If we don't have a DB backend defined, then add appropriate config
39     if ! grep -q db_backend /etc/onak.conf; then
40         echo "# Auto added on package update" >> /etc/onak.conf
41         echo "backends_dir /usr/lib/onak/backends" >> /etc/onak.conf
42         echo "db_backend db4" >> /etc/onak.conf
43     fi
44
45     # If we still have the old default mail_dir setting, fix it
46     if grep -q "mail_dir /community/pgp-keyserver/incoming" /etc/onak.conf; then
47         sed -i.bak "s/community\/pgp-keyserver\/incoming/var\/spool\/onak/" \
48                 /etc/onak.conf
49     fi
50
51 fi
52
53 #DEBHELPER#