postgresql7.spec 23 KB

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