Konfigurationsort für viele Flags ist Abschnitt 'features', nicht 'system'
[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 config_postgresql_accounts_sec() {
37
38         POSTGRESQL_PG_HBA_CONF="/etc/postgresql/8.3/main/pg_hba.conf"
39
40         echo "# added by lx-office-erp postinst-script" >> $POSTGRESQL_PG_HBA_CONF
41         echo "host            all lx_office_erp 127.0.0.1 255.255.255.0 password" >> $POSTGRESQL_PG_HBA_CONF
42
43         /etc/init.d/postgresql* reload
44 }
45
46
47 config_postgresql_roles() {
48
49         echo "CREATE USER lx_office_erp with CREATEDB ;" > /tmp/lxdb-install.sql
50
51         db_get lx-office-erp/lx-office-erp-user-postgresql-password
52         POSTGRES_LX_OFFICE_ERP_USER_PASSWORD="$RET"
53
54         echo "ALTER USER lx_office_erp PASSWORD '$POSTGRES_LX_OFFICE_ERP_USER_PASSWORD' ;" \
55          >> /tmp/lxdb-install.sql
56
57         echo "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpgsql';" >> /tmp/lxdb-instal.sql
58
59         su postgres -c "psql --dbname template1 < /tmp/lxdb-install.sql"
60
61         /etc/init.d/postgresql* reload
62 }
63
64
65
66 config_postgresql_sql_routines() {
67
68         PLPGSQL="/usr/lib/postgresql/8.3/lib/plpgsql.so"
69         echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler" > /tmp/lxdb-install.sql
70         echo "AS '$PLPGSQL', 'plpgsql_call_handler'" >> /tmp/lxdb-install.sql
71         echo "LANGUAGE c;" >> /tmp/lxdb-install.sql
72         echo "CREATE PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;" >> /tmp/lxdb-install.sql
73         su postgres -c "psql --dbname template1 < /tmp/lxdb-install.sql"
74
75         /etc/init.d/postgresql-8.3 reload
76 }
77
78
79 set_lx_office_erp_web_admin_password() {
80
81         if ! [ -f /etc/lx-office-erp/lx_office.conf ] ; then
82                 cp /etc/lx-office-erp/lx_office.conf.default /etc/lx-office-erp/lx_office.conf
83         fi
84         db_get lx-office-erp/admin-password
85         ADMINPASSWORD="$RET"
86
87         cat /etc/lx-office-erp/lx_office.conf | \
88         sed --expression "s/admin_password = /admin_password = $ADMINPASSWORD/g" \
89         > /tmp/1.txt
90
91         mv /tmp/1.txt /etc/lx-office-erp/lx_office.conf
92
93 }
94
95
96 set_lx_office_erp_authentication_db_user_password() {
97         db_get lx-office-erp/lx-office-erp-user-postgresql-password
98         PASSWORD="$RET"
99
100         cat /etc/lx-office-erp/lx_office.conf | \
101         sed --expression "s/^password = /password = $PASSWORD/g" \
102         > /tmp/1.txt
103
104         cat /tmp/1.txt | \
105         sed --expression "s/^user = postgres/user = lxoffice/g" \
106         >  /etc/lx-office-erp/lx_office.conf
107
108 }
109
110
111 set_user_rights() {
112         chown -R www-data:www-data /usr/lib/lx-office-erp/users
113         chown -R www-data:www-data /usr/lib/lx-office-erp/templates
114         chown www-data:www-data /etc/lx-office-erp/lx_office.conf
115         chown www-data:www-data /usr/lib/lx-office-erp/menu.ini
116         chmod 0600 /etc/lx-office-erp/lx_office.conf
117 }
118
119 disable_ipv6_on_lo_interface() {
120         #Ist wohl nicht mehr notwendig.
121         # 2009-04-25
122         # Perls Libraries are not yet ipv6 read
123         echo "WICHTIG: ipv6 ist nunmehr auf dem Loopback-Interface deaktiviert, um die Funktionsfähigkeit von Lx-Office-ERP zu gewährleisten!"
124         ifconfig lo inet6 del ::1/128 2> /dev/null || true
125
126         # make the changes permanent (triggered on next reboot)
127         RCLOCAL="/etc/rc.local"
128         echo "# lx-office-erp: Perl libraries are not yet fully ipv6-ready" >> $RCLOCAL
129         echo "ifconfig lo inet6 del ::1/128" >> $RCLOCAL
130
131 }
132 mk_new_menu() {
133     if [ -e /usr/lib/lx-office-crm ] ; then
134         #crm vorhanden, dann die menu.ini mit der höchsten VersNr nehmen
135         for i in `ls -1 /usr/lib/lx-office-crm/update/menu*ini` ; do
136             cat $i > /usr/lib/lx-office-erp/menu.ini
137         done;
138         cat /usr/lib/lx-office-erp/menu.default >> /usr/lib/lx-office-erp/menu.ini
139     else
140         cp /usr/lib/lx-office-erp/menu.default /usr/lib/lx-office-erp/menu.ini
141     fi
142 }
143
144 mk_new_config() {
145     if ! [ -f /etc/lx-office-erp/lx_office.conf ] ; then
146         cp /etc/lx-office-erp/lx_office.conf.default /etc/lx-office-erp/lx_office.conf
147     fi
148 }
149
150 mk_links() {
151     if ! [ -f /usr/lib/lx-office-erp/config/lx_office.conf ] ; then
152         ln -s /etc/lx-office-erp/lx_office.conf /usr/lib/lx-office-erp/config/lx_office.conf
153     fi;
154     if ! [ -f /usr/lib/lx-office-erp/config/lx_office.conf.default ] ; then
155         ln -s /etc/lx-office-erp/lx_office.conf.default /usr/lib/lx-office-erp/config/lx_office.conf.default
156     fi;
157     if [ -e /etc/lx-office-erp/authentication.pl ] ; then
158         rm /etc/lx-office-erp/authentication.pl
159     fi
160     if [ -e /etc/apache2 ] ; then
161         if ! [ -f /etc/apache2/conf.d/lx-office-erp.apache2.conf ] ; then
162             ln -s /etc/lx-office-erp/lx-office-erp.apache2.conf /etc/apache2/conf.d/lx-office-erp.apache2.conf
163         fi;
164     fi;
165     if [ -e /etc/cherokee/sites-available ] ; then
166         if ! [ -f /etc/cherokee/sites-available/lx-office-erp.cherokee ] ; then
167             cat /etc/lx-office-erp/lx-office-erp.cherokee.handler >> /etc/cherokee/sites-available/default
168             ln -s /etc/lx-office-erp/lx-office-erp.cherokee /etc/cherokee/sites-available/lx-office-erp.cherokee
169         fi;
170     fi;
171     if [ -e /etc/lighttpd ] ; then 
172         if ! [ -f /etc/lighttpd/conf-enabled/lx-office-erp.lighttpd ] ; then
173             ln -s /etc/lx-office-erp/lx-office-erp.lighttpd /etc/lighttpf/conf-enabled/10-lx-office-erp
174         fi;
175     fi;
176 }
177 reload_web_server() {
178     if [ -f /etc/init.d/apache* ] ; then
179             /etc/init.d/apache* reload
180     fi
181     if [ -f /etc/init.d/cherokee ] ; then
182             /etc/init.d/cherokee reload
183     fi
184     if [ -f /etc/init.d/lighttpd ] ; then 
185             /etc/init.d/lighttpd reload
186     fi
187 }
188 case "$1" in
189
190     upgrade)
191         echo " ! "`date`" $1 !" >> /tmp/lxo-erp.log
192
193         VER=`cat /var/www/lx-office-erp/VERSION | cut -d '.' -f2`
194         if [ $VER = '6' ]; then
195             echo " ! 2.6 !" >> /tmp/lxo-erp.log
196             echo "Version 2.6.x"
197             mk_new_menu
198         else
199             mk_new_menu
200             mk_new_config
201             config_postgresql_factory_script
202             set_lx_office_erp_web_admin_password
203             set_lx_office_erp_authentication_db_user_password
204             #  disable_ipv6_on_lo_interface
205             mk_links
206         fi;
207
208         set_user_rights
209         reload_web_server
210     ;;
211
212     install|configure)
213         echo " ! "`date`" $1 !" >> /tmp/lxo-erp.log
214
215         mk_new_menu
216         mk_new_config
217         config_postgresql_factory_script
218         set_lx_office_erp_web_admin_password
219         set_lx_office_erp_authentication_db_user_password
220         # disable_ipv6_on_lo_interface
221         mk_links
222
223         set_user_rights
224         reload_web_server
225
226     ;;
227
228     abort-upgrade|abort-remove|abort-deconfigure)
229     ;;
230
231     *)
232         echo "postinst called with unknown argument \`$1'" >&2
233         exit 1
234     ;;
235 esac
236
237 # dh_installdeb will replace this with shell code automatically
238 # generated by other debhelper scripts.
239
240
241 echo "done!!"
242
243 exit 0