##
## postgresql.spec -- OpenPKG RPM Specification
## Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
## Copyright (c) 2000-2003 The OpenPKG Project
## Copyright (c) 2000-2003 Ralf S. Engelschall
##
## Permission to use, copy, modify, and distribute this software for
## any purpose with or without fee is hereby granted, provided that
## the above copyright notice and this permission notice appear in all
## copies.
##
## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
## SUCH DAMAGE.
##
# package versions
%define V_postgresql 7.3.2
%define V_libpqpp 4.0
%define V_libpqxx 1.3.6
%define V_pgperl 2.0.2
%define V_psqlodbc 7.2.5
# package information
Name: postgresql
Summary: PostgreSQL Database
URL: http://www.postgresql.org/
Vendor: PostgreSQL Group
Packager: The OpenPKG Project
Distribution: OpenPKG [BASE]
Group: Database
License: GPL
Version: %{V_postgresql}
Release: 20030204
# package options
%option with_cxx no
%option with_perl no
%option with_odbc no
# list of sources
Source0: ftp://ftp.postgresql.org/pub/source/v%{V_postgresql}/postgresql-%{V_postgresql}.tar.gz
Source1: ftp://gborg.postgresql.org/pub/libpqpp/stable/libpq++-%{V_libpqpp}.tar.gz
Source2: ftp://gborg.postgresql.org/pub/libpqxx/stable/libpqxx-%{V_libpqxx}.tar.gz
Source3: ftp://gborg.postgresql.org/pub/pgperl/stable/pgperl-%{V_pgperl}.tar.gz
Source4: ftp://ftp.us.postgresql.org/odbc/versions/src/psqlodbc-%{V_psqlodbc}.tar.gz
Source5: rc.postgresql
Source6: pg_migrate
# build information
Prefix: %{l_prefix}
BuildRoot: %{l_buildroot}
BuildPreReq: OpenPKG, openpkg >= 20030103, make, gcc, readline, flex, bison, zlib, openssl
PreReq: OpenPKG, openpkg >= 20030103
%if "%{with_perl}" == "yes"
BuildPreReq: perl, perl-openpkg
PreReq: perl, perl-openpkg
%endif
%if "%{with_odbc}" == "yes"
BuildPreReq: unixodbc
PreReq: unixodbc
%endif
AutoReq: no
AutoReqProv: no
%description
PostgreSQL is a sophisticated Object-Relational DBMS, supporting
almost all SQL constructs, including subselects, transactions,
and user-defined types and functions. It is the most advanced
open-source database available anywhere.
%prep
%setup0 -q
%if "%{with_cxx}" == "yes"
%setup1 -q -T -D -a 1
%setup2 -q -T -D -a 2
%endif
%if "%{with_perl}" == "yes"
%setup3 -q -T -D -a 3
%endif
%if "%{with_odbc}" == "yes"
%setup4 -q -T -D -a 4
%endif
# adjust source tree
%{l_shtool} subst \
-e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
src/include/pg_config.h.in
%{l_shtool} subst \
-e 's;^\(sqlmansect *=\).*$;\1 7;' \
src/makefiles/Makefile.solaris
%{l_shtool} subst \
-e 's;$(INSTALL_SHLIB);#$(INSTALL_SHLIB);g' \
src/backend/utils/mb/conversion_procs/proc.mk
%build
# configure package
CC="%{l_cc}" \
CFLAGS="%{l_cflags -O}" \
CPPFLAGS="%{l_cppflags}" \
LDFLAGS="%{l_ldflags}" \
./configure \
--prefix=%{l_prefix} \
--with-openssl=%{l_prefix} \
--with-readline \
--with-zlib \
--disable-syslog \
--disable-shared
# build package
%{l_make} %{l_mflags -O}
# build C++ bindings (both old and new one)
%if "%{with_cxx}" == "yes"
( cd libpq++-%{V_libpqpp}
CXX="%{l_cxx}"
CFLAGS="%{l_cflags -O}"
CPPFLAGS="-DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT= "
CPPFLAGS="$CPPFLAGS -I. -I../src/interfaces/libpq -I../src/interfaces"
CPPFLAGS="$CPPFLAGS -I../src/include %{l_cppflags}"
LDFLAGS="%{l_ldflags}"
OBJS="pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o"
for o in $OBJS; do
$CXX $CFLAGS $CPPFLAGS $LDFLAGS -c -o $o `echo $o | sed -e 's;\.o$;.cc;'`
done
rm -f libpq++.a
ar rc libpq++.a $OBJS
)
( cd libpqxx-%{V_libpqxx}
export CC="%{l_cc}"
export CXX="%{l_cxx}"
export CFLAGS="%{l_cflags -O}"
export CXXFLAGS="%{l_cxxflags -O}"
export CPPFLAGS="-I`pwd`/../src/include %{l_cppflags}"
export LDFLAGS="%{l_ldflags}"
export LIBS="-lssl -lcrypto -lcrypt"
./configure \
--with-postgres-lib=`pwd`/../src/interfaces/libpq \
--with-postgres-include=`pwd`/../src/interfaces/libpq \
--disable-shared
# %{l_make} %{l_mflags -O}
/cw/bin/gmake %{l_mflags -O}
)
%endif
# build Perl bindings
%if "%{with_perl}" == "yes"
rm -rf $RPM_BUILD_ROOT
( cd Pg-%{V_pgperl}
%{l_prefix}/bin/perl-openpkg prolog
export POSTGRES_INCLUDE=dummy
export POSTGRES_LIB=dummy
%{l_shtool} subst \
-e 's;-I$POSTGRES_INCLUDE;-I../src/interfaces/libpq -I../src/include;' \
-e 's;-L$POSTGRES_LIB;-L../src/interfaces/libpq;' \
-e 's;-lpq;-lpq %{l_ldflags} -lssl -lcrypto -lcrypt;' \
Makefile.PL
%{l_prefix}/bin/perl-openpkg install
%{l_prefix}/bin/perl-openpkg epilog
)
%endif
# build ODBC driver
%if "%{with_odbc}" == "yes"
( cd psqlodbc-%{V_psqlodbc}
export CC="%{l_cc}"
export CXX="%{l_cxx}"
export CFLAGS="%{l_cflags -O}"
export CXXFLAGS="%{l_cxxflags -O}"
export CPPFLAGS="-I`pwd`/../src/include"
CPPFLAGS="$CPPFLAGS -I`pwd`/../src/interfaces -I`pwd`/../src/interfaces/libpq"
CPPFLAGS="$CPPFLAGS %{l_cppflags}"
export LDFLAGS="-L`pwd`/../src/interfaces/libpq %{l_ldflags}"
./configure \
--prefix=%{l_prefix} \
--with-unixodbc \
--with-odbcinst=%{l_prefix}/etc/unixodbc
%{l_make} %{l_mflags -O}
)
%endif
%install
%if "%{with_perl}" != "yes"
rm -rf $RPM_BUILD_ROOT
%endif
# perform standard installation procedure
%{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
# strip down installation
rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/lib*.so*
# namespace adjustments to installation
for prog in \
createdb createlang createuser dropdb droplang \
dropuser initdb initlocation ipcclean vacuumdb; do
mv $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
$RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
mv $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
$RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
done
( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
for man in *.7; do
mv $man pg_$man
done
)
# create additional directories
%{l_shtool} mkdir -f -p -m 755 \
$RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
$RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
# install migration utility
%{l_shtool} install -c -m 755 \
-e 's;@l_prefix@;%{l_prefix};g' \
-e 's;@l_rusr@;%{l_rusr};g' \
-e 's;@l_rgrp@;%{l_rgrp};g' \
%{SOURCE pg_migrate} \
$RPM_BUILD_ROOT%{l_prefix}/bin/
# install C++ bindings (both old and new one)
%if "%{with_cxx}" == "yes"
( cd libpq++-%{V_libpqpp}
%{l_shtool} mkdir -f -p -m 755 \
$RPM_BUILD_ROOT%{l_prefix}/include/libpq++
%{l_shtool} install -c -m 644 \
libpq++.h pgconnection.h pgdatabase.h pgtransdb.h pgcursordb.h pglobject.h \
$RPM_BUILD_ROOT%{l_prefix}/include/libpq++/
%{l_shtool} install -c -m 644 \
libpq++.a \
$RPM_BUILD_ROOT%{l_prefix}/lib/
)
( cd libpqxx-%{V_libpqxx}
%{l_shtool} mkdir -f -p -m 755 \
$RPM_BUILD_ROOT%{l_prefix}/include/pqxx
%{l_shtool} install -c -m 644 \
include/pqxx/*.h \
$RPM_BUILD_ROOT%{l_prefix}/include/pqxx/
%{l_shtool} install -c -m 644 \
src/.libs/libpqxx.a \
$RPM_BUILD_ROOT%{l_prefix}/lib/
)
%endif
# build ODBC driver
%if "%{with_odbc}" == "yes"
( cd psqlodbc-%{V_psqlodbc}
%{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
)
%endif
# install run-command script
%{l_shtool} mkdir -f -p -m 755 \
$RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
%{l_shtool} install -c -m 755 \
-e 's;@l_prefix@;%{l_prefix};g' \
-e 's;@l_rusr@;%{l_rusr};g' \
-e 's;@l_rgrp@;%{l_rgrp};g' \
%{SOURCE rc.postgresql} \
$RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
# determine installation files
%{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
%{l_files_std} \
'%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
'%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
%files -f files
%clean
rm -rf $RPM_BUILD_ROOT
%pre
if [ $1 -gt 1 ]; then
# upgrading of installation
if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
-f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
# database migration dumping hint
v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
v_new_all="%{V_postgresql}"
v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
if [ ".$v_old_maj" != ".$v_new_maj" ]; then
if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$PG_MIGRATE" != .ignore ]; then
( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
echo "which is a major version change. We expect a database incompatibility,"
echo "so we strongly recommend that you backup your existing database"
echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
echo "Alternatively, if you want force this package to be installed without"
echo "performing a database dump, run the following command before upgrading:"
echo " \$ PG_MIGRATE=ignore; export PG_MIGRATE"
) | %{l_rpmtool} msg -b -t error
exit 1
fi
fi
fi
rm -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART >/dev/null 2>&1 || true
if [ ".`$l_prefix/etc/rc postgresql status 2>&1 | grep 'is running'`" != . ]; then
echo "Shutting down currently running database engine." | %{l_rpmtool} msg -b -t notice
$RPM_INSTALL_PREFIX/etc/rc postgresql stop
touch $RPM_INSTALL_PREFIX/var/posgresql/RESTART
sleep 4
fi
fi
%post
if [ $1 -eq 1 ]; then
# create initial database
su - %{l_rusr} -c \
"LC_CTYPE=C; export LC_CTYPE; umask 022; \
(echo 'postgresql'; echo 'postgresql') |\
$RPM_INSTALL_PREFIX/bin/pg_initdb \
-U postgresql -W -D $RPM_INSTALL_PREFIX/var/postgresql/db" 2>&1 |\
$RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
-p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
# adjust initial authentication configuration
cp $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf \
$RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
( cat $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old |\
sed -e 's;^\([^#]\);# \1;' -e 's;^$;#;'
echo ""
echo "# OpenPKG PostgreSQL default access policy"
echo "local all all md5"
echo "host all all 127.0.0.1 255.255.255.255 md5"
echo ""
) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf
rm -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
# display information about next steps
( echo "An initial PostgreSQL DB was created with the two standard"
echo "databases 'template0' and 'template1'. The owner of both"
echo "is the DB user 'postgresql'. Its initial password is 'postgresql'."
echo "After starting PostgreSQL you should change this as quick as"
echo "possible with the following command:"
echo "\$ $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1 \\"
echo " -c \"ALTER USER postgresql WITH PASSWORD ''\""
) | %{l_rpmtool} msg -b -t notice
# optionally link into unixODBC
%if "%{with_odbc}" == "yes"
( echo "[PostgreSQL]"
echo "Description = PostgreSQL ODBC driver"
echo "Driver = $RPM_INSTALL_PREFIX/lib/psqlodbc.so"
echo "Threading = 2"
) $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r
%endif
elif [ $1 -gt 1 ]; then
# upgrading of installation
if [ -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART ]; then
echo "Starting database engine again." | %{l_rpmtool} msg -b -t notice
$RPM_INSTALL_PREFIX/etc/rc postgresql start
rm -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART >/dev/null 2>&1 || true
sleep 2
fi
if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
# database migration restoring hint
v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
v_new_all="%{V_postgresql}"
v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
if [ ".$v_old_maj" != ".$v_new_maj" ]; then
( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
echo "which is a major version upgrade. We expect a database incompatibility,"
echo "so we strongly recommend you to recreate the existing database under"
echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dump restore"
) | %{l_rpmtool} msg -b -t warn
fi
fi
fi