postgresql.spec 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. ##
  2. ## postgresql.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2006 OpenPKG Foundation e.V. <http://openpkg.net/>
  4. ## Copyright (c) 2000-2006 Ralf S. Engelschall <http://engelschall.com/>
  5. ##
  6. ## Permission to use, copy, modify, and distribute this software for
  7. ## any purpose with or without fee is hereby granted, provided that
  8. ## the above copyright notice and this permission notice appear in all
  9. ## copies.
  10. ##
  11. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  12. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  14. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  15. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  17. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  18. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  19. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  20. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  21. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  22. ## SUCH DAMAGE.
  23. ##
  24. # package versions
  25. %define V_postgresql 8.1.2
  26. %define V_libpqpp 4.0
  27. %define V_libpqxx 2.5.5
  28. %define V_pgperl 2.0.2
  29. %define V_psqlodbc 08.01.0200
  30. %define V_slony1 1.1.5
  31. %define V_pgcluster 1.5.0rc5
  32. %define V_mysqlcompat 1.0b3
  33. # package information
  34. Name: postgresql
  35. Summary: PostgreSQL Database
  36. URL: http://www.postgresql.org/
  37. Vendor: PostgreSQL Group
  38. Packager: OpenPKG
  39. Distribution: OpenPKG
  40. Class: BASE
  41. Group: Database
  42. License: GPL
  43. Version: %{V_postgresql}
  44. Release: 20060131
  45. # package options
  46. %option with_server yes
  47. %option with_cxx no
  48. %option with_perl no
  49. %option with_odbc no
  50. %option with_compat no
  51. %option with_tcl no
  52. %option with_slony1 no
  53. %option with_pgcluster no
  54. %option with_kerberos no
  55. %option with_mysqlcompat no
  56. # list of sources
  57. Source0: ftp://ftp.postgresql.org/pub/source/v%{V_postgresql}/postgresql-%{V_postgresql}.tar.gz
  58. Source1: ftp://gborg.postgresql.org/pub/libpqpp/stable/libpq++-%{V_libpqpp}.tar.gz
  59. Source2: ftp://gborg.postgresql.org/pub/libpqxx/stable/libpqxx-%{V_libpqxx}.tar.gz
  60. Source3: ftp://gborg.postgresql.org/pub/pgperl/stable/pgperl-%{V_pgperl}.tar.gz
  61. Source4: ftp://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-%{V_psqlodbc}.tar.gz
  62. Source5: http://developer.postgresql.org/~wieck/slony1/download/slony1-%{V_slony1}.tar.bz2
  63. Source6: http://pgfoundry.org/frs/download.php/621/pgcluster-%{V_pgcluster}-patch.tar.gz
  64. Source7: http://pgfoundry.org/frs/download.php/548/mysqlcompat-%{V_pgcluster}.tar.gz
  65. Source8: rc.postgresql
  66. Source9: pg_migrate
  67. Patch0: postgresql.patch
  68. # build information
  69. Prefix: %{l_prefix}
  70. BuildRoot: %{l_buildroot}
  71. BuildPreReq: OpenPKG, openpkg >= 20040130, make, gcc, flex, bison, gzip
  72. PreReq: OpenPKG, openpkg >= 20040130
  73. BuildPreReq: readline, zlib, openssl, getopt
  74. PreReq: readline, zlib, openssl, getopt
  75. %if "%{with_perl}" == "yes"
  76. BuildPreReq: perl, perl-openpkg >= 5.8.3-20040126
  77. PreReq: perl
  78. %endif
  79. %if "%{with_odbc}" == "yes"
  80. BuildPreReq: unixodbc
  81. PreReq: unixodbc
  82. %endif
  83. %if "%{with_tcl}" == "yes"
  84. BuildPreReq: tcl, tcl::with_x11 = yes, X11
  85. PreReq: tcl, tcl::with_x11 = yes, X11
  86. %endif
  87. %if "%{with_kerberos}" == "yes"
  88. BuildPreReq: kerberos
  89. PreReq: kerberos
  90. %endif
  91. AutoReq: no
  92. AutoReqProv: no
  93. %description
  94. PostgreSQL is a sophisticated Object-Relational DBMS, supporting
  95. almost all SQL constructs, including subselects, transactions,
  96. and user-defined types and functions. It is the most advanced
  97. open-source database available anywhere.
  98. This PostgreSQL package optionally contains two database replication
  99. solutions: the Slony-I single-master/multiple-slave replication
  100. engine, and the PGCluster multi-master replication engine.
  101. Additionally, there is a third option using the OpenPKG PGPool
  102. package which offers a connection pooling/replication frontend.
  103. %track
  104. prog postgresql = {
  105. version = %{V_postgresql}
  106. url = ftp://ftp.postgresql.org/pub/source/
  107. regex = v(\d+\.\d+(\.\d+)*)(?!beta)
  108. url = ftp://ftp.postgresql.org/pub/source/v__NEWVER__/
  109. regex = postgresql-(\d+\.\d+(\.\d+)*)\.tar\.(?:gz|bz2)
  110. }
  111. prog postgresql:libpq++ = {
  112. version = %{V_libpqpp}
  113. url = ftp://gborg.postgresql.org/pub/libpqpp/stable/
  114. regex = libpq\+\+-(__VER__)\.tar\.gz
  115. }
  116. prog postgresql:libpqxx = {
  117. version = %{V_libpqxx}
  118. url = ftp://gborg.postgresql.org/pub/libpqxx/stable/
  119. regex = libpqxx-(__VER__)\.tar\.gz
  120. }
  121. prog postgresql:pgperl = {
  122. version = %{V_pgperl}
  123. url = ftp://gborg.postgresql.org/pub/pgperl/stable/
  124. regex = pgperl-(__VER__)\.tar\.gz
  125. }
  126. prog postgresql:psqlodbc = {
  127. version = %{V_psqlodbc}
  128. url = ftp://ftp.postgresql.org/pub/odbc/versions/src/
  129. regex = psqlodbc-(\d{2}\.\d{2}\.\d{4})\.tar\.gz
  130. }
  131. prog postgresql:slony1 = {
  132. version = %{V_slony1}
  133. url = http://developer.postgresql.org/~wieck/slony1/download/
  134. regex = slony1-(\d+\.\d+\.\d+)\.tar\.bz2
  135. }
  136. prog postgresql:pgcluster = {
  137. comment = "rse: beside the filename also the path changes for new versions"
  138. version = %{V_pgcluster}
  139. url = http://pgfoundry.org/frs/?group_id=1000072&release_id=168
  140. regex = pgcluster-(__VER__)-patch\.tar\.gz
  141. }
  142. prog postgresql:mysqlcompat = {
  143. comment = "rse: beside the filename also the path changes for new versions"
  144. version = %{V_mysqlcompat}
  145. url = http://pgfoundry.org/frs/?group_id=1000154&release_id=379
  146. regex = mysqlcompat-(__VER__)\.tar\.gz
  147. }
  148. %prep
  149. %setup -q
  150. %patch -p0
  151. %if "%{with_cxx}" == "yes"
  152. %setup -q -T -D -a 1
  153. %setup -q -T -D -a 2
  154. case "%{l_platform -t}" in
  155. *-sunos* )
  156. %{l_shtool} subst \
  157. -e 's;strerror_r(0,0,0);strerror((int)0);g' \
  158. -e 's;strerror_r((int)0, (char \*)0, (size_t)0);strerror((int)0);g' \
  159. libpqxx-%{V_libpqxx}/configure
  160. %{l_shtool} subst \
  161. -e 's;strerror_r(err, buf, sizeof(buf));strerror(err);g' \
  162. libpqxx-%{V_libpqxx}/src/largeobject.cxx \
  163. libpqxx-%{V_libpqxx}/configure
  164. ;;
  165. esac
  166. %endif
  167. %if "%{with_perl}" == "yes"
  168. %setup -q -T -D -a 3
  169. %endif
  170. %if "%{with_odbc}" == "yes"
  171. %setup -q -T -D -a 4
  172. %endif
  173. %if "%{with_slony1}" == "yes"
  174. %setup -q -T -D -a 5
  175. %endif
  176. %if "%{with_pgcluster}" == "yes"
  177. %setup -q -T -D -a 6
  178. cat pgcluster-*-patch |\
  179. sed -e 's;(char .)\(ptr .= readlen\);\1;' |\
  180. %{l_patch} -p1
  181. %endif
  182. %if "%{with_mysqlcompat}" == "yes"
  183. %setup -q -T -D -a 7
  184. %endif
  185. %if "%{with_kerberos}" == "yes"
  186. %{l_shtool} subst \
  187. -e 's;krb5 -ldes -lasn1 -lroken;krb5 -lk5crypto -lkrb5support -lcom_err;g' \
  188. configure
  189. %endif
  190. # adjust source tree
  191. %{l_shtool} subst \
  192. -e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
  193. src/include/pg_config_manual.h
  194. %{l_shtool} subst \
  195. -e 's;^\(sqlmansect *=\).*$;\1 7;' \
  196. src/makefiles/Makefile.solaris
  197. %{l_shtool} subst \
  198. -e 's;$(INSTALL_SHLIB);#$(INSTALL_SHLIB);g' \
  199. src/backend/utils/mb/conversion_procs/proc.mk
  200. %{l_shtool} subst \
  201. -e 's;# Shared library stuff;enable_shared = yes;g' \
  202. src/pl/plpgsql/src/Makefile
  203. %build
  204. rm -rf $RPM_BUILD_ROOT
  205. # configure package
  206. ( echo "ac_cv_func_isinf=no"
  207. ) >config.cache
  208. export CC="%{l_cc}"
  209. export CFLAGS="%{l_cflags -O}"
  210. export CPPFLAGS="%{l_cppflags readline} -DOPENSSL_DISABLE_OLD_DES_SUPPORT"
  211. export LDFLAGS="%{l_ldflags}"
  212. %if "%{with_slony1}" == "yes"
  213. CFLAGS="$CFLAGS -pthread"
  214. %endif
  215. %if "%{with_tcl}" == "yes"
  216. CPPFLAGS="$CPPFLAGS %{l_cppflags tcl}"
  217. LDFLAGS="$LDFLAGS -L`%{l_rc} --query x11_libdir`"
  218. %endif
  219. %if "%{with_kerberos}" == "yes"
  220. CPPFLAGS="$CPPFLAGS %{l_cppflags kerberos}"
  221. LDFLAGS="$LDFLAGS %{l_ldflags kerberos}"
  222. %endif
  223. export TAR="%{l_tar}"
  224. export YACC="bison -y"
  225. ./configure \
  226. --cache-file=./config.cache \
  227. --prefix=%{l_prefix} \
  228. --sysconfdir=%{l_prefix}/etc/postgresql \
  229. --includedir=%{l_prefix}/include/postgresql \
  230. --with-openssl \
  231. --with-readline \
  232. --with-zlib \
  233. %if "%{with_tcl}" == "yes"
  234. --with-tcl \
  235. --with-tclconfig="%{l_prefix}/lib" \
  236. --with-tkconfig="%{l_prefix}/lib" \
  237. %endif
  238. %if "%{with_slony1}" == "yes"
  239. --enable-thread-safety \
  240. %endif
  241. %if "%{with_kerberos}" == "yes"
  242. --with-krb5 \
  243. --with-krb-srvnam=postgresql \
  244. %endif
  245. --disable-syslog \
  246. --disable-shared
  247. # build package
  248. %{l_make} %{l_mflags}
  249. # build C++ bindings (both old and new one)
  250. %if "%{with_cxx}" == "yes"
  251. ( cd libpq++-%{V_libpqpp}
  252. CXX="%{l_cxx}"
  253. CFLAGS="%{l_cflags -O}"
  254. CPPFLAGS="-DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT= "
  255. CPPFLAGS="$CPPFLAGS -I. -I../src/interfaces/libpq -I../src/interfaces"
  256. CPPFLAGS="$CPPFLAGS -I../src/include %{l_cppflags}"
  257. LDFLAGS="%{l_ldflags}"
  258. OBJS="pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o"
  259. for o in $OBJS; do
  260. $CXX $CFLAGS $CPPFLAGS $LDFLAGS -c -o $o `echo $o | sed -e 's;\.o$;.cc;'`
  261. done
  262. rm -f libpq++.a
  263. ar rc libpq++.a $OBJS
  264. ) || exit $?
  265. ln -s `pwd`/src/interfaces/libpq/*.h src/include/
  266. ( cd libpqxx-%{V_libpqxx}
  267. %{l_shtool} subst \
  268. -e 's;\(cut\)\( .*/configitems\)\( -f [0-9]\);\1\3\2;g' \
  269. configure
  270. ( echo "#!/bin/sh"
  271. echo "case \"\$1\" in"
  272. echo " --includedir ) echo \"`pwd`/../src/include\" ;;"
  273. echo " --libdir ) echo \"`pwd`/../src/interfaces/libpq\" ;;"
  274. echo "esac"
  275. ) >pg_config
  276. chmod a+x pg_config
  277. export PG_CONFIG=`pwd`/pg_config
  278. export CC="%{l_cc}"
  279. export CXX="%{l_cxx}"
  280. export CFLAGS="%{l_cflags -O}"
  281. export CXXFLAGS="%{l_cxxflags -O}"
  282. export CPPFLAGS="-I`pwd`/../src/include %{l_cppflags}"
  283. export LDFLAGS="%{l_ldflags}"
  284. export LIBS="-lssl -lcrypto -lcrypt"
  285. case "%{l_platform -t}" in
  286. *-sunos* ) LIBS="$LIBS -lsocket -lnsl" ;;
  287. esac
  288. ./configure \
  289. --disable-shared
  290. %{l_make} %{l_mflags -O}
  291. ) || exit $?
  292. %endif
  293. # build Perl bindings
  294. %if "%{with_perl}" == "yes"
  295. %{l_prefix}/bin/perl-openpkg prepare
  296. ( cd Pg-%{V_pgperl}
  297. export POSTGRES_INCLUDE=dummy
  298. export POSTGRES_LIB=dummy
  299. %{l_shtool} subst \
  300. -e 's;-I$POSTGRES_INCLUDE;-I../src/interfaces/libpq -I../src/include;' \
  301. -e 's;-L$POSTGRES_LIB;-L../src/interfaces/libpq;' \
  302. -e 's;-lpq;-lpq %{l_ldflags} -lssl -lcrypto -lcrypt;' \
  303. Makefile.PL
  304. ) || exit $?
  305. ( export POSTGRES_INCLUDE=dummy
  306. export POSTGRES_LIB=dummy
  307. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} configure build
  308. ) || exit $?
  309. %endif
  310. # build ODBC driver
  311. %if "%{with_odbc}" == "yes"
  312. ( cd psqlodbc-%{V_psqlodbc}
  313. export CC="%{l_cc}"
  314. export CXX="%{l_cxx}"
  315. export CFLAGS="%{l_cflags -O}"
  316. export CXXFLAGS="%{l_cxxflags -O}"
  317. export CPPFLAGS="-I`pwd`/../src/include"
  318. CPPFLAGS="$CPPFLAGS -I`pwd`/../src/interfaces -I`pwd`/../src/interfaces/libpq"
  319. CPPFLAGS="$CPPFLAGS %{l_cppflags}"
  320. export LDFLAGS="-L`pwd`/../src/interfaces/libpq %{l_ldflags}"
  321. ./configure \
  322. --prefix=%{l_prefix} \
  323. --with-unixodbc \
  324. --with-odbcinst=%{l_prefix}/etc/unixodbc
  325. %{l_make} %{l_mflags -O}
  326. ) || exit $?
  327. %endif
  328. # build Slony-1 replication engine
  329. %if "%{with_slony1}" == "yes"
  330. ( cd slony1-%{V_slony1}
  331. ln ../src/pl/plpgsql/src/libplpgsql.so \
  332. ../src/pl/plpgsql/src/plpgsql.so
  333. %{l_shtool} subst \
  334. -e 's;-lpq;-lpq -lssl -lcrypto -lcrypt;' \
  335. src/slon/Makefile src/slonik/Makefile
  336. export CC="%{l_cc}"
  337. export CFLAGS="%{l_cflags -O}"
  338. export CPPFLAGS="%{l_cppflags}"
  339. export LDFLAGS="%{l_ldflags}"
  340. export LIBS="-lssl -lcrypto -lcrypt"
  341. ./configure \
  342. --prefix=%{l_prefix} \
  343. --sysconfdir=%{l_prefix}/etc/postgresql \
  344. --with-pgconfigdir=../src/bin/pg_config \
  345. --with-pgincludedir=../src/include \
  346. --with-pgincludeserverdir=../src/interfaces/libpq \
  347. --with-pglibdir=../src/interfaces/libpq \
  348. --with-pgpkglibdir=../src/pl/plpgsql/src \
  349. --with-pgsharedir=../src/backend/utils/misc
  350. %{l_make} %{l_mflags -O}
  351. ) || exit $?
  352. %endif
  353. # rebuild pg_config with hard-coded path to avoid that it provides
  354. # dynamically resolved paths which circumvent symlinks, etc.
  355. ( cd src/bin/pg_config
  356. %{l_shtool} subst \
  357. -e 's:find_my_exec(argv.0., mypath):0; strcpy(mypath, "%{l_prefix}/bin/pg_config"):' \
  358. pg_config.c
  359. %{l_make} %{l_mflags}
  360. ) || exit $?
  361. %install
  362. rm -rf $RPM_BUILD_ROOT
  363. # perform standard installation procedure
  364. cp /dev/null register.txt
  365. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  366. # strip down installation
  367. rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
  368. strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
  369. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
  370. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
  371. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
  372. # namespace adjustments to installation
  373. for prog in \
  374. createdb createlang createuser dropdb droplang clusterdb \
  375. dropuser initdb ipcclean vacuumdb; do
  376. %if "%{with_compat}" == "yes"
  377. cmd="ln"
  378. %else
  379. cmd="mv"
  380. %endif
  381. $cmd $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
  382. $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
  383. $cmd $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
  384. $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
  385. done
  386. ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
  387. for man in *.7; do
  388. mv $man pg_$man
  389. done
  390. ) || exit $?
  391. # create additional directories
  392. %{l_shtool} mkdir -f -p -m 755 \
  393. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  394. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql \
  395. %endif
  396. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
  397. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
  398. # install migration utility
  399. %if "%{with_compat}" == "yes"
  400. l_pguser="postgres"
  401. l_pgpass="postgres"
  402. %else
  403. l_pguser="postgresql"
  404. l_pgpass="postgresql"
  405. %endif
  406. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  407. -e "s;@l_pguser@;${l_pguser};g" \
  408. -e "s;@l_pgpass@;${l_pgpass};g" \
  409. %{SOURCE pg_migrate} \
  410. $RPM_BUILD_ROOT%{l_prefix}/bin/
  411. # install C++ bindings (both old and new one)
  412. %if "%{with_cxx}" == "yes"
  413. ( cd libpq++-%{V_libpqpp}
  414. %{l_shtool} mkdir -f -p -m 755 \
  415. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++
  416. %{l_shtool} install -c -m 644 \
  417. libpq++.h pgconnection.h pgdatabase.h pgtransdb.h pgcursordb.h pglobject.h \
  418. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++/
  419. %{l_shtool} install -c -m 644 \
  420. libpq++.a \
  421. $RPM_BUILD_ROOT%{l_prefix}/lib/
  422. ) || exit $?
  423. ( cd libpqxx-%{V_libpqxx}
  424. %{l_shtool} mkdir -f -p -m 755 \
  425. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx
  426. %{l_shtool} install -c -m 644 \
  427. include/pqxx/* \
  428. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/
  429. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/Makefile*
  430. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/config.h*
  431. %{l_shtool} install -c -m 644 \
  432. src/.libs/libpqxx.a \
  433. $RPM_BUILD_ROOT%{l_prefix}/lib/
  434. ) || exit $?
  435. %endif
  436. # install Perl binding
  437. %if "%{with_perl}" == "yes"
  438. ( export POSTGRES_INCLUDE=dummy
  439. export POSTGRES_LIB=dummy
  440. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} install
  441. ) || exit $?
  442. %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
  443. %else
  444. >perl-openpkg-files
  445. %endif
  446. # install ODBC driver
  447. %if "%{with_odbc}" == "yes"
  448. ( cd psqlodbc-%{V_psqlodbc}
  449. %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
  450. ) || exit $?
  451. %endif
  452. # install Slony-1 replication engine
  453. %if "%{with_slony1}" == "yes"
  454. ( cd slony1-%{V_slony1}
  455. %{l_make} %{l_mflags} install \
  456. DESTDIR=$RPM_BUILD_ROOT \
  457. pgconfigdir=%{l_prefix}/bin \
  458. pgincludedir=%{l_prefix}/include/postgresql \
  459. pgincludeserverdir=%{l_prefix}/include/postgresql/libpq \
  460. pglibdir=%{l_prefix}/lib/postgresql \
  461. pgpkglibdir=%{l_prefix}/lib/postgresql \
  462. pgsharedir=%{l_prefix}/share/postgresql
  463. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/slony1*v7[34].sql
  464. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v73.sql
  465. mv $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v74.sql \
  466. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.sql
  467. ( echo "# Slony-1 configuration for replication engine slon(1)"
  468. echo "SLON_CLUSTER_NAME=\"example\""
  469. echo "SLON_CONNECT_DBNAME=\"example\""
  470. echo "SLON_CONNECT_USER=\"postgresql\""
  471. echo "SLON_CONNECT_PASS=\"postgresql\""
  472. echo "SLON_CONNECT_HOST=\"localhost\""
  473. echo "SLON_SYNC_INTERVAL=\"10000\""
  474. echo "SLON_SYNC_TIMEOUT=\"60000\""
  475. echo "SLON_SYNC_GROUPSIZE=\"6\""
  476. echo "SLON_SYNC_LOGLEVEL=\"1\""
  477. ) >$RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/slony1.conf
  478. ) || exit $?
  479. %endif
  480. # post-adjust pgcluster configuration filenames
  481. %if "%{with_pgcluster}" == "yes"
  482. cp $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/pglb.conf.sample \
  483. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pglb.conf
  484. cp $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/pgreplicate.conf.sample \
  485. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgreplicate.conf
  486. %endif
  487. # install MySQL compatibility layer
  488. %if "%{with_mysqlcompat}" == "yes"
  489. %{l_shtool} mkdir -f -p -m 755 \
  490. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/mysqlcompat
  491. %{l_shtool} install -c -m 644 \
  492. mysqlcompat-%{V_mysqlcompat}/README \
  493. mysqlcompat-%{V_mysqlcompat}/*.sql \
  494. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/mysqlcompat/
  495. %endif
  496. # install run-command script
  497. %{l_shtool} mkdir -f -p -m 755 \
  498. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  499. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  500. %{SOURCE rc.postgresql} \
  501. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  502. # optionally strip down to client-only installation
  503. %if "%{with_server}" != "yes"
  504. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_[a-bd-z]*
  505. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_c[a-np-z]*
  506. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_controldata
  507. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/post*
  508. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_[a-bd-z]*
  509. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_c[a-np-z]*
  510. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_controldata.1
  511. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/post*
  512. rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  513. rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/postgresql/server
  514. rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/postgresql
  515. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/postgresql
  516. rm -rf $RPM_BUILD_ROOT%{l_prefix}/var/postgresql
  517. %endif
  518. # determine installation files
  519. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  520. %if "%{with_server}" == "yes"
  521. %{l_files_std} `cat perl-openpkg-files` \
  522. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  523. '%config %{l_prefix}/etc/postgresql/*' \
  524. %endif
  525. '%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
  526. '%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
  527. %else
  528. %{l_files_std} `cat perl-openpkg-files`
  529. %endif
  530. %files -f files
  531. %clean
  532. rm -rf $RPM_BUILD_ROOT
  533. %pre
  534. %if "%{with_server}" == "yes"
  535. # before upgrade, check migration dump, save status and stop service
  536. [ $1 -eq 2 ] || exit 0
  537. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
  538. -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
  539. # database migration dumping hint
  540. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  541. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  542. v_new_all="%{V_postgresql}"
  543. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  544. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  545. if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$RPM_POSTGRESQL_MIGRATE" != .ignore ]; then
  546. ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  547. echo "which is a major version change. We expect a database incompatibility,"
  548. echo "so we strongly recommend that you backup your existing database"
  549. echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
  550. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
  551. echo "If this fails for some reasons, try to dump your data manually:"
  552. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dumpall -U postgresql -o | \\ "
  553. echo " $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -9 \\ "
  554. echo " >$RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2"
  555. echo "Alternatively, if you want to force this package to be installed without"
  556. echo "performing a database dump, run the following command before upgrading:"
  557. echo " \$ RPM_POSTGRESQL_MIGRATE=ignore; export RPM_POSTGRESQL_MIGRATE"
  558. ) | %{l_rpmtool} msg -b -t error
  559. exit 1
  560. fi
  561. fi
  562. fi
  563. eval `%{l_rc} postgresql status 2>/dev/null | tee %{l_tmpfile}`
  564. %{l_rc} postgresql stop 2>/dev/null
  565. exit 0
  566. %endif
  567. %post
  568. %if "%{with_server}" == "yes"
  569. if [ $1 -eq 1 ]; then
  570. # create initial database
  571. %if "%{with_compat}" == "yes"
  572. l_pguser="postgres"
  573. l_pgpass="postgres"
  574. %else
  575. l_pguser="postgresql"
  576. l_pgpass="postgresql"
  577. %endif
  578. su - %{l_rusr} -c \
  579. "LC_CTYPE=C; export LC_CTYPE; umask 022; \
  580. rm -rf $RPM_INSTALL_PREFIX/var/postgresql/db/*; \
  581. echo $l_pgpass >$RPM_INSTALL_PREFIX/var/postgresql/run/pw; \
  582. $RPM_INSTALL_PREFIX/bin/pg_initdb \
  583. -U $l_pguser --pwfile=$RPM_INSTALL_PREFIX/var/postgresql/run/pw \
  584. -D $RPM_INSTALL_PREFIX/var/postgresql/db; \
  585. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/pw" 2>&1 |\
  586. $RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
  587. -p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
  588. # adjust initial authentication configuration
  589. cp $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf \
  590. $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  591. ( cat $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old |\
  592. sed -e 's;^\([^#]\);# \1;' -e 's;^$;#;'
  593. echo ""
  594. echo "# OpenPKG PostgreSQL default access policy"
  595. echo "local all all md5"
  596. echo "host all all 127.0.0.1 255.255.255.255 md5"
  597. echo ""
  598. ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf
  599. rm -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  600. # display information about next steps
  601. ( echo "An initial PostgreSQL DB was created with the two standard"
  602. echo "databases 'template0' and 'template1'. The owner of both"
  603. echo "is the DB user '$l_pguser'. Its initial password is '$l_pgpass'."
  604. echo "After starting PostgreSQL with"
  605. echo " \$ $RPM_INSTALL_PREFIX/etc/rc postgresql start"
  606. echo "you should immediately change this with the following command:"
  607. echo " \$ $RPM_INSTALL_PREFIX/bin/psql -U $l_pguser -d template1 \\"
  608. echo " -c \"ALTER USER $l_pguser WITH PASSWORD '<new-password>'\""
  609. echo "Then you usually create a database for a user <user> with"
  610. echo "password <password> under path /u/<user>/rdbms with the commands:"
  611. echo " \$ mkdir /u/<user>/rdbms"
  612. echo " \$ chmod 700 /u/<user>/rdbms"
  613. echo " \$ chown %{l_rusr}:%{l_rgrp} /u/<user>/rdbms"
  614. echo " \$ $RPM_INSTALL_PREFIX/bin/psql -U $l_pguser -d template1"
  615. echo " template1=> CREATE USER <user>"
  616. echo " ENCRYPTED PASSWORD '<password>'"
  617. echo " NOCREATEDB NOCREATEUSER;"
  618. echo " template1=> CREATE TABLESPACE dss OWNER dss"
  619. echo " LOCATION '/u/<user>/rdbms';"
  620. echo " template1=> CREATE DATABASE <user>"
  621. echo " \$ echo 'localhost:*:<user>:<user>:<password>'"
  622. echo " >/home/<user>/.pgpass"
  623. ) | %{l_rpmtool} msg -b -t notice
  624. # optionally link into unixODBC
  625. %if "%{with_odbc}" == "yes"
  626. ( echo "[PostgreSQL]"
  627. echo "Description = PostgreSQL ODBC driver"
  628. echo "Driver = $RPM_INSTALL_PREFIX/lib/psqlodbc.so"
  629. echo "Threading = 2"
  630. ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r
  631. %endif
  632. fi
  633. if [ $1 -eq 2 ]; then
  634. # after upgrade, restore status
  635. { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
  636. [ ".$postgresql_active" = .yes ] && %{l_rc} postgresql start
  637. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
  638. # database migration restoring hint
  639. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  640. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  641. v_new_all="%{V_postgresql}"
  642. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  643. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  644. ( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  645. echo "which is a major version upgrade. We expect a database incompatibility,"
  646. echo "so we strongly recommend you to recreate the existing database under"
  647. echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
  648. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate restore"
  649. echo "If this fails for some reasons, try to restore your data manually:"
  650. echo " \$ $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -d -c \\ "
  651. echo " $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 | \\ "
  652. echo " $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1"
  653. ) | %{l_rpmtool} msg -b -t warn
  654. fi
  655. fi
  656. fi
  657. exit 0
  658. %endif
  659. %preun
  660. %if "%{with_server}" == "yes"
  661. # before erase, stop service and remove log files
  662. [ $1 -eq 0 ] || exit 0
  663. %{l_rc} postgresql stop 2>/dev/null
  664. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/* >/dev/null 2>&1 || true
  665. exit 0
  666. %endif