Mon, 22 Nov 2010 16:54:26 +0100
Import package vendor original specs for necessary manipulations.
1 ##
2 ## postgresql.spec -- OpenPKG RPM Package Specification
3 ## Copyright (c) 2000-2010 OpenPKG Foundation e.V. <http://openpkg.net/>
4 ##
5 ## Permission to use, copy, modify, and distribute this software for
6 ## any purpose with or without fee is hereby granted, provided that
7 ## the above copyright notice and this permission notice appear in all
8 ## copies.
9 ##
10 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
11 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
13 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
14 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
16 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
17 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
18 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
20 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
21 ## SUCH DAMAGE.
22 ##
24 # package versions
25 %define V_postgresql 9.0.0
26 %define V_postgresql_dist 9.0.0
27 %define V_postgresql_dir 9.0.0
28 %define V_libpqxx 3.1
29 %define V_perl 5.10.0
30 %define V_pgperl 2.0.2
31 %define V_psqlodbc 09.00.0200
32 %define V_pgjdbc 9.0-801
33 %define V_slony1_major 1.2
34 %define V_slony1_minor 21
35 %define V_pgcluster 1.9.0rc5
36 %define V_pgcluster_dir 1706
37 %define V_mysqlcompat 1.0b3
38 %define V_mysqlcompat_dir 548
40 # package information
41 Name: postgresql
42 Summary: PostgreSQL Database
43 URL: http://www.postgresql.org/
44 Vendor: PostgreSQL Group
45 Packager: OpenPKG Foundation e.V.
46 Distribution: OpenPKG Community
47 Class: BASE
48 Group: Database
49 License: GPL
50 Version: %{V_postgresql}
51 Release: 20101101
53 # package options
54 %option with_server yes
55 %option with_cxx no
56 %option with_perl no
57 %option with_odbc no
58 %option with_jdbc no
59 %option with_compat no
60 %option with_tcl no
61 %option with_slony1 no
62 %option with_pgcluster no
63 %option with_kerberos no
64 %option with_mysqlcompat no
65 %option with_xml no
66 %option with_uuid no
67 %option with_conversion no
69 # list of sources
70 Source0: ftp://ftp.postgresql.org/pub/source/v%{V_postgresql_dir}/postgresql-%{V_postgresql_dist}.tar.bz2
71 Source1: http://pqxx.org/download/software/libpqxx/libpqxx-%{V_libpqxx}.tar.gz
72 Source2: ftp://gborg.postgresql.org/pub/pgperl/stable/pgperl-%{V_pgperl}.tar.gz
73 Source3: ftp://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-%{V_psqlodbc}.tar.gz
74 Source4: http://slony.info/downloads/%{V_slony1_major}/source/slony1-%{V_slony1_major}.%{V_slony1_minor}.tar.bz2
75 Source5: http://pgfoundry.org/frs/download.php/%{V_pgcluster_dir}/pgcluster-%{V_pgcluster}.patch.tar.gz
76 Source6: http://pgfoundry.org/frs/download.php/%{V_mysqlcompat_dir}/mysqlcompat-%{V_mysqlcompat}.tar.gz
77 Source7: http://jdbc.postgresql.org/download/postgresql-jdbc-%{V_pgjdbc}.src.tar.gz
78 Source8: rc.postgresql
79 Source9: pg_migrate
80 Source10: pg_passwd
81 Patch0: postgresql.patch
83 # build information
84 BuildPreReq: OpenPKG, openpkg >= 20100101, make, gcc, flex, bison, gzip
85 PreReq: OpenPKG, openpkg >= 20100101
86 BuildPreReq: readline, zlib, openssl, getopt
87 PreReq: readline, zlib, openssl, getopt
88 %if "%{with_perl}" == "yes"
89 BuildPreReq: perl >= %{V_perl}, perl-openpkg >= %{V_perl}-20061013
90 PreReq: perl >= %{V_perl}
91 %endif
92 %if "%{with_odbc}" == "yes"
93 BuildPreReq: unixodbc
94 PreReq: unixodbc
95 %endif
96 %if "%{with_jdbc}" == "yes"
97 BuildPreReq: java, JAVA-JDK, ant
98 PreReq: java, JAVA-JDK
99 %endif
100 %if "%{with_tcl}" == "yes"
101 BuildPreReq: tcl, tcl::with_x11 = yes, X11
102 PreReq: tcl, tcl::with_x11 = yes, X11
103 %endif
104 %if "%{with_kerberos}" == "yes"
105 BuildPreReq: KERBEROS
106 PreReq: KERBEROS
107 %endif
108 %if "%{with_xml}" == "yes"
109 BuildPreReq: libxml, libxslt, zlib
110 PreReq: libxml, libxslt, zlib
111 %endif
112 %if "%{with_uuid}" == "yes"
113 BuildPreReq: uuid
114 PreReq: uuid
115 %endif
117 %description
118 PostgreSQL is a sophisticated Object-Relational Database Management
119 System (ORDBMS). It is fully ACID compliant and has full support
120 for foreign keys, joins, views, triggers, and stored procedures (in
121 multiple languages). It includes most SQL92 and SQL99 data types
122 and also supports storage of binary large objects. It is the most
123 advanced Open-Source RDBMS available anywhere.
125 As an enterprise class RDBMS, PostgreSQL boasts sophisticated
126 features such as Multi-Version Concurrency Control (MVCC), Point In
127 Time Recovery (PITR), tablespaces, asynchronous replication, nested
128 transactions (savepoints), online/hot backups, a sophisticated
129 query planner/optimizer, and Write Ahead Logging (WAL) for fault
130 tolerance. It supports international character sets, multibyte
131 character encodings, Unicode, and it is locale-aware for sorting,
132 case-sensitivity, and formatting. It is highly scalable both in the
133 sheer quantity of data it can manage and in the number of concurrent
134 users it can accommodate.
136 %track
137 prog postgresql = {
138 version = %{V_postgresql_dist}
139 url = ftp://ftp.postgresql.org/pub/source/
140 regex = v(\d+\.\d+(\.\d+)*(?:beta\d*)?)
141 url = ftp://ftp.postgresql.org/pub/source/v__NEWVER__/
142 regex = postgresql-(\d+(\.\d+)+)\.tar\.(bz2|gz)
143 }
144 prog postgresql:libpqxx = {
145 version = %{V_libpqxx}
146 url = http://pqxx.org/development/libpqxx/wiki/DownloadPage
147 regex = libpqxx-(__VER__)\.tar\.gz
148 }
149 prog postgresql:pgperl = {
150 version = %{V_pgperl}
151 url = ftp://gborg.postgresql.org/pub/pgperl/stable/
152 regex = pgperl-(__VER__)\.tar\.gz
153 }
154 prog postgresql:psqlodbc = {
155 version = %{V_psqlodbc}
156 url = ftp://ftp.postgresql.org/pub/odbc/versions/src/
157 regex = psqlodbc-(\d{2}\.\d{2}\.\d{4})\.tar\.gz
158 }
159 prog postgresql:jdbc = {
160 version = %{V_pgjdbc}
161 url = http://jdbc.postgresql.org/download.html
162 regex = postgresql-jdbc-(\d+\.\d+-\d+)\.src\.tar\.gz
163 }
164 prog postgresql:slony1 = {
165 version = %{V_slony1_major}.%{V_slony1_minor}
166 url = http://slony.info/downloads/%{V_slony1_major}/source/
167 regex = slony1-(\d+\.\d+\.\d+)\.tar\.bz2
168 }
169 prog postgresql:pgcluster = {
170 version = %{V_pgcluster}.%{V_pgcluster_dir}
171 url = http://pgfoundry.org/frs/?group_id=1000072
172 regex = /(\d+/pgcluster-__VER__)\.patch\.tar\.gz
173 transform = "s/^(\\d+)\/pgcluster-(.+)$/$2.$1/; $_"
174 }
175 prog postgresql:mysqlcompat = {
176 version = %{V_mysqlcompat}.%{V_mysqlcompat_dir}
177 url = http://pgfoundry.org/frs/?group_id=1000154
178 regex = (\d+/mysqlcompat-__VER__)\.tar\.gz
179 transform = "s/^(\\d+)\/mysqlcompat-(.+)$/$2.$1/; $_"
180 }
182 %prep
183 %setup -q
184 %patch -p0
185 %if "%{with_cxx}" == "yes"
186 %setup -q -T -D -a 1
187 case "%{l_platform -t}" in
188 *-sunos* )
189 %{l_shtool} subst \
190 -e 's;strerror_r(0,0,0);strerror((int)0);g' \
191 -e 's;strerror_r((int)0, (char \*)0, (size_t)0);strerror((int)0);g' \
192 libpqxx-%{V_libpqxx}/configure
193 %{l_shtool} subst \
194 -e 's;strerror_r(err, buf, sizeof(buf));strerror(err);g' \
195 libpqxx-%{V_libpqxx}/src/largeobject.cxx \
196 libpqxx-%{V_libpqxx}/configure
197 %{l_shtool} subst \
198 -e 's;\(strerror(err) ==\) -1;\1 (char *)-1;' \
199 libpqxx-%{V_libpqxx}/src/largeobject.cxx
200 ;;
201 esac
202 %{l_shtool} subst \
203 -e 's;^function \(add_compiler_opts() {\);\1;' \
204 libpqxx-%{V_libpqxx}/configure
205 %endif
206 %if "%{with_perl}" == "yes"
207 %setup -q -T -D -a 2
208 %endif
209 %if "%{with_odbc}" == "yes"
210 %setup -q -T -D -a 3
211 %endif
212 %if "%{with_slony1}" == "yes"
213 %setup -q -T -D -a 4
214 %endif
215 %if "%{with_pgcluster}" == "yes"
216 %setup -q -T -D -a 5
217 sed -e '/^diff.*libpq\.rc/,/^diff/d' pgcluster-*-patch |\
218 %{l_patch} -p1
219 %endif
220 %if "%{with_mysqlcompat}" == "yes"
221 %setup -q -T -D -a 6
222 %endif
223 %if "%{with_jdbc}" == "yes"
224 %setup -q -T -D -a 7
225 %endif
227 # adjust source tree
228 %{l_shtool} subst \
229 -e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
230 src/include/pg_config_manual.h
231 %{l_shtool} subst \
232 -e 's;^\(sqlmansect *=\).*$;\1 7;' \
233 src/makefiles/Makefile.solaris
234 %if "%{with_conversion}" == "yes"
235 %{l_shtool} subst \
236 -e '/^SQLSCRIPT =/{x;s/.*/enable_shared = yes/;G;}' \
237 src/backend/utils/mb/conversion_procs/Makefile
238 %{l_shtool} subst \
239 -e '/^all:/{x;s/.*/enable_shared = yes/;G;}' \
240 src/backend/utils/mb/conversion_procs/proc.mk
241 %endif
242 %if "%{with_uuid}" == "yes"
243 %{l_shtool} subst \
244 -e '/^SHLIB_LINK/{x;s/.*/enable_shared = yes/;G;}' \
245 contrib/uuid-ossp/Makefile
246 %endif
247 %{l_shtool} subst \
248 -e 's;# Shared library stuff;enable_shared = yes;g' \
249 src/pl/plpgsql/src/Makefile
251 %build
253 # configure package
254 echo "ac_cv_func_isinf=no" >config.cache
255 export CC="%{l_cc}"
256 export CFLAGS="%{l_cflags -O}"
257 export CPPFLAGS="%{l_cppflags readline}"
258 export LDFLAGS="%{l_ldflags}"
259 export LIBS=""
260 %if "%{with_slony1}" == "yes"
261 CFLAGS="$CFLAGS -pthread"
262 %endif
263 %if "%{with_tcl}" == "yes"
264 CPPFLAGS="$CPPFLAGS %{l_cppflags tcl}"
265 LDFLAGS="$LDFLAGS -L`%{l_rc} --query x11_libdir`"
266 %endif
267 %if "%{with_kerberos}" == "yes"
268 CPPFLAGS="$CPPFLAGS `krb5-config --cflags`"
269 LIBS="$LIBS `krb5-config --libs`"
270 %endif
271 %if "%{with_pgcluster}" == "yes"
272 case "%{l_platform -t}" in
273 *-freebsd* ) LIBS="$LIBS -lcompat" ;;
274 esac
275 %endif
276 %if "%{with_xml}" == "yes"
277 LIBS="$LIBS -liconv"
278 %endif
279 export TAR="%{l_tar}"
280 export YACC="bison -y"
281 ./configure \
282 --cache-file=./config.cache \
283 --prefix=%{l_prefix} \
284 --mandir=%{l_prefix}/man \
285 --sysconfdir=%{l_prefix}/etc/postgresql \
286 --includedir=%{l_prefix}/include/postgresql \
287 --with-openssl \
288 --with-readline \
289 --with-zlib \
290 %if "%{with_tcl}" == "yes"
291 --with-tcl \
292 --with-tclconfig="%{l_prefix}/lib" \
293 --with-tkconfig="%{l_prefix}/lib" \
294 %endif
295 %if "%{with_slony1}" == "yes"
296 --enable-thread-safety \
297 %endif
298 %if "%{with_kerberos}" == "yes"
299 --with-krb5 \
300 --with-krb-srvnam=postgresql \
301 %endif
302 %if "%{with_xml}" == "yes"
303 --with-libxml \
304 --with-libxslt \
305 %endif
306 %if "%{with_uuid}" == "yes"
307 --with-ossp-uuid \
308 %endif
309 --disable-shared
311 # build package
312 %{l_make} %{l_mflags}
314 # build C++ bindings (both old and new one)
315 %if "%{with_cxx}" == "yes"
316 ln -s `pwd`/src/interfaces/libpq/*.h src/include/
317 ( cd libpqxx-%{V_libpqxx}
318 %{l_shtool} subst \
319 -e 's;\(cut\)\( .*/configitems\)\( -f [0-9]\);\1\3\2;g' \
320 configure
321 ( echo "#!/bin/sh"
322 echo "case \"\$1\" in"
323 echo " --includedir ) echo \"`pwd`/../src/include\" ;;"
324 echo " --libdir ) echo \"`pwd`/../src/interfaces/libpq\" ;;"
325 echo "esac"
326 ) >pg_config
327 chmod a+x pg_config
328 export PG_CONFIG=`pwd`/pg_config
329 export CC="%{l_cc}"
330 export CXX="%{l_cxx}"
331 export CFLAGS="%{l_cflags -O}"
332 export CXXFLAGS="%{l_cxxflags -O}"
333 export CPPFLAGS="-I`pwd`/../src/include %{l_cppflags}"
334 export LDFLAGS="%{l_ldflags}"
335 export LIBS="-lssl -lcrypto -lcrypt"
336 case "%{l_platform -t}" in
337 *-sunos* ) LIBS="$LIBS -lsocket -lnsl" ;;
338 esac
339 ./configure \
340 --disable-shared
341 %{l_make} %{l_mflags -O}
342 ) || exit $?
343 %endif
345 # build Perl bindings
346 %if "%{with_perl}" == "yes"
347 %{l_prefix}/bin/perl-openpkg prepare
348 ( cd Pg-%{V_pgperl}
349 export POSTGRES_INCLUDE=dummy
350 export POSTGRES_LIB=dummy
351 %{l_shtool} subst \
352 -e 's;-I$POSTGRES_INCLUDE;-I../src/interfaces/libpq -I../src/include;' \
353 -e 's;-L$POSTGRES_LIB;-L../src/interfaces/libpq;' \
354 -e 's;-lpq;-lpq %{l_ldflags} -lssl -lcrypto -lcrypt;' \
355 Makefile.PL
356 ) || exit $?
357 ( export POSTGRES_INCLUDE=dummy
358 export POSTGRES_LIB=dummy
359 %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} configure build
360 ) || exit $?
361 %endif
363 # build ODBC driver
364 %if "%{with_odbc}" == "yes"
365 ( cd psqlodbc-%{V_psqlodbc}
366 export CC="%{l_cc}"
367 export CXX="%{l_cxx}"
368 export CFLAGS="%{l_cflags -O}"
369 export CXXFLAGS="%{l_cxxflags -O}"
370 export CPPFLAGS="-I`pwd`/../src/include"
371 CPPFLAGS="$CPPFLAGS -I`pwd`/../src/interfaces -I`pwd`/../src/interfaces/libpq"
372 CPPFLAGS="$CPPFLAGS %{l_cppflags}"
373 export LDFLAGS="-L`pwd`/../src/interfaces/libpq %{l_ldflags}"
374 export LIBS="-lssl -lcrypto"
375 ./configure \
376 --prefix=%{l_prefix} \
377 --with-unixodbc=%{l_prefix} \
378 --with-odbcinst=%{l_prefix}/etc/unixodbc
379 %{l_make} %{l_mflags -O}
380 ) || exit $?
381 %endif
383 # build JDBC driver
384 %if "%{with_jdbc}" == "yes"
385 ( cd postgresql-jdbc-%{V_pgjdbc}.src
386 export JAVA_PLATFORM="sun-jdk"
387 eval `%{l_prefix}/bin/java-toolkit -e`
388 %{l_prefix}/bin/ant
389 ) || exit $?
390 %endif
392 # build Slony-1 replication engine
393 %if "%{with_slony1}" == "yes"
394 ( cd slony1-%{V_slony1_major}.%{V_slony1_minor}
395 ln ../src/pl/plpgsql/src/libplpgsql.so \
396 ../src/pl/plpgsql/src/plpgsql.so
397 %{l_shtool} subst \
398 -e 's;-lpq;-lpq @LIBS@;' \
399 Makefile.global.in
400 export CC="%{l_cc}"
401 export CFLAGS="%{l_cflags -O}"
402 export CPPFLAGS="%{l_cppflags}"
403 export LDFLAGS="%{l_ldflags}"
404 export LIBS="-lssl -lcrypto -lcrypt"
405 ./configure \
406 --prefix=%{l_prefix} \
407 --sysconfdir=%{l_prefix}/etc/postgresql \
408 --with-pgconfigdir=../src/bin/pg_config \
409 --with-pgincludedir=../src/include \
410 --with-pgincludeserverdir=../src/interfaces/libpq \
411 --with-pglibdir=../src/interfaces/libpq \
412 --with-pgpkglibdir=../src/pl/plpgsql/src \
413 --with-pgsharedir=../src/backend/utils/misc
414 %{l_make} %{l_mflags -O}
415 ) || exit $?
416 %endif
418 # build OSSP uuid based UUID generator functions
419 %if "%{with_uuid}" == "yes"
420 ( cd contrib/uuid-ossp
421 %{l_make} %{l_mflags}
422 %{l_make} %{l_mflags} uuid-ossp.so
423 ) || exit $?
424 %endif
426 # rebuild pg_config with hard-coded path to avoid that it provides
427 # dynamically resolved paths which circumvent symlinks, etc.
428 ( cd src/bin/pg_config
429 %{l_shtool} subst \
430 -e 's:find_my_exec(argv.0., mypath):0; strcpy(mypath, "%{l_prefix}/bin/pg_config"):' \
431 pg_config.c
432 %{l_make} %{l_mflags}
433 ) || exit $?
435 %install
437 # perform standard installation procedure
438 cp /dev/null register.txt
439 %{l_make} %{l_mflags} install install-docs DESTDIR=$RPM_BUILD_ROOT
441 # strip down installation
442 rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
443 strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
444 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
445 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
446 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
448 # namespace adjustments to installation
449 for prog in \
450 createdb createlang createuser dropdb droplang clusterdb \
451 dropuser initdb vacuumdb reindexdb; do
452 %if "%{with_compat}" == "yes"
453 cmd="ln"
454 %else
455 cmd="mv"
456 %endif
457 $cmd $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
458 $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
459 $cmd $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
460 $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
461 done
462 ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
463 for man in *.7; do
464 mv $man pg_$man
465 done
466 ) || exit $?
468 # create additional directories
469 %{l_shtool} mkdir -f -p -m 755 \
470 %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
471 $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql \
472 %endif
473 $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
474 $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
476 # install addon utilities
477 %{l_shtool} install -c -m 755 %{l_value -s -a} \
478 %{SOURCE pg_migrate} $RPM_BUILD_ROOT%{l_prefix}/bin/
479 %{l_shtool} install -c -m 755 %{l_value -s -a} \
480 -e "s;@l_bash@;%{l_bash};g" \
481 %{SOURCE pg_passwd} $RPM_BUILD_ROOT%{l_prefix}/bin/
483 # install C++ bindings (both old and new one)
484 %if "%{with_cxx}" == "yes"
485 ( cd libpqxx-%{V_libpqxx}
486 %{l_shtool} mkdir -f -p -m 755 \
487 $RPM_BUILD_ROOT%{l_prefix}/include/pqxx
488 %{l_shtool} install -c -m 644 \
489 include/pqxx/* \
490 $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/
491 rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/Makefile*
492 rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/config.h*
493 %{l_shtool} install -c -m 644 \
494 src/.libs/libpqxx.a \
495 $RPM_BUILD_ROOT%{l_prefix}/lib/
496 ) || exit $?
497 %endif
499 # install Perl binding
500 %if "%{with_perl}" == "yes"
501 ( export POSTGRES_INCLUDE=dummy
502 export POSTGRES_LIB=dummy
503 %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} install
504 ) || exit $?
505 %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
506 %else
507 >perl-openpkg-files
508 %endif
510 # install ODBC driver
511 %if "%{with_odbc}" == "yes"
512 ( cd psqlodbc-%{V_psqlodbc}
513 %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
514 ) || exit $?
515 %endif
517 # install JDBC driver
518 %if "%{with_jdbc}" == "yes"
519 ( cd postgresql-jdbc-%{V_pgjdbc}.src
520 %{l_shtool} install -c -m 644 \
521 jars/postgresql.jar $RPM_BUILD_ROOT%{l_prefix}/lib/
522 ) || exit $?
523 %endif
525 # install Slony-1 replication engine
526 %if "%{with_slony1}" == "yes"
527 ( cd slony1-%{V_slony1_major}.%{V_slony1_minor}
528 %{l_shtool} subst \
529 -e 's;$(SQL_NAME80);$(SQL_NAME74);g' \
530 src/xxid/Makefile
531 %{l_make} %{l_mflags} install \
532 DESTDIR=$RPM_BUILD_ROOT \
533 pgconfigdir=%{l_prefix}/bin \
534 pgincludedir=%{l_prefix}/include/postgresql \
535 pgincludeserverdir=%{l_prefix}/include/postgresql/libpq \
536 pglibdir=%{l_prefix}/lib/postgresql \
537 pgpkglibdir=%{l_prefix}/lib/postgresql \
538 pgsharedir=%{l_prefix}/share/postgresql
539 rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/slony1*v7[34].sql
540 rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v73.sql
541 mv $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v74.sql \
542 $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.sql
543 ( echo "# Slony-1 configuration for replication engine slon(1)"
544 echo "SLON_CLUSTER_NAME=\"example\""
545 echo "SLON_CONNECT_DBNAME=\"example\""
546 echo "SLON_CONNECT_USER=\"postgresql\""
547 echo "SLON_CONNECT_PASS=\"postgresql\""
548 echo "SLON_CONNECT_HOST=\"localhost\""
549 echo "SLON_SYNC_INTERVAL=\"10000\""
550 echo "SLON_SYNC_TIMEOUT=\"60000\""
551 echo "SLON_SYNC_GROUPSIZE=\"6\""
552 echo "SLON_SYNC_LOGLEVEL=\"1\""
553 ) >$RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/slony1.conf
554 ) || exit $?
555 %endif
557 # install OSSP uuid based UUID generator functions
558 %if "%{with_uuid}" == "yes"
559 ( cd contrib/uuid-ossp
560 %{l_shtool} install -c -m 644 \
561 uuid-ossp.sql uuid-ossp.so \
562 $RPM_BUILD_ROOT%{l_prefix}/lib/postgresql/
563 ) || exit $?
564 %endif
566 # adjust default configuration for hourly auto-vacuum operation
567 %{l_shtool} subst \
568 -e 's;^# *\(stats_start_collector *=\) *[^#]*\(#.*\);\1 on \2;' \
569 -e 's;^# *\(stats_row_level *=\) *[^#]*\(#.*\);\1 on \2;' \
570 -e 's;^# *\(autovacuum *=\) *[^#]*\(#.*\);\1 on \2;' \
571 -e 's;^# *\(autovacuum_naptime *=\) *[^#]*\(#.*\);\1 1h \2;' \
572 $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/postgresql.conf.sample
574 # post-adjust pgcluster configuration filenames
575 %if "%{with_pgcluster}" == "yes"
576 cp $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/pgreplicate.conf.sample \
577 $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgreplicate.conf
578 %endif
580 # install MySQL compatibility layer
581 %if "%{with_mysqlcompat}" == "yes"
582 %{l_shtool} mkdir -f -p -m 755 \
583 $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/mysqlcompat
584 %{l_shtool} install -c -m 644 \
585 mysqlcompat-%{V_mysqlcompat}/README \
586 mysqlcompat-%{V_mysqlcompat}/*.sql \
587 $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/mysqlcompat/
588 %endif
590 # install run-command script
591 %{l_shtool} mkdir -f -p -m 755 \
592 $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
593 %{l_shtool} install -c -m 755 %{l_value -s -a} \
594 %{SOURCE rc.postgresql} \
595 $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
597 # optionally strip down to client-only installation
598 %if "%{with_server}" != "yes"
599 rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_[a-bd-z]*
600 rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_c[a-np-z]*
601 rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_controldata
602 rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/post*
603 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_[a-bd-z]*
604 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_c[a-np-z]*
605 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_controldata.1
606 rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/post*
607 rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
608 rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/postgresql/server
609 rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/postgresql
610 rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/postgresql
611 rm -rf $RPM_BUILD_ROOT%{l_prefix}/var/postgresql
612 %endif
614 # determine installation files
615 %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
616 %if "%{with_server}" == "yes"
617 %{l_files_std} `cat perl-openpkg-files` \
618 %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
619 '%config %{l_prefix}/etc/postgresql/*' \
620 %endif
621 '%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
622 '%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
623 %else
624 %{l_files_std} `cat perl-openpkg-files`
625 %endif
627 %files -f files
629 %clean
631 %pre
632 %if "%{with_server}" == "yes"
633 # before upgrade, check migration dump, save status and stop service
634 [ $1 -eq 2 ] || exit 0
635 if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
636 -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
637 # database migration dumping hint
638 v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
639 v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
640 v_new_all="%{V_postgresql}"
641 v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
642 if [ ".$v_old_maj" != ".$v_new_maj" ]; then
643 ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
644 echo "which is a major version change. We expect a database incompatibility,"
645 echo "so a full database backup and restore is required!"
646 ) | %{l_rpmtool} msg -b -t notice
647 if [ ".$RPM_POSTGRESQL_MIGRATE" != .ignore ]; then
648 if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 ]; then
649 ( echo "We are performing a full backup of your existing database"
650 echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) for you by running:"
651 echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
652 echo "If this fails for some reasons, try to dump your data manually:"
653 echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dumpall -U postgresql -o | \\ "
654 echo " $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -9 \\ "
655 echo " >$RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2"
656 echo "Alternatively, if you want to force this package to be installed without"
657 echo "a previously created database dump, run the following command"
658 echo "before trying this package upgrade again:"
659 echo " \$ RPM_POSTGRESQL_MIGRATE=ignore; export RPM_POSTGRESQL_MIGRATE"
660 ) | %{l_rpmtool} msg -b -t notice
661 $RPM_INSTALL_PREFIX/bin/pg_migrate dump
662 if [ $? -ne 0 ] || [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 ]; then
663 ( echo "Automatic database dump creation failed!"
664 echo "PLEASE INVESTIGATE MANUALLY YOURSELF!"
665 ) | %{l_rpmtool} msg -b -t error
666 exit 1
667 fi
668 fi
669 fi
670 fi
671 fi
672 eval `%{l_rc} postgresql status 2>/dev/null | tee %{l_tmpfile}`
673 %{l_rc} postgresql stop 2>/dev/null
674 exit 0
675 %endif
677 %post
678 %if "%{with_server}" == "yes"
679 %if "%{with_compat}" == "yes"
680 l_pguser="postgres"
681 l_pgpass="postgres"
682 %else
683 l_pguser="postgresql"
684 l_pgpass="postgresql"
685 %endif
686 if [ $1 -eq 1 ]; then
687 # create initial database
688 su - %{l_rusr} -c \
689 "LC_CTYPE=C; export LC_CTYPE; umask 077; \
690 rm -rf $RPM_INSTALL_PREFIX/var/postgresql/db/*; \
691 echo $l_pgpass >$RPM_INSTALL_PREFIX/var/postgresql/run/pg_initdb.pw; \
692 $RPM_INSTALL_PREFIX/bin/pg_initdb \
693 --encoding=SQL_ASCII --locale=C --auth=md5 --username=$l_pguser \
694 --pwfile=$RPM_INSTALL_PREFIX/var/postgresql/run/pg_initdb.pw \
695 --pgdata=$RPM_INSTALL_PREFIX/var/postgresql/db; \
696 rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/pg_initdb.pw" 2>&1 | \
697 $RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
698 -p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
699 if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION ]; then
700 echo "ERROR: failed to create initial PostgreSQL database" 1>&2
701 exit 1
702 fi
703 ( umask 077
704 ( echo "##"
705 echo "## pg_superuser.conf -- PostgreSQL database superuser configuration"
706 echo "##"
707 echo ""
708 echo "superuser_database=\"template1\""
709 echo "superuser_username=\"$l_pguser\""
710 echo "superuser_password=\"$l_pgpass\""
711 echo ""
712 ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf
713 chown %{l_rusr}:%{l_rgrp} $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf || exit $?
714 chmod 600 $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf || exit $?
715 ) || exit $?
717 # display information about next steps
718 ( echo "An initial PostgreSQL DB was created with the two standard"
719 echo "databases 'template0' and 'template1'. The owner of both"
720 echo "is the DB user '$l_pguser'. Its initial password is '$l_pgpass'."
721 echo ""
722 echo "After starting PostgreSQL with"
723 echo " \$ $RPM_INSTALL_PREFIX/bin/openpkg rc postgresql start"
724 echo "you should immediately change this with the following command:"
725 echo " \$ $RPM_INSTALL_PREFIX/bin/pg_passwd postgresql template1"
726 echo ""
727 echo "Then you usually create a database for a user <user> (assuming that"
728 echo "his home directory is /u/<user>) with password <password> under"
729 echo "path /u/<user>/rdbms with the commands:"
730 echo " \$ mkdir /u/<user>/rdbms"
731 echo " \$ chmod 700 /u/<user>/rdbms"
732 echo " \$ chown %{l_rusr}:%{l_rgrp} /u/<user>/rdbms"
733 echo " \$ $RPM_INSTALL_PREFIX/bin/psql -U $l_pguser -d template1"
734 echo " template1=> CREATE ROLE <user>"
735 echo " LOGIN ENCRYPTED PASSWORD '<password>'"
736 echo " NOCREATEDB NOCREATEROLE;"
737 echo " template1=> CREATE TABLESPACE <user> OWNER <user>"
738 echo " LOCATION '/u/<user>/rdbms';"
739 echo " template1=> CREATE DATABASE <user> OWNER <user>"
740 echo " TABLESPACE <user>;"
741 echo " \$ echo 'localhost:*:<user>:<user>:<password>' >>/u/<user>/.pgpass"
742 echo " \$ chmod 600 <user> /u/<user>/.pgpass"
743 echo " \$ chown <user> /u/<user>/.pgpass"
744 echo "After this the user <user> will be able to connect to his RDBMS with:"
745 echo " \$ $RPM_INSTALL_PREFIX/bin/psql"
746 ) | %{l_rpmtool} msg -b -t notice
747 fi
749 %if "%{with_odbc}" == "yes"
750 # optionally link into ODBC
751 if ! $RPM_INSTALL_PREFIX/bin/odbcinst -q -d -n "PostgreSQL" >/dev/null 2>&1; then
752 ( echo "[PostgreSQL]"
753 echo "Description = PostgreSQL ODBC driver"
754 echo "Driver = $RPM_INSTALL_PREFIX/lib/psqlodbc.so"
755 echo "Threading = 2"
756 ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r -n "PostgreSQL"
757 fi
758 %endif
760 if [ $1 -eq 2 ]; then
761 # after upgrade, restore status
762 { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
763 [ ".$postgresql_active" = .yes ] && %{l_rc} postgresql start
764 if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
765 ! -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf ]; then
766 ( umask 077
767 ( echo "##"
768 echo "## pg_superuser.conf -- PostgreSQL database superuser configuration"
769 echo "##"
770 echo ""
771 echo "superuser_database=\"template1\""
772 echo "superuser_username=\"$l_pguser\""
773 echo "superuser_password=\"\""
774 echo ""
775 ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf
776 chown %{l_rusr}:%{l_rgrp} $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf || exit $?
777 chmod 600 $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf || exit $?
778 ) || exit $?
779 ( echo "Created still missing \"pg_superuser.conf\" configuration file."
780 echo "You should update its content by resetting the PostgreSQL"
781 echo "superuser account password with the following command:"
782 echo " \$ $RPM_INSTALL_PREFIX/bin/pg_passwd postgresql template1"
783 ) | %{l_rpmtool} msg -b -t warn
784 fi
785 if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
786 # database migration restoring hint
787 v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
788 v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
789 v_new_all="%{V_postgresql}"
790 v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
791 if [ ".$v_old_maj" != ".$v_new_maj" ]; then
792 ( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
793 echo "which is a major version upgrade. We expect a database incompatibility,"
794 echo "so we strongly recommend you to recreate the existing database under"
795 echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
796 echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate restore"
797 echo "If this fails for some reasons, try to restore your data manually:"
798 echo " \$ $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -d -c \\ "
799 echo " $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 | \\ "
800 echo " $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1"
801 ) | %{l_rpmtool} msg -b -t warn
802 fi
803 fi
804 fi
805 exit 0
806 %endif
808 %preun
809 %if "%{with_server}" == "yes"
810 # before erase, stop service and remove log files
811 [ $1 -eq 0 ] || exit 0
812 %{l_rc} postgresql stop 2>/dev/null
813 rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/* >/dev/null 2>&1 || true
814 # optionally unlink from ODBC
815 %if "%{with_odbc}" == "yes"
816 $RPM_INSTALL_PREFIX/bin/odbcinst -u -d -n "PostgreSQL"
817 %endif
818 exit 0
819 %endif