Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 96a5b393

Von Moritz Bunkus vor mehr als 12 Jahren hinzugefügt

  • ID 96a5b393976dd5c772d8610001be81eb6dda4259
  • Vorgänger adc9b96c
  • Nachfolger 008c2e15

Nicht mehr benutzte Scripte entfernen

Unterschiede anzeigen:

scripts/inst_postgres.sh
#!/bin/bash
#set -x
function writeln()
{
tput cup $1 $2 # Cursor positionieren
tput el # Rest der Zeile löschen
shift 2 # Parameter für die Koordinaten entfernen
echo -n $*" " # Rest der Parameterliste ausgeben
}
tput clear
#Als root anmelden
if [ `id -u` -gt 0 ]; then echo "Bitte als root anmelden"; exit 1; fi
writeln 1 1 PostgreSQL fuer Lx-Office vorbereiten
writeln 2 1 1. plpgsql.so suchen
PLPGSQL=""
#Datei plpgsql.so suchen
POSTGRESQL=`dpkg -l | grep -E "postgresql-[0-9]" | cut -d" " -f3 | sort -r | head -1 -`
#Mit Paketmanager (Apt) suchen
if [ "$POSTGRESQL#" == "#" ]; then
writeln 1 1 $FEHLER
writeln 2 1 Keine PostgreSQL mit Paketmanager installiert
writeln 3 1 Datenbank bitte manuell einrichten.
exit 0
else
PLPGSQL=`dpkg -L $POSTGRESQL | grep plpgsql.so`
fi
#Mit Paketmanager (RPM) suchen ?
#PLPGSQL=`rpm -q --list postgres | grep plpgsql.so`
if [ "$PLPGSQL#" == "#" ]; then
#Probleme mit Paketmanager, dann zunaechst mit locate, geht schneller
updatedb
writeln 3 3 --locate
tmp=`locate plpgsql.so 2>/dev/null`
PLPGSQL=`echo $tmp | cut -d " " -f 1`
fi
if [ "$PLPGSQL#" == "#" ]; then
#noch nicht gefunden, also mit find suchen
writeln 3 15 --find /usr/lib
tmp=`find /usr/lib -name plpgsql.so -type f`
PLPGSQL=`echo $tmp | cut -d " " -f 1`
fi
if [ "$PLPGSQL#" == "#" ]; then
while :; do
writeln 4 1 'plpgsql.so' nicht gefunden.
tput bold
writeln 5 1 "Bitte den Pfad eingeben: "
tput rmso
read PLPGSQL
[ "$PLPGSQL#" != "#" ] && [ -f $PLPGSQL ] && break
tput bel
done
fi
writeln 6 1 ok. 'plpgsql.so' gefunden
#Kann der User postgres die db erreichen
cnt=`ps aux | grep postgres | wc -l`
if [ $cnt -eq 0 ]; then
tput bel
tput bold
echo Die postgreSQL-Datebbank ist nicht gestartet!
tput rmso
exit 1
fi
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"`
if [ $v8 -eq 0 ]; then
tput bel
tput bold
echo User postgres konnte die Datenbank 8.2.x - 8.9.x nicht ansprechen
tput rmso
exit 1;
else
tput clear
writeln 1 1 Datenbank Version 8.2.x - 8.9.x konnte erreicht werden.
fi
echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler" > lxdbinst.sql
echo "AS '$PLPGSQL', 'plpgsql_call_handler'" >> lxdbinst.sql
echo "LANGUAGE c;" >> lxdbinst.sql
echo "CREATE PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;" >> lxdbinst.sql
writeln 2 1 Datenbankbenutzer einrichten
tput bold
writeln 3 1 "Bitte den Datenbank-Benutzernamen (Kleinbuchstaben) eingeben [lxoffice]: "
tput rmso
read LXOUSER
if [ "$LXOUSER#" == "#" ]; then LXOUSER="lxoffice"; fi
while :; do
tput bold
writeln 4 1 "Bitte ein Kennwort eingeben : "
tput rmso
read USRPWD
if ! [ "$USRPWD#" == "#" ]; then break; fi
tput bel
done;
echo "CREATE USER $LXOUSER with CREATEDB ;" >> lxdbinst.sql
echo "ALTER USER $LXOUSER PASSWORD '$USRPWD';" >> lxdbinst.sql
echo "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpgsql';" >> lxdbinst.sql
su postgres -c "psql template1 < lxdbinst.sql"
echo "Fehlermeldungen die 'already exists' enthalten koennen ignoriert werden"
writeln 11 1 Datenbank fuer Lx-Office vorbereitet
writeln 12 1 Datenbankberechtigung einrichten
#wo ist die pg_hba.conf
writeln 13 3 --find erst /etc dann /var/lib
tmp=`find /etc/postgresql -name pg_hba.conf -type f`
[ "$tmp#" == "#" ] && tmp=`find /var/lib -name pg_hba.conf -type f`
PGHBA=`echo $tmp | cut -d " " -f 1`
if [ "$PGHBA#" == "#" ]; then
while :; do
writeln 14 1 'pg_hba.conf' nicht gefunden.
tput bold
writeln 15 1 "Bitte den Pfad eingeben: "
tput rmso
read PGHBA
[ "$PGHBA#" != "#" ] && [ -f $PGHBA ] && break
tput bel
done
fi
writeln 16 1 ok. 'pg_hba.conf' gefunden
cnt=`grep $LXOUSER $PGHBA | wc -l `
if [ $cnt -eq 0 ]; then
mv $PGHBA $PGHBA.org
echo "local all $LXOUSER password" > $PGHBA
echo "host all $LXOUSER 127.0.0.1 255.255.255.255 password" >> $PGHBA
cat $PGHBA.org >> $PGHBA
fi
#CONFDIR=`dirname $PGHBA`
#postgresql.conf anpassen, liegt vermutlich im gleichen Verzeichnis wie pg_hba.conf
#if ! [ -f $CONFDIR/postgresql.conf ]; then
# #doch nicht da, dann fragen
# while :; do
# writeln 13 1 'postgresql.conf' nicht gefunden.
# tput bold
# writeln 14 1 "Bitte den Pfad eingeben: "
# tput rmso
# read PGCONF
# [ "$PGCONF#" != "#" ] && [ -f $PGCONF ] && break
# tput bel
# done
# CONFDIR=`dirname $PGCONF`
#fi
#mv $CONFDIR/postgresql.conf $CONFDIR/postgresql.conf.org
#Bei der V8.x OID einschalten.
#sed 's/^.*default_with_oids.*/default_with_oids = true/i' $CONFDIR/postgresql.conf.org > $CONFDIR/postgresql.conf
#cnt=`grep default_with_oids $CONFDIR/postgresql.conf | wc -l`
#if [ $cnt -eq 0 ]; then
# cp $CONFDIR/postgresql.conf.org $CONFDIR/postgresql.conf
# echo "default_with_oids = true" >> $CONFDIR/postgresql.conf
#fi
tmp=`ls -r1 /etc/init.d/postgres*`
PGSQL=`echo $tmp | cut -d " " -f 1`
writeln 18 1 Datenbank neu starten
$PGSQL restart
tput bold
tput smso
writeln 20 12 ok. Das sollte es gewesen sein.
tput rmso
tput rmso
echo
scripts/inst_postgres_deb.sh
#!/bin/bash
# e = exit on error
set -e
# x = xtrace
#set -x
FEHLER="Achtung!! Es hat ein Problem gegeben"
ERRCNT=0
source /usr/share/debconf/confmodule
#Als root anmelden
if [ `id -u` -gt 0 ]; then echo "Bitte als root anmelden"; exit 1; fi
POSTGRESQL=`dpkg -l | grep -E "postgresql-[0-9]" | cut -d" " -f3 | sort -r | head -1 -`
#Datei plpgsql.so suchen
#Mit Paketmanager suchen
if [ "$POSTGRESQL#" == "#" ]; then
echo $FEHLER
echo Keine PostgreSQL mit Paketmanager installiert
echo Datenbank bitte manuell einrichten.
exit 0
else
PLPGSQL=`dpkg -L $POSTGRESQL | grep plpgsql.so `
fi
if [ "$PLPGSQL#" == "#" ]; then
#Probleme mit Paketmanager, dann zunaechst mit locate, geht schneller
updatedb
tmp=`locate plpgsql.so 2>/dev/null`
PLPGSQL=`echo $tmp | cut -d " " -f 1`
fi
if [ "$PLPGSQL#" == "#" ]; then
#noch nicht gefunden, also mit find suchen
tmp=`find /usr/lib -name plpgsql.so -type f`
PLPGSQL=`echo $tmp | cut -d " " -f 1`
fi
if [ "$PLPGSQL#" == "#" ]; then
echo $FEHLER
echo 'plpgsql.so' nicht gefunden.
echo Datenbank manuell einrichten.
exit 0
fi
#Kann der User postgres die db erreichen
cnt=`ps aux | grep postgres | wc -l`
if [ $cnt -eq 0 ]; then
echo $FEHLER
echo Die postgreSQL-Datebbank ist nicht gestartet!
echo Datenbank manuell einrichten.
exit 0
fi
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"`
if [ $v8 -eq 0 ]; then
echo $FEHLER
echo Datenbank Version 8x konnte nicht erreicht werden.
exit 0
fi
echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler" > lxdbinst.sql
echo "AS '$PLPGSQL', 'plpgsql_call_handler'" >> lxdbinst.sql
echo "LANGUAGE c;" >> lxdbinst.sql
echo "CREATE PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;" >> lxdbinst.sql
#writeln 2 1 Datenbankbenutzer einrichten
LXOUSER="lxoffice"
db_get lx-office-erp/lx-office-erp-user-postgresql-password
USRPWD="$RET"
echo "CREATE USER $LXOUSER with CREATEDB ;" >> lxdbinst.sql
echo "ALTER USER $LXOUSER PASSWORD '$USRPWD';" >> lxdbinst.sql
echo "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpgsql';" >> lxdbinst.sql
su postgres -c "psql template1 < lxdbinst.sql"
echo "Fehlermeldungen die 'already exists' enthalten koennen ignoriert werden"
#writeln 12 1 Datenbankberechtigung einrichten
PGHBA=`find /etc/postgresql -name pg_hba.conf -type f | sort -r | head -1 -`
if [ "$PGHBA#" == "#" ] ; then
PGHBA=`find /var/lib -name pg_hba.conf -type f | sort -r | head -1 -`
fi
if [ "$PGHBA#" == "#" ]; then
echo $FEHLER
echo 'pg_hba.conf' nicht gefunden.
echo "Berechtigungen bitte selber einrichten"
ERRCNT=1
fi
cnt=`grep $LXOUSER $PGHBA | wc -l `
if [ $cnt -eq 0 ]; then
mv $PGHBA $PGHBA.org
echo "local all $LXOUSER password" > $PGHBA
echo "host all $LXOUSER 127.0.0.1 255.255.255.255 password" >> $PGHBA
cat $PGHBA.org >> $PGHBA
fi
#CONFDIR=`dirname $PGHBA`
#postgresql.conf anpassen, liegt vermutlich im gleichen Verzeichnis wie pg_hba.conf
#if ! [ -f $CONFDIR/postgresql.conf ]; then
# echo $FEHLER
# echo 'postgresql.conf' nicht gefunden.
# echo PostgreSQL selber konfigurieren
# ERRCNT=1
#fi
#mv $CONFDIR/postgresql.conf $CONFDIR/postgresql.conf.org
#Bei der V8.x OID einschalten.
#sed 's/^.*default_with_oids.*/default_with_oids = true/i' $CONFDIR/postgresql.conf.org > $CONFDIR/postgresql.conf
#cnt=`grep default_with_oids $CONFDIR/postgresql.conf | wc -l`
#if [ $cnt -eq 0 ]; then
# cp $CONFDIR/postgresql.conf.org $CONFDIR/postgresql.conf
# echo "default_with_oids = true" >> $CONFDIR/postgresql.conf
#fi
PGSQL=`ls -r1 /etc/init.d/postgres* | head -1 -`
#writeln 18 1 Datenbank neu starten
$PGSQL reload
if [ $ERRCNT -gt 0 ]; then
echo $FEHLER
echo Das betrifft aber nicht die Lx-Office Installation
echo sondern die Konfiguration der Datenbank.
echo $POSTGRESQL , $PGHBA , $CONFDIR/postgresql.conf ??
sleep 10
fi
scripts/migrate_template_to_t8.pl
#!/usr/bin/perl -w
use strict;
use Pod::Usage;
use List::Util qw(reduce);
use List::MoreUtils qw(zip);
use constant DEBUG => 0;
unless ( caller(0) ) {
pod2usage(2) unless @ARGV;
migrate_file(@ARGV);
};
sub migrate_file {
my $file = shift or return;
my $contents = do { local( @ARGV, $/ ) = $file ; <> }
or die "cannot read file";
my %substitutions = (
"<translate>" => "[% '",
"</translate>" => "' | \$T8 %]",
);
my $last_match = '';
my $num_matches;
my $in_template;
my $inline_counter = 0;
# now replace <translate> with [% '
# and </translate> with ' | $T8 %]
while ($contents =~ m# ( < /? translate> | \[% | %\] ) #xg) {
my $match = $1;
my $pos = pos $contents;
if ($match eq '[%') {
$in_template = 1;
DEBUG && warn "entering [% block %] at pos $pos";
next;
}
if ($match eq '%]') {
$in_template = 0;
DEBUG && warn "leaving [% block %] at pos $pos";
next;
}
if ($in_template) {
$inline_counter++ if $match eq '<translate>';
next;
}
DEBUG && warn "found token $match at pos $pos";
my $sub_by = $substitutions{$match};
unless ($sub_by) {
DEBUG && warn "found token $& but got no substitute";
next;
}
die "unbalanced tokens - two times '$match' in file $file"
if $last_match eq $match;
$last_match = $match;
$num_matches++;
# alter string. substr is faster than s/// for strings of this size.
substr $contents, $-[0], $+[0] - $-[0], $sub_by;
# set match pos for m//g matching on the altered string.
pos $contents = $-[0] + length $sub_by;
}
warn "found $inline_counter occurances of inline translates in file $file $/"
if $inline_counter;
exit 0 unless $num_matches;
die "unbalanced tokens in file $file" if $num_matches % 2;
if ($contents !~ m/\[%-? USE T8 %\]/) {
$contents = "[%- USE T8 %]$/" . $contents;
}
# all fine? spew back
do {
open my $fh, ">$file" or die "can't write $file $!";
print $fh $contents;
};
}
1;
__END__
=head1 NAME
migrate_template_to_t8.pl - helper script to migrate templates to T8 module
=head1 SYNOPSIS
# single:
scripts/migrate_template_to_t8.pl <file>
# bash:
for file in `find templates | grep master\.html`;
do scripts/migrate_template_to_t8.pl $file;
done;
# as a lib:
require "scripts/migrate_template_to_t8.pl";
migrate_file($file);
=head1 DESCRIPTION
This script will do the following actions in a template file
=over 8
=item 1.
Change every occurance of C<<< <translate>Text</translate> >>> to C<<< [%
'Text' | $T8 %] >>>
=item 2.
Add [%- USE T8 %] at the top if something needs to be translated
=back
Note! This script is written to help with the process of migrating old
templates. It is assumed that anyone working on Lx-Office is working with a
version control system. This script will change your files. You have been
warned.
Due to the nature of the previous locale system, it is not easily possible to
migrate translates in other template blocks. As of this writing this is used in
about 20 occurances throughout the code. If such a construct is found, a
warning will be generated. lib uses of this will have to trap the warning.
=head1 DIAGNOSIS
=head2 found I<NUM> occurances of inline translates in file I<FILE>
If a processed file has <translate> blocks in template blocks, these will be
ignored. This warning is thrown at the end of processing.
=head2 unbalanced tokens in file I<FILE>
The script could not resolve pairs of <translate> </translate>s. The file will
not be changed in this case.
=head1 AUTHOR
Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
=cut

Auch abrufbar als: Unified diff