postgresql.spec 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. ##
  2. ## postgresql.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2005 OpenPKG Foundation e.V. <http://openpkg.net/>
  4. ## Copyright (c) 2000-2005 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. # FIXME: rse: pgcluster no longer applies after PostgreSQL 8.1 upgrade
  25. # package versions
  26. %define V_postgresql 8.1.0
  27. %define V_libpqpp 4.0
  28. %define V_libpqxx 2.5.5
  29. %define V_pgperl 2.0.2
  30. %define V_psqlodbc 08.00.0102
  31. %define V_slony1 1.1.2
  32. %define V_pgcluster 1.3.0c
  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: 20051105
  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. # list of sources
  55. Source0: ftp://ftp.postgresql.org/pub/source/v%{V_postgresql}/postgresql-%{V_postgresql}.tar.gz
  56. Source1: ftp://gborg.postgresql.org/pub/libpqpp/stable/libpq++-%{V_libpqpp}.tar.gz
  57. Source2: ftp://gborg.postgresql.org/pub/libpqxx/stable/libpqxx-%{V_libpqxx}.tar.gz
  58. Source3: ftp://gborg.postgresql.org/pub/pgperl/stable/pgperl-%{V_pgperl}.tar.gz
  59. Source4: ftp://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-%{V_psqlodbc}.tar.gz
  60. Source5: http://developer.postgresql.org/~wieck/slony1/download/slony1-%{V_slony1}.tar.bz2
  61. Source6: http://pgfoundry.org/frs/download.php/219/pgcluster-%{V_pgcluster}-patch.tar.gz
  62. Source7: rc.postgresql
  63. Source8: pg_migrate
  64. Patch0: postgresql.patch
  65. # build information
  66. Prefix: %{l_prefix}
  67. BuildRoot: %{l_buildroot}
  68. BuildPreReq: OpenPKG, openpkg >= 20040130, make, gcc, flex, bison, gzip
  69. PreReq: OpenPKG, openpkg >= 20040130
  70. BuildPreReq: readline, zlib, openssl, getopt
  71. PreReq: readline, zlib, openssl, getopt
  72. %if "%{with_perl}" == "yes"
  73. BuildPreReq: perl, perl-openpkg >= 5.8.3-20040126
  74. PreReq: perl
  75. %endif
  76. %if "%{with_odbc}" == "yes"
  77. BuildPreReq: unixodbc
  78. PreReq: unixodbc
  79. %endif
  80. %if "%{with_tcl}" == "yes"
  81. BuildPreReq: tcl, tcl::with_x11 = yes, X11
  82. PreReq: tcl, tcl::with_x11 = yes, X11
  83. %endif
  84. AutoReq: no
  85. AutoReqProv: no
  86. %description
  87. PostgreSQL is a sophisticated Object-Relational DBMS, supporting
  88. almost all SQL constructs, including subselects, transactions,
  89. and user-defined types and functions. It is the most advanced
  90. open-source database available anywhere.
  91. This PostgreSQL package optionally contains three database
  92. replication solutions: the PGPool connection pooling/replication
  93. frontend, the Slony-I single-master/multiple-slave replication
  94. engine, and the PGCluster multi-master replication engine.
  95. %track
  96. prog postgresql = {
  97. version = %{V_postgresql}
  98. url = ftp://ftp.postgresql.org/pub/source/
  99. regex = v(\d+\.\d+(\.\d+)*)(?!beta)
  100. url = ftp://ftp.postgresql.org/pub/source/v__NEWVER__/
  101. regex = postgresql-(\d+\.\d+(\.\d+)*)\.tar\.(?:gz|bz2)
  102. }
  103. prog postgresql:libpq++ = {
  104. version = %{V_libpqpp}
  105. url = ftp://gborg.postgresql.org/pub/libpqpp/stable/
  106. regex = libpq\+\+-(__VER__)\.tar\.gz
  107. }
  108. prog postgresql:libpqxx = {
  109. version = %{V_libpqxx}
  110. url = ftp://gborg.postgresql.org/pub/libpqxx/stable/
  111. regex = libpqxx-(__VER__)\.tar\.gz
  112. }
  113. prog postgresql:pgperl = {
  114. version = %{V_pgperl}
  115. url = ftp://gborg.postgresql.org/pub/pgperl/stable/
  116. regex = pgperl-(__VER__)\.tar\.gz
  117. }
  118. prog postgresql:psqlodbc = {
  119. version = %{V_psqlodbc}
  120. url = ftp://ftp.postgresql.org/pub/odbc/versions/src/
  121. regex = psqlodbc-(\d{2}\.\d{2}\.\d{4})\.tar\.gz
  122. }
  123. prog postgresql:slony1 = {
  124. version = %{V_slony1}
  125. url = http://developer.postgresql.org/~wieck/slony1/download/
  126. regex = slony1-(\d+\.\d+\.\d+)\.tar\.bz2
  127. }
  128. prog postgresql:pgcluster = {
  129. comment = "steve: beside the filename also the url hat to be changed to download the current version"
  130. version = %{V_pgcluster}
  131. url = http://pgfoundry.org/frs/?group_id=1000072&release_id=168
  132. regex = pgcluster-(__VER__)-patch\.tar\.gz
  133. }
  134. %prep
  135. %setup -q
  136. %patch -p0
  137. %if "%{with_cxx}" == "yes"
  138. %setup -q -T -D -a 1
  139. %setup -q -T -D -a 2
  140. case "%{l_platform -t}" in
  141. *-sunos* )
  142. %{l_shtool} subst \
  143. -e 's;strerror_r(0,0,0);strerror((int)0);g' \
  144. -e 's;strerror_r((int)0, (char \*)0, (size_t)0);strerror((int)0);g' \
  145. libpqxx-%{V_libpqxx}/configure
  146. %{l_shtool} subst \
  147. -e 's;strerror_r(err, buf, sizeof(buf));strerror(err);g' \
  148. libpqxx-%{V_libpqxx}/src/largeobject.cxx \
  149. libpqxx-%{V_libpqxx}/configure
  150. ;;
  151. esac
  152. %endif
  153. %if "%{with_perl}" == "yes"
  154. %setup -q -T -D -a 3
  155. %endif
  156. %if "%{with_odbc}" == "yes"
  157. %setup -q -T -D -a 4
  158. %endif
  159. %if "%{with_slony1}" == "yes"
  160. %setup -q -T -D -a 5
  161. %endif
  162. %if "%{with_pgcluster}" == "yes"
  163. %setup -q -T -D -a 6
  164. cat pgcluster-*-patch | \
  165. sed -e 's;\($.exec_prefix./etc\);\1/postgresql;' \
  166. -e '/preproc\.c/,/Makefile\.aix/d' | \
  167. %{l_patch} -p1
  168. %endif
  169. # adjust source tree
  170. %{l_shtool} subst \
  171. -e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
  172. src/include/pg_config_manual.h
  173. %{l_shtool} subst \
  174. -e 's;^\(sqlmansect *=\).*$;\1 7;' \
  175. src/makefiles/Makefile.solaris
  176. %{l_shtool} subst \
  177. -e 's;$(INSTALL_SHLIB);#$(INSTALL_SHLIB);g' \
  178. src/backend/utils/mb/conversion_procs/proc.mk
  179. %{l_shtool} subst \
  180. -e 's;# Shared library stuff;enable_shared = yes;g' \
  181. src/pl/plpgsql/src/Makefile
  182. %build
  183. rm -rf $RPM_BUILD_ROOT
  184. # configure package
  185. ( echo "ac_cv_func_isinf=no"
  186. ) >config.cache
  187. CC="%{l_cc}" \
  188. %if "%{with_slony1}" == "yes"
  189. CFLAGS="%{l_cflags -O} -pthread" \
  190. %else
  191. CFLAGS="%{l_cflags -O}" \
  192. %endif
  193. %if "%{with_tcl}" == "yes"
  194. CPPFLAGS="%{l_cppflags readline tcl} -DOPENSSL_DISABLE_OLD_DES_SUPPORT" \
  195. LDFLAGS="%{l_ldflags} -L`%{l_rc} --query x11_libdir`" \
  196. %else
  197. CPPFLAGS="%{l_cppflags readline} -DOPENSSL_DISABLE_OLD_DES_SUPPORT" \
  198. LDFLAGS="%{l_ldflags}" \
  199. %endif
  200. TAR="%{l_tar}" \
  201. YACC="bison -y" \
  202. ./configure \
  203. --cache-file=./config.cache \
  204. --prefix=%{l_prefix} \
  205. --sysconfdir=%{l_prefix}/etc/postgresql \
  206. --includedir=%{l_prefix}/include/postgresql \
  207. --with-openssl \
  208. --with-readline \
  209. --with-zlib \
  210. %if "%{with_tcl}" == "yes"
  211. --with-tcl \
  212. --with-tclconfig="%{l_prefix}/lib" \
  213. --with-tkconfig="%{l_prefix}/lib" \
  214. %endif
  215. %if "%{with_slony1}" == "yes"
  216. --enable-thread-safety \
  217. %endif
  218. --disable-syslog \
  219. --disable-shared
  220. # build package
  221. %{l_make} %{l_mflags}
  222. # build C++ bindings (both old and new one)
  223. %if "%{with_cxx}" == "yes"
  224. ( cd libpq++-%{V_libpqpp}
  225. CXX="%{l_cxx}"
  226. CFLAGS="%{l_cflags -O}"
  227. CPPFLAGS="-DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT= "
  228. CPPFLAGS="$CPPFLAGS -I. -I../src/interfaces/libpq -I../src/interfaces"
  229. CPPFLAGS="$CPPFLAGS -I../src/include %{l_cppflags}"
  230. LDFLAGS="%{l_ldflags}"
  231. OBJS="pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o"
  232. for o in $OBJS; do
  233. $CXX $CFLAGS $CPPFLAGS $LDFLAGS -c -o $o `echo $o | sed -e 's;\.o$;.cc;'`
  234. done
  235. rm -f libpq++.a
  236. ar rc libpq++.a $OBJS
  237. ) || exit $?
  238. ln -s `pwd`/src/interfaces/libpq/*.h src/include/
  239. ( cd libpqxx-%{V_libpqxx}
  240. %{l_shtool} subst \
  241. -e 's;\(cut\)\( .*/configitems\)\( -f [0-9]\);\1\3\2;g' \
  242. configure
  243. ( echo "#!/bin/sh"
  244. echo "case \"\$1\" in"
  245. echo " --includedir ) echo \"`pwd`/../src/include\" ;;"
  246. echo " --libdir ) echo \"`pwd`/../src/interfaces/libpq\" ;;"
  247. echo "esac"
  248. ) >pg_config
  249. chmod a+x pg_config
  250. export PG_CONFIG=`pwd`/pg_config
  251. export CC="%{l_cc}"
  252. export CXX="%{l_cxx}"
  253. export CFLAGS="%{l_cflags -O}"
  254. export CXXFLAGS="%{l_cxxflags -O}"
  255. export CPPFLAGS="-I`pwd`/../src/include %{l_cppflags}"
  256. export LDFLAGS="%{l_ldflags}"
  257. export LIBS="-lssl -lcrypto -lcrypt"
  258. case "%{l_platform -t}" in
  259. *-sunos* ) LIBS="$LIBS -lsocket -lnsl" ;;
  260. esac
  261. ./configure \
  262. --disable-shared
  263. %{l_make} %{l_mflags -O}
  264. ) || exit $?
  265. %endif
  266. # build Perl bindings
  267. %if "%{with_perl}" == "yes"
  268. %{l_prefix}/bin/perl-openpkg prepare
  269. ( cd Pg-%{V_pgperl}
  270. export POSTGRES_INCLUDE=dummy
  271. export POSTGRES_LIB=dummy
  272. %{l_shtool} subst \
  273. -e 's;-I$POSTGRES_INCLUDE;-I../src/interfaces/libpq -I../src/include;' \
  274. -e 's;-L$POSTGRES_LIB;-L../src/interfaces/libpq;' \
  275. -e 's;-lpq;-lpq %{l_ldflags} -lssl -lcrypto -lcrypt;' \
  276. Makefile.PL
  277. ) || exit $?
  278. ( export POSTGRES_INCLUDE=dummy
  279. export POSTGRES_LIB=dummy
  280. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} configure build
  281. ) || exit $?
  282. %endif
  283. # build ODBC driver
  284. %if "%{with_odbc}" == "yes"
  285. ( cd psqlodbc-%{V_psqlodbc}
  286. export CC="%{l_cc}"
  287. export CXX="%{l_cxx}"
  288. export CFLAGS="%{l_cflags -O}"
  289. export CXXFLAGS="%{l_cxxflags -O}"
  290. export CPPFLAGS="-I`pwd`/../src/include"
  291. CPPFLAGS="$CPPFLAGS -I`pwd`/../src/interfaces -I`pwd`/../src/interfaces/libpq"
  292. CPPFLAGS="$CPPFLAGS %{l_cppflags}"
  293. export LDFLAGS="-L`pwd`/../src/interfaces/libpq %{l_ldflags}"
  294. ./configure \
  295. --prefix=%{l_prefix} \
  296. --with-unixodbc \
  297. --with-odbcinst=%{l_prefix}/etc/unixodbc
  298. %{l_make} %{l_mflags -O}
  299. ) || exit $?
  300. %endif
  301. # build Slony-1 replication engine
  302. %if "%{with_slony1}" == "yes"
  303. ( cd slony1-%{V_slony1}
  304. ln ../src/pl/plpgsql/src/libplpgsql.so \
  305. ../src/pl/plpgsql/src/plpgsql.so
  306. %{l_shtool} subst \
  307. -e 's;-lpq;-lpq -lssl -lcrypto -lcrypt;' \
  308. src/slon/Makefile src/slonik/Makefile
  309. export CC="%{l_cc}"
  310. export CFLAGS="%{l_cflags -O}"
  311. export CPPFLAGS="%{l_cppflags}"
  312. export LDFLAGS="%{l_ldflags}"
  313. export LIBS="-lssl -lcrypto -lcrypt"
  314. ./configure \
  315. --prefix=%{l_prefix} \
  316. --sysconfdir=%{l_prefix}/etc/postgresql \
  317. --with-pgconfigdir=../src/bin/pg_config \
  318. --with-pgincludedir=../src/include \
  319. --with-pgincludeserverdir=../src/interfaces/libpq \
  320. --with-pglibdir=../src/interfaces/libpq \
  321. --with-pgpkglibdir=../src/pl/plpgsql/src \
  322. --with-pgsharedir=../src/backend/utils/misc
  323. %{l_make} %{l_mflags -O}
  324. ) || exit $?
  325. %endif
  326. %install
  327. rm -rf $RPM_BUILD_ROOT
  328. # perform standard installation procedure
  329. cp /dev/null register.txt
  330. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  331. # strip down installation
  332. rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
  333. strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
  334. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
  335. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
  336. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
  337. # namespace adjustments to installation
  338. for prog in \
  339. createdb createlang createuser dropdb droplang clusterdb \
  340. dropuser initdb ipcclean vacuumdb; do
  341. %if "%{with_compat}" == "yes"
  342. cmd="ln"
  343. %else
  344. cmd="mv"
  345. %endif
  346. $cmd $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
  347. $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
  348. $cmd $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
  349. $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
  350. done
  351. ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
  352. for man in *.7; do
  353. mv $man pg_$man
  354. done
  355. ) || exit $?
  356. # create additional directories
  357. %{l_shtool} mkdir -f -p -m 755 \
  358. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  359. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql \
  360. %endif
  361. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
  362. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
  363. # install migration utility
  364. %if "%{with_compat}" == "yes"
  365. l_pguser="postgres"
  366. l_pgpass="postgres"
  367. %else
  368. l_pguser="postgresql"
  369. l_pgpass="postgresql"
  370. %endif
  371. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  372. -e "s;@l_pguser@;${l_pguser};g" \
  373. -e "s;@l_pgpass@;${l_pgpass};g" \
  374. %{SOURCE pg_migrate} \
  375. $RPM_BUILD_ROOT%{l_prefix}/bin/
  376. # install C++ bindings (both old and new one)
  377. %if "%{with_cxx}" == "yes"
  378. ( cd libpq++-%{V_libpqpp}
  379. %{l_shtool} mkdir -f -p -m 755 \
  380. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++
  381. %{l_shtool} install -c -m 644 \
  382. libpq++.h pgconnection.h pgdatabase.h pgtransdb.h pgcursordb.h pglobject.h \
  383. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++/
  384. %{l_shtool} install -c -m 644 \
  385. libpq++.a \
  386. $RPM_BUILD_ROOT%{l_prefix}/lib/
  387. ) || exit $?
  388. ( cd libpqxx-%{V_libpqxx}
  389. %{l_shtool} mkdir -f -p -m 755 \
  390. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx
  391. %{l_shtool} install -c -m 644 \
  392. include/pqxx/* \
  393. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/
  394. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/Makefile*
  395. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/config.h*
  396. %{l_shtool} install -c -m 644 \
  397. src/.libs/libpqxx.a \
  398. $RPM_BUILD_ROOT%{l_prefix}/lib/
  399. ) || exit $?
  400. %endif
  401. # install Perl binding
  402. %if "%{with_perl}" == "yes"
  403. ( export POSTGRES_INCLUDE=dummy
  404. export POSTGRES_LIB=dummy
  405. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} install
  406. ) || exit $?
  407. %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
  408. %else
  409. >perl-openpkg-files
  410. %endif
  411. # install ODBC driver
  412. %if "%{with_odbc}" == "yes"
  413. ( cd psqlodbc-%{V_psqlodbc}
  414. %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
  415. ) || exit $?
  416. %endif
  417. # install Slony-1 replication engine
  418. %if "%{with_slony1}" == "yes"
  419. ( cd slony1-%{V_slony1}
  420. %{l_make} %{l_mflags} install \
  421. DESTDIR=$RPM_BUILD_ROOT \
  422. pgconfigdir=%{l_prefix}/bin \
  423. pgincludedir=%{l_prefix}/include/postgresql \
  424. pgincludeserverdir=%{l_prefix}/include/postgresql/libpq \
  425. pglibdir=%{l_prefix}/lib/postgresql \
  426. pgpkglibdir=%{l_prefix}/lib/postgresql \
  427. pgsharedir=%{l_prefix}/share/postgresql
  428. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/slony1*v7[34].sql
  429. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v73.sql
  430. mv $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v74.sql \
  431. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.sql
  432. ( echo "# Slony-1 configuration for replication engine slon(1)"
  433. echo "SLON_CLUSTER_NAME=\"example\""
  434. echo "SLON_CONNECT_DBNAME=\"example\""
  435. echo "SLON_CONNECT_USER=\"postgresql\""
  436. echo "SLON_CONNECT_PASS=\"postgresql\""
  437. echo "SLON_CONNECT_HOST=\"localhost\""
  438. echo "SLON_SYNC_INTERVAL=\"10000\""
  439. echo "SLON_SYNC_TIMEOUT=\"60000\""
  440. echo "SLON_SYNC_GROUPSIZE=\"6\""
  441. echo "SLON_SYNC_LOGLEVEL=\"1\""
  442. ) >$RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/slony1.conf
  443. ) || exit $?
  444. %endif
  445. %if "%{with_pgcluster}" == "yes"
  446. # post-adjust pgcluster configuration filenames
  447. mv $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pglb.conf.sample \
  448. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pglb.conf
  449. mv $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgreplicate.conf.sample \
  450. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgreplicate.conf
  451. %endif
  452. # install run-command script
  453. %{l_shtool} mkdir -f -p -m 755 \
  454. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  455. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  456. %{SOURCE rc.postgresql} \
  457. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  458. # optionally strip down to client-only installation
  459. %if "%{with_server}" != "yes"
  460. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_[a-bd-z]*
  461. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_c[a-np-z]*
  462. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_controldata
  463. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/post*
  464. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_[a-bd-z]*
  465. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_c[a-np-z]*
  466. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_controldata.1
  467. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/post*
  468. rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  469. rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/postgresql/server
  470. rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/postgresql
  471. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/postgresql
  472. rm -rf $RPM_BUILD_ROOT%{l_prefix}/var/postgresql
  473. %endif
  474. # determine installation files
  475. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  476. %if "%{with_server}" == "yes"
  477. %{l_files_std} `cat perl-openpkg-files` \
  478. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  479. '%config %{l_prefix}/etc/postgresql/*' \
  480. %endif
  481. '%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
  482. '%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
  483. %else
  484. %{l_files_std} `cat perl-openpkg-files`
  485. %endif
  486. %files -f files
  487. %clean
  488. rm -rf $RPM_BUILD_ROOT
  489. %pre
  490. %if "%{with_server}" == "yes"
  491. # before upgrade, check migration dump, save status and stop service
  492. [ $1 -eq 2 ] || exit 0
  493. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
  494. -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
  495. # database migration dumping hint
  496. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  497. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  498. v_new_all="%{V_postgresql}"
  499. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  500. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  501. if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$RPM_POSTGRESQL_MIGRATE" != .ignore ]; then
  502. ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  503. echo "which is a major version change. We expect a database incompatibility,"
  504. echo "so we strongly recommend that you backup your existing database"
  505. echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
  506. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
  507. echo "If this fails for some reasons, try to dump your data manually:"
  508. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dumpall -U postgresql -o | \\ "
  509. echo " $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -9 \\ "
  510. echo " >$RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2"
  511. echo "Alternatively, if you want to force this package to be installed without"
  512. echo "performing a database dump, run the following command before upgrading:"
  513. echo " \$ RPM_POSTGRESQL_MIGRATE=ignore; export RPM_POSTGRESQL_MIGRATE"
  514. ) | %{l_rpmtool} msg -b -t error
  515. exit 1
  516. fi
  517. fi
  518. fi
  519. eval `%{l_rc} postgresql status 2>/dev/null | tee %{l_tmpfile}`
  520. %{l_rc} postgresql stop 2>/dev/null
  521. exit 0
  522. %endif
  523. %post
  524. %if "%{with_server}" == "yes"
  525. if [ $1 -eq 1 ]; then
  526. # create initial database
  527. %if "%{with_compat}" == "yes"
  528. l_pguser="postgres"
  529. l_pgpass="postgres"
  530. %else
  531. l_pguser="postgresql"
  532. l_pgpass="postgresql"
  533. %endif
  534. su - %{l_rusr} -c \
  535. "LC_CTYPE=C; export LC_CTYPE; umask 022; \
  536. rm -rf $RPM_INSTALL_PREFIX/var/postgresql/db/*; \
  537. echo $l_pgpass >$RPM_INSTALL_PREFIX/var/postgresql/run/pw; \
  538. $RPM_INSTALL_PREFIX/bin/pg_initdb \
  539. -U $l_pguser --pwfile=$RPM_INSTALL_PREFIX/var/postgresql/run/pw \
  540. -D $RPM_INSTALL_PREFIX/var/postgresql/db; \
  541. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/pw" 2>&1 |\
  542. $RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
  543. -p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
  544. # adjust initial authentication configuration
  545. cp $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf \
  546. $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  547. ( cat $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old |\
  548. sed -e 's;^\([^#]\);# \1;' -e 's;^$;#;'
  549. echo ""
  550. echo "# OpenPKG PostgreSQL default access policy"
  551. echo "local all all md5"
  552. echo "host all all 127.0.0.1 255.255.255.255 md5"
  553. echo ""
  554. ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf
  555. rm -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  556. # display information about next steps
  557. ( echo "An initial PostgreSQL DB was created with the two standard"
  558. echo "databases 'template0' and 'template1'. The owner of both"
  559. echo "is the DB user '$l_pguser'. Its initial password is '$l_pgpass'."
  560. echo "After starting PostgreSQL with"
  561. echo " \$ $RPM_INSTALL_PREFIX/etc/rc postgresql start"
  562. echo "you should immediately change this with the following command:"
  563. echo " \$ $RPM_INSTALL_PREFIX/bin/psql -U $l_pguser -d template1 \\"
  564. echo " -c \"ALTER USER $l_pguser WITH PASSWORD '<new-password>'\""
  565. ) | %{l_rpmtool} msg -b -t notice
  566. # optionally link into unixODBC
  567. %if "%{with_odbc}" == "yes"
  568. ( echo "[PostgreSQL]"
  569. echo "Description = PostgreSQL ODBC driver"
  570. echo "Driver = $RPM_INSTALL_PREFIX/lib/psqlodbc.so"
  571. echo "Threading = 2"
  572. ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r
  573. %endif
  574. fi
  575. if [ $1 -eq 2 ]; then
  576. # after upgrade, restore status
  577. { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
  578. [ ".$postgresql_active" = .yes ] && %{l_rc} postgresql start
  579. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
  580. # database migration restoring hint
  581. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  582. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  583. v_new_all="%{V_postgresql}"
  584. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  585. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  586. ( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  587. echo "which is a major version upgrade. We expect a database incompatibility,"
  588. echo "so we strongly recommend you to recreate the existing database under"
  589. echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
  590. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate restore"
  591. echo "If this fails for some reasons, try to restore your data manually:"
  592. echo " \$ $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -d -c \\ "
  593. echo " $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 | \\ "
  594. echo " $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1"
  595. ) | %{l_rpmtool} msg -b -t warn
  596. fi
  597. fi
  598. fi
  599. exit 0
  600. %endif
  601. %preun
  602. %if "%{with_server}" == "yes"
  603. # before erase, stop service and remove log files
  604. [ $1 -eq 0 ] || exit 0
  605. %{l_rc} postgresql stop 2>/dev/null
  606. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/* >/dev/null 2>&1 || true
  607. exit 0
  608. %endif