posaune v_0.0-3
authorMichael Wagner <michael@wagnertech.de>
Mon, 29 Nov 2021 13:25:12 +0000 (14:25 +0100)
committerMichael Wagner <michael@wagnertech.de>
Mon, 29 Nov 2021 13:25:12 +0000 (14:25 +0100)
debian/kivitendo.postinst [new file with mode: 0755]

diff --git a/debian/kivitendo.postinst b/debian/kivitendo.postinst
new file mode 100755 (executable)
index 0000000..7307ac8
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/sh
+set -e
+
+# kivitendo postinst
+
+# check configuration file
+if [ ! -e /opt/kivitendo-erp/config/kivitendo.conf ]
+then
+       echo "Type new kivitendo admin and DB password:"
+       read a
+       sed "s/admin123/$a/" /opt/kivitendo-erp/config/kivitendo.conf.default >/opt/kivitendo-erp/config/kivitendo.conf
+fi
+
+# test DB login
+if ! su postgres -c "psql -c '\du'" | grep kivitendo >/dev/null
+then
+       echo "No user named 'kivitendo' found. It is now created."
+       if [ -n "$a" ]
+       then
+               # password is given
+               su postgres -c "createuser -ds kivitendo ; psql -c \"ALTER USER kivitendo WITH PASSWORD '$a';\""
+       else
+               su postgres -c "createuser -dPs kivitendo"
+       fi
+fi
+main=$(ls -d /etc/postgresql/*/main/)
+if ! grep kivitendo $main/pg_hba.conf >/dev/null
+then
+       echo "adding kivitendo user access to $main/pg_hba.conf"
+       awk 'BEGIN {
+                       found=0; }
+               /# "local/ {
+                       if (found == 0) {
+                               print;
+                               print "local   all   kivitendo   md5";
+                               found=1;
+                               next;
+                       }}
+               /^local.*all.*all/ {
+                       if (found == 0) {
+                               print "local   all   kivitendo   md5";
+                               print;
+                               found=1;
+                               next;
+                       }}
+               /^host/ {
+                       if (found == 0) {
+                               print "local   all   kivitendo   md5";
+                               print;
+                               found=1;
+                               next;
+                       }}
+               {print;}
+               ' $main/pg_hba.conf > /tmp/pg_hba.conf
+       mv /tmp/pg_hba.conf $main/pg_hba.conf
+       chown postgres:postgres $main/pg_hba.conf
+       systemctl reload postgresql
+fi
+
+# allow write access to some directories
+chown www-data /opt/kivitendo-erp/users /opt/kivitendo-erp/templates
+chgrp www-data /opt/kivitendo-erp/users /opt/kivitendo-erp/templates
+
+systemctl restart apache2
+
+# call installation check
+/opt/kivitendo-erp/scripts/installation_check.pl
+
+if [ ! -d /opt/kivitendo-erp/webdav ]
+then
+       mkdir /opt/kivitendo-erp/webdav
+       chown www-data:www-data /opt/kivitendo-erp/webdav
+fi
+