5    tput cup $1 $2  # Cursor positionieren
 
   6    tput el         # Rest der Zeile löschen
 
   7    shift 2         # Parameter für die Koordinaten entfernen
 
   8    echo -n $*" "   # Rest der Parameterliste ausgeben
 
  14 if [ `id -u` -gt 0 ]; then echo "Bitte als root anmelden"; exit 1; fi
 
  16 writeln 1 1 PostgreSQL fuer Lx-Office vorbereiten
 
  17 writeln 2 1 1. plpgsql.so suchen
 
  19 #Datei plpgsql.so suchen
 
  21 #Mit Paketmanager (RPM oder APT) suchen
 
  22 #PLPGSQL=`dpkg -L postgresql | grep plpgsql.so`
 
  23 #PLPGSQL=`rpm -q --list postgres | grep plpgsql.so`
 
  25 if [ "$PLPGSQL#" == "#" ]; then
 
  26         #Probleme mit Paketmanager, dann zunaechst mit locate, geht schneller
 
  28         tmp=`locate plpgsql.so 2>/dev/null`
 
  29         PLPGSQL=`echo $tmp | cut -d " " -f 1`
 
  31 if [ "$PLPGSQL#" == "#" ]; then
 
  32         #noch nicht gefunden, also mit find suchen
 
  33         writeln 3 15 --find /usr/lib
 
  34         tmp=`find /usr/lib -name  plpgsql.so -type f`
 
  35         PLPGSQL=`echo $tmp | cut -d " " -f 1`
 
  37 if [ "$PLPGSQL#" == "#" ]; then
 
  39                 writeln 4 1 'plpgsql.so' nicht gefunden.
 
  41                 writeln 5 1 "Bitte den Pfad eingeben: "
 
  44                 [ "$PLPGSQL#" != "#" ] && [ -f $PLPGSQL ] && break
 
  48 writeln 6 1 ok. 'plpgsql.so' gefunden
 
  50 #Kann der User postgres die db erreichen
 
  51 cnt=`ps aux | grep postgres | wc -l`
 
  52 if [ $cnt -eq 0 ]; then
 
  55         echo Die postgreSQL-Datebbank ist nicht gestartet!
 
  59 v7=`su postgres -c "echo 'select version()' | psql template1 2>/dev/null | grep -E "[Ss][Qq][Ll][[:space:]]+7\.[0-9]\.[0-9]" | wc -l"`
 
  60 v8=`su postgres -c "echo 'select version()' | psql template1 2>/dev/null | grep -E "[Ss][Qq][Ll][[:space:]]+8\.[0-9]\.[0-9]" | wc -l"`
 
  61 #cnt=`echo  $v7 + $v8 | bc -l`
 
  62 if [ $v8 -eq 0 ]; then 
 
  63         if [ $v7 -eq 0 ]; then
 
  66                 echo User postgres konnte die Datenbank nicht ansprechen
 
  71                 writeln 1 1 Datenbank Version 7x konnte erreicht werden.
 
  75         writeln 1 1 Datenbank Version 8x konnte erreicht werden.
 
  78 echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler" > lxdbinst.sql
 
  79 echo "AS '$PLPGSQL', 'plpgsql_call_handler'" >> lxdbinst.sql
 
  80 echo "LANGUAGE c;" >> lxdbinst.sql
 
  81 echo "CREATE PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;" >> lxdbinst.sql
 
  83 writeln 2 1 Datenbankbenutzer einrichten
 
  85 writeln 3 1 "Bitte den Datenbank-Benutzernamen (Kleinbuchstaben) eingeben [lxoffice]: "
 
  88 if [ "$LXOUSER#" == "#" ]; then LXOUSER="lxoffice"; fi
 
  91         writeln 4 1 "Bitte ein Kennwort eingeben : "
 
  94         if ! [ "$USRPWD#" == "#" ]; then break; fi
 
  98 echo "CREATE USER $LXOUSER with CREATEDB ;" >> lxdbinst.sql
 
  99 echo "ALTER USER $LXOUSER PASSWORD '$USRPWD';" >> lxdbinst.sql
 
 100 echo "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpgsql';" >> lxdbinst.sql
 
 102 su postgres -c "psql template1 < lxdbinst.sql"
 
 104 echo "Fehlermeldungen die 'already exists' enthalten koennen ignoriert werden"
 
 106 writeln 11 1 Datenbank fuer Lx-Office vorbereitet
 
 108 writeln 12 1 Datenbankberechtigung einrichten
 
 109 #wo ist die pg_hba.conf
 
 110 writeln 13 3 --find erst /etc dann /var/lib
 
 111 tmp=`find /etc -name pg_hba.conf -type f`
 
 112 [ "$tmp#" == "#" ] && tmp=`find /var/lib -name  pg_hba.conf -type f`
 
 113 PGHBA=`echo $tmp | cut -d " " -f 1`
 
 115 if [ "$PGHBA#" == "#" ]; then
 
 117                 writeln 14 1 'pg_hba.conf' nicht gefunden.
 
 119                 writeln 15 1 "Bitte den Pfad eingeben: "
 
 122                 [ "$PGHBA#" != "#" ] && [ -f $PGHBA ] && break
 
 126 writeln 16 1 ok. 'pg_hba.conf' gefunden
 
 128 cnt=`grep $LXOUSER $PGHBA | wc -l `
 
 130 if [ $cnt -eq 0 ]; then 
 
 132         echo "local   all         $LXOUSER                                           password" > $PGHBA
 
 133         echo "host    all         $LXOUSER      127.0.0.1         255.255.255.255    password" >> $PGHBA
 
 134         cat $PGHBA.org >> $PGHBA
 
 137 CONFDIR=`dirname $PGHBA`
 
 139 #postgresql.conf anpassen, liegt vermutlich im gleichen Verzeichnis wie pg_hba.conf
 
 140 if ! [ -f $CONFDIR/postgresql.conf ]; then
 
 141         #doch nicht da, dann fragen
 
 143                 writeln 13 1 'postgresql.conf' nicht gefunden.
 
 145                 writeln 14 1 "Bitte den Pfad eingeben: "
 
 148                 [ "$PGCONF#" != "#" ] && [ -f $PGCONF ] && break
 
 151         CONFDIR=`dirname $PGCONF`
 
 154 mv $CONFDIR/postgresql.conf $CONFDIR/postgresql.conf.org
 
 155 if ! [ $v7 -eq 0 ]; then 
 
 156         #Nur bei der V7.x:  tcpip_socket = true
 
 157         sed 's/^.*tcpip_socket.*/tcpip_socket = true/i' $CONFDIR/postgresql.conf.org > $CONFDIR/postgresql.conf
 
 158         cnt=`grep tcpip_socket $CONFDIR/postgresql.conf | wc -l`
 
 159         if [ $cnt -eq 0 ]; then
 
 160                 cp $CONFDIR/postgresql.conf.org $CONFDIR/postgresql.conf
 
 161                 echo "tcpip_socket = true" >> $CONFDIR/postgresql.conf
 
 164         #Bei der V8.x OID einschalten.
 
 165         sed 's/^.*default_with_oids.*/default_with_oids = true/i' $CONFDIR/postgresql.conf.org > $CONFDIR/postgresql.conf
 
 166         cnt=`grep default_with_oids $CONFDIR/postgresql.conf | wc -l`
 
 167         if [ $cnt -eq 0 ]; then
 
 168                 cp $CONFDIR/postgresql.conf.org $CONFDIR/postgresql.conf
 
 169                 echo "default_with_oids = true" >> $CONFDIR/postgresql.conf
 
 174 tmp=`ls /etc/init.d/postgres*`
 
 175 PGSQL=`echo $tmp | cut -d " " -f 1`
 
 177 writeln 18 1 Datenbank neu starten
 
 182 writeln 20 12 ok. Das sollte es gewesen sein.