postgresql.spec 25 KB

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