postgresql.spec 31 KB

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