postgresql.spec 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. ##
  2. ## postgresql.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
  4. ## Copyright (c) 2000-2007 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.2.4
  26. %define V_libpqpp 4.0
  27. %define V_libpqxx 2.5.5
  28. %define V_perl 5.8.8
  29. %define V_pgperl 2.0.2
  30. %define V_psqlodbc 08.02.0200
  31. %define V_slony1 1.2.6
  32. %define V_slony1_dir 1215
  33. %define V_pgcluster 1.7.0rc5
  34. %define V_pgcluster_dir 1297
  35. %define V_mysqlcompat 1.0b3
  36. %define V_mysqlcompat_dir 548
  37. # package information
  38. Name: postgresql
  39. Summary: PostgreSQL Database
  40. URL: http://www.postgresql.org/
  41. Vendor: PostgreSQL Group
  42. Packager: OpenPKG Foundation e.V.
  43. Distribution: OpenPKG Community
  44. Class: BASE
  45. Group: Database
  46. License: GPL
  47. Version: %{V_postgresql}
  48. Release: 20070420
  49. # package options
  50. %option with_server yes
  51. %option with_cxx no
  52. %option with_perl no
  53. %option with_odbc no
  54. %option with_compat no
  55. %option with_tcl no
  56. %option with_slony1 no
  57. %option with_pgcluster no
  58. %option with_kerberos no
  59. %option with_mysqlcompat no
  60. %option with_int_datetime no
  61. # list of sources
  62. Source0: ftp://ftp.postgresql.org/pub/source/v%{V_postgresql}/postgresql-%{V_postgresql}.tar.bz2
  63. Source1: ftp://gborg.postgresql.org/pub/libpqpp/stable/libpq++-%{V_libpqpp}.tar.gz
  64. Source2: ftp://gborg.postgresql.org/pub/libpqxx/stable/libpqxx-%{V_libpqxx}.tar.gz
  65. Source3: ftp://gborg.postgresql.org/pub/pgperl/stable/pgperl-%{V_pgperl}.tar.gz
  66. Source4: ftp://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-%{V_psqlodbc}.tar.gz
  67. Source5: http://pgfoundry.org/frs/download.php/%{V_slony1_dir}/slony1-%{V_slony1}-tar.bz2
  68. Source6: http://pgfoundry.org/frs/download.php/%{V_pgcluster_dir}/pgcluster-%{V_pgcluster}-patch.tar.gz
  69. Source7: http://pgfoundry.org/frs/download.php/%{V_mysqlcompat_dir}/mysqlcompat-%{V_mysqlcompat}.tar.gz
  70. Source8: rc.postgresql
  71. Source9: pg_migrate
  72. Patch0: postgresql.patch
  73. # build information
  74. Prefix: %{l_prefix}
  75. BuildRoot: %{l_buildroot}
  76. BuildPreReq: OpenPKG, openpkg >= 20060823, make, gcc, flex, bison, gzip
  77. PreReq: OpenPKG, openpkg >= 20060823
  78. BuildPreReq: readline, zlib, openssl, getopt
  79. PreReq: readline, zlib, openssl, getopt
  80. %if "%{with_perl}" == "yes"
  81. BuildPreReq: perl >= %{V_perl}, perl-openpkg >= %{V_perl}-20061013
  82. PreReq: perl >= %{V_perl}
  83. %endif
  84. %if "%{with_odbc}" == "yes"
  85. BuildPreReq: unixodbc
  86. PreReq: unixodbc
  87. %endif
  88. %if "%{with_tcl}" == "yes"
  89. BuildPreReq: tcl, tcl::with_x11 = yes, X11
  90. PreReq: tcl, tcl::with_x11 = yes, X11
  91. %endif
  92. %if "%{with_kerberos}" == "yes"
  93. BuildPreReq: kerberos
  94. PreReq: kerberos
  95. %endif
  96. AutoReq: no
  97. AutoReqProv: no
  98. %description
  99. PostgreSQL is a sophisticated Object-Relational Database Management
  100. System (ORDBMS). It is fully ACID compliant and has full support
  101. for foreign keys, joins, views, triggers, and stored procedures (in
  102. multiple languages). It includes most SQL92 and SQL99 data types
  103. and also supports storage of binary large objects. It is the most
  104. advanced Open-Source RDBMS available anywhere.
  105. As an enterprise class RDBMS, PostgreSQL boasts sophisticated
  106. features such as Multi-Version Concurrency Control (MVCC), Point In
  107. Time Recovery (PITR), tablespaces, asynchronous replication, nested
  108. transactions (savepoints), online/hot backups, a sophisticated
  109. query planner/optimizer, and Write Ahead Logging (WAL) for fault
  110. tolerance. It supports international character sets, multibyte
  111. character encodings, Unicode, and it is locale-aware for sorting,
  112. case-sensitivity, and formatting. It is highly scalable both in the
  113. sheer quantity of data it can manage and in the number of concurrent
  114. users it can accommodate.
  115. %track
  116. prog postgresql = {
  117. version = %{V_postgresql}
  118. url = ftp://ftp.postgresql.org/pub/source/
  119. regex = v(\d+\.\d+(\.\d+)*)
  120. url = ftp://ftp.postgresql.org/pub/source/v__NEWVER__/
  121. regex = postgresql-(\d+(\.\d+)+)\.tar\.(bz2|gz)
  122. }
  123. prog postgresql:libpq++ = {
  124. version = %{V_libpqpp}
  125. url = ftp://gborg.postgresql.org/pub/libpqpp/stable/
  126. regex = libpq\+\+-(__VER__)\.tar\.gz
  127. }
  128. prog postgresql:libpqxx = {
  129. version = %{V_libpqxx}
  130. url = ftp://gborg.postgresql.org/pub/libpqxx/stable/
  131. regex = libpqxx-(__VER__)\.tar\.gz
  132. }
  133. prog postgresql:pgperl = {
  134. version = %{V_pgperl}
  135. url = ftp://gborg.postgresql.org/pub/pgperl/stable/
  136. regex = pgperl-(__VER__)\.tar\.gz
  137. }
  138. prog postgresql:psqlodbc = {
  139. version = %{V_psqlodbc}
  140. url = ftp://ftp.postgresql.org/pub/odbc/versions/src/
  141. regex = psqlodbc-(\d{2}\.\d{2}\.\d{4})\.tar\.gz
  142. }
  143. prog postgresql:slony1 = {
  144. version = %{V_slony1}.%{V_slony1_dir}
  145. url = http://pgfoundry.org/frs/?group_id=1000122
  146. regex = /(\d+/slony1-\d+\.\d+\.\d+)[-.]tar\.bz2
  147. transform = "s/^(\\d+)\/slony1-(\d+\.\d+\.\d+)$/$2.$1/; $_"
  148. }
  149. prog postgresql:pgcluster = {
  150. version = %{V_pgcluster}.%{V_pgcluster_dir}
  151. url = http://pgfoundry.org/frs/?group_id=1000072
  152. regex = /(\d+/pgcluster-__VER__)-patch\.tar\.gz
  153. transform = "s/^(\\d+)\/pgcluster-(.+)$/$2.$1/; $_"
  154. }
  155. prog postgresql:mysqlcompat = {
  156. version = %{V_mysqlcompat}.%{V_mysqlcompat_dir}
  157. url = http://pgfoundry.org/frs/?group_id=1000154
  158. regex = (\d+/mysqlcompat-__VER__)\.tar\.gz
  159. transform = "s/^(\\d+)\/mysqlcompat-(.+)$/$2.$1/; $_"
  160. }
  161. %prep
  162. %setup -q
  163. %patch -p0
  164. %if "%{with_cxx}" == "yes"
  165. %setup -q -T -D -a 1
  166. %setup -q -T -D -a 2
  167. case "%{l_platform -t}" in
  168. *-sunos* )
  169. %{l_shtool} subst \
  170. -e 's;strerror_r(0,0,0);strerror((int)0);g' \
  171. -e 's;strerror_r((int)0, (char \*)0, (size_t)0);strerror((int)0);g' \
  172. libpqxx-%{V_libpqxx}/configure
  173. %{l_shtool} subst \
  174. -e 's;strerror_r(err, buf, sizeof(buf));strerror(err);g' \
  175. libpqxx-%{V_libpqxx}/src/largeobject.cxx \
  176. libpqxx-%{V_libpqxx}/configure
  177. %{l_shtool} subst \
  178. -e 's;\(strerror(err) ==\) -1;\1 (char *)-1;' \
  179. libpqxx-%{V_libpqxx}/src/largeobject.cxx
  180. ;;
  181. esac
  182. %{l_shtool} subst \
  183. -e 's;^function \(add_compiler_opts() {\);\1;' \
  184. libpqxx-%{V_libpqxx}/configure
  185. %endif
  186. %if "%{with_perl}" == "yes"
  187. %setup -q -T -D -a 3
  188. %endif
  189. %if "%{with_odbc}" == "yes"
  190. %setup -q -T -D -a 4
  191. %endif
  192. %if "%{with_slony1}" == "yes"
  193. %setup -q -T -D -a 5
  194. %endif
  195. %if "%{with_pgcluster}" == "yes"
  196. %setup -q -T -D -a 6
  197. sed -e '/^diff.*libpq\.rc/,/^diff/d' pgcluster-*-patch |\
  198. %{l_patch} -p1
  199. %endif
  200. %if "%{with_mysqlcompat}" == "yes"
  201. %setup -q -T -D -a 7
  202. %endif
  203. %if "%{with_kerberos}" == "yes"
  204. %{l_shtool} subst \
  205. -e 's;krb5 -ldes -lasn1 -lroken;krb5 -lk5crypto -lkrb5support -lcom_err;g' \
  206. configure
  207. %endif
  208. # adjust source tree
  209. %{l_shtool} subst \
  210. -e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
  211. src/include/pg_config_manual.h
  212. %{l_shtool} subst \
  213. -e 's;^\(sqlmansect *=\).*$;\1 7;' \
  214. src/makefiles/Makefile.solaris
  215. %{l_shtool} subst \
  216. -e 's;$(INSTALL_SHLIB);#$(INSTALL_SHLIB);g' \
  217. src/backend/utils/mb/conversion_procs/proc.mk
  218. %{l_shtool} subst \
  219. -e 's;# Shared library stuff;enable_shared = yes;g' \
  220. src/pl/plpgsql/src/Makefile
  221. %build
  222. rm -rf $RPM_BUILD_ROOT
  223. # configure package
  224. echo "ac_cv_func_isinf=no" >config.cache
  225. export CC="%{l_cc}"
  226. export CFLAGS="%{l_cflags -O}"
  227. export CPPFLAGS="%{l_cppflags readline}"
  228. export LDFLAGS="%{l_ldflags}"
  229. export LIBS=""
  230. %if "%{with_slony1}" == "yes"
  231. CFLAGS="$CFLAGS -pthread"
  232. %endif
  233. %if "%{with_tcl}" == "yes"
  234. CPPFLAGS="$CPPFLAGS %{l_cppflags tcl}"
  235. LDFLAGS="$LDFLAGS -L`%{l_rc} --query x11_libdir`"
  236. %endif
  237. %if "%{with_kerberos}" == "yes"
  238. CPPFLAGS="$CPPFLAGS %{l_cppflags kerberos}"
  239. LDFLAGS="$LDFLAGS %{l_ldflags kerberos}"
  240. %endif
  241. %if "%{with_pgcluster}" == "yes"
  242. case "%{l_platform -t}" in
  243. *-freebsd* ) LIBS="$LIBS -lcompat" ;;
  244. esac
  245. %endif
  246. export TAR="%{l_tar}"
  247. export YACC="bison -y"
  248. ./configure \
  249. --cache-file=./config.cache \
  250. --prefix=%{l_prefix} \
  251. --sysconfdir=%{l_prefix}/etc/postgresql \
  252. --includedir=%{l_prefix}/include/postgresql \
  253. --with-openssl \
  254. --with-readline \
  255. --with-zlib \
  256. %if "%{with_tcl}" == "yes"
  257. --with-tcl \
  258. --with-tclconfig="%{l_prefix}/lib" \
  259. --with-tkconfig="%{l_prefix}/lib" \
  260. %endif
  261. %if "%{with_slony1}" == "yes"
  262. --enable-thread-safety \
  263. %endif
  264. %if "%{with_kerberos}" == "yes"
  265. --with-krb5 \
  266. --with-krb-srvnam=postgresql \
  267. %endif
  268. %if "%{with_int_datetime}" == "yes"
  269. --enable-integer-datetimes \
  270. %endif
  271. --disable-syslog \
  272. --disable-shared
  273. # build package
  274. %{l_make} %{l_mflags}
  275. # build C++ bindings (both old and new one)
  276. %if "%{with_cxx}" == "yes"
  277. ( cd libpq++-%{V_libpqpp}
  278. CXX="%{l_cxx}"
  279. CFLAGS="%{l_cflags -O}"
  280. CPPFLAGS="-DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT= "
  281. CPPFLAGS="$CPPFLAGS -I. -I../src/interfaces/libpq -I../src/interfaces"
  282. CPPFLAGS="$CPPFLAGS -I../src/include %{l_cppflags}"
  283. LDFLAGS="%{l_ldflags}"
  284. OBJS="pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o"
  285. for o in $OBJS; do
  286. $CXX $CFLAGS $CPPFLAGS $LDFLAGS -c -o $o `echo $o | sed -e 's;\.o$;.cc;'`
  287. done
  288. rm -f libpq++.a
  289. ar rc libpq++.a $OBJS
  290. ) || exit $?
  291. ln -s `pwd`/src/interfaces/libpq/*.h src/include/
  292. ( cd libpqxx-%{V_libpqxx}
  293. %{l_shtool} subst \
  294. -e 's;\(cut\)\( .*/configitems\)\( -f [0-9]\);\1\3\2;g' \
  295. configure
  296. ( echo "#!/bin/sh"
  297. echo "case \"\$1\" in"
  298. echo " --includedir ) echo \"`pwd`/../src/include\" ;;"
  299. echo " --libdir ) echo \"`pwd`/../src/interfaces/libpq\" ;;"
  300. echo "esac"
  301. ) >pg_config
  302. chmod a+x pg_config
  303. export PG_CONFIG=`pwd`/pg_config
  304. export CC="%{l_cc}"
  305. export CXX="%{l_cxx}"
  306. export CFLAGS="%{l_cflags -O}"
  307. export CXXFLAGS="%{l_cxxflags -O}"
  308. export CPPFLAGS="-I`pwd`/../src/include %{l_cppflags}"
  309. export LDFLAGS="%{l_ldflags}"
  310. export LIBS="-lssl -lcrypto -lcrypt"
  311. case "%{l_platform -t}" in
  312. *-sunos* ) LIBS="$LIBS -lsocket -lnsl" ;;
  313. esac
  314. ./configure \
  315. --disable-shared
  316. %{l_make} %{l_mflags -O}
  317. ) || exit $?
  318. %endif
  319. # build Perl bindings
  320. %if "%{with_perl}" == "yes"
  321. %{l_prefix}/bin/perl-openpkg prepare
  322. ( cd Pg-%{V_pgperl}
  323. export POSTGRES_INCLUDE=dummy
  324. export POSTGRES_LIB=dummy
  325. %{l_shtool} subst \
  326. -e 's;-I$POSTGRES_INCLUDE;-I../src/interfaces/libpq -I../src/include;' \
  327. -e 's;-L$POSTGRES_LIB;-L../src/interfaces/libpq;' \
  328. -e 's;-lpq;-lpq %{l_ldflags} -lssl -lcrypto -lcrypt;' \
  329. Makefile.PL
  330. ) || exit $?
  331. ( export POSTGRES_INCLUDE=dummy
  332. export POSTGRES_LIB=dummy
  333. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} configure build
  334. ) || exit $?
  335. %endif
  336. # build ODBC driver
  337. %if "%{with_odbc}" == "yes"
  338. ( cd psqlodbc-%{V_psqlodbc}
  339. export CC="%{l_cc}"
  340. export CXX="%{l_cxx}"
  341. export CFLAGS="%{l_cflags -O}"
  342. export CXXFLAGS="%{l_cxxflags -O}"
  343. export CPPFLAGS="-I`pwd`/../src/include"
  344. CPPFLAGS="$CPPFLAGS -I`pwd`/../src/interfaces -I`pwd`/../src/interfaces/libpq"
  345. CPPFLAGS="$CPPFLAGS %{l_cppflags}"
  346. export LDFLAGS="-L`pwd`/../src/interfaces/libpq %{l_ldflags}"
  347. ./configure \
  348. --prefix=%{l_prefix} \
  349. --with-unixodbc \
  350. --with-odbcinst=%{l_prefix}/etc/unixodbc
  351. %{l_make} %{l_mflags -O}
  352. ) || exit $?
  353. %endif
  354. # build Slony-1 replication engine
  355. %if "%{with_slony1}" == "yes"
  356. ( cd slony1-%{V_slony1}
  357. ln ../src/pl/plpgsql/src/libplpgsql.so \
  358. ../src/pl/plpgsql/src/plpgsql.so
  359. %{l_shtool} subst \
  360. -e 's;-lpq;-lpq @LIBS@;' \
  361. Makefile.global.in
  362. export CC="%{l_cc}"
  363. export CFLAGS="%{l_cflags -O}"
  364. export CPPFLAGS="%{l_cppflags}"
  365. export LDFLAGS="%{l_ldflags}"
  366. export LIBS="-lssl -lcrypto -lcrypt"
  367. ./configure \
  368. --prefix=%{l_prefix} \
  369. --sysconfdir=%{l_prefix}/etc/postgresql \
  370. --with-pgconfigdir=../src/bin/pg_config \
  371. --with-pgincludedir=../src/include \
  372. --with-pgincludeserverdir=../src/interfaces/libpq \
  373. --with-pglibdir=../src/interfaces/libpq \
  374. --with-pgpkglibdir=../src/pl/plpgsql/src \
  375. --with-pgsharedir=../src/backend/utils/misc
  376. %{l_make} %{l_mflags -O}
  377. ) || exit $?
  378. %endif
  379. # rebuild pg_config with hard-coded path to avoid that it provides
  380. # dynamically resolved paths which circumvent symlinks, etc.
  381. ( cd src/bin/pg_config
  382. %{l_shtool} subst \
  383. -e 's:find_my_exec(argv.0., mypath):0; strcpy(mypath, "%{l_prefix}/bin/pg_config"):' \
  384. pg_config.c
  385. %{l_make} %{l_mflags}
  386. ) || exit $?
  387. %install
  388. rm -rf $RPM_BUILD_ROOT
  389. # perform standard installation procedure
  390. cp /dev/null register.txt
  391. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  392. # strip down installation
  393. rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
  394. strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
  395. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
  396. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
  397. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
  398. # namespace adjustments to installation
  399. for prog in \
  400. createdb createlang createuser dropdb droplang clusterdb \
  401. dropuser initdb ipcclean vacuumdb reindexdb; do
  402. %if "%{with_compat}" == "yes"
  403. cmd="ln"
  404. %else
  405. cmd="mv"
  406. %endif
  407. $cmd $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
  408. $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
  409. $cmd $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
  410. $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
  411. done
  412. ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
  413. for man in *.7; do
  414. mv $man pg_$man
  415. done
  416. ) || exit $?
  417. # create additional directories
  418. %{l_shtool} mkdir -f -p -m 755 \
  419. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  420. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql \
  421. %endif
  422. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
  423. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
  424. # install migration utility
  425. %if "%{with_compat}" == "yes"
  426. l_pguser="postgres"
  427. l_pgpass="postgres"
  428. %else
  429. l_pguser="postgresql"
  430. l_pgpass="postgresql"
  431. %endif
  432. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  433. -e "s;@l_pguser@;${l_pguser};g" \
  434. -e "s;@l_pgpass@;${l_pgpass};g" \
  435. %{SOURCE pg_migrate} \
  436. $RPM_BUILD_ROOT%{l_prefix}/bin/
  437. # install C++ bindings (both old and new one)
  438. %if "%{with_cxx}" == "yes"
  439. ( cd libpq++-%{V_libpqpp}
  440. %{l_shtool} mkdir -f -p -m 755 \
  441. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++
  442. %{l_shtool} install -c -m 644 \
  443. libpq++.h pgconnection.h pgdatabase.h pgtransdb.h pgcursordb.h pglobject.h \
  444. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++/
  445. %{l_shtool} install -c -m 644 \
  446. libpq++.a \
  447. $RPM_BUILD_ROOT%{l_prefix}/lib/
  448. ) || exit $?
  449. ( cd libpqxx-%{V_libpqxx}
  450. %{l_shtool} mkdir -f -p -m 755 \
  451. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx
  452. %{l_shtool} install -c -m 644 \
  453. include/pqxx/* \
  454. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/
  455. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/Makefile*
  456. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/config.h*
  457. %{l_shtool} install -c -m 644 \
  458. src/.libs/libpqxx.a \
  459. $RPM_BUILD_ROOT%{l_prefix}/lib/
  460. ) || exit $?
  461. %endif
  462. # install Perl binding
  463. %if "%{with_perl}" == "yes"
  464. ( export POSTGRES_INCLUDE=dummy
  465. export POSTGRES_LIB=dummy
  466. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} install
  467. ) || exit $?
  468. %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
  469. %else
  470. >perl-openpkg-files
  471. %endif
  472. # install ODBC driver
  473. %if "%{with_odbc}" == "yes"
  474. ( cd psqlodbc-%{V_psqlodbc}
  475. %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
  476. ) || exit $?
  477. %endif
  478. # install Slony-1 replication engine
  479. %if "%{with_slony1}" == "yes"
  480. ( cd slony1-%{V_slony1}
  481. %{l_shtool} subst \
  482. -e 's;$(SQL_NAME80);$(SQL_NAME74);g' \
  483. src/xxid/Makefile
  484. %{l_make} %{l_mflags} install \
  485. DESTDIR=$RPM_BUILD_ROOT \
  486. pgconfigdir=%{l_prefix}/bin \
  487. pgincludedir=%{l_prefix}/include/postgresql \
  488. pgincludeserverdir=%{l_prefix}/include/postgresql/libpq \
  489. pglibdir=%{l_prefix}/lib/postgresql \
  490. pgpkglibdir=%{l_prefix}/lib/postgresql \
  491. pgsharedir=%{l_prefix}/share/postgresql
  492. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/slony1*v7[34].sql
  493. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v73.sql
  494. mv $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v74.sql \
  495. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.sql
  496. ( echo "# Slony-1 configuration for replication engine slon(1)"
  497. echo "SLON_CLUSTER_NAME=\"example\""
  498. echo "SLON_CONNECT_DBNAME=\"example\""
  499. echo "SLON_CONNECT_USER=\"postgresql\""
  500. echo "SLON_CONNECT_PASS=\"postgresql\""
  501. echo "SLON_CONNECT_HOST=\"localhost\""
  502. echo "SLON_SYNC_INTERVAL=\"10000\""
  503. echo "SLON_SYNC_TIMEOUT=\"60000\""
  504. echo "SLON_SYNC_GROUPSIZE=\"6\""
  505. echo "SLON_SYNC_LOGLEVEL=\"1\""
  506. ) >$RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/slony1.conf
  507. ) || exit $?
  508. %endif
  509. # post-adjust pgcluster configuration filenames
  510. %if "%{with_pgcluster}" == "yes"
  511. cp $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/pgreplicate.conf.sample \
  512. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgreplicate.conf
  513. %endif
  514. # install MySQL compatibility layer
  515. %if "%{with_mysqlcompat}" == "yes"
  516. %{l_shtool} mkdir -f -p -m 755 \
  517. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/mysqlcompat
  518. %{l_shtool} install -c -m 644 \
  519. mysqlcompat-%{V_mysqlcompat}/README \
  520. mysqlcompat-%{V_mysqlcompat}/*.sql \
  521. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/mysqlcompat/
  522. %endif
  523. # install run-command script
  524. %{l_shtool} mkdir -f -p -m 755 \
  525. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  526. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  527. %{SOURCE rc.postgresql} \
  528. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  529. # optionally strip down to client-only installation
  530. %if "%{with_server}" != "yes"
  531. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_[a-bd-z]*
  532. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_c[a-np-z]*
  533. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_controldata
  534. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/post*
  535. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_[a-bd-z]*
  536. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_c[a-np-z]*
  537. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_controldata.1
  538. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/post*
  539. rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  540. rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/postgresql/server
  541. rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/postgresql
  542. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/postgresql
  543. rm -rf $RPM_BUILD_ROOT%{l_prefix}/var/postgresql
  544. %endif
  545. # determine installation files
  546. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  547. %if "%{with_server}" == "yes"
  548. %{l_files_std} `cat perl-openpkg-files` \
  549. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  550. '%config %{l_prefix}/etc/postgresql/*' \
  551. %endif
  552. '%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
  553. '%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
  554. %else
  555. %{l_files_std} `cat perl-openpkg-files`
  556. %endif
  557. %files -f files
  558. %clean
  559. rm -rf $RPM_BUILD_ROOT
  560. %pre
  561. %if "%{with_server}" == "yes"
  562. # before upgrade, check migration dump, save status and stop service
  563. [ $1 -eq 2 ] || exit 0
  564. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
  565. -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
  566. # database migration dumping hint
  567. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  568. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  569. v_new_all="%{V_postgresql}"
  570. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  571. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  572. if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$RPM_POSTGRESQL_MIGRATE" != .ignore ]; then
  573. ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  574. echo "which is a major version change. We expect a database incompatibility,"
  575. echo "so we strongly recommend that you backup your existing database"
  576. echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
  577. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
  578. echo "If this fails for some reasons, try to dump your data manually:"
  579. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dumpall -U postgresql -o | \\ "
  580. echo " $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -9 \\ "
  581. echo " >$RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2"
  582. echo "Alternatively, if you want to force this package to be installed without"
  583. echo "performing a database dump, run the following command before upgrading:"
  584. echo " \$ RPM_POSTGRESQL_MIGRATE=ignore; export RPM_POSTGRESQL_MIGRATE"
  585. ) | %{l_rpmtool} msg -b -t error
  586. exit 1
  587. fi
  588. fi
  589. fi
  590. eval `%{l_rc} postgresql status 2>/dev/null | tee %{l_tmpfile}`
  591. %{l_rc} postgresql stop 2>/dev/null
  592. exit 0
  593. %endif
  594. %post
  595. %if "%{with_server}" == "yes"
  596. if [ $1 -eq 1 ]; then
  597. # create initial database
  598. %if "%{with_compat}" == "yes"
  599. l_pguser="postgres"
  600. l_pgpass="postgres"
  601. %else
  602. l_pguser="postgresql"
  603. l_pgpass="postgresql"
  604. %endif
  605. su - %{l_rusr} -c \
  606. "LC_CTYPE=C; export LC_CTYPE; umask 022; \
  607. rm -rf $RPM_INSTALL_PREFIX/var/postgresql/db/*; \
  608. echo $l_pgpass >$RPM_INSTALL_PREFIX/var/postgresql/run/pw; \
  609. $RPM_INSTALL_PREFIX/bin/pg_initdb \
  610. -U $l_pguser --pwfile=$RPM_INSTALL_PREFIX/var/postgresql/run/pw \
  611. -D $RPM_INSTALL_PREFIX/var/postgresql/db; \
  612. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/pw" 2>&1 |\
  613. $RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
  614. -p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
  615. # adjust initial authentication configuration
  616. cp $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf \
  617. $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  618. ( cat $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old |\
  619. sed -e 's;^\([^#]\);# \1;' -e 's;^$;#;'
  620. echo ""
  621. echo "# OpenPKG PostgreSQL default access policy"
  622. echo "local all all md5"
  623. echo "host all all 127.0.0.1 255.255.255.255 md5"
  624. echo ""
  625. ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf
  626. rm -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  627. # display information about next steps
  628. ( echo "An initial PostgreSQL DB was created with the two standard"
  629. echo "databases 'template0' and 'template1'. The owner of both"
  630. echo "is the DB user '$l_pguser'. Its initial password is '$l_pgpass'."
  631. echo "After starting PostgreSQL with"
  632. echo " \$ $RPM_INSTALL_PREFIX/bin/openpkg rc postgresql start"
  633. echo "you should immediately change this with the following command:"
  634. echo " \$ $RPM_INSTALL_PREFIX/bin/psql -U $l_pguser -d template1 \\"
  635. echo " -c \"ALTER ROLE $l_pguser WITH PASSWORD '<new-password>'\""
  636. echo "Then you usually create a database for a user <user> (assuming that"
  637. echo "his home directory is /u/<user>) with password <password> under"
  638. echo "path /u/<user>/rdbms with the commands:"
  639. echo " \$ mkdir /u/<user>/rdbms"
  640. echo " \$ chmod 700 /u/<user>/rdbms"
  641. echo " \$ chown %{l_rusr}:%{l_rgrp} /u/<user>/rdbms"
  642. echo " \$ $RPM_INSTALL_PREFIX/bin/psql -U $l_pguser -d template1"
  643. echo " template1=> CREATE ROLE <user> LOGIN"
  644. echo " ENCRYPTED PASSWORD '<password>'"
  645. echo " NOCREATEDB NOCREATEROLE;"
  646. echo " template1=> CREATE TABLESPACE <user> OWNER <user>"
  647. echo " LOCATION '/u/<user>/rdbms';"
  648. echo " template1=> CREATE DATABASE <user> OWNER <user>"
  649. echo " TABLESPACE <user>;"
  650. echo " \$ echo 'localhost:*:<user>:<user>:<password>' >>/u/<user>/.pgpass"
  651. echo " \$ chmod 600 <user> /u/<user>/.pgpass; chown <user> /u/<user>/.pgpass"
  652. echo "After this the user <user> will be able to connect to his RDBMS with:"
  653. echo " \$ psql"
  654. ) | %{l_rpmtool} msg -b -t notice
  655. # optionally link into ODBC
  656. %if "%{with_odbc}" == "yes"
  657. ( echo "[PostgreSQL]"
  658. echo "Description = PostgreSQL ODBC driver"
  659. echo "Driver = $RPM_INSTALL_PREFIX/lib/psqlodbc.so"
  660. echo "Threading = 2"
  661. ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r -n "PostgreSQL"
  662. %endif
  663. fi
  664. if [ $1 -eq 2 ]; then
  665. # after upgrade, restore status
  666. { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
  667. [ ".$postgresql_active" = .yes ] && %{l_rc} postgresql start
  668. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
  669. # database migration restoring hint
  670. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  671. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  672. v_new_all="%{V_postgresql}"
  673. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  674. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  675. ( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  676. echo "which is a major version upgrade. We expect a database incompatibility,"
  677. echo "so we strongly recommend you to recreate the existing database under"
  678. echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
  679. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate restore"
  680. echo "If this fails for some reasons, try to restore your data manually:"
  681. echo " \$ $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -d -c \\ "
  682. echo " $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 | \\ "
  683. echo " $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1"
  684. ) | %{l_rpmtool} msg -b -t warn
  685. fi
  686. fi
  687. fi
  688. exit 0
  689. %endif
  690. %preun
  691. %if "%{with_server}" == "yes"
  692. # before erase, stop service and remove log files
  693. [ $1 -eq 0 ] || exit 0
  694. %{l_rc} postgresql stop 2>/dev/null
  695. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/* >/dev/null 2>&1 || true
  696. # optionally unlink from ODBC
  697. %if "%{with_odbc}" == "yes"
  698. $RPM_INSTALL_PREFIX/bin/odbcinst -u -d -n "PostgreSQL"
  699. %endif
  700. exit 0
  701. %endif