Merge branch 'master' into after-262
[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         db_get lx-office-erp/admin-password
82         ADMINPASSWORD="$RET"
83
84         cat /etc/lx-office-erp/authentication.pl.default | \
85         sed --expression "s/\$self->{admin_password} = 'admin';/\$self->{admin_password} = '$ADMINPASSWORD';/g" \
86         > /tmp/1.txt
87
88         mv /tmp/1.txt /etc/lx-office-erp/authentication.pl
89
90 }
91
92
93 set_lx_office_erp_authentication_db_password() {
94         db_get lx-office-erp/lx-office-erp-user-postgresql-password
95         PASSWORD="$RET"
96
97         cat /etc/lx-office-erp/authentication.pl | \
98         sed --expression "s/'password' => '',/'password' => '$PASSWORD',/g" \
99         > /tmp/1.txt
100
101         mv /tmp/1.txt /etc/lx-office-erp/authentication.pl
102
103 }
104
105 set_lx_office_erp_authentication_db_user() {
106         USER="lxoffice"
107
108         cat /etc/lx-office-erp/authentication.pl | \
109         sed --expression "s/'user'     => 'postgres',/'user'     => '$USER',/g" \
110         > /tmp/1.txt
111
112         mv /tmp/1.txt /etc/lx-office-erp/authentication.pl
113 }
114
115 set_user_rights() {
116         chown -R www-data:www-data /usr/lib/lx-office-erp/users
117         chown -R www-data:www-data /usr/lib/lx-office-erp/templates
118         chown www-data:www-data /etc/lx-office-erp/lx_office.conf
119         chown www-data:www-data /usr/lib/lx-office-erp/menu.ini
120         chown www-data:www-data /etc/lx-office-erp/authentication.pl
121         chmod 0600 /etc/lx-office-erp/lx_office.conf
122         chmod 0600 /etc/lx-office-erp/authentication.pl
123 }
124
125 disable_ipv6_on_lo_interface() {
126         # 2009-04-25
127         # Perls Libraries are not yet ipv6 read
128         echo "WICHTIG: ipv6 ist nunmehr auf dem Loopback-Interface deaktiviert, um die Funktionsfähigkeit von Lx-Office-ERP zu gewährleisten!"
129         ifconfig lo inet6 del ::1/128 2> /dev/null || true
130
131         # make the changes permanent (triggered on next reboot)
132         RCLOCAL="/etc/rc.local"
133         echo "# lx-office-erp: Perl libraries are not yet fully ipv6-ready" >> $RCLOCAL
134         echo "ifconfig lo inet6 del ::1/128" >> $RCLOCAL
135
136 }
137 mk_new_menu() {
138     if [ -e /usr/lib/lx-office-crm ] ; then
139         #crm vorhanden, dann die menu.ini mit der höchsten VersNr nehmen
140         for i in `ls -1 /usr/lib/lx-office-crm/update/menu*ini` ; do
141             cat $i > /usr/lib/lx-office-erp/menu.ini
142         done;
143         cat /usr/lib/lx-office-erp/menu.default >> /usr/lib/lx-office-erp/menu.ini
144     else
145         cp /usr/lib/lx-office-erp/menu.default /usr/lib/lx-office-erp/menu.ini
146     fi
147 }
148
149 mk_new_config() {
150     if ! [ -f /etc/lx-office-erp/lx_office.conf ] ; then
151         cp /etc/lx-office-erp/lx_office.conf.default /etc/lx-office-erp/lx_office.conf
152     fi
153 }
154
155 mk_links() {
156     if ! [ -f /usr/lib/lx-office-erp/config/authentication.pl ] ; then
157         ln -s /etc/lx-office-erp/authentication.pl /usr/lib/lx-office-erp/config/authentication.pl
158     fi;
159     if ! [ -f /usr/lib/lx-office-erp/config/lx_office.conf ] ; then
160         ln -s /etc/lx-office-erp/lx_office.conf /usr/lib/lx-office-erp/config/lx_office.conf
161     fi;
162     if [ -e /etc/apache2 ] ; then
163         if ! [ -f /etc/apache2/conf.d/lx-office-erp.apache2.conf ] ; then
164             ln -s /etc/lx-office-erp/lx-office-erp.apache2.conf /etc/apache2/conf.d/lx-office-erp.apache2.conf
165         fi;
166     fi;
167     if [ -e /etc/cherokee/sites-available ] ; then
168         if ! [ -f /etc/cherokee/sites-available/lx-office-erp.cherokee ] ; then
169             cat /etc/lx-office-erp/lx-office-erp.cherokee.handler >> /etc/cherokee/sites-available/default
170             ln -s /etc/lx-office-erp/lx-office-erp.cherokee /etc/cherokee/sites-available/lx-office-erp.cherokee
171         fi;
172     fi;
173 }
174 reload_web_server() {
175     if [ -f /etc/init.d/apache* ] ; then
176             /etc/init.d/apache* reload
177     fi
178     if [ -f /etc/init.d/cherokee ] ; then
179             /etc/init.d/cherokee reload
180     fi
181 }
182 case "$1" in
183
184     upgrade)
185         echo " ! "`date`" $1 !" >> /tmp/lxo-erp.log
186
187         VER=`cat /var/www/lx-office-erp/VERSION | cut -d '.' -f2`
188         if [ $VER = '6' ]; then
189             echo " ! 2.6 !" >> /tmp/lxo-erp.log
190             echo "Version 2.6"
191             mk_new_menu
192         else
193             mk_new_menu
194             mk_new_config
195             config_postgresql_factory_script
196             set_lx_office_erp_web_admin_password
197             set_lx_office_erp_authentication_db_user
198             set_lx_office_erp_authentication_db_password
199                 disable_ipv6_on_lo_interface
200             mk_links
201         fi;
202
203         set_user_rights
204         reload_web_server
205     ;;
206
207     install|configure)
208         echo " ! "`date`" $1 !" >> /tmp/lxo-erp.log
209
210         mk_new_menu
211         mk_new_config
212         config_postgresql_factory_script
213         set_lx_office_erp_web_admin_password
214         set_lx_office_erp_authentication_db_user
215         set_lx_office_erp_authentication_db_password
216         disable_ipv6_on_lo_interface
217         mk_links
218
219         set_user_rights
220         reload_web_server
221
222     ;;
223
224     abort-upgrade|abort-remove|abort-deconfigure)
225     ;;
226
227     *)
228         echo "postinst called with unknown argument \`$1'" >&2
229         exit 1
230     ;;
231 esac
232
233 # dh_installdeb will replace this with shell code automatically
234 # generated by other debhelper scripts.
235
236
237 echo "done!!"
238
239 exit 0