postgresql.spec 24 KB

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