postgresql.spec 29 KB

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