posaune
[projects.git] / debian / kivitendo.postinst
1 #!/bin/sh
2 set -e
3
4 # kivitendo postinst
5
6 # check configuration file
7 if [ ! -e /opt/kivitendo-erp/config/kivitendo.conf ]
8 then
9         echo "Type new kivitendo admin and DB password:"
10         read a
11         sed "s/admin123/$a/" /opt/kivitendo-erp/config/kivitendo.conf.default >/opt/kivitendo-erp/config/kivitendo.conf
12 fi
13
14 # test DB login
15 if ! su postgres -c "psql -c '\du'" | grep kivitendo >/dev/null
16 then
17         echo "No user named 'kivitendo' found. It is now created."
18         if [ -n "$a" ]
19         then
20                 # password is given
21                 su postgres -c "createuser -ds kivitendo ; psql -c \"ALTER USER kivitendo WITH PASSWORD '$a';\""
22         else
23                 su postgres -c "createuser -dPs kivitendo"
24         fi
25 fi
26 main=$(ls -d /etc/postgresql/*/main/)
27 if ! grep kivitendo $main/pg_hba.conf >/dev/null
28 then
29         echo "adding kivitendo user access to $main/pg_hba.conf"
30         awk 'BEGIN {
31                         found=0; }
32                 /# "local/ {
33                         if (found == 0) {
34                                 print;
35                                 print "local   all   kivitendo   md5";
36                                 found=1;
37                                 next;
38                         }}
39                 /^local.*all.*all/ {
40                         if (found == 0) {
41                                 print "local   all   kivitendo   md5";
42                                 print;
43                                 found=1;
44                                 next;
45                         }}
46                 /^host/ {
47                         if (found == 0) {
48                                 print "local   all   kivitendo   md5";
49                                 print;
50                                 found=1;
51                                 next;
52                         }}
53                 {print;}
54                 ' $main/pg_hba.conf > /tmp/pg_hba.conf
55         mv /tmp/pg_hba.conf $main/pg_hba.conf
56         chown postgres:postgres $main/pg_hba.conf
57         systemctl reload postgresql
58 fi
59
60 # allow write access to some directories
61 chown www-data /opt/kivitendo-erp/users /opt/kivitendo-erp/templates
62 chgrp www-data /opt/kivitendo-erp/users /opt/kivitendo-erp/templates
63
64 systemctl restart apache2
65
66 # call installation check
67 /opt/kivitendo-erp/scripts/installation_check.pl
68
69 if [ ! -d /opt/kivitendo-erp/webdav ]
70 then
71         mkdir /opt/kivitendo-erp/webdav
72         chown www-data:www-data /opt/kivitendo-erp/webdav
73 fi
74