Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 96a5b393

Von Moritz Bunkus vor fast 12 Jahren hinzugefügt

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

Nicht mehr benutzte Scripte entfernen

Unterschiede anzeigen:

scripts/inst_postgres.sh
1
#!/bin/bash
2
#set -x
3
function writeln()
4
{
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
9
}
10

  
11
tput clear
12

  
13
#Als root anmelden
14
if [ `id -u` -gt 0 ]; then echo "Bitte als root anmelden"; exit 1; fi
15

  
16
writeln 1 1 PostgreSQL fuer Lx-Office vorbereiten
17
writeln 2 1 1. plpgsql.so suchen
18
PLPGSQL=""
19
#Datei plpgsql.so suchen
20

  
21
POSTGRESQL=`dpkg -l | grep -E "postgresql-[0-9]" | cut -d" " -f3 | sort -r | head -1 -`
22

  
23
#Mit Paketmanager (Apt) suchen
24
if [ "$POSTGRESQL#" == "#" ]; then
25
    writeln 1 1 $FEHLER
26
    writeln 2 1 Keine PostgreSQL mit Paketmanager installiert
27
    writeln 3 1 Datenbank bitte manuell einrichten.
28
    exit 0
29
else
30
   PLPGSQL=`dpkg -L $POSTGRESQL | grep plpgsql.so`
31
fi
32

  
33
#Mit Paketmanager (RPM) suchen ?
34
#PLPGSQL=`rpm -q --list postgres | grep plpgsql.so`
35

  
36
if [ "$PLPGSQL#" == "#" ]; then
37
	#Probleme mit Paketmanager, dann zunaechst mit locate, geht schneller
38
	updatedb
39
	writeln 3 3 --locate
40
	tmp=`locate plpgsql.so 2>/dev/null`
41
	PLPGSQL=`echo $tmp | cut -d " " -f 1`
42
fi
43
if [ "$PLPGSQL#" == "#" ]; then
44
	#noch nicht gefunden, also mit find suchen
45
	writeln 3 15 --find /usr/lib
46
	tmp=`find /usr/lib -name  plpgsql.so -type f`
47
	PLPGSQL=`echo $tmp | cut -d " " -f 1`
48
fi	
49
if [ "$PLPGSQL#" == "#" ]; then
50
	while :; do
51
		writeln 4 1 'plpgsql.so' nicht gefunden.
52
		tput bold
53
   		writeln 5 1 "Bitte den Pfad eingeben: "
54
		tput rmso
55
   		read PLPGSQL
56
   		[ "$PLPGSQL#" != "#" ] && [ -f $PLPGSQL ] && break
57
   		tput bel
58
	done
59
fi
60
writeln 6 1 ok. 'plpgsql.so' gefunden
61

  
62
#Kann der User postgres die db erreichen
63
cnt=`ps aux | grep postgres | wc -l`
64
if [ $cnt -eq 0 ]; then
65
	tput bel
66
	tput bold
67
	echo Die postgreSQL-Datebbank ist nicht gestartet!
68
	tput rmso
69
	exit 1
70
fi
71
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"`
72
if [ $v8 -eq 0 ]; then 
73
	tput bel
74
	tput bold
75
	echo User postgres konnte die Datenbank 8.2.x -  8.9.x nicht ansprechen
76
	tput rmso
77
	exit 1; 
78
else
79
	tput clear
80
	writeln 1 1 Datenbank Version 8.2.x - 8.9.x konnte erreicht werden.
81
fi
82

  
83
echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler" > lxdbinst.sql
84
echo "AS '$PLPGSQL', 'plpgsql_call_handler'" >> lxdbinst.sql
85
echo "LANGUAGE c;" >> lxdbinst.sql
86
echo "CREATE PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;" >> lxdbinst.sql
87

  
88
writeln 2 1 Datenbankbenutzer einrichten
89
tput bold
90
writeln 3 1 "Bitte den Datenbank-Benutzernamen (Kleinbuchstaben) eingeben [lxoffice]: "
91
tput rmso
92
read LXOUSER
93
if [ "$LXOUSER#" == "#" ]; then LXOUSER="lxoffice"; fi
94
while :; do
95
	tput bold
96
	writeln 4 1 "Bitte ein Kennwort eingeben : "
97
	tput rmso
98
	read USRPWD
99
	if ! [ "$USRPWD#" == "#" ]; then break; fi
100
	tput bel
101
done;
102

  
103
echo "CREATE USER $LXOUSER with CREATEDB ;" >> lxdbinst.sql
104
echo "ALTER USER $LXOUSER PASSWORD '$USRPWD';" >> lxdbinst.sql
105
echo "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpgsql';" >> lxdbinst.sql
106

  
107
su postgres -c "psql template1 < lxdbinst.sql"
108

  
109
echo "Fehlermeldungen die 'already exists' enthalten koennen ignoriert werden"
110

  
111
writeln 11 1 Datenbank fuer Lx-Office vorbereitet
112

  
113
writeln 12 1 Datenbankberechtigung einrichten
114
#wo ist die pg_hba.conf
115
writeln 13 3 --find erst /etc dann /var/lib
116
tmp=`find /etc/postgresql -name pg_hba.conf -type f`
117
[ "$tmp#" == "#" ] && tmp=`find /var/lib -name  pg_hba.conf -type f`
118
PGHBA=`echo $tmp | cut -d " " -f 1`
119

  
120
if [ "$PGHBA#" == "#" ]; then
121
	while :; do
122
		writeln 14 1 'pg_hba.conf' nicht gefunden.
123
		tput bold
124
   		writeln 15 1 "Bitte den Pfad eingeben: "
125
		tput rmso
126
   		read PGHBA
127
   		[ "$PGHBA#" != "#" ] && [ -f $PGHBA ] && break
128
   		tput bel
129
	done
130
fi
131
writeln 16 1 ok. 'pg_hba.conf' gefunden
132

  
133
cnt=`grep $LXOUSER $PGHBA | wc -l `
134

  
135
if [ $cnt -eq 0 ]; then 
136
	mv $PGHBA  $PGHBA.org
137
	echo "local   all         $LXOUSER                                           password" > $PGHBA
138
	echo "host    all         $LXOUSER      127.0.0.1         255.255.255.255    password" >> $PGHBA
139
	cat $PGHBA.org >> $PGHBA
140
fi 
141

  
142
#CONFDIR=`dirname $PGHBA`
143

  
144
#postgresql.conf anpassen, liegt vermutlich im gleichen Verzeichnis wie pg_hba.conf
145
#if ! [ -f $CONFDIR/postgresql.conf ]; then
146
#	#doch nicht da, dann fragen
147
#        while :; do
148
#		writeln 13 1 'postgresql.conf' nicht gefunden.
149
#		tput bold
150
#                writeln 14 1 "Bitte den Pfad eingeben: "
151
#		tput rmso
152
#                read PGCONF
153
#                [ "$PGCONF#" != "#" ] && [ -f $PGCONF ] && break
154
#                tput bel
155
#        done
156
#	CONFDIR=`dirname $PGCONF`
157
#fi
158

  
159
#mv $CONFDIR/postgresql.conf $CONFDIR/postgresql.conf.org
160
#Bei der V8.x OID einschalten.
161
#sed 's/^.*default_with_oids.*/default_with_oids = true/i' $CONFDIR/postgresql.conf.org > $CONFDIR/postgresql.conf
162
#cnt=`grep default_with_oids $CONFDIR/postgresql.conf | wc -l`
163
#if [ $cnt -eq 0 ]; then
164
#	cp $CONFDIR/postgresql.conf.org $CONFDIR/postgresql.conf
165
#	echo "default_with_oids = true" >> $CONFDIR/postgresql.conf
166
#fi
167
 
168
tmp=`ls -r1 /etc/init.d/postgres*`
169
PGSQL=`echo $tmp | cut -d " " -f 1`
170

  
171
writeln 18 1 Datenbank neu starten
172
$PGSQL restart
173

  
174
tput bold
175
tput smso
176
writeln 20 12 ok. Das sollte es gewesen sein.
177
tput rmso
178
tput rmso
179
echo 
scripts/inst_postgres_deb.sh
1
#!/bin/bash
2
# e = exit on error
3
set -e
4
# x = xtrace
5
#set -x
6

  
7
FEHLER="Achtung!! Es hat ein Problem gegeben"
8
ERRCNT=0
9
source /usr/share/debconf/confmodule
10

  
11
#Als root anmelden
12
if [ `id -u` -gt 0 ]; then echo "Bitte als root anmelden"; exit 1; fi
13

  
14
POSTGRESQL=`dpkg -l | grep -E "postgresql-[0-9]" | cut -d" " -f3 | sort -r | head -1 -`
15

  
16
#Datei plpgsql.so suchen
17
#Mit Paketmanager  suchen
18
if [ "$POSTGRESQL#" == "#" ]; then
19
    echo $FEHLER
20
    echo Keine PostgreSQL mit Paketmanager installiert
21
    echo Datenbank bitte manuell einrichten.
22
    exit 0
23
else
24
   PLPGSQL=`dpkg -L $POSTGRESQL | grep plpgsql.so `
25
fi
26

  
27
if [ "$PLPGSQL#" == "#" ]; then
28
    #Probleme mit Paketmanager, dann zunaechst mit locate, geht schneller
29
    updatedb
30
    tmp=`locate plpgsql.so 2>/dev/null`
31
    PLPGSQL=`echo $tmp | cut -d " " -f 1`
32
fi
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`
37
fi	
38
if [ "$PLPGSQL#" == "#" ]; then
39
    echo $FEHLER
40
    echo  'plpgsql.so' nicht gefunden.
41
    echo Datenbank manuell einrichten.
42
    exit 0
43
fi
44

  
45
#Kann der User postgres die db erreichen
46
cnt=`ps aux | grep postgres | wc -l`
47
if [ $cnt -eq 0 ]; then
48
    echo $FEHLER
49
    echo Die postgreSQL-Datebbank ist nicht gestartet!
50
    echo Datenbank manuell einrichten.
51
    exit 0
52
fi
53

  
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 
56
    echo $FEHLER
57
    echo Datenbank Version 8x konnte nicht erreicht werden.
58
    exit 0
59
fi
60

  
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
65

  
66
#writeln 2 1 Datenbankbenutzer einrichten
67
LXOUSER="lxoffice"
68
db_get lx-office-erp/lx-office-erp-user-postgresql-password
69
USRPWD="$RET"
70

  
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
74

  
75
su postgres -c "psql template1 < lxdbinst.sql"
76

  
77
echo "Fehlermeldungen die 'already exists' enthalten koennen ignoriert werden"
78

  
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 -`
83
fi
84

  
85
if [ "$PGHBA#" == "#" ]; then
86
    echo $FEHLER
87
    echo 'pg_hba.conf' nicht gefunden.
88
    echo "Berechtigungen bitte selber einrichten"
89
    ERRCNT=1
90
fi
91

  
92
cnt=`grep $LXOUSER $PGHBA | wc -l `
93

  
94
if [ $cnt -eq 0 ]; then 
95
    mv $PGHBA  $PGHBA.org
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
99
fi 
100

  
101
#CONFDIR=`dirname $PGHBA`
102

  
103
#postgresql.conf anpassen, liegt vermutlich im gleichen Verzeichnis wie pg_hba.conf
104
#if ! [ -f $CONFDIR/postgresql.conf ]; then
105
#    echo $FEHLER
106
#    echo 'postgresql.conf' nicht gefunden.
107
#    echo PostgreSQL selber konfigurieren
108
#    ERRCNT=1
109
#fi
110

  
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
118
#fi
119

  
120
 
121
PGSQL=`ls -r1 /etc/init.d/postgres*  | head -1 -`
122

  
123
#writeln 18 1 Datenbank neu starten
124
$PGSQL reload
125

  
126
if [ $ERRCNT -gt 0 ]; then
127
    echo $FEHLER
128
    echo Das betrifft aber nicht die Lx-Office Installation
129
    echo sondern die Konfiguration der Datenbank.
130
    echo $POSTGRESQL , $PGHBA , $CONFDIR/postgresql.conf ??
131
    sleep 10
132
fi
scripts/migrate_template_to_t8.pl
1
#!/usr/bin/perl -w
2

  
3
use strict;
4
use Pod::Usage;
5
use List::Util qw(reduce);
6
use List::MoreUtils qw(zip);
7

  
8
use constant DEBUG => 0;
9

  
10
unless ( caller(0) ) {
11
  pod2usage(2) unless @ARGV;
12
  migrate_file(@ARGV);
13
};
14

  
15
sub migrate_file {
16
  my $file = shift or return;
17

  
18
  my $contents = do { local( @ARGV, $/ ) = $file ; <> }
19
    or die "cannot read file";
20

  
21
  my %substitutions = (
22
    "<translate>"  => "[% '",
23
    "</translate>" => "' | \$T8 %]",
24
  );
25

  
26
  my $last_match = '';
27
  my $num_matches;
28
  my $in_template;
29
  my $inline_counter = 0;
30

  
31
  # now replace <translate> with [% '
32
  # and </translate> with ' | $T8 %]
33
  while ($contents =~ m# ( < /? translate> | \[% | %\] ) #xg) {
34
    my $match  = $1;
35
    my $pos    = pos $contents;
36

  
37
    if ($match eq '[%') {
38
      $in_template = 1;
39
      DEBUG && warn "entering [% block %] at pos $pos";
40
      next;
41
    }
42
    if ($match eq '%]') {
43
      $in_template = 0;
44
      DEBUG && warn "leaving [% block %] at pos $pos";
45
      next;
46
    }
47

  
48
    if ($in_template) {
49
      $inline_counter++ if $match eq '<translate>';
50
      next;
51
    }
52

  
53
    DEBUG && warn "found token $match at pos $pos";
54

  
55
    my $sub_by = $substitutions{$match};
56

  
57
    unless ($sub_by) {
58
      DEBUG && warn "found token $& but got no substitute";
59
      next;
60
    }
61

  
62
    die "unbalanced tokens - two times '$match' in file $file"
63
      if $last_match eq $match;
64

  
65
    $last_match = $match;
66
    $num_matches++;
67

  
68
    # alter string. substr is faster than s/// for strings of this size.
69
    substr $contents, $-[0], $+[0] - $-[0], $sub_by;
70

  
71
    # set match pos for m//g matching on the altered string.
72
    pos $contents = $-[0] + length $sub_by;
73
  }
74

  
75
  warn "found $inline_counter occurances of inline translates in file $file $/"
76
    if $inline_counter;
77

  
78
  exit 0 unless $num_matches;
79

  
80
  die "unbalanced tokens in file $file" if $num_matches % 2;
81

  
82
  if ($contents !~ m/\[%-? USE T8 %\]/) {
83
    $contents = "[%- USE T8 %]$/" . $contents;
84
  }
85

  
86
  # all fine? spew back
87

  
88
  do {
89
    open my $fh, ">$file" or die "can't write $file $!";
90
    print $fh $contents;
91
  };
92
}
93

  
94
1;
95

  
96
__END__
97

  
98
=head1 NAME
99

  
100
migrate_template_to_t8.pl - helper script to migrate templates to T8 module
101

  
102
=head1 SYNOPSIS
103

  
104
  # single:
105
  scripts/migrate_template_to_t8.pl <file>
106

  
107
  # bash:
108
  for file in `find templates | grep master\.html`;
109
    do scripts/migrate_template_to_t8.pl $file;
110
  done;
111

  
112
  # as a lib:
113
  require "scripts/migrate_template_to_t8.pl";
114
  migrate_file($file);
115

  
116
=head1 DESCRIPTION
117

  
118
This script will do the following actions in a template file
119

  
120
=over 8
121

  
122
=item 1.
123

  
124
Change every occurance of C<<< <translate>Text</translate> >>> to C<<< [%
125
'Text' | $T8 %] >>>
126

  
127
=item 2.
128

  
129
Add [%- USE T8 %] at the top if something needs to be translated
130

  
131
=back
132

  
133
Note! This script is written to help with the process of migrating old
134
templates. It is assumed that anyone working on Lx-Office is working with a
135
version control system. This script will change your files. You have been
136
warned.
137

  
138
Due to the nature of the previous locale system, it is not easily possible to
139
migrate translates in other template blocks. As of this writing this is used in
140
about 20 occurances throughout the code. If such a construct is found, a
141
warning will be generated. lib uses of this will have to trap the warning.
142

  
143
=head1 DIAGNOSIS
144

  
145
=head2 found I<NUM> occurances of inline translates in file I<FILE>
146

  
147
If a processed file has <translate> blocks in template blocks, these will be
148
ignored.  This warning is thrown at the end of processing.
149

  
150
=head2 unbalanced tokens in file I<FILE>
151

  
152
The script could not resolve pairs of <translate> </translate>s. The file will
153
not be changed in this case.
154

  
155
=head1 AUTHOR
156

  
157
Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
158

  
159
=cut

Auch abrufbar als: Unified diff