postgresql.spec 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. ##
  2. ## postgresql.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2005 OpenPKG Foundation e.V. <http://openpkg.net/>
  4. ## Copyright (c) 2000-2005 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.0.3
  26. %define V_libpqpp 4.0
  27. %define V_libpqxx 2.5.3
  28. %define V_pgperl 2.0.2
  29. %define V_psqlodbc 08.00.0101
  30. %define V_slony1 1.0.5
  31. %define V_pgpool 2.5.2
  32. %define V_pgcluster 1.3.0c
  33. # package information
  34. Name: postgresql
  35. Summary: PostgreSQL Database
  36. URL: http://www.postgresql.org/
  37. Vendor: PostgreSQL Group
  38. Packager: OpenPKG
  39. Distribution: OpenPKG
  40. Class: BASE
  41. Group: Database
  42. License: GPL
  43. Version: %{V_postgresql}
  44. Release: 20050519
  45. # package options
  46. %option with_server yes
  47. %option with_cxx no
  48. %option with_perl no
  49. %option with_odbc no
  50. %option with_compat no
  51. %option with_tcl no
  52. %option with_slony1 no
  53. %option with_pgpool no
  54. %option with_pgcluster no
  55. # list of sources
  56. Source0: ftp://ftp.postgresql.org/pub/source/v%{V_postgresql}/postgresql-%{V_postgresql}.tar.gz
  57. Source1: ftp://gborg.postgresql.org/pub/libpqpp/stable/libpq++-%{V_libpqpp}.tar.gz
  58. Source2: ftp://gborg.postgresql.org/pub/libpqxx/stable/libpqxx-%{V_libpqxx}.tar.gz
  59. Source3: ftp://gborg.postgresql.org/pub/pgperl/stable/pgperl-%{V_pgperl}.tar.gz
  60. Source4: ftp://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-%{V_psqlodbc}.tar.gz
  61. Source5: http://developer.postgresql.org/~wieck/slony1/download/slony1-%{V_slony1}.tar.gz
  62. Source6: http://www2b.biglobe.ne.jp/~caco/pgpool/pgpool-%{V_pgpool}.tar.gz
  63. Source7: http://pgfoundry.org/frs/download.php/180/pgcluster-%{V_pgcluster}-patch.tar.gz
  64. Source8: rc.postgresql
  65. Source9: pg_migrate
  66. Patch0: postgresql.patch
  67. Patch1: postgresql.patch.slony1
  68. # build information
  69. Prefix: %{l_prefix}
  70. BuildRoot: %{l_buildroot}
  71. BuildPreReq: OpenPKG, openpkg >= 20040130, make, gcc, flex, bison, gzip
  72. PreReq: OpenPKG, openpkg >= 20040130
  73. BuildPreReq: readline, zlib, openssl, getopt
  74. PreReq: readline, zlib, openssl, getopt
  75. %if "%{with_perl}" == "yes"
  76. BuildPreReq: perl, perl-openpkg >= 5.8.3-20040126
  77. PreReq: perl
  78. %endif
  79. %if "%{with_odbc}" == "yes"
  80. BuildPreReq: unixodbc
  81. PreReq: unixodbc
  82. %endif
  83. %if "%{with_tcl}" == "yes"
  84. BuildPreReq: tcl, tcl::with_x11 = yes, X11
  85. PreReq: tcl, tcl::with_x11 = yes, X11
  86. %endif
  87. AutoReq: no
  88. AutoReqProv: no
  89. %description
  90. PostgreSQL is a sophisticated Object-Relational DBMS, supporting
  91. almost all SQL constructs, including subselects, transactions,
  92. and user-defined types and functions. It is the most advanced
  93. open-source database available anywhere.
  94. %track
  95. prog postgresql = {
  96. version = %{V_postgresql}
  97. url = ftp://ftp.postgresql.org/pub/source/
  98. regex = v(\d+\.\d+(\.\d+)*)(?!beta)
  99. url = ftp://ftp.postgresql.org/pub/source/v__NEWVER__/
  100. regex = postgresql-(\d+\.\d+(\.\d+)*)\.tar\.(?:gz|bz2)
  101. }
  102. prog postgresql:libpq++ = {
  103. version = %{V_libpqpp}
  104. url = ftp://gborg.postgresql.org/pub/libpqpp/stable/
  105. regex = libpq\+\+-(__VER__)\.tar\.gz
  106. }
  107. prog postgresql:libpqxx = {
  108. version = %{V_libpqxx}
  109. url = ftp://gborg.postgresql.org/pub/libpqxx/stable/
  110. regex = libpqxx-(__VER__)\.tar\.gz
  111. }
  112. prog postgresql:pgperl = {
  113. version = %{V_pgperl}
  114. url = ftp://gborg.postgresql.org/pub/pgperl/stable/
  115. regex = pgperl-(__VER__)\.tar\.gz
  116. }
  117. prog postgresql:psqlodbc = {
  118. version = %{V_psqlodbc}
  119. url = ftp://ftp.postgresql.org/pub/odbc/versions/src/
  120. regex = psqlodbc-(\d{2}\.\d{2}\.\d{4})\.tar\.gz
  121. }
  122. prog postgresql:slony1 = {
  123. version = %{V_slony1}
  124. url = http://developer.postgresql.org/~wieck/slony1/download/
  125. regex = slony1-(\d+\.\d+\.\d+)\.tar\.gz
  126. }
  127. prog postgresql:pgpool = {
  128. version = %{V_pgpool}
  129. url = http://www2b.biglobe.ne.jp/~caco/pgpool/
  130. regex = pgpool-(__VER__)\.tar\.gz
  131. }
  132. prog postgresql:pgcluster = {
  133. version = %{V_pgcluster}
  134. url = http://pgfoundry.org/frs/?group_id=1000072&release_id=168
  135. regex = pgcluster-(__VER__)-patch\.tar\.gz
  136. }
  137. %prep
  138. %setup -q
  139. %patch -p0
  140. %if "%{with_cxx}" == "yes"
  141. %setup -q -T -D -a 1
  142. %setup -q -T -D -a 2
  143. case "%{l_platform -t}" in
  144. *-sunos* )
  145. %{l_shtool} subst \
  146. -e 's;strerror_r(0,0,0);strerror((int)0);g' \
  147. -e 's;strerror_r((int)0, (char \*)0, (size_t)0);strerror((int)0);g' \
  148. libpqxx-%{V_libpqxx}/configure
  149. %{l_shtool} subst \
  150. -e 's;strerror_r(err, buf, sizeof(buf));strerror(err);g' \
  151. libpqxx-%{V_libpqxx}/src/largeobject.cxx \
  152. libpqxx-%{V_libpqxx}/configure
  153. ;;
  154. esac
  155. %endif
  156. %if "%{with_perl}" == "yes"
  157. %setup -q -T -D -a 3
  158. %endif
  159. %if "%{with_odbc}" == "yes"
  160. %setup -q -T -D -a 4
  161. %endif
  162. %if "%{with_slony1}" == "yes"
  163. %setup -q -T -D -a 5
  164. %patch -p0 -d slony1-%{V_slony1} -P 1
  165. %endif
  166. %if "%{with_pgpool}" == "yes"
  167. %setup -q -T -D -a 6
  168. %endif
  169. %if "%{with_pgcluster}" == "yes"
  170. %setup -q -T -D -a 7
  171. cat pgcluster-*-patch | \
  172. sed -e 's;\($.exec_prefix./etc\);\1/postgresql;' | \
  173. %{l_patch} -p1
  174. %endif
  175. # adjust source tree
  176. %{l_shtool} subst \
  177. -e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
  178. src/include/pg_config_manual.h
  179. %{l_shtool} subst \
  180. -e 's;^\(sqlmansect *=\).*$;\1 7;' \
  181. src/makefiles/Makefile.solaris
  182. %{l_shtool} subst \
  183. -e 's;$(INSTALL_SHLIB);#$(INSTALL_SHLIB);g' \
  184. src/backend/utils/mb/conversion_procs/proc.mk
  185. %{l_shtool} subst \
  186. -e 's;# Shared library stuff;enable_shared = yes;g' \
  187. src/pl/plpgsql/src/Makefile
  188. %build
  189. rm -rf $RPM_BUILD_ROOT
  190. # configure package
  191. CC="%{l_cc}" \
  192. %if "%{with_slony1}" == "yes"
  193. CFLAGS="%{l_cflags -O} -pthread" \
  194. %else
  195. CFLAGS="%{l_cflags -O}" \
  196. %endif
  197. %if "%{with_tcl}" == "yes"
  198. CPPFLAGS="%{l_cppflags readline tcl} -DOPENSSL_DISABLE_OLD_DES_SUPPORT" \
  199. LDFLAGS="%{l_ldflags} -L`%{l_rc} --query x11_libdir`" \
  200. %else
  201. CPPFLAGS="%{l_cppflags readline} -DOPENSSL_DISABLE_OLD_DES_SUPPORT" \
  202. LDFLAGS="%{l_ldflags}" \
  203. %endif
  204. TAR="%{l_tar}" \
  205. YACC="bison -y" \
  206. ./configure \
  207. --cache-file=./config.cache \
  208. --prefix=%{l_prefix} \
  209. --sysconfdir=%{l_prefix}/etc/postgresql \
  210. --includedir=%{l_prefix}/include/postgresql \
  211. --with-openssl \
  212. --with-readline \
  213. --with-zlib \
  214. %if "%{with_tcl}" == "yes"
  215. --with-tcl \
  216. --with-tclconfig="%{l_prefix}/lib" \
  217. --with-tkconfig="%{l_prefix}/lib" \
  218. %endif
  219. %if "%{with_slony1}" == "yes"
  220. --enable-thread-safety \
  221. %endif
  222. --disable-syslog \
  223. --disable-shared
  224. # build package
  225. %{l_make} %{l_mflags}
  226. # build C++ bindings (both old and new one)
  227. %if "%{with_cxx}" == "yes"
  228. ( cd libpq++-%{V_libpqpp}
  229. CXX="%{l_cxx}"
  230. CFLAGS="%{l_cflags -O}"
  231. CPPFLAGS="-DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT= "
  232. CPPFLAGS="$CPPFLAGS -I. -I../src/interfaces/libpq -I../src/interfaces"
  233. CPPFLAGS="$CPPFLAGS -I../src/include %{l_cppflags}"
  234. LDFLAGS="%{l_ldflags}"
  235. OBJS="pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o"
  236. for o in $OBJS; do
  237. $CXX $CFLAGS $CPPFLAGS $LDFLAGS -c -o $o `echo $o | sed -e 's;\.o$;.cc;'`
  238. done
  239. rm -f libpq++.a
  240. ar rc libpq++.a $OBJS
  241. ) || exit $?
  242. ln -s `pwd`/src/interfaces/libpq/*.h src/include/
  243. ( cd libpqxx-%{V_libpqxx}
  244. %{l_shtool} subst \
  245. -e 's;\(cut\)\( .*/configitems\)\( -f [0-9]\);\1\3\2;g' \
  246. configure
  247. ( echo "#!/bin/sh"
  248. echo "case \"\$1\" in"
  249. echo " --includedir ) echo \"`pwd`/../src/include\" ;;"
  250. echo " --libdir ) echo \"`pwd`/../src/interfaces/libpq\" ;;"
  251. echo "esac"
  252. ) >pg_config
  253. chmod a+x pg_config
  254. export PG_CONFIG=`pwd`/pg_config
  255. export CC="%{l_cc}"
  256. export CXX="%{l_cxx}"
  257. export CFLAGS="%{l_cflags -O}"
  258. export CXXFLAGS="%{l_cxxflags -O}"
  259. export CPPFLAGS="-I`pwd`/../src/include %{l_cppflags}"
  260. export LDFLAGS="%{l_ldflags}"
  261. export LIBS="-lssl -lcrypto -lcrypt"
  262. case "%{l_platform -t}" in
  263. *-sunos* ) LIBS="$LIBS -lsocket -lnsl" ;;
  264. esac
  265. ./configure \
  266. --disable-shared
  267. %{l_make} %{l_mflags -O}
  268. ) || exit $?
  269. %endif
  270. # build Perl bindings
  271. %if "%{with_perl}" == "yes"
  272. %{l_prefix}/bin/perl-openpkg prepare
  273. ( cd Pg-%{V_pgperl}
  274. export POSTGRES_INCLUDE=dummy
  275. export POSTGRES_LIB=dummy
  276. %{l_shtool} subst \
  277. -e 's;-I$POSTGRES_INCLUDE;-I../src/interfaces/libpq -I../src/include;' \
  278. -e 's;-L$POSTGRES_LIB;-L../src/interfaces/libpq;' \
  279. -e 's;-lpq;-lpq %{l_ldflags} -lssl -lcrypto -lcrypt;' \
  280. Makefile.PL
  281. ) || exit $?
  282. ( export POSTGRES_INCLUDE=dummy
  283. export POSTGRES_LIB=dummy
  284. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} configure build
  285. ) || exit $?
  286. %endif
  287. # build ODBC driver
  288. %if "%{with_odbc}" == "yes"
  289. ( cd psqlodbc-%{V_psqlodbc}
  290. export CC="%{l_cc}"
  291. export CXX="%{l_cxx}"
  292. export CFLAGS="%{l_cflags -O}"
  293. export CXXFLAGS="%{l_cxxflags -O}"
  294. export CPPFLAGS="-I`pwd`/../src/include"
  295. CPPFLAGS="$CPPFLAGS -I`pwd`/../src/interfaces -I`pwd`/../src/interfaces/libpq"
  296. CPPFLAGS="$CPPFLAGS %{l_cppflags}"
  297. export LDFLAGS="-L`pwd`/../src/interfaces/libpq %{l_ldflags}"
  298. ./configure \
  299. --prefix=%{l_prefix} \
  300. --with-unixodbc \
  301. --with-odbcinst=%{l_prefix}/etc/unixodbc
  302. %{l_make} %{l_mflags -O}
  303. ) || exit $?
  304. %endif
  305. # build Slony-1 replication engine
  306. %if "%{with_slony1}" == "yes"
  307. ( cd slony1-%{V_slony1}
  308. %{l_shtool} subst \
  309. -e 's;-lpq;-lpq -lssl -lcrypto -lcrypt;' \
  310. src/slon/Makefile src/slonik/Makefile
  311. export CC="%{l_cc}"
  312. export CFLAGS="%{l_cflags -O}"
  313. export CPPFLAGS="%{l_cppflags}"
  314. ./configure \
  315. --prefix=%{l_prefix} \
  316. --with-pgsourcetree=`pwd`/..
  317. %{l_make} %{l_mflags -O}
  318. ) || exit $?
  319. %endif
  320. # build pgpool frontend
  321. %if "%{with_pgpool}" == "yes"
  322. ( cd pgpool-%{V_pgpool}
  323. export CC="%{l_cc}"
  324. export CFLAGS="%{l_cflags -O} %{l_cppflags}"
  325. export LDFLAGS="%{l_ldflags}"
  326. export LIBS="-lgetopt"
  327. ./configure \
  328. --prefix=%{l_prefix} \
  329. --sysconfdir=%{l_prefix}/etc/postgresql \
  330. --with-pgsrc=/dummy
  331. %{l_make} %{l_mflags}
  332. ) || exit $?
  333. %endif
  334. %install
  335. rm -rf $RPM_BUILD_ROOT
  336. # perform standard installation procedure
  337. cp /dev/null register.txt
  338. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  339. # strip down installation
  340. rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
  341. strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
  342. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
  343. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
  344. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
  345. # namespace adjustments to installation
  346. for prog in \
  347. createdb createlang createuser dropdb droplang clusterdb \
  348. dropuser initdb ipcclean vacuumdb; do
  349. %if "%{with_compat}" == "yes"
  350. cmd="ln"
  351. %else
  352. cmd="mv"
  353. %endif
  354. $cmd $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
  355. $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
  356. $cmd $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
  357. $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
  358. done
  359. ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
  360. for man in *.7; do
  361. mv $man pg_$man
  362. done
  363. ) || exit $?
  364. # create additional directories
  365. %{l_shtool} mkdir -f -p -m 755 \
  366. %if "%{with_slony1}" == "yes" || "%{with_pgpool}" == "yes" || "%{with_pgcluster}" == "yes"
  367. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql \
  368. %endif
  369. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
  370. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
  371. # install migration utility
  372. %if "%{with_compat}" == "yes"
  373. l_pguser="postgres"
  374. l_pgpass="postgres"
  375. %else
  376. l_pguser="postgresql"
  377. l_pgpass="postgresql"
  378. %endif
  379. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  380. -e "s;@l_pguser@;${l_pguser};g" \
  381. -e "s;@l_pgpass@;${l_pgpass};g" \
  382. %{SOURCE pg_migrate} \
  383. $RPM_BUILD_ROOT%{l_prefix}/bin/
  384. # install C++ bindings (both old and new one)
  385. %if "%{with_cxx}" == "yes"
  386. ( cd libpq++-%{V_libpqpp}
  387. %{l_shtool} mkdir -f -p -m 755 \
  388. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++
  389. %{l_shtool} install -c -m 644 \
  390. libpq++.h pgconnection.h pgdatabase.h pgtransdb.h pgcursordb.h pglobject.h \
  391. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++/
  392. %{l_shtool} install -c -m 644 \
  393. libpq++.a \
  394. $RPM_BUILD_ROOT%{l_prefix}/lib/
  395. ) || exit $?
  396. ( cd libpqxx-%{V_libpqxx}
  397. %{l_shtool} mkdir -f -p -m 755 \
  398. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx
  399. %{l_shtool} install -c -m 644 \
  400. include/pqxx/* \
  401. $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/
  402. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/Makefile*
  403. rm -f $RPM_BUILD_ROOT%{l_prefix}/include/pqxx/config.h*
  404. %{l_shtool} install -c -m 644 \
  405. src/.libs/libpqxx.a \
  406. $RPM_BUILD_ROOT%{l_prefix}/lib/
  407. ) || exit $?
  408. %endif
  409. # install Perl binding
  410. %if "%{with_perl}" == "yes"
  411. ( export POSTGRES_INCLUDE=dummy
  412. export POSTGRES_LIB=dummy
  413. %{l_prefix}/bin/perl-openpkg -d Pg-%{V_pgperl} install
  414. ) || exit $?
  415. %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
  416. %else
  417. >perl-openpkg-files
  418. %endif
  419. # install ODBC driver
  420. %if "%{with_odbc}" == "yes"
  421. ( cd psqlodbc-%{V_psqlodbc}
  422. %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
  423. ) || exit $?
  424. %endif
  425. # install Slony-1 replication engine
  426. %if "%{with_slony1}" == "yes"
  427. ( cd slony1-%{V_slony1}
  428. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  429. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/slony1*v7[34].sql
  430. rm -f $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v73.sql
  431. mv $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.v74.sql \
  432. $RPM_BUILD_ROOT%{l_prefix}/share/postgresql/xxid.sql
  433. ( echo "# Slony-1 configuration for replication engine slon(1)"
  434. echo "SLON_CLUSTER_NAME=\"example\""
  435. echo "SLON_CONNECT_DBNAME=\"example\""
  436. echo "SLON_CONNECT_USER=\"postgresql\""
  437. echo "SLON_CONNECT_PASS=\"postgresql\""
  438. echo "SLON_CONNECT_HOST=\"localhost\""
  439. echo "SLON_SYNC_INTERVAL=\"10000\""
  440. echo "SLON_SYNC_TIMEOUT=\"60000\""
  441. echo "SLON_SYNC_GROUPSIZE=\"6\""
  442. echo "SLON_SYNC_LOGLEVEL=\"1\""
  443. ) >$RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/slony1.conf
  444. ) || exit $?
  445. %endif
  446. # install pgpool frontend
  447. %if "%{with_pgpool}" == "yes"
  448. ( cd pgpool-%{V_pgpool}
  449. %{l_shtool} install -c -s -m 755 \
  450. pgpool $RPM_BUILD_ROOT%{l_prefix}/bin/
  451. %{l_shtool} install -c -m 644 \
  452. -e "s;\(socket_dir = \).*;\1'%{l_prefix}/var/postgresql/run';" \
  453. -e "s;\(backend_socket_dir = \).*;\1'%{l_prefix}/var/postgresql/run';" \
  454. -e "s;\(logdir = \).*;\1'%{l_prefix}/var/postgresql/run';" \
  455. pgpool.conf.sample $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgpool.conf
  456. ) || exit $?
  457. %endif
  458. %if "%{with_pgcluster}" == "yes"
  459. # post-adjust pgcluster configuration filenames
  460. mv $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pglb.conf.sample \
  461. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pglb.conf
  462. mv $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgreplicate.conf.sample \
  463. $RPM_BUILD_ROOT%{l_prefix}/etc/postgresql/pgreplicate.conf
  464. %endif
  465. # install run-command script
  466. %{l_shtool} mkdir -f -p -m 755 \
  467. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  468. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  469. %{SOURCE rc.postgresql} \
  470. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  471. # optionally strip down to client-only installation
  472. %if "%{with_server}" != "yes"
  473. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_[a-bd-z]*
  474. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_c[a-np-z]*
  475. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/pg_controldata
  476. rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/post*
  477. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_[a-bd-z]*
  478. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_c[a-np-z]*
  479. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_controldata.1
  480. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/post*
  481. rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  482. rm -rf $RPM_BUILD_ROOT%{l_prefix}/include/postgresql/server
  483. rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/postgresql
  484. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/postgresql
  485. rm -rf $RPM_BUILD_ROOT%{l_prefix}/var/postgresql
  486. %endif
  487. # determine installation files
  488. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  489. %if "%{with_server}" == "yes"
  490. %{l_files_std} `cat perl-openpkg-files` \
  491. %if "%{with_slony1}" == "yes" || "%{with_pgpool}" == "yes" || "%{with_pgcluster}" == "yes"
  492. '%config %{l_prefix}/etc/postgresql/*' \
  493. %endif
  494. '%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
  495. '%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
  496. %else
  497. %{l_files_std} `cat perl-openpkg-files`
  498. %endif
  499. %files -f files
  500. %clean
  501. rm -rf $RPM_BUILD_ROOT
  502. %pre
  503. %if "%{with_server}" == "yes"
  504. # before upgrade, check migration dump, save status and stop service
  505. [ $1 -eq 2 ] || exit 0
  506. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
  507. -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
  508. # database migration dumping hint
  509. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  510. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  511. v_new_all="%{V_postgresql}"
  512. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  513. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  514. if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$RPM_POSTGRESQL_MIGRATE" != .ignore ]; then
  515. ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  516. echo "which is a major version change. We expect a database incompatibility,"
  517. echo "so we strongly recommend that you backup your existing database"
  518. echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
  519. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
  520. echo "If this fails for some reasons, try to dump your data manually:"
  521. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dumpall -U postgresql -o | \\ "
  522. echo " $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -9 \\ "
  523. echo " >$RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2"
  524. echo "Alternatively, if you want to force this package to be installed without"
  525. echo "performing a database dump, run the following command before upgrading:"
  526. echo " \$ RPM_POSTGRESQL_MIGRATE=ignore; export RPM_POSTGRESQL_MIGRATE"
  527. ) | %{l_rpmtool} msg -b -t error
  528. exit 1
  529. fi
  530. fi
  531. fi
  532. eval `%{l_rc} postgresql status 2>/dev/null | tee %{l_tmpfile}`
  533. %{l_rc} postgresql stop 2>/dev/null
  534. exit 0
  535. %endif
  536. %post
  537. %if "%{with_server}" == "yes"
  538. if [ $1 -eq 1 ]; then
  539. # create initial database
  540. %if "%{with_compat}" == "yes"
  541. l_pguser="postgres"
  542. l_pgpass="postgres"
  543. %else
  544. l_pguser="postgresql"
  545. l_pgpass="postgresql"
  546. %endif
  547. su - %{l_rusr} -c \
  548. "LC_CTYPE=C; export LC_CTYPE; umask 022; \
  549. rm -rf $RPM_INSTALL_PREFIX/var/postgresql/db/*; \
  550. echo $l_pgpass >$RPM_INSTALL_PREFIX/var/postgresql/run/pw; \
  551. $RPM_INSTALL_PREFIX/bin/pg_initdb \
  552. -U $l_pguser --pwfile=$RPM_INSTALL_PREFIX/var/postgresql/run/pw \
  553. -D $RPM_INSTALL_PREFIX/var/postgresql/db; \
  554. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/pw" 2>&1 |\
  555. $RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
  556. -p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
  557. # adjust initial authentication configuration
  558. cp $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf \
  559. $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  560. ( cat $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old |\
  561. sed -e 's;^\([^#]\);# \1;' -e 's;^$;#;'
  562. echo ""
  563. echo "# OpenPKG PostgreSQL default access policy"
  564. echo "local all all md5"
  565. echo "host all all 127.0.0.1 255.255.255.255 md5"
  566. echo ""
  567. ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf
  568. rm -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  569. # display information about next steps
  570. ( echo "An initial PostgreSQL DB was created with the two standard"
  571. echo "databases 'template0' and 'template1'. The owner of both"
  572. echo "is the DB user '$l_pguser'. Its initial password is '$l_pgpass'."
  573. echo "After starting PostgreSQL with"
  574. echo " \$ $RPM_INSTALL_PREFIX/etc/rc postgresql start"
  575. echo "you should immediately change this with the following command:"
  576. echo " \$ $RPM_INSTALL_PREFIX/bin/psql -U $l_pguser -d template1 \\"
  577. echo " -c \"ALTER USER $l_pguser WITH PASSWORD '<new-password>'\""
  578. ) | %{l_rpmtool} msg -b -t notice
  579. # optionally link into unixODBC
  580. %if "%{with_odbc}" == "yes"
  581. ( echo "[PostgreSQL]"
  582. echo "Description = PostgreSQL ODBC driver"
  583. echo "Driver = $RPM_INSTALL_PREFIX/lib/psqlodbc.so"
  584. echo "Threading = 2"
  585. ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r
  586. %endif
  587. fi
  588. if [ $1 -eq 2 ]; then
  589. # after upgrade, restore status
  590. { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
  591. [ ".$postgresql_active" = .yes ] && %{l_rc} postgresql start
  592. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
  593. # database migration restoring hint
  594. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  595. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  596. v_new_all="%{V_postgresql}"
  597. v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  598. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  599. ( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  600. echo "which is a major version upgrade. We expect a database incompatibility,"
  601. echo "so we strongly recommend you to recreate the existing database under"
  602. echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
  603. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate restore"
  604. echo "If this fails for some reasons, try to restore your data manually:"
  605. echo " \$ $RPM_INSTALL_PREFIX/lib/openpkg/bzip2 -d -c \\ "
  606. echo " $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 | \\ "
  607. echo " $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1"
  608. ) | %{l_rpmtool} msg -b -t warn
  609. fi
  610. fi
  611. fi
  612. exit 0
  613. %endif
  614. %preun
  615. %if "%{with_server}" == "yes"
  616. # before erase, stop service and remove log files
  617. [ $1 -eq 0 ] || exit 0
  618. %{l_rc} postgresql stop 2>/dev/null
  619. rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/* >/dev/null 2>&1 || true
  620. exit 0
  621. %endif