cfcaa85384b012b101bacba41ec680149b9567d2
[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 "! Postinst $1 !"
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.sh.."
30
31         cd /usr/lib/lx-office-erp/
32
33         ./scripts/inst_postgres_deb.sh
34
35         echo "Factory postgresql config script done."
36 }
37
38
39 config_postgresql_accounts_sec() {
40
41         POSTGRESQL_PG_HBA_CONF="/etc/postgresql/8.3/main/pg_hba.conf"
42
43         echo "# added by lx-office-erp postinst-script" >> $POSTGRESQL_PG_HBA_CONF
44         echo "host            all lx_office_erp 127.0.0.1 255.255.255.0 password" >> $POSTGRESQL_PG_HBA_CONF
45
46         /etc/init.d/postgresql* reload
47 }
48
49
50 config_postgresql_roles() {
51
52         echo "CREATE USER lx_office_erp with CREATEDB ;" > /tmp/lxdb-install.sql
53
54         db_get lx-office-erp/lx-office-erp-user-postgresql-password
55         POSTGRES_LX_OFFICE_ERP_USER_PASSWORD="$RET"
56
57         echo "ALTER USER lx_office_erp PASSWORD '$POSTGRES_LX_OFFICE_ERP_USER_PASSWORD' ;" \
58          >> /tmp/lxdb-install.sql
59
60         echo "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpgsql';" >> /tmp/lxdb-instal.sql
61
62         su postgres -c "psql --dbname template1 < /tmp/lxdb-install.sql"
63
64         /etc/init.d/postgresql* reload
65 }
66
67
68
69 config_postgresql_sql_routines() {
70
71         PLPGSQL="/usr/lib/postgresql/8.3/lib/plpgsql.so"
72         echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler" > /tmp/lxdb-install.sql
73         echo "AS '$PLPGSQL', 'plpgsql_call_handler'" >> /tmp/lxdb-install.sql
74         echo "LANGUAGE c;" >> /tmp/lxdb-install.sql
75         echo "CREATE PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;" >> /tmp/lxdb-install.sql
76         su postgres -c "psql --dbname template1 < /tmp/lxdb-install.sql"
77
78         /etc/init.d/postgresql-8.3 reload
79 }
80
81
82 set_lx_office_erp_web_admin_password() {
83
84         db_get lx-office-erp/admin-password
85         ADMINPASSWORD="$RET"
86
87         cat /usr/lib/lx-office-erp/config/authentication.pl.default | \
88         sed --expression "s/\$self->{admin_password} = 'admin';/\$self->{admin_password} = '$ADMINPASSWORD';/g" \
89         > /tmp/1.txt
90
91         mv /tmp/1.txt /usr/lib/lx-office-erp/config/authentication.pl
92
93         chmod 0600 /usr/lib/lx-office-erp/config/authentication.pl
94         chown www-data:www-data /usr/lib/lx-office-erp/config/authentication.pl
95
96 }
97
98
99 set_lx_office_erp_authentication_db_password() {
100         db_get lx-office-erp/lx-office-erp-user-postgresql-password
101         PASSWORD="$RET"
102
103         cat /usr/lib/lx-office-erp/config/authentication.pl | \
104         sed --expression "s/'password' => '',/'password' => '$PASSWORD',/g" \
105         > /tmp/1.txt
106
107         mv /tmp/1.txt /usr/lib/lx-office-erp/config/authentication.pl
108
109 }
110
111 set_lx_office_erp_authentication_db_user() {
112         USER="lxoffice"
113
114         cat /usr/lib/lx-office-erp/config/authentication.pl | \
115         sed --expression "s/'user'     => 'postgres',/'user'     => '$USER',/g" \
116         > /tmp/1.txt
117
118         mv /tmp/1.txt /usr/lib/lx-office-erp/config/authentication.pl
119 }
120
121
122 disable_ipv6_on_lo_interface() {
123         # 2009-04-25
124         # Perls Libraries are not yet ipv6 read
125         echo "WICHTIG: ipv6 ist nunmehr auf dem Loopback-Interface deaktiviert, um die Funktionsfähigkeit von Lx-Office-ERP zu gewährleisten!"
126         ifconfig lo inet6 del ::1/128 2> /dev/null || true
127
128         # make the changes permanent (triggered on next reboot)
129         RCLOCAL="/etc/rc.local"
130         echo "# lx-office-erp: Perl libraries are not yet fully ipv6-ready" >> $RCLOCAL
131         echo "ifconfig lo inet6 del ::1/128" >> $RCLOCAL
132
133 }
134
135
136
137
138 case "$1" in
139     install) 
140         echo "Install"
141
142     upgrade)
143         echo "Upgrade"
144
145     configure)
146
147 #       config_postgresql_sql_routines
148 #       config_postgresql_roles
149 #       config_postgresql_accounts_sec
150
151     config_postgresql_factory_script
152
153         chown -R www-data:www-data /usr/lib/lx-office-erp/users
154         chown -R www-data:www-data /usr/lib/lx-office-erp/templates
155
156         set_lx_office_erp_web_admin_password
157         set_lx_office_erp_authentication_db_user
158         set_lx_office_erp_authentication_db_password
159         
160         disable_ipv6_on_lo_interface
161
162         /etc/init.d/apache* reload
163
164     ;;
165
166     abort-upgrade|abort-remove|abort-deconfigure)
167     ;;
168
169     *)
170         echo "postinst called with unknown argument \`$1'" >&2
171         exit 1
172     ;;
173 esac
174
175 # dh_installdeb will replace this with shell code automatically
176 # generated by other debhelper scripts.
177
178
179
180 echo "done!!"
181
182 exit 0