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