postgresql.spec 31 KB

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