postgresql.spec 25 KB

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