postgresql81.spec 29 KB

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