postgresql82.spec 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. ##
  2. ## postgresql82.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_base 8.2
  26. %define V_postgresql_beta 3
  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.02.0200
  31. %define V_slony1 1.1.5
  32. %define V_pgcluster 1.5.0rc9
  33. %define V_pgcluster_dir 1123
  34. %define V_mysqlcompat 1.0b3
  35. %define V_mysqlcompat_dir 548
  36. # package information
  37. Name: postgresql82
  38. Summary: PostgreSQL Database (BETA VERSION)
  39. URL: http://www.postgresql.org/
  40. Vendor: PostgreSQL Group
  41. Packager: OpenPKG Foundation e.V.
  42. Distribution: OpenPKG Community
  43. Class: BASE
  44. Group: Database
  45. License: GPL
  46. Version: %{V_postgresql_base}b%{V_postgresql_beta}
  47. Release: 20061120
  48. # package options
  49. %option with_server yes
  50. %option with_cxx no
  51. %option with_perl no
  52. %option with_odbc no
  53. %option with_compat no
  54. %option with_tcl no
  55. %option with_slony1 no
  56. %option with_pgcluster no
  57. %option with_kerberos no
  58. %option with_mysqlcompat no
  59. %option with_int_datetime no
  60. %option with_setproctitle no
  61. # list of sources
  62. Source0: ftp://ftp.postgresql.org/pub/source/v%{V_postgresql_base}beta/postgresql-%{V_postgresql_base}beta%{V_postgresql_beta}.tar.gz
  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://developer.postgresql.org/~wieck/slony1/download/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: postgresql82.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, perl-openpkg >= 5.8.3-20040126
  82. PreReq: 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. Provides: postgresql = %{version}-%{release}
  99. Conflicts: postgresql
  100. %description
  101. PostgreSQL is a sophisticated Object-Relational Database Management
  102. System (ORDBMS). It is fully ACID compliant and has full support
  103. for foreign keys, joins, views, triggers, and stored procedures (in
  104. multiple languages). It includes most SQL92 and SQL99 data types
  105. and also supports storage of binary large objects. It is the most
  106. advanced Open-Source RDBMS available anywhere.
  107. As an enterprise class RDBMS, PostgreSQL boasts sophisticated
  108. features such as Multi-Version Concurrency Control (MVCC), Point In
  109. Time Recovery (PITR), tablespaces, asynchronous replication, nested
  110. transactions (savepoints), online/hot backups, a sophisticated
  111. query planner/optimizer, and Write Ahead Logging (WAL) for fault
  112. tolerance. It supports international character sets, multibyte
  113. character encodings, Unicode, and it is locale-aware for sorting,
  114. case-sensitivity, and formatting. It is highly scalable both in the
  115. sheer quantity of data it can manage and in the number of concurrent
  116. users it can accommodate.
  117. NOTICE: THIS IS AN EXPERIMENTAL BETA VERSION!
  118. %track
  119. prog postgresql82 = {
  120. version = %{V_postgresql_base}beta%{V_postgresql_beta}
  121. url = ftp://ftp.postgresql.org/pub/source/
  122. regex = v(8\.2(\.\d+)*(beta)?)
  123. url = ftp://ftp.postgresql.org/pub/source/v__NEWVER__/
  124. regex = postgresql-(\d+\.\d+(\.\d+)*(beta\d+)?)\.tar\.(?:gz|bz2)
  125. }
  126. prog postgresql82:libpq++ = {
  127. version = %{V_libpqpp}
  128. url = ftp://gborg.postgresql.org/pub/libpqpp/stable/
  129. regex = libpq\+\+-(__VER__)\.tar\.gz
  130. }
  131. prog postgresql82:libpqxx = {
  132. version = %{V_libpqxx}
  133. url = ftp://gborg.postgresql.org/pub/libpqxx/stable/
  134. regex = libpqxx-(__VER__)\.tar\.gz
  135. }
  136. prog postgresql82:pgperl = {
  137. version = %{V_pgperl}
  138. url = ftp://gborg.postgresql.org/pub/pgperl/stable/
  139. regex = pgperl-(__VER__)\.tar\.gz
  140. }
  141. prog postgresql82:psqlodbc = {
  142. version = %{V_psqlodbc}
  143. url = ftp://ftp.postgresql.org/pub/odbc/versions/src/
  144. regex = psqlodbc-(\d{2}\.\d{2}\.\d{4})\.tar\.gz
  145. }
  146. prog postgresql82:slony1 = {
  147. version = %{V_slony1}
  148. url = http://developer.postgresql.org/~wieck/slony1/download/
  149. regex = slony1-(\d+\.\d+\.\d+)\.tar\.bz2
  150. }
  151. prog postgresql82:pgcluster = {
  152. version = %{V_pgcluster}.%{V_pgcluster_dir}
  153. url = http://pgfoundry.org/frs/?group_id=1000072&release_id=168
  154. regex = /(\d+/pgcluster-__VER__)-patch\.tar\.gz
  155. transform = "s/^(\\d+)\/pgcluster-(.+)$/$2.$1/; $_"
  156. }
  157. prog postgresql82:mysqlcompat = {
  158. version = %{V_mysqlcompat}.%{V_mysqlcompat_dir}
  159. url = http://pgfoundry.org/frs/?group_id=1000154&release_id=379
  160. regex = (\d+/mysqlcompat-__VER__)\.tar\.gz
  161. transform = "s/^(\\d+)\/mysqlcompat-(.+)$/$2.$1/; $_"
  162. }
  163. %prep
  164. %setup -q -n postgresql-%{V_postgresql_base}beta%{V_postgresql_beta}
  165. %patch -p0
  166. %if "%{with_cxx}" == "yes"
  167. %setup -q -T -D -a 1
  168. %setup -q -T -D -a 2
  169. case "%{l_platform -t}" in
  170. *-sunos* )
  171. %{l_shtool} subst \
  172. -e 's;strerror_r(0,0,0);strerror((int)0);g' \
  173. -e 's;strerror_r((int)0, (char \*)0, (size_t)0);strerror((int)0);g' \
  174. libpqxx-%{V_libpqxx}/configure
  175. %{l_shtool} subst \
  176. -e 's;strerror_r(err, buf, sizeof(buf));strerror(err);g' \
  177. libpqxx-%{V_libpqxx}/src/largeobject.cxx \
  178. libpqxx-%{V_libpqxx}/configure
  179. %{l_shtool} subst \
  180. -e 's;\(strerror(err) ==\) -1;\1 (char *)-1;' \
  181. libpqxx-%{V_libpqxx}/src/largeobject.cxx
  182. ;;
  183. esac
  184. %{l_shtool} subst \
  185. -e 's;^function \(add_compiler_opts() {\);\1;' \
  186. libpqxx-%{V_libpqxx}/configure
  187. %endif
  188. %if "%{with_perl}" == "yes"
  189. %setup -q -T -D -a 3
  190. %endif
  191. %if "%{with_odbc}" == "yes"
  192. %setup -q -T -D -a 4
  193. %endif
  194. %if "%{with_slony1}" == "yes"
  195. %setup -q -T -D -a 5
  196. %endif
  197. %if "%{with_pgcluster}" == "yes"
  198. %setup -q -T -D -a 6
  199. sed -e '/^diff.*libpq\.rc/,/^diff/d' pgcluster-*-patch |\
  200. sed -e 's;(char .)\(ptr .= readlen\);\1;' |\
  201. %{l_patch} -p1
  202. %endif
  203. %if "%{with_mysqlcompat}" == "yes"
  204. %setup -q -T -D -a 7
  205. %endif
  206. %if "%{with_kerberos}" == "yes"
  207. %{l_shtool} subst \
  208. -e 's;krb5 -ldes -lasn1 -lroken;krb5 -lk5crypto -lkrb5support -lcom_err;g' \
  209. configure
  210. %endif
  211. # adjust source tree
  212. %{l_shtool} subst \
  213. -e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
  214. src/include/pg_config_manual.h
  215. %{l_shtool} subst \
  216. -e 's;^\(sqlmansect *=\).*$;\1 7;' \
  217. src/makefiles/Makefile.solaris
  218. %{l_shtool} subst \
  219. -e 's;$(INSTALL_SHLIB);#$(INSTALL_SHLIB);g' \
  220. src/backend/utils/mb/conversion_procs/proc.mk
  221. %{l_shtool} subst \
  222. -e 's;# Shared library stuff;enable_shared = yes;g' \
  223. src/pl/plpgsql/src/Makefile
  224. %build
  225. rm -rf $RPM_BUILD_ROOT
  226. # configure package
  227. ( echo "ac_cv_func_isinf=no"
  228. %if "%{with_setproctitle}" == "no"
  229. echo "ac_cv_lib_util_setproctitle=no"
  230. echo "ac_cv_func_setproctitle=no"
  231. echo "ac_cv_func_setproctitle_func=no"
  232. %endif
  233. ) >config.cache
  234. export CC="%{l_cc}"
  235. export CFLAGS="%{l_cflags -O}"
  236. export CPPFLAGS="%{l_cppflags readline} -DOPENSSL_DISABLE_OLD_DES_SUPPORT"
  237. export LDFLAGS="%{l_ldflags}"
  238. %if "%{with_slony1}" == "yes"
  239. CFLAGS="$CFLAGS -pthread"
  240. %endif
  241. %if "%{with_tcl}" == "yes"
  242. CPPFLAGS="$CPPFLAGS %{l_cppflags tcl}"
  243. LDFLAGS="$LDFLAGS -L`%{l_rc} --query x11_libdir`"
  244. %endif
  245. %if "%{with_kerberos}" == "yes"
  246. CPPFLAGS="$CPPFLAGS %{l_cppflags kerberos}"
  247. LDFLAGS="$LDFLAGS %{l_ldflags kerberos}"
  248. %endif
  249. export TAR="%{l_tar}"
  250. export YACC="bison -y"
  251. ./configure \
  252. --cache-file=./config.cache \
  253. --prefix=%{l_prefix} \
  254. --sysconfdir=%{l_prefix}/etc/postgresql \
  255. --includedir=%{l_prefix}/include/postgresql \
  256. --with-openssl \
  257. --with-readline \
  258. --with-zlib \
  259. %if "%{with_tcl}" == "yes"
  260. --with-tcl \
  261. --with-tclconfig="%{l_prefix}/lib" \
  262. --with-tkconfig="%{l_prefix}/lib" \
  263. %endif
  264. %if "%{with_slony1}" == "yes"
  265. --enable-thread-safety \
  266. %endif
  267. %if "%{with_kerberos}" == "yes"
  268. --with-krb5 \
  269. --with-krb-srvnam=postgresql \
  270. %endif
  271. %if "%{with_int_datetime}" == "yes"
  272. --enable-integer-datetimes \
  273. %endif
  274. --disable-syslog \
  275. --disable-shared
  276. # build package
  277. %{l_make} %{l_mflags}
  278. # build C++ bindings (both old and new one)
  279. %if "%{with_cxx}" == "yes"
  280. ( cd libpq++-%{V_libpqpp}
  281. CXX="%{l_cxx}"
  282. CFLAGS="%{l_cflags -O}"
  283. CPPFLAGS="-DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT= "
  284. CPPFLAGS="$CPPFLAGS -I. -I../src/interfaces/libpq -I../src/interfaces"
  285. CPPFLAGS="$CPPFLAGS -I../src/include %{l_cppflags}"
  286. LDFLAGS="%{l_ldflags}"
  287. OBJS="pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o"
  288. for o in $OBJS; do
  289. $CXX $CFLAGS $CPPFLAGS $LDFLAGS -c -o $o `echo $o | sed -e 's;\.o$;.cc;'`
  290. done
  291. rm -f libpq++.a
  292. ar rc libpq++.a $OBJS
  293. ) || exit $?
  294. ln -s `pwd`/src/interfaces/libpq/*.h src/include/
  295. ( cd libpqxx-%{V_libpqxx}
  296. %{l_shtool} subst \
  297. -e 's;\(cut\)\( .*/configitems\)\( -f [0-9]\);\1\3\2;g' \
  298. configure
  299. ( echo "#!/bin/sh"
  300. echo "case \"\$1\" in"
  301. echo " --includedir ) echo \"`pwd`/../src/include\" ;;"
  302. echo " --libdir ) echo \"`pwd`/../src/interfaces/libpq\" ;;"
  303. echo "esac"
  304. ) >pg_config
  305. chmod a+x pg_config
  306. export PG_CONFIG=`pwd`/pg_config
  307. export CC="%{l_cc}"
  308. export CXX="%{l_cxx}"
  309. export CFLAGS="%{l_cflags -O}"
  310. export CXXFLAGS="%{l_cxxflags -O}"
  311. export CPPFLAGS="-I`pwd`/../src/include %{l_cppflags}"
  312. export LDFLAGS="%{l_ldflags}"
  313. export LIBS="-lssl -lcrypto -lcrypt"
  314. case "%{l_platform -t}" in
  315. *-sunos* ) LIBS="$LIBS -lsocket -lnsl" ;;
  316. esac
  317. ./configure \
  318. --disable-shared
  319. %{l_make} %{l_mflags -O}
  320. ) || exit $?
  321. %endif
  322. # build Perl bindings
  323. %if "%{with_perl}" == "yes"
  324. %{l_prefix}/bin/perl-openpkg prepare
  325. ( cd Pg-%{V_pgperl}
  326. export POSTGRES_INCLUDE=dummy
  327. export POSTGRES_LIB=dummy
  328. %{l_shtool} subst \
  329. -e 's;-I$POSTGRES_INCLUDE;-I../src/interfaces/libpq -I../src/include;' \
  330. -e 's;-L$POSTGRES_LIB;-L../src/interfaces/libpq;' \
  331. -e 's;-lpq;-lpq %{l_ldflags} -lssl -lcrypto -lcrypt;' \
  332. Makefile.PL
  333. ) || exit $?
  334. ( export POSTGRES_INCLUDE=dummy
  335. export POSTGRES_LIB=dummy
  336. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} configure build
  337. ) || exit $?
  338. %endif
  339. # build ODBC driver
  340. %if "%{with_odbc}" == "yes"
  341. ( cd psqlodbc-%{V_psqlodbc}
  342. export CC="%{l_cc}"
  343. export CXX="%{l_cxx}"
  344. export CFLAGS="%{l_cflags -O}"
  345. export CXXFLAGS="%{l_cxxflags -O}"
  346. export CPPFLAGS="-I`pwd`/../src/include"
  347. CPPFLAGS="$CPPFLAGS -I`pwd`/../src/interfaces -I`pwd`/../src/interfaces/libpq"
  348. CPPFLAGS="$CPPFLAGS %{l_cppflags}"
  349. export LDFLAGS="-L`pwd`/../src/interfaces/libpq %{l_ldflags}"
  350. ./configure \
  351. --prefix=%{l_prefix} \
  352. --with-unixodbc \
  353. --with-odbcinst=%{l_prefix}/etc/unixodbc
  354. %{l_make} %{l_mflags -O}
  355. ) || exit $?
  356. %endif
  357. # build Slony-1 replication engine
  358. %if "%{with_slony1}" == "yes"
  359. ( cd slony1-%{V_slony1}
  360. ln ../src/pl/plpgsql/src/libplpgsql.so \
  361. ../src/pl/plpgsql/src/plpgsql.so
  362. %{l_shtool} subst \
  363. -e 's;-lpq;-lpq -lssl -lcrypto -lcrypt;' \
  364. src/slon/Makefile src/slonik/Makefile
  365. export CC="%{l_cc}"
  366. export CFLAGS="%{l_cflags -O}"
  367. export CPPFLAGS="%{l_cppflags}"
  368. export LDFLAGS="%{l_ldflags}"
  369. export LIBS="-lssl -lcrypto -lcrypt"
  370. ./configure \
  371. --prefix=%{l_prefix} \
  372. --sysconfdir=%{l_prefix}/etc/postgresql \
  373. --with-pgconfigdir=../src/bin/pg_config \
  374. --with-pgincludedir=../src/include \
  375. --with-pgincludeserverdir=../src/interfaces/libpq \
  376. --with-pglibdir=../src/interfaces/libpq \
  377. --with-pgpkglibdir=../src/pl/plpgsql/src \
  378. --with-pgsharedir=../src/backend/utils/misc
  379. %{l_make} %{l_mflags -O}
  380. ) || exit $?
  381. %endif
  382. # rebuild pg_config with hard-coded path to avoid that it provides
  383. # dynamically resolved paths which circumvent symlinks, etc.
  384. ( cd src/bin/pg_config
  385. %{l_shtool} subst \
  386. -e 's:find_my_exec(argv.0., mypath):0; strcpy(mypath, "%{l_prefix}/bin/pg_config"):' \
  387. pg_config.c
  388. %{l_make} %{l_mflags}
  389. ) || exit $?
  390. %install
  391. rm -rf $RPM_BUILD_ROOT
  392. # perform standard installation procedure
  393. cp /dev/null register.txt
  394. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  395. # strip down installation
  396. rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
  397. strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
  398. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
  399. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
  400. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
  401. # namespace adjustments to installation
  402. for prog in \
  403. createdb createlang createuser dropdb droplang clusterdb \
  404. dropuser initdb ipcclean vacuumdb reindexdb; do
  405. %if "%{with_compat}" == "yes"
  406. cmd="ln"
  407. %else
  408. cmd="mv"
  409. %endif
  410. $cmd $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
  411. $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
  412. $cmd $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
  413. $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
  414. done
  415. ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
  416. for man in *.7; do
  417. mv $man pg_$man
  418. done
  419. ) || exit $?
  420. # create additional directories
  421. %{l_shtool} mkdir -f -p -m 755 \
  422. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  423. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql \
  424. %endif
  425. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
  426. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
  427. # install migration utility
  428. %if "%{with_compat}" == "yes"
  429. l_pguser="postgres"
  430. l_pgpass="postgres"
  431. %else
  432. l_pguser="postgresql"
  433. l_pgpass="postgresql"
  434. %endif
  435. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  436. -e "s;@l_pguser@;${l_pguser};g" \
  437. -e "s;@l_pgpass@;${l_pgpass};g" \
  438. %{SOURCE pg_migrate} \
  439. $RPM_BUILD_ROOT%{l_prefix}/bin/
  440. # install C++ bindings (both old and new one)
  441. %if "%{with_cxx}" == "yes"
  442. ( cd libpq++-%{V_libpqpp}
  443. %{l_shtool} mkdir -f -p -m 755 \
  444. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++
  445. %{l_shtool} install -c -m 644 \
  446. libpq++.h pgconnection.h pgdatabase.h pgtransdb.h pgcursordb.h pglobject.h \
  447. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++/
  448. %{l_shtool} install -c -m 644 \
  449. libpq++.a \
  450. $RPM_BUILD_ROOT%{l_prefix}/lib/
  451. ) || exit $?
  452. ( cd libpqxx-%{V_libpqxx}
  453. %{l_shtool} mkdir -f -p -m 755 \
  454. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx
  455. %{l_shtool} install -c -m 644 \
  456. include/pqxx/* \
  457. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/
  458. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/Makefile*
  459. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/config.h*
  460. %{l_shtool} install -c -m 644 \
  461. src/.libs/libpqxx.a \
  462. $RPM_BUILD_ROOT%{l_prefix}/lib/
  463. ) || exit $?
  464. %endif
  465. # install Perl binding
  466. %if "%{with_perl}" == "yes"
  467. ( export POSTGRES_INCLUDE=dummy
  468. export POSTGRES_LIB=dummy
  469. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} install
  470. ) || exit $?
  471. %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
  472. %else
  473. >perl-openpkg-files
  474. %endif
  475. # install ODBC driver
  476. %if "%{with_odbc}" == "yes"
  477. ( cd psqlodbc-%{V_psqlodbc}
  478. %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
  479. ) || exit $?
  480. %endif
  481. # install Slony-1 replication engine
  482. %if "%{with_slony1}" == "yes"
  483. ( cd slony1-%{V_slony1}
  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_base}b%{V_postgresql_beta}"
  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/etc/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 USER $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 unixODBC
  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
  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_base}b%{V_postgresql_beta}"
  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. exit 0
  697. %endif