Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / DEBIAN / DEBIAN / postinst
index b0a525c..1109584 100755 (executable)
@@ -7,7 +7,9 @@
 set -e
 # x = xtrace
 #set -x
-echo " ! "`date`" Postinst $1 !" >> /tmp/lxo-erp.log
+
+debugfile=$(mktemp /tmp/lx-erp.log.XXXXXX)
+echo " ! "`date`" Postinst $1 !" >> $debugfile
 
 source /usr/share/debconf/confmodule
 
@@ -26,228 +28,169 @@ source /usr/share/debconf/confmodule
 
 config_postgresql_factory_script() {
 
-       echo "Starting factory postgresql config script: scripts/inst_postgres_deb.sh.."
-       cd /usr/lib/lx-office-erp/
-       ./scripts/inst_postgres_deb.sh
-       echo "Factory postgresql config script done."
-}
-
-
-config_postgresql_accounts_sec() {
-
-       POSTGRESQL_PG_HBA_CONF="/etc/postgresql/8.3/main/pg_hba.conf"
-
-       echo "# added by lx-office-erp postinst-script" >> $POSTGRESQL_PG_HBA_CONF
-       echo "host            all lx_office_erp 127.0.0.1 255.255.255.0 password" >> $POSTGRESQL_PG_HBA_CONF
-
-       /etc/init.d/postgresql* reload
-}
-
-
-config_postgresql_roles() {
-
-       echo "CREATE USER lx_office_erp with CREATEDB ;" > /tmp/lxdb-install.sql
-
-        db_get lx-office-erp/lx-office-erp-user-postgresql-password
-        POSTGRES_LX_OFFICE_ERP_USER_PASSWORD="$RET"
-
-        echo "ALTER USER lx_office_erp PASSWORD '$POSTGRES_LX_OFFICE_ERP_USER_PASSWORD' ;" \
-         >> /tmp/lxdb-install.sql
-
-       echo "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpgsql';" >> /tmp/lxdb-instal.sql
-
-        su postgres -c "psql --dbname template1 < /tmp/lxdb-install.sql"
-
-        /etc/init.d/postgresql* reload
-}
-
-
-
-config_postgresql_sql_routines() {
-
-       PLPGSQL="/usr/lib/postgresql/8.3/lib/plpgsql.so"
-       echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler" > /tmp/lxdb-install.sql
-       echo "AS '$PLPGSQL', 'plpgsql_call_handler'" >> /tmp/lxdb-install.sql
-       echo "LANGUAGE c;" >> /tmp/lxdb-install.sql
-       echo "CREATE PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;" >> /tmp/lxdb-install.sql
-       su postgres -c "psql --dbname template1 < /tmp/lxdb-install.sql"
-
-       /etc/init.d/postgresql-8.3 reload
+  echo "Starting factory postgresql config script: scripts/inst_postgres_deb.sh.."
+  cd /usr/lib/lx-office-erp/
+  ./scripts/inst_postgres_deb.sh
+  echo "Factory postgresql config script done."
 }
 
 
 set_lx_office_erp_web_admin_password() {
+  db_get lx-office-erp/admin-password
+  ADMINPASSWORD="$RET"
 
-       db_get lx-office-erp/admin-password
-       ADMINPASSWORD="$RET"
-
-       cat /etc/lx-office-erp/authentication.pl.default | \
-       sed --expression "s/\$self->{admin_password} = 'admin';/\$self->{admin_password} = '$ADMINPASSWORD';/g" \
-       > /tmp/1.txt
-
-       mv /tmp/1.txt /etc/lx-office-erp/authentication.pl
-
+  sed --in-place --expression "s/^admin_password.*=.*/admin_password = $ADMINPASSWORD/" /etc/lx-office-erp/lx_office.conf
 }
 
 
-set_lx_office_erp_authentication_db_password() {
-       db_get lx-office-erp/lx-office-erp-user-postgresql-password
-       PASSWORD="$RET"
-
-       cat /etc/lx-office-erp/authentication.pl | \
-       sed --expression "s/'password' => '',/'password' => '$PASSWORD',/g" \
-       > /tmp/1.txt
-
-       mv /tmp/1.txt /etc/lx-office-erp/authentication.pl
+set_lx_office_erp_authentication_db_user_password() {
+  db_get lx-office-erp/lx-office-erp-user-postgresql-password
+  PASSWORD="$RET"
 
+  sed --in-place --expression "s/^password.*=.*/password = $PASSWORD/" /etc/lx-office-erp/lx_office.conf
+  sed --in-place --expression "s/^user.*=.*postgres/user = lxoffice/g" /etc/lx-office-erp/lx_office.conf
 }
 
-set_lx_office_erp_authentication_db_user() {
-       USER="lxoffice"
-
-       cat /etc/lx-office-erp/authentication.pl | \
-       sed --expression "s/'user'     => 'postgres',/'user'     => '$USER',/g" \
-       > /tmp/1.txt
-
-       mv /tmp/1.txt /etc/lx-office-erp/authentication.pl
-}
 
 set_user_rights() {
-       chown -R www-data:www-data /usr/lib/lx-office-erp/users
-       chown -R www-data:www-data /usr/lib/lx-office-erp/templates
-       chown www-data:www-data /etc/lx-office-erp/lx-erp.conf
-       chown www-data:www-data /usr/lib/lx-office-erp/menu.ini
-       chown www-data:www-data /etc/lx-office-erp/authentication.pl
-       chmod 0600 /etc/lx-office-erp/lx-erp.conf
-       chmod 0600 /etc/lx-office-erp/authentication.pl
+  chown -R www-data:www-data /usr/lib/lx-office-erp/users
+  chown -R www-data:www-data /usr/lib/lx-office-erp/templates
+  chown www-data:www-data /etc/lx-office-erp/lx_office.conf
+  chown www-data:www-data /usr/lib/lx-office-erp/menu.ini
+  chmod 0600 /etc/lx-office-erp/lx_office.conf
 }
 
-disable_ipv6_on_lo_interface() {
-       # 2009-04-25
-        # Perls Libraries are not yet ipv6 read
-        echo "WICHTIG: ipv6 ist nunmehr auf dem Loopback-Interface deaktiviert, um die Funktionsfähigkeit von Lx-Office-ERP zu gewährleisten!"
-        ifconfig lo inet6 del ::1/128 2> /dev/null || true
-
-       # make the changes permanent (triggered on next reboot)
-       RCLOCAL="/etc/rc.local"
-       echo "# lx-office-erp: Perl libraries are not yet fully ipv6-ready" >> $RCLOCAL
-       echo "ifconfig lo inet6 del ::1/128" >> $RCLOCAL
-
-}
 mk_new_menu() {
-    if [ -e /usr/lib/lx-office-crm ] ; then 
+  if [ -e /usr/lib/lx-office-crm ] ; then
         #crm vorhanden, dann die menu.ini mit der höchsten VersNr nehmen
-        for i in `ls -1 /usr/lib/lx-office-crm/update/menu*ini` ; do 
-            cat $i > /usr/lib/lx-office-erp/menu.ini
-        done;
-        cat /usr/lib/lx-office-erp/menu.default >> /usr/lib/lx-office-erp/menu.ini
-    else
-        cp /usr/lib/lx-office-erp/menu.default /usr/lib/lx-office-erp/menu.ini
-    fi
-}  
+    for i in `ls -1 /usr/lib/lx-office-crm/update/menu*ini` ; do
+      cat $i > /usr/lib/lx-office-erp/menu.ini
+    done;
+    cat /usr/lib/lx-office-erp/menu.default >> /usr/lib/lx-office-erp/menu.ini
+  else
+    cp /usr/lib/lx-office-erp/menu.default /usr/lib/lx-office-erp/menu.ini
+  fi
+}
 
 mk_new_config() {
-    if ! [ -f /etc/lx-office-erp/lx-erp.conf ] ; then
-        cp /etc/lx-office-erp/lx-erp.conf.default /etc/lx-office-erp/lx-erp.conf
-    fi
-    if ! [ -f /etc/lx-office-erp/console.conf ] ; then
-        cp /etc/lx-office-erp/console.conf.default /etc/lx-office-erp/console.conf
-    fi
-}  
+  if ! [ -f /etc/lx-office-erp/lx_office.conf ] ; then
+    cp /etc/lx-office-erp/lx_office.conf.default /etc/lx-office-erp/lx_office.conf
+  fi
+}
 
 mk_links() {
-    if ! [ -f /usr/lib/lx-office-erp/config/authentication.pl ] ; then
-        ln -s /etc/lx-office-erp/authentication.pl /usr/lib/lx-office-erp/config/authentication.pl
-    fi;
-    if ! [ -f /usr/lib/lx-office-erp/config/lx-erp.conf ] ; then
-        ln -s /etc/lx-office-erp/lx-erp.conf /usr/lib/lx-office-erp/config/lx-erp.conf
-    fi;
-    if ! [ -f /usr/lib/lx-office-erp/config/console.conf ] ; then
-        ln -s /etc/lx-office-erp/console.conf /usr/lib/lx-office-erp/config/console.conf
-    fi;
-    if [ -e /etc/apache2 ] ; then 
-        if ! [ -f /etc/apache2/conf.d/lx-office-erp.apache2.conf ] ; then
-            ln -s /etc/lx-office-erp/lx-office-erp.apache2.conf /etc/apache2/conf.d/lx-office-erp.apache2.conf
-        fi;
+  for file in lx_office.conf lx_office.conf.default ; do
+    test -f /usr/lib/lx-office-erp/config/${file} || ln -s /etc/lx-office-erp/${file} /usr/lib/lx-office-erp/config/${file}
+  done
+  for file in lx-erp.conf authentication.pl ; do
+    if [ -f /usr/lib/lx-office-erp/config/${file} ] ; then
+      rm /usr/lib/lx-office-erp/config/${file}
+    fi
+  done
+  if [ -e /etc/apache2 ] ; then
+    if ! [ -f /etc/apache2/conf.d/lx-office-erp.apache2.conf ] ; then
+      ln -s /etc/lx-office-erp/lx-office-erp.apache2.conf /etc/apache2/conf.d/lx-office-erp.apache2.conf
     fi;
-    if [ -e /etc/cherokee/sites-available ] ; then 
-        if ! [ -f /etc/cherokee/sites-available/lx-office-erp.cherokee ] ; then
-            cat /etc/lx-office-erp/lx-office-erp.cherokee.handler >> /etc/cherokee/sites-available/default
-            ln -s /etc/lx-office-erp/lx-office-erp.cherokee /etc/cherokee/sites-available/lx-office-erp.cherokee
-        fi;
+  fi;
+  if [ -e /etc/cherokee/sites-available ] ; then
+    if ! [ -f /etc/cherokee/sites-available/lx-office-erp.cherokee ] ; then
+      cat /etc/lx-office-erp/lx-office-erp.cherokee.handler >> /etc/cherokee/sites-available/default
+      ln -s /etc/lx-office-erp/lx-office-erp.cherokee /etc/cherokee/sites-available/lx-office-erp.cherokee
     fi;
-    if [ -e /etc/lighttpd ] ; then 
-        if ! [ -f /etc/lighttpd/conf-enabled/lx-office-erp.lighttpd ] ; then
-            ln -s /etc/lx-office-erp/lx-office-erp.lighttpd /etc/lighttpf/conf-enabled/10-lx-office-erp
-        fi;
+  fi;
+  if [ -e /etc/lighttpd ] ; then
+    if ! [ -f /etc/lighttpd/conf-enabled/lx-office-erp.lighttpd ] ; then
+      ln -s /etc/lx-office-erp/lx-office-erp.lighttpd /etc/lighttpf/conf-enabled/10-lx-office-erp
     fi;
+  fi;
 }
-reload_web_server() {
-    if [ -f /etc/init.d/apache* ] ; then 
-            /etc/init.d/apache* reload
-    fi
-    if [ -f /etc/init.d/cherokee ] ; then 
-            /etc/init.d/cherokee reload
-    fi
-    if [ -f /etc/init.d/lighttpd ] ; then 
-            /etc/init.d/lighttpd reload
+web_server_ctrl() {
+  local action=$1
+  if [ -x "/etc/init.d/apache2" ]; then
+    if [ -x /usr/sbin/invoke-rc.d ]; then
+      invoke-rc.d apache2 $action ||true
+    else
+      /etc/init.d/apache2 $action ||true
     fi
+  fi
+  if [ -f /etc/init.d/cherokee ] ; then
+    /etc/init.d/cherokee $action || true
+  fi
+  if [ -f /etc/init.d/lighttpd ] ; then
+    /etc/init.d/lighttpd $action || true
+  fi
+
+  # if [ $action = restart ] ; then
+  #   echo Sleeping
+  #   sleep 5
+  #   echo Awake
+  # fi
 }
+
+enable_fcgi() {
+  if [ -x /usr/sbin/a2enmod -a -f /usr/lib/apache2/modules/mod_fcgid.so ] ; then
+    /usr/sbin/a2enmod fcgid
+    # web_server_ctrl restart
+  fi
+}
+
 case "$1" in
 
-    upgrade)
-        echo " ! "`date`" $1 !" >> /tmp/lxo-erp.log
-
-        VER=`cat /var/www/lx-office-erp/VERSION | cut -d '.' -f2`
-        if [ $VER = '6' ]; then
-            echo " ! 2.6 !" >> /tmp/lxo-erp.log
-            echo "Version 2.6"
-            mk_new_menu
-        else
-            mk_new_menu
-            mk_new_config
-            config_postgresql_factory_script
-            set_lx_office_erp_web_admin_password
-            set_lx_office_erp_authentication_db_user
-            set_lx_office_erp_authentication_db_password
-               disable_ipv6_on_lo_interface
-            mk_links
-        fi;
-
-        set_user_rights
-        reload_web_server
+  upgrade)
+    echo " ! "`date`" $1 !" >> $debugfile
+
+    enable_fcgi
+
+    VER=`cat /var/www/lx-office-erp/VERSION | cut -d '.' -f2`
+    if [ $VER = '6' ]; then
+      echo " ! 2.6 !" >> $debugfile
+      echo "Version 2.6.x"
+      mk_new_menu
+    else
+      mk_new_menu
+      mk_new_config
+      config_postgresql_factory_script
+      set_lx_office_erp_web_admin_password
+      set_lx_office_erp_authentication_db_user_password
+      mk_links
+    fi;
+
+    set_user_rights
+    ps auxw
+
+    db_stop || true
+    web_server_ctrl restart
+
     ;;
 
-    install|configure)
-        echo " ! "`date`" $1 !" >> /tmp/lxo-erp.log
-        
-        mk_new_menu
-        mk_new_config
-        config_postgresql_factory_script
-        set_lx_office_erp_web_admin_password
-        set_lx_office_erp_authentication_db_user
-        set_lx_office_erp_authentication_db_password
-        disable_ipv6_on_lo_interface
-        mk_links
-
-        set_user_rights
-        reload_web_server
+  install|configure)
+    echo " ! "`date`" $1 !" >> $debugfile
+
+    enable_fcgi
+
+    mk_new_menu
+    mk_new_config
+    config_postgresql_factory_script
+    set_lx_office_erp_web_admin_password
+    set_lx_office_erp_authentication_db_user_password
+    mk_links
+
+    set_user_rights
+
+    db_stop || true
+    web_server_ctrl restart
 
     ;;
 
-    abort-upgrade|abort-remove|abort-deconfigure)
+  abort-upgrade|abort-remove|abort-deconfigure)
     ;;
 
-    *)
-        echo "postinst called with unknown argument \`$1'" >&2
-        exit 1
+  *)
+    echo "postinst called with unknown argument \`$1'" >&2
+    exit 1
     ;;
 esac
 
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-
 echo "done!!"
 
 exit 0