936221ca69cb44abd8a229000b9ce91657893065
[kivitendo-erp.git] / DEBIAN / DEBIAN / postinst
1 #!/bin/bash
2 # postinst script for lx-office-erp-svn
3 #
4 # see: dh_installdeb(1)
5
6 # e = exit on error
7 set -e
8 # x = xtrace
9 #set -x
10 echo " ! "`date`" Postinst $1 !" >> /tmp/lxo-erp.log
11
12 source /usr/share/debconf/confmodule
13
14 # summary of how this script can be called:
15 #        * <postinst> `configure' <most-recently-configured-version>
16 #        * <old-postinst> `abort-upgrade' <new version>
17 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
18 #          <new-version>
19 #        * <postinst> `abort-remove'
20 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
21 #          <failed-install-package> <version> `removing'
22 #          <conflicting-package> <version>
23 # for details, see http://www.debian.org/doc/debian-policy/ or
24 # the debian-policy package
25
26
27 config_postgresql_factory_script() {
28
29         echo "Starting factory postgresql config script: scripts/inst_postgres_deb.sh.."
30         cd /usr/lib/lx-office-erp/
31         ./scripts/inst_postgres_deb.sh
32         echo "Factory postgresql config script done."
33 }
34
35
36 set_lx_office_erp_web_admin_password() {
37         db_get lx-office-erp/admin-password
38         ADMINPASSWORD="$RET"
39
40         sed --in-place --expression "s/^admin_password.*=.*/admin_password = $ADMINPASSWORD/" /etc/lx-office-erp/lx_office.conf
41 }
42
43
44 set_lx_office_erp_authentication_db_user_password() {
45         db_get lx-office-erp/lx-office-erp-user-postgresql-password
46         PASSWORD="$RET"
47
48         sed --in-place --expression "s/^password.*=.*/password = $PASSWORD/" /etc/lx-office-erp/lx_office.conf
49         sed --in-place --expression "s/^user.*=.*postgres/user = lxoffice/g" /etc/lx-office-erp/lx_office.conf
50 }
51
52
53 set_user_rights() {
54         chown -R www-data:www-data /usr/lib/lx-office-erp/users
55         chown -R www-data:www-data /usr/lib/lx-office-erp/templates
56         chown www-data:www-data /etc/lx-office-erp/lx_office.conf
57         chown www-data:www-data /usr/lib/lx-office-erp/menu.ini
58         chmod 0600 /etc/lx-office-erp/lx_office.conf
59 }
60
61 mk_new_menu() {
62     if [ -e /usr/lib/lx-office-crm ] ; then
63         #crm vorhanden, dann die menu.ini mit der höchsten VersNr nehmen
64         for i in `ls -1 /usr/lib/lx-office-crm/update/menu*ini` ; do
65             cat $i > /usr/lib/lx-office-erp/menu.ini
66         done;
67         cat /usr/lib/lx-office-erp/menu.default >> /usr/lib/lx-office-erp/menu.ini
68     else
69         cp /usr/lib/lx-office-erp/menu.default /usr/lib/lx-office-erp/menu.ini
70     fi
71 }
72
73 mk_new_config() {
74     if ! [ -f /etc/lx-office-erp/lx_office.conf ] ; then
75         cp /etc/lx-office-erp/lx_office.conf.default /etc/lx-office-erp/lx_office.conf
76     fi
77 }
78
79 mk_links() {
80     if ! [ -f /usr/lib/lx-office-erp/config/lx_office.conf ] ; then
81         ln -s /etc/lx-office-erp/lx_office.conf /usr/lib/lx-office-erp/config/lx_office.conf
82     fi
83     if [ -e /etc/apache2 ] ; then
84         if ! [ -f /etc/apache2/conf.d/lx-office-erp.apache2.conf ] ; then
85             ln -s /etc/lx-office-erp/lx-office-erp.apache2.conf /etc/apache2/conf.d/lx-office-erp.apache2.conf
86         fi;
87     fi;
88     if [ -e /etc/cherokee/sites-available ] ; then
89         if ! [ -f /etc/cherokee/sites-available/lx-office-erp.cherokee ] ; then
90             cat /etc/lx-office-erp/lx-office-erp.cherokee.handler >> /etc/cherokee/sites-available/default
91             ln -s /etc/lx-office-erp/lx-office-erp.cherokee /etc/cherokee/sites-available/lx-office-erp.cherokee
92         fi;
93     fi;
94     if [ -e /etc/lighttpd ] ; then
95         if ! [ -f /etc/lighttpd/conf-enabled/lx-office-erp.lighttpd ] ; then
96             ln -s /etc/lx-office-erp/lx-office-erp.lighttpd /etc/lighttpf/conf-enabled/10-lx-office-erp
97         fi;
98     fi;
99 }
100 reload_web_server() {
101     if [ -f /etc/init.d/apache* ] ; then
102             /etc/init.d/apache* reload
103     fi
104     if [ -f /etc/init.d/cherokee ] ; then
105             /etc/init.d/cherokee reload
106     fi
107     if [ -f /etc/init.d/lighttpd ] ; then
108             /etc/init.d/lighttpd reload
109     fi
110 }
111 case "$1" in
112
113     upgrade)
114         echo " ! "`date`" $1 !" >> /tmp/lxo-erp.log
115
116         VER=`cat /var/www/lx-office-erp/VERSION | cut -d '.' -f2`
117         if [ $VER = '7' ]; then
118             echo " ! 2.7 !" >> /tmp/lxo-erp.log
119             echo "Version 2.7.x"
120             mk_new_menu
121         else
122             mk_new_menu
123             mk_new_config
124             config_postgresql_factory_script
125             set_lx_office_erp_web_admin_password
126             set_lx_office_erp_authentication_db_user_password
127             mk_links
128         fi;
129
130         set_user_rights
131         reload_web_server
132     ;;
133
134     install|configure)
135         echo " ! "`date`" $1 !" >> /tmp/lxo-erp.log
136
137         mk_new_menu
138         mk_new_config
139         config_postgresql_factory_script
140         set_lx_office_erp_web_admin_password
141         set_lx_office_erp_authentication_db_user_password
142         mk_links
143
144         set_user_rights
145         reload_web_server
146
147     ;;
148
149     abort-upgrade|abort-remove|abort-deconfigure)
150     ;;
151
152     *)
153         echo "postinst called with unknown argument \`$1'" >&2
154         exit 1
155     ;;
156 esac
157
158 echo "done!!"
159
160 exit 0