postgresql.spec 20 KB

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