postgresql.spec 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. ##
  2. ## postgresql.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2008 OpenPKG Foundation e.V. <http://openpkg.net/>
  4. ##
  5. ## Permission to use, copy, modify, and distribute this software for
  6. ## any purpose with or without fee is hereby granted, provided that
  7. ## the above copyright notice and this permission notice appear in all
  8. ## copies.
  9. ##
  10. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  11. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  12. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  13. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  14. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  15. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  16. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  18. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  19. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  20. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  21. ## SUCH DAMAGE.
  22. ##
  23. # package versions
  24. %define V_postgresql 8.3.1
  25. %define V_postgresql_dist 8.3.1
  26. %define V_postgresql_dir 8.3.1
  27. %define V_libpqxx 2.6.9
  28. %define V_perl 5.8.8
  29. %define V_pgperl 2.0.2
  30. %define V_psqlodbc 08.03.0200
  31. %define V_pgjdbc 8.3-603
  32. %define V_slony1_major 1.2
  33. %define V_slony1_minor 13
  34. %define V_pgcluster 1.9.0rc5
  35. %define V_pgcluster_dir 1706
  36. %define V_mysqlcompat 1.0b3
  37. %define V_mysqlcompat_dir 548
  38. # package information
  39. Name: postgresql
  40. Summary: PostgreSQL Database
  41. URL: http://www.postgresql.org/
  42. Vendor: PostgreSQL Group
  43. Packager: OpenPKG Foundation e.V.
  44. Distribution: OpenPKG Community
  45. Class: BASE
  46. Group: Database
  47. License: GPL
  48. Version: %{V_postgresql}
  49. Release: 20080505
  50. # package options
  51. %option with_server yes
  52. %option with_cxx no
  53. %option with_perl no
  54. %option with_odbc no
  55. %option with_jdbc no
  56. %option with_compat no
  57. %option with_tcl no
  58. %option with_slony1 no
  59. %option with_pgcluster no
  60. %option with_kerberos no
  61. %option with_mysqlcompat no
  62. %option with_int_datetime no
  63. %option with_xml no
  64. # list of sources
  65. Source0: ftp://ftp.postgresql.org/pub/source/v%{V_postgresql_dir}/postgresql-%{V_postgresql_dist}.tar.bz2
  66. Source1: http://pqxx.org/download/software/libpqxx/libpqxx-%{V_libpqxx}.tar.gz
  67. Source2: ftp://gborg.postgresql.org/pub/pgperl/stable/pgperl-%{V_pgperl}.tar.gz
  68. Source3: ftp://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-%{V_psqlodbc}.tar.gz
  69. Source4: http://slony.info/downloads/%{V_slony1_major}/source/slony1-%{V_slony1_major}.%{V_slony1_minor}.tar.bz2
  70. Source5: http://pgfoundry.org/frs/download.php/%{V_pgcluster_dir}/pgcluster-%{V_pgcluster}.patch.tar.gz
  71. Source6: http://pgfoundry.org/frs/download.php/%{V_mysqlcompat_dir}/mysqlcompat-%{V_mysqlcompat}.tar.gz
  72. Source7: http://jdbc.postgresql.org/download/postgresql-jdbc-%{V_pgjdbc}.src.tar.gz
  73. Source8: rc.postgresql
  74. Source9: pg_migrate
  75. Source10: pg_passwd
  76. Patch0: postgresql.patch
  77. # build information
  78. Prefix: %{l_prefix}
  79. BuildRoot: %{l_buildroot}
  80. BuildPreReq: OpenPKG, openpkg >= 20060823, make, gcc, flex, bison, gzip
  81. PreReq: OpenPKG, openpkg >= 20060823
  82. BuildPreReq: readline, zlib, openssl, getopt
  83. PreReq: readline, zlib, openssl, getopt
  84. %if "%{with_perl}" == "yes"
  85. BuildPreReq: perl >= %{V_perl}, perl-openpkg >= %{V_perl}-20061013
  86. PreReq: perl >= %{V_perl}
  87. %endif
  88. %if "%{with_odbc}" == "yes"
  89. BuildPreReq: unixodbc
  90. PreReq: unixodbc
  91. %endif
  92. %if "%{with_jdbc}" == "yes"
  93. BuildPreReq: java, JAVA-JDK, ant
  94. PreReq: java, JAVA-JDK
  95. %endif
  96. %if "%{with_tcl}" == "yes"
  97. BuildPreReq: tcl, tcl::with_x11 = yes, X11
  98. PreReq: tcl, tcl::with_x11 = yes, X11
  99. %endif
  100. %if "%{with_kerberos}" == "yes"
  101. BuildPreReq: KERBEROS
  102. PreReq: KERBEROS
  103. %endif
  104. %if "%{with_xml}" == "yes"
  105. BuildPreReq: libxml, libxslt, zlib
  106. PreReq: libxml, libxslt, zlib
  107. %endif
  108. AutoReq: no
  109. AutoReqProv: no
  110. %description
  111. PostgreSQL is a sophisticated Object-Relational Database Management
  112. System (ORDBMS). It is fully ACID compliant and has full support
  113. for foreign keys, joins, views, triggers, and stored procedures (in
  114. multiple languages). It includes most SQL92 and SQL99 data types
  115. and also supports storage of binary large objects. It is the most
  116. advanced Open-Source RDBMS available anywhere.
  117. As an enterprise class RDBMS, PostgreSQL boasts sophisticated
  118. features such as Multi-Version Concurrency Control (MVCC), Point In
  119. Time Recovery (PITR), tablespaces, asynchronous replication, nested
  120. transactions (savepoints), online/hot backups, a sophisticated
  121. query planner/optimizer, and Write Ahead Logging (WAL) for fault
  122. tolerance. It supports international character sets, multibyte
  123. character encodings, Unicode, and it is locale-aware for sorting,
  124. case-sensitivity, and formatting. It is highly scalable both in the
  125. sheer quantity of data it can manage and in the number of concurrent
  126. users it can accommodate.
  127. %track
  128. prog postgresql = {
  129. version = %{V_postgresql_dist}
  130. url = ftp://ftp.postgresql.org/pub/source/
  131. regex = v(\d+\.\d+(\.\d+)*(?:beta\d*)?)
  132. url = ftp://ftp.postgresql.org/pub/source/v__NEWVER__/
  133. regex = postgresql-(\d+(\.\d+)+)\.tar\.(bz2|gz)
  134. }
  135. prog postgresql:libpqxx = {
  136. version = %{V_libpqxx}
  137. url = http://pqxx.org/development/libpqxx/wiki/DownloadPage
  138. regex = libpqxx-(__VER__)\.tar\.gz
  139. }
  140. prog postgresql:pgperl = {
  141. version = %{V_pgperl}
  142. url = ftp://gborg.postgresql.org/pub/pgperl/stable/
  143. regex = pgperl-(__VER__)\.tar\.gz
  144. }
  145. prog postgresql:psqlodbc = {
  146. version = %{V_psqlodbc}
  147. url = ftp://ftp.postgresql.org/pub/odbc/versions/src/
  148. regex = psqlodbc-(\d{2}\.\d{2}\.\d{4})\.tar\.gz
  149. }
  150. prog postgresql:jdbc = {
  151. version = %{V_pgjdbc}
  152. url = http://jdbc.postgresql.org/download.html
  153. regex = postgresql-jdbc-(\d+\.\d+-\d+)\.src\.tar\.gz
  154. }
  155. prog postgresql:slony1 = {
  156. version = %{V_slony1_major}.%{V_slony1_minor}
  157. url = http://slony.info/downloads/%{V_slony1_major}/source/
  158. regex = slony1-(\d+\.\d+\.\d+)\.tar\.bz2
  159. }
  160. prog postgresql:pgcluster = {
  161. version = %{V_pgcluster}.%{V_pgcluster_dir}
  162. url = http://pgfoundry.org/frs/?group_id=1000072
  163. regex = /(\d+/pgcluster-__VER__)\.patch\.tar\.gz
  164. transform = "s/^(\\d+)\/pgcluster-(.+)$/$2.$1/; $_"
  165. }
  166. prog postgresql:mysqlcompat = {
  167. version = %{V_mysqlcompat}.%{V_mysqlcompat_dir}
  168. url = http://pgfoundry.org/frs/?group_id=1000154
  169. regex = (\d+/mysqlcompat-__VER__)\.tar\.gz
  170. transform = "s/^(\\d+)\/mysqlcompat-(.+)$/$2.$1/; $_"
  171. }
  172. %prep
  173. %setup -q
  174. %patch -p0
  175. %if "%{with_cxx}" == "yes"
  176. %setup -q -T -D -a 1
  177. case "%{l_platform -t}" in
  178. *-sunos* )
  179. %{l_shtool} subst \
  180. -e 's;strerror_r(0,0,0);strerror((int)0);g' \
  181. -e 's;strerror_r((int)0, (char \*)0, (size_t)0);strerror((int)0);g' \
  182. libpqxx-%{V_libpqxx}/configure
  183. %{l_shtool} subst \
  184. -e 's;strerror_r(err, buf, sizeof(buf));strerror(err);g' \
  185. libpqxx-%{V_libpqxx}/src/largeobject.cxx \
  186. libpqxx-%{V_libpqxx}/configure
  187. %{l_shtool} subst \
  188. -e 's;\(strerror(err) ==\) -1;\1 (char *)-1;' \
  189. libpqxx-%{V_libpqxx}/src/largeobject.cxx
  190. ;;
  191. esac
  192. %{l_shtool} subst \
  193. -e 's;^function \(add_compiler_opts() {\);\1;' \
  194. libpqxx-%{V_libpqxx}/configure
  195. %endif
  196. %if "%{with_perl}" == "yes"
  197. %setup -q -T -D -a 2
  198. %endif
  199. %if "%{with_odbc}" == "yes"
  200. %setup -q -T -D -a 3
  201. %endif
  202. %if "%{with_slony1}" == "yes"
  203. %setup -q -T -D -a 4
  204. %endif
  205. %if "%{with_pgcluster}" == "yes"
  206. %setup -q -T -D -a 5
  207. sed -e '/^diff.*libpq\.rc/,/^diff/d' pgcluster-*-patch |\
  208. %{l_patch} -p1
  209. %endif
  210. %if "%{with_mysqlcompat}" == "yes"
  211. %setup -q -T -D -a 6
  212. %endif
  213. %if "%{with_jdbc}" == "yes"
  214. %setup -q -T -D -a 7
  215. %endif
  216. # adjust source tree
  217. %{l_shtool} subst \
  218. -e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
  219. src/include/pg_config_manual.h
  220. %{l_shtool} subst \
  221. -e 's;^\(sqlmansect *=\).*$;\1 7;' \
  222. src/makefiles/Makefile.solaris
  223. %{l_shtool} subst \
  224. -e 's;$(INSTALL_SHLIB);#$(INSTALL_SHLIB);g' \
  225. src/backend/utils/mb/conversion_procs/proc.mk
  226. %{l_shtool} subst \
  227. -e 's;# Shared library stuff;enable_shared = yes;g' \
  228. src/pl/plpgsql/src/Makefile
  229. %build
  230. rm -rf $RPM_BUILD_ROOT
  231. # configure package
  232. echo "ac_cv_func_isinf=no" >config.cache
  233. export CC="%{l_cc}"
  234. export CFLAGS="%{l_cflags -O}"
  235. export CPPFLAGS="%{l_cppflags readline}"
  236. export LDFLAGS="%{l_ldflags}"
  237. export LIBS=""
  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 `krb5-config --cflags`"
  247. LIBS="$LIBS `krb5-config --libs`"
  248. %endif
  249. %if "%{with_pgcluster}" == "yes"
  250. case "%{l_platform -t}" in
  251. *-freebsd* ) LIBS="$LIBS -lcompat" ;;
  252. esac
  253. %endif
  254. %if "%{with_xml}" == "yes"
  255. LIBS="$LIBS -liconv"
  256. %endif
  257. export TAR="%{l_tar}"
  258. export YACC="bison -y"
  259. ./configure \
  260. --cache-file=./config.cache \
  261. --prefix=%{l_prefix} \
  262. --sysconfdir=%{l_prefix}/etc/postgresql \
  263. --includedir=%{l_prefix}/include/postgresql \
  264. --with-openssl \
  265. --with-readline \
  266. --with-zlib \
  267. %if "%{with_tcl}" == "yes"
  268. --with-tcl \
  269. --with-tclconfig="%{l_prefix}/lib" \
  270. --with-tkconfig="%{l_prefix}/lib" \
  271. %endif
  272. %if "%{with_slony1}" == "yes"
  273. --enable-thread-safety \
  274. %endif
  275. %if "%{with_kerberos}" == "yes"
  276. --with-krb5 \
  277. --with-krb-srvnam=postgresql \
  278. %endif
  279. %if "%{with_int_datetime}" == "yes"
  280. --enable-integer-datetimes \
  281. %endif
  282. %if "%{with_xml}" == "yes"
  283. --with-libxml \
  284. --with-libxslt \
  285. %endif
  286. --disable-syslog \
  287. --disable-shared
  288. # build package
  289. %{l_make} %{l_mflags}
  290. # build C++ bindings (both old and new one)
  291. %if "%{with_cxx}" == "yes"
  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 JDBC driver
  356. %if "%{with_jdbc}" == "yes"
  357. ( cd postgresql-jdbc-%{V_pgjdbc}.src
  358. export JAVA_PLATFORM="sun-jdk"
  359. eval `%{l_prefix}/bin/java-toolkit -e`
  360. %{l_prefix}/bin/ant
  361. ) || exit $?
  362. %endif
  363. # build Slony-1 replication engine
  364. %if "%{with_slony1}" == "yes"
  365. ( cd slony1-%{V_slony1_major}.%{V_slony1_minor}
  366. ln ../src/pl/plpgsql/src/libplpgsql.so \
  367. ../src/pl/plpgsql/src/plpgsql.so
  368. %{l_shtool} subst \
  369. -e 's;-lpq;-lpq @LIBS@;' \
  370. Makefile.global.in
  371. export CC="%{l_cc}"
  372. export CFLAGS="%{l_cflags -O}"
  373. export CPPFLAGS="%{l_cppflags}"
  374. export LDFLAGS="%{l_ldflags}"
  375. export LIBS="-lssl -lcrypto -lcrypt"
  376. ./configure \
  377. --prefix=%{l_prefix} \
  378. --sysconfdir=%{l_prefix}/etc/postgresql \
  379. --with-pgconfigdir=../src/bin/pg_config \
  380. --with-pgincludedir=../src/include \
  381. --with-pgincludeserverdir=../src/interfaces/libpq \
  382. --with-pglibdir=../src/interfaces/libpq \
  383. --with-pgpkglibdir=../src/pl/plpgsql/src \
  384. --with-pgsharedir=../src/backend/utils/misc
  385. %{l_make} %{l_mflags -O}
  386. ) || exit $?
  387. %endif
  388. # rebuild pg_config with hard-coded path to avoid that it provides
  389. # dynamically resolved paths which circumvent symlinks, etc.
  390. ( cd src/bin/pg_config
  391. %{l_shtool} subst \
  392. -e 's:find_my_exec(argv.0., mypath):0; strcpy(mypath, "%{l_prefix}/bin/pg_config"):' \
  393. pg_config.c
  394. %{l_make} %{l_mflags}
  395. ) || exit $?
  396. %install
  397. rm -rf $RPM_BUILD_ROOT
  398. # perform standard installation procedure
  399. cp /dev/null register.txt
  400. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  401. # strip down installation
  402. rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
  403. strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
  404. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
  405. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
  406. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
  407. # namespace adjustments to installation
  408. for prog in \
  409. createdb createlang createuser dropdb droplang clusterdb \
  410. dropuser initdb ipcclean vacuumdb reindexdb; do
  411. %if "%{with_compat}" == "yes"
  412. cmd="ln"
  413. %else
  414. cmd="mv"
  415. %endif
  416. $cmd $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
  417. $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
  418. $cmd $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
  419. $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
  420. done
  421. ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
  422. for man in *.7; do
  423. mv $man pg_$man
  424. done
  425. ) || exit $?
  426. # create additional directories
  427. %{l_shtool} mkdir -f -p -m 755 \
  428. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  429. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql \
  430. %endif
  431. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
  432. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
  433. # install addon utilities
  434. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  435. %{SOURCE pg_migrate} $RPM_BUILD_ROOT%{l_prefix}/bin/
  436. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  437. -e "s;@l_bash@;%{l_bash};g" \
  438. %{SOURCE pg_passwd} $RPM_BUILD_ROOT%{l_prefix}/bin/
  439. # install C++ bindings (both old and new one)
  440. %if "%{with_cxx}" == "yes"
  441. ( cd libpqxx-%{V_libpqxx}
  442. %{l_shtool} mkdir -f -p -m 755 \
  443. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx
  444. %{l_shtool} install -c -m 644 \
  445. include/pqxx/* \
  446. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/
  447. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/Makefile*
  448. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/config.h*
  449. %{l_shtool} install -c -m 644 \
  450. src/.libs/libpqxx.a \
  451. $RPM_BUILD_ROOT%{l_prefix}/lib/
  452. ) || exit $?
  453. %endif
  454. # install Perl binding
  455. %if "%{with_perl}" == "yes"
  456. ( export POSTGRES_INCLUDE=dummy
  457. export POSTGRES_LIB=dummy
  458. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} install
  459. ) || exit $?
  460. %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
  461. %else
  462. >perl-openpkg-files
  463. %endif
  464. # install ODBC driver
  465. %if "%{with_odbc}" == "yes"
  466. ( cd psqlodbc-%{V_psqlodbc}
  467. %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
  468. ) || exit $?
  469. %endif
  470. # install JDBC driver
  471. %if "%{with_jdbc}" == "yes"
  472. ( cd postgresql-jdbc-%{V_pgjdbc}.src
  473. %{l_shtool} install -c -m 644 \
  474. jars/postgresql.jar $RPM_BUILD_ROOT%{l_prefix}/lib/
  475. ) || exit $?
  476. %endif
  477. # install Slony-1 replication engine
  478. %if "%{with_slony1}" == "yes"
  479. ( cd slony1-%{V_slony1_major}.%{V_slony1_minor}
  480. %{l_shtool} subst \
  481. -e 's;$(SQL_NAME80);$(SQL_NAME74);g' \
  482. src/xxid/Makefile
  483. %{l_make} %{l_mflags} install \
  484. DESTDIR=$RPM_BUILD_ROOT \
  485. pgconfigdir=%{l_prefix}/bin \
  486. pgincludedir=%{l_prefix}/include/postgresql \
  487. pgincludeserverdir=%{l_prefix}/include/postgresql/libpq \
  488. pglibdir=%{l_prefix}/lib/postgresql \
  489. pgpkglibdir=%{l_prefix}/lib/postgresql \
  490. pgsharedir=%{l_prefix}/share/postgresql
  491. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/slony1*v7[34].sql
  492. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v73.sql
  493. mv $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v74.sql \
  494. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.sql
  495. ( echo "# Slony-1 configuration for replication engine slon(1)"
  496. echo "SLON_CLUSTER_NAME=\"example\""
  497. echo "SLON_CONNECT_DBNAME=\"example\""
  498. echo "SLON_CONNECT_USER=\"postgresql\""
  499. echo "SLON_CONNECT_PASS=\"postgresql\""
  500. echo "SLON_CONNECT_HOST=\"localhost\""
  501. echo "SLON_SYNC_INTERVAL=\"10000\""
  502. echo "SLON_SYNC_TIMEOUT=\"60000\""
  503. echo "SLON_SYNC_GROUPSIZE=\"6\""
  504. echo "SLON_SYNC_LOGLEVEL=\"1\""
  505. ) >$RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/slony1.conf
  506. ) || exit $?
  507. %endif
  508. # adjust default configuration for hourly auto-vacuum operation
  509. %{l_shtool} subst \
  510. -e 's;^# *\(stats_start_collector *=\) *[^#]*\(#.*\);\1 on \2;' \
  511. -e 's;^# *\(stats_row_level *=\) *[^#]*\(#.*\);\1 on \2;' \
  512. -e 's;^# *\(autovacuum *=\) *[^#]*\(#.*\);\1 on \2;' \
  513. -e 's;^# *\(autovacuum_naptime *=\) *[^#]*\(#.*\);\1 1h \2;' \
  514. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/postgresql.conf.sample
  515. # post-adjust pgcluster configuration filenames
  516. %if "%{with_pgcluster}" == "yes"
  517. cp $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/pgreplicate.conf.sample \
  518. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgreplicate.conf
  519. %endif
  520. # install MySQL compatibility layer
  521. %if "%{with_mysqlcompat}" == "yes"
  522. %{l_shtool} mkdir -f -p -m 755 \
  523. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/mysqlcompat
  524. %{l_shtool} install -c -m 644 \
  525. mysqlcompat-%{V_mysqlcompat}/README \
  526. mysqlcompat-%{V_mysqlcompat}/*.sql \
  527. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/mysqlcompat/
  528. %endif
  529. # install run-command script
  530. %{l_shtool} mkdir -f -p -m 755 \
  531. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  532. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  533. %{SOURCE rc.postgresql} \
  534. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  535. # optionally strip down to client-only installation
  536. %if "%{with_server}" != "yes"
  537. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_[a-bd-z]*
  538. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_c[a-np-z]*
  539. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_controldata
  540. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/post*
  541. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_[a-bd-z]*
  542. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_c[a-np-z]*
  543. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_controldata.1
  544. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/post*
  545. rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  546. rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/postgresql/server
  547. rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/postgresql
  548. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/postgresql
  549. rm -rf $RPM_BUILD_ROOT%{l_prefix}/var/postgresql
  550. %endif
  551. # determine installation files
  552. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  553. %if "%{with_server}" == "yes"
  554. %{l_files_std} `cat perl-openpkg-files` \
  555. %if "%{with_slony1}" == "yes" || "%{with_pgcluster}" == "yes"
  556. '%config %{l_prefix}/etc/postgresql/*' \
  557. %endif
  558. '%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
  559. '%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
  560. %else
  561. %{l_files_std} `cat perl-openpkg-files`
  562. %endif
  563. %files -f files
  564. %clean
  565. rm -rf $RPM_BUILD_ROOT
  566. %pre
  567. %if "%{with_server}" == "yes"
  568. # before upgrade, check migration dump, save status and stop service
  569. [ $1 -eq 2 ] || exit 0
  570. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
  571. -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
  572. # database migration dumping hint
  573. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  574. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  575. v_new_all="%{V_postgresql}"
  576. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  577. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  578. if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$RPM_POSTGRESQL_MIGRATE" != .ignore ]; then
  579. ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  580. echo "which is a major version change. We expect a database incompatibility,"
  581. echo "so we strongly recommend that you backup your existing database"
  582. echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
  583. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
  584. echo "If this fails for some reasons, try to dump your data manually:"
  585. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dumpall -U postgresql -o | \\ "
  586. echo " $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -9 \\ "
  587. echo " >$RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2"
  588. echo "Alternatively, if you want to force this package to be installed without"
  589. echo "performing a database dump, run the following command before upgrading:"
  590. echo " \$ RPM_POSTGRESQL_MIGRATE=ignore; export RPM_POSTGRESQL_MIGRATE"
  591. ) | %{l_rpmtool} msg -b -t error
  592. exit 1
  593. fi
  594. fi
  595. fi
  596. eval `%{l_rc} postgresql status 2>/dev/null | tee %{l_tmpfile}`
  597. %{l_rc} postgresql stop 2>/dev/null
  598. exit 0
  599. %endif
  600. %post
  601. %if "%{with_server}" == "yes"
  602. %if "%{with_compat}" == "yes"
  603. l_pguser="postgres"
  604. l_pgpass="postgres"
  605. %else
  606. l_pguser="postgresql"
  607. l_pgpass="postgresql"
  608. %endif
  609. if [ $1 -eq 1 ]; then
  610. # create initial database
  611. su - %{l_rusr} -c \
  612. "LC_CTYPE=C; export LC_CTYPE; umask 077; \
  613. rm -rf $RPM_INSTALL_PREFIX/var/postgresql/db/*; \
  614. echo $l_pgpass >$RPM_INSTALL_PREFIX/var/postgresql/run/pg_initdb.pw; \
  615. $RPM_INSTALL_PREFIX/bin/pg_initdb \
  616. --encoding=SQL_ASCII --locale=C --auth=md5 --username=$l_pguser \
  617. --pwfile=$RPM_INSTALL_PREFIX/var/postgresql/run/pg_initdb.pw \
  618. --pgdata=$RPM_INSTALL_PREFIX/var/postgresql/db; \
  619. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/pg_initdb.pw" 2>&1 | \
  620. $RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
  621. -p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
  622. if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION ]; then
  623. echo "ERROR: failed to create initial PostgreSQL database" 1>&2
  624. exit 1
  625. fi
  626. ( umask 077
  627. ( echo "##"
  628. echo "## pg_superuser.conf -- PostgreSQL database superuser configuration"
  629. echo "##"
  630. echo ""
  631. echo "superuser_database=\"template1\""
  632. echo "superuser_username=\"$l_pguser\""
  633. echo "superuser_password=\"$l_pgpass\""
  634. echo ""
  635. ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf
  636. chown %{l_rusr}:%{l_rgrp} $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf || exit $?
  637. chmod 600 $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf || exit $?
  638. ) || exit $?
  639. # display information about next steps
  640. ( echo "An initial PostgreSQL DB was created with the two standard"
  641. echo "databases 'template0' and 'template1'. The owner of both"
  642. echo "is the DB user '$l_pguser'. Its initial password is '$l_pgpass'."
  643. echo ""
  644. echo "After starting PostgreSQL with"
  645. echo " \$ $RPM_INSTALL_PREFIX/bin/openpkg rc postgresql start"
  646. echo "you should immediately change this with the following command:"
  647. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_passwd postgresql template1"
  648. echo ""
  649. echo "Then you usually create a database for a user <user> (assuming that"
  650. echo "his home directory is /u/<user>) with password <password> under"
  651. echo "path /u/<user>/rdbms with the commands:"
  652. echo " \$ mkdir /u/<user>/rdbms"
  653. echo " \$ chmod 700 /u/<user>/rdbms"
  654. echo " \$ chown %{l_rusr}:%{l_rgrp} /u/<user>/rdbms"
  655. echo " \$ $RPM_INSTALL_PREFIX/bin/psql -U $l_pguser -d template1"
  656. echo " template1=> CREATE ROLE <user>"
  657. echo " LOGIN ENCRYPTED PASSWORD '<password>'"
  658. echo " NOCREATEDB NOCREATEROLE;"
  659. echo " template1=> CREATE TABLESPACE <user> OWNER <user>"
  660. echo " LOCATION '/u/<user>/rdbms';"
  661. echo " template1=> CREATE DATABASE <user> OWNER <user>"
  662. echo " TABLESPACE <user>;"
  663. echo " \$ echo 'localhost:*:<user>:<user>:<password>' >>/u/<user>/.pgpass"
  664. echo " \$ chmod 600 <user> /u/<user>/.pgpass"
  665. echo " \$ chown <user> /u/<user>/.pgpass"
  666. echo "After this the user <user> will be able to connect to his RDBMS with:"
  667. echo " \$ $RPM_INSTALL_PREFIX/bin/psql"
  668. ) | %{l_rpmtool} msg -b -t notice
  669. fi
  670. %if "%{with_odbc}" == "yes"
  671. # optionally link into ODBC
  672. if ! $RPM_INSTALL_PREFIX/bin/odbcinst -q -d -n "PostgreSQL" >/dev/null 2>&1; then
  673. ( echo "[PostgreSQL]"
  674. echo "Description = PostgreSQL ODBC driver"
  675. echo "Driver = $RPM_INSTALL_PREFIX/lib/psqlodbc.so"
  676. echo "Threading = 2"
  677. ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r -n "PostgreSQL"
  678. fi
  679. %endif
  680. if [ $1 -eq 2 ]; then
  681. # after upgrade, restore status
  682. { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
  683. [ ".$postgresql_active" = .yes ] && %{l_rc} postgresql start
  684. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
  685. ! -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf ]; then
  686. ( umask 077
  687. ( echo "##"
  688. echo "## pg_superuser.conf -- PostgreSQL database superuser configuration"
  689. echo "##"
  690. echo ""
  691. echo "superuser_database=\"template1\""
  692. echo "superuser_username=\"$l_pguser\""
  693. echo "superuser_password=\"\""
  694. echo ""
  695. ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf
  696. chown %{l_rusr}:%{l_rgrp} $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf || exit $?
  697. chmod 600 $RPM_INSTALL_PREFIX/var/postgresql/db/pg_superuser.conf || exit $?
  698. ) || exit $?
  699. ( echo "Created still missing \"pg_superuser.conf\" configuration file."
  700. echo "You should update its content by resetting the PostgreSQL"
  701. echo "superuser account password with the following command:"
  702. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_passwd postgresql template1"
  703. ) | %{l_rpmtool} msg -b -t warn
  704. fi
  705. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
  706. # database migration restoring hint
  707. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  708. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  709. v_new_all="%{V_postgresql}"
  710. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  711. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  712. ( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  713. echo "which is a major version upgrade. We expect a database incompatibility,"
  714. echo "so we strongly recommend you to recreate the existing database under"
  715. echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
  716. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate restore"
  717. echo "If this fails for some reasons, try to restore your data manually:"
  718. echo " \$ $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -d -c \\ "
  719. echo " $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 | \\ "
  720. echo " $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1"
  721. ) | %{l_rpmtool} msg -b -t warn
  722. fi
  723. fi
  724. fi
  725. exit 0
  726. %endif
  727. %preun
  728. %if "%{with_server}" == "yes"
  729. # before erase, stop service and remove log files
  730. [ $1 -eq 0 ] || exit 0
  731. %{l_rc} postgresql stop 2>/dev/null
  732. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/* >/dev/null 2>&1 || true
  733. # optionally unlink from ODBC
  734. %if "%{with_odbc}" == "yes"
  735. $RPM_INSTALL_PREFIX/bin/odbcinst -u -d -n "PostgreSQL"
  736. %endif
  737. exit 0
  738. %endif