7 FEHLER="Achtung!! Es hat ein Problem gegeben"
 
   9 source /usr/share/debconf/confmodule
 
  12 if [ `id -u` -gt 0 ]; then echo "Bitte als root anmelden"; exit 1; fi
 
  14 POSTGRESQL=`dpkg -l | grep -E "postgresql-[0-9]" | cut -d" " -f3 | sort -r | head -1 -`
 
  16 #Datei plpgsql.so suchen
 
  17 #Mit Paketmanager  suchen
 
  18 if [ "$POSTGRESQL#" == "#" ]; then
 
  20     echo Keine PostgreSQL mit Paketmanager installiert
 
  21     echo Datenbank bitte manuell einrichten.
 
  24    PLPGSQL=`dpkg -L $POSTGRESQL | grep plpgsql.so `
 
  27 if [ "$PLPGSQL#" == "#" ]; then
 
  28     #Probleme mit Paketmanager, dann zunaechst mit locate, geht schneller
 
  30     tmp=`locate plpgsql.so 2>/dev/null`
 
  31     PLPGSQL=`echo $tmp | cut -d " " -f 1`
 
  33 if [ "$PLPGSQL#" == "#" ]; then
 
  34     #noch nicht gefunden, also mit find suchen
 
  35     tmp=`find /usr/lib -name  plpgsql.so -type f`
 
  36     PLPGSQL=`echo $tmp | cut -d " " -f 1`
 
  38 if [ "$PLPGSQL#" == "#" ]; then
 
  40     echo  'plpgsql.so' nicht gefunden.
 
  41     echo Datenbank manuell einrichten.
 
  45 #Kann der User postgres die db erreichen
 
  46 cnt=`ps aux | grep postgres | wc -l`
 
  47 if [ $cnt -eq 0 ]; then
 
  49     echo Die postgreSQL-Datebbank ist nicht gestartet!
 
  50     echo Datenbank manuell einrichten.
 
  54 v8=`su postgres -c "echo 'select version()' | psql template1 2>/dev/null | grep -E "[Ss][Qq][Ll][[:space:]]+8\.[2-9]\.[0-9]" | wc -l"`
 
  55 if [ $v8 -eq 0 ]; then 
 
  57     echo Datenbank Version 8x konnte nicht erreicht werden.
 
  61 echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler" > lxdbinst.sql
 
  62 echo "AS '$PLPGSQL', 'plpgsql_call_handler'" >> lxdbinst.sql
 
  63 echo "LANGUAGE c;" >> lxdbinst.sql
 
  64 echo "CREATE PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;" >> lxdbinst.sql
 
  66 #writeln 2 1 Datenbankbenutzer einrichten
 
  68 db_get lx-office-erp/lx-office-erp-user-postgresql-password
 
  71 echo "CREATE USER $LXOUSER with CREATEDB ;" >> lxdbinst.sql
 
  72 echo "ALTER USER $LXOUSER PASSWORD '$USRPWD';" >> lxdbinst.sql
 
  73 echo "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpgsql';" >> lxdbinst.sql
 
  75 su postgres -c "psql template1 < lxdbinst.sql"
 
  77 echo "Fehlermeldungen die 'already exists' enthalten koennen ignoriert werden"
 
  79 #writeln 12 1 Datenbankberechtigung einrichten
 
  80 PGHBA=`find /etc/postgresql -name pg_hba.conf -type f | sort -r | head -1 -`
 
  81 if [ "$PGHBA#" == "#" ] ; then
 
  82    PGHBA=`find /var/lib -name  pg_hba.conf -type f | sort -r | head -1 -`
 
  85 if [ "$PGHBA#" == "#" ]; then
 
  87     echo 'pg_hba.conf' nicht gefunden.
 
  88     echo "Berechtigungen bitte selber einrichten"
 
  92 cnt=`grep $LXOUSER $PGHBA | wc -l `
 
  94 if [ $cnt -eq 0 ]; then 
 
  96     echo "local   all         $LXOUSER                                           password" > $PGHBA
 
  97     echo "host    all         $LXOUSER      127.0.0.1         255.255.255.255    password" >> $PGHBA
 
  98     cat $PGHBA.org >> $PGHBA
 
 101 CONFDIR=`dirname $PGHBA`
 
 103 #postgresql.conf anpassen, liegt vermutlich im gleichen Verzeichnis wie pg_hba.conf
 
 104 if ! [ -f $CONFDIR/postgresql.conf ]; then
 
 106     echo 'postgresql.conf' nicht gefunden.
 
 107     echo PostgreSQL selber konfigurieren
 
 111 mv $CONFDIR/postgresql.conf $CONFDIR/postgresql.conf.org
 
 112 #Bei der V8.x OID einschalten.
 
 113 sed 's/^.*default_with_oids.*/default_with_oids = true/i' $CONFDIR/postgresql.conf.org > $CONFDIR/postgresql.conf
 
 114 cnt=`grep default_with_oids $CONFDIR/postgresql.conf | wc -l`
 
 115 if [ $cnt -eq 0 ]; then
 
 116         cp $CONFDIR/postgresql.conf.org $CONFDIR/postgresql.conf
 
 117         echo "default_with_oids = true" >> $CONFDIR/postgresql.conf
 
 121 PGSQL=`ls -r1 /etc/init.d/postgres*  | head -1 -`
 
 123 #writeln 18 1 Datenbank neu starten
 
 126 if [ $ERRCNT -gt 0 ]; then
 
 128     echo Das betrifft aber nicht die Lx-Office Installation
 
 129     echo sondern die Konfiguration der Datenbank.
 
 130     echo $POSTGRESQL , $PGHBA , $CONFDIR/postgresql.conf ??