Namensgebung accrual/cash für Soll-/Ist-Versteuerung angepasst
[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
11 debugfile=$(mktemp /tmp/lx-erp.log.XXXXXX)
12 echo " ! "`date`" Postinst $1 !" >> $debugfile
13
14 source /usr/share/debconf/confmodule
15
16 # summary of how this script can be called:
17 #        * <postinst> `configure' <most-recently-configured-version>
18 #        * <old-postinst> `abort-upgrade' <new version>
19 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
20 #          <new-version>
21 #        * <postinst> `abort-remove'
22 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
23 #          <failed-install-package> <version> `removing'
24 #          <conflicting-package> <version>
25 # for details, see http://www.debian.org/doc/debian-policy/ or
26 # the debian-policy package
27
28
29 config_postgresql_factory_script() {
30
31   echo "Starting factory postgresql config script: scripts/inst_postgres_deb.sh.."
32   cd /usr/lib/lx-office-erp/
33   ./scripts/inst_postgres_deb.sh
34   echo "Factory postgresql config script done."
35 }
36
37
38 set_lx_office_erp_web_admin_password() {
39   db_get lx-office-erp/admin-password
40   ADMINPASSWORD="$RET"
41
42   sed --in-place --expression "s/^admin_password.*=.*/admin_password = $ADMINPASSWORD/" /etc/lx-office-erp/lx_office.conf
43 }
44
45
46 set_lx_office_erp_authentication_db_user_password() {
47   db_get lx-office-erp/lx-office-erp-user-postgresql-password
48   PASSWORD="$RET"
49
50   sed --in-place --expression "s/^password.*=.*/password = $PASSWORD/" /etc/lx-office-erp/lx_office.conf
51   sed --in-place --expression "s/^user.*=.*postgres/user = lxoffice/g" /etc/lx-office-erp/lx_office.conf
52 }
53
54
55 set_user_rights() {
56   chown -R www-data:www-data /usr/lib/lx-office-erp/users
57   chown -R www-data:www-data /usr/lib/lx-office-erp/templates
58   chown www-data:www-data /etc/lx-office-erp/lx_office.conf
59   chown www-data:www-data /usr/lib/lx-office-erp/menu.ini
60   chmod 0600 /etc/lx-office-erp/lx_office.conf
61 }
62
63 mk_new_menu() {
64   if [ -e /usr/lib/lx-office-crm ] ; then
65         #crm vorhanden, dann die menu.ini mit der höchsten VersNr nehmen
66     for i in `ls -1 /usr/lib/lx-office-crm/update/menu*ini` ; do
67       cat $i > /usr/lib/lx-office-erp/menu.ini
68     done;
69     cat /usr/lib/lx-office-erp/menu.default >> /usr/lib/lx-office-erp/menu.ini
70   else
71     cp /usr/lib/lx-office-erp/menu.default /usr/lib/lx-office-erp/menu.ini
72   fi
73 }
74
75 mk_new_config() {
76   if ! [ -f /etc/lx-office-erp/lx_office.conf ] ; then
77     cp /etc/lx-office-erp/lx_office.conf.default /etc/lx-office-erp/lx_office.conf
78   fi
79 }
80
81 mk_links() {
82   for file in lx_office.conf lx_office.conf.default ; do
83     test -f /usr/lib/lx-office-erp/config/${file} || ln -s /etc/lx-office-erp/${file} /usr/lib/lx-office-erp/config/${file}
84   done
85   for file in lx-erp.conf authentication.pl ; do
86     if [ -f /usr/lib/lx-office-erp/config/${file} ] ; then
87       rm /usr/lib/lx-office-erp/config/${file}
88     fi
89   done
90   if [ -e /etc/apache2 ] ; then
91     if ! [ -f /etc/apache2/conf.d/lx-office-erp.apache2.conf ] ; then
92       ln -s /etc/lx-office-erp/lx-office-erp.apache2.conf /etc/apache2/conf.d/lx-office-erp.apache2.conf
93     fi;
94   fi;
95   if [ -e /etc/cherokee/sites-available ] ; then
96     if ! [ -f /etc/cherokee/sites-available/lx-office-erp.cherokee ] ; then
97       cat /etc/lx-office-erp/lx-office-erp.cherokee.handler >> /etc/cherokee/sites-available/default
98       ln -s /etc/lx-office-erp/lx-office-erp.cherokee /etc/cherokee/sites-available/lx-office-erp.cherokee
99     fi;
100   fi;
101   if [ -e /etc/lighttpd ] ; then
102     if ! [ -f /etc/lighttpd/conf-enabled/lx-office-erp.lighttpd ] ; then
103       ln -s /etc/lx-office-erp/lx-office-erp.lighttpd /etc/lighttpf/conf-enabled/10-lx-office-erp
104     fi;
105   fi;
106 }
107 web_server_ctrl() {
108   local action=$1
109   if [ -x "/etc/init.d/apache2" ]; then
110     if [ -x /usr/sbin/invoke-rc.d ]; then
111       invoke-rc.d apache2 $action ||true
112     else
113       /etc/init.d/apache2 $action ||true
114     fi
115   fi
116   if [ -f /etc/init.d/cherokee ] ; then
117     /etc/init.d/cherokee $action || true
118   fi
119   if [ -f /etc/init.d/lighttpd ] ; then
120     /etc/init.d/lighttpd $action || true
121   fi
122
123   # if [ $action = restart ] ; then
124   #   echo Sleeping
125   #   sleep 5
126   #   echo Awake
127   # fi
128 }
129
130 enable_fcgi() {
131   if [ -x /usr/sbin/a2enmod -a -f /usr/lib/apache2/modules/mod_fcgid.so ] ; then
132     /usr/sbin/a2enmod fcgid
133     # web_server_ctrl restart
134   fi
135 }
136
137 case "$1" in
138
139   upgrade)
140     echo " ! "`date`" $1 !" >> $debugfile
141
142     enable_fcgi
143
144     VER=`cat /var/www/lx-office-erp/VERSION | cut -d '.' -f2`
145     if [ $VER = '6' ]; then
146       echo " ! 2.6 !" >> $debugfile
147       echo "Version 2.6.x"
148       mk_new_menu
149     else
150       mk_new_menu
151       mk_new_config
152       config_postgresql_factory_script
153       set_lx_office_erp_web_admin_password
154       set_lx_office_erp_authentication_db_user_password
155       mk_links
156     fi;
157
158     set_user_rights
159     ps auxw
160
161     db_stop || true
162     web_server_ctrl restart
163
164     ;;
165
166   install|configure)
167     echo " ! "`date`" $1 !" >> $debugfile
168
169     enable_fcgi
170
171     mk_new_menu
172     mk_new_config
173     config_postgresql_factory_script
174     set_lx_office_erp_web_admin_password
175     set_lx_office_erp_authentication_db_user_password
176     mk_links
177
178     set_user_rights
179
180     db_stop || true
181     web_server_ctrl restart
182
183     ;;
184
185   abort-upgrade|abort-remove|abort-deconfigure)
186     ;;
187
188   *)
189     echo "postinst called with unknown argument \`$1'" >&2
190     exit 1
191     ;;
192 esac
193
194 echo "done!!"
195
196 exit 0