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