postgresql.spec 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. ##
  2. ## postgresql.spec -- OpenPKG RPM Specification
  3. ## Copyright (c) 2000-2002 Cable & Wireless Deutschland GmbH
  4. ## Copyright (c) 2000-2002 The OpenPKG Project <http://www.openpkg.org/>
  5. ## Copyright (c) 2000-2002 Ralf S. Engelschall <rse@engelschall.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 options
  26. %ifndef with_openssl
  27. %define with_openssl no
  28. %endif
  29. %ifndef with_odbc
  30. %define with_odbc no
  31. %endif
  32. %ifndef with_perl
  33. %define with_perl no
  34. %endif
  35. %ifndef with_tcl
  36. %define with_tcl no
  37. %endif
  38. # package component versions
  39. %define V_libpqxx 4.0
  40. # package information
  41. Name: postgresql
  42. Summary: PostgreSQL Database
  43. URL: http://www.postgresql.org/
  44. Vendor: PostgreSQL Group
  45. Packager: The OpenPKG Project
  46. Distribution: OpenPKG [BASE]
  47. Group: Database
  48. License: GPL
  49. Version: 7.3
  50. Release: 20021219
  51. # list of sources
  52. Source0: ftp://ftp.postgresql.org/pub/source/v%{version}/postgresql-%{version}.tar.gz
  53. Source1: ftp://gborg.postgresql.org/pub/libpqpp/stable/libpq++-%{V_libpqxx}.tar.gz
  54. Source2: rc.postgresql
  55. Source3: pg_migrate
  56. # build information
  57. Prefix: %{l_prefix}
  58. BuildRoot: %{l_buildroot}
  59. BuildPreReq: OpenPKG, openpkg >= 20020416, make, gcc, readline, flex, bison
  60. PreReq: OpenPKG, openpkg >= 20020416
  61. %if "%{with_openssl}" == "yes"
  62. BuildPreReq: openssl
  63. %endif
  64. %if "%{with_odbc}" == "yes"
  65. BuildPreReq: unixodbc
  66. PreReq: unixodbc
  67. %endif
  68. %if "%{with_perl}" == "yes"
  69. BuildPreReq: perl
  70. PreReq: perl
  71. %endif
  72. %if "%{with_tcl}" == "yes"
  73. BuildPreReq: tcl
  74. PreReq: tcl
  75. %endif
  76. AutoReq: no
  77. AutoReqProv: no
  78. %description
  79. PostgreSQL is a sophisticated Object-Relational DBMS, supporting
  80. almost all SQL constructs, including subselects, transactions,
  81. and user-defined types and functions. It is the most advanced
  82. open-source database available anywhere.
  83. Options:
  84. --define 'with_openssl %{with_openssl}'
  85. --define 'with_odbc %{with_odbc}'
  86. --define 'with_perl %{with_perl}'
  87. --define 'with_tcl %{with_tcl}'
  88. %prep
  89. %setup0 -q
  90. %setup1 -q -T -D -a 1
  91. %{l_shtool} subst \
  92. -e 's;\(#define.*DEFAULT_PGSOCKET_DIR[^"]*"\)/tmp\("\);\1%{l_prefix}/var/postgresql/run\2;' \
  93. src/include/pg_config.h.in
  94. %build
  95. # configure package
  96. CC="%{l_cc}"; export CC
  97. CFLAGS="%{l_cflags -O}"; export CFLAGS
  98. CPPFLAGS="%{l_cppflags}"; export CPPFLAGS
  99. LDFLAGS="%{l_ldflags}"; export LDFLAGS
  100. %if "%{with_odbc}" == "yes"
  101. %endif
  102. %if "%{with_tcl}" == "yes"
  103. CFLAGS="$CFLAGS -I%{l_prefix}/include/tcl"
  104. LDFLAGS="$LDFLAGS -L%{l_prefix}/lib"
  105. %endif
  106. ./configure \
  107. --prefix=%{l_prefix} \
  108. %if "%{with_openssl}" == "yes"
  109. --with-openssl=%{l_prefix} \
  110. %endif
  111. %if "%{with_odbc}" == "yes"
  112. --enable-odbc \
  113. --with-unixodbc \
  114. --with-odbcinst=%{l_prefix}/etc/unixodbc \
  115. %endif
  116. %if "%{with_perl}" == "yes"
  117. --with-perl \
  118. %endif
  119. %if "%{with_tcl}" == "yes"
  120. --with-tcl \
  121. %endif
  122. --without-CXX \
  123. --disable-syslog
  124. # build package
  125. %{l_make} %{l_mflags -O}
  126. # build libpq++ (C++ bindings)
  127. ( cd libpq++-%{V_libpqxx}
  128. CXX="%{l_cxx}"
  129. CFLAGS="%{l_cflags -O}"
  130. CPPFLAGS="-DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT= -I. -I../src/interfaces -I../src/interfaces/libpq %{l_cppflags}"
  131. LDFLAGS="%{l_ldflags}"
  132. OBJS="pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o"
  133. for o in $OBJS; do
  134. $CXX $CFLAGS $CPPFLAGS $LDFLAGS -c -o $o `basename $o .o`.cc
  135. done
  136. ar r libpq++.a $OBJS
  137. )
  138. %install
  139. rm -rf $RPM_BUILD_ROOT
  140. # perform standard installation procedure
  141. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  142. # strip down installation
  143. rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
  144. strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
  145. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
  146. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
  147. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
  148. rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/lib*.so*
  149. # namespace adjustments to installation
  150. for prog in \
  151. createdb createlang createuser dropdb droplang \
  152. dropuser initdb initlocation ipcclean vacuumdb; do
  153. mv $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
  154. $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
  155. mv $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
  156. $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
  157. done
  158. ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
  159. for man in *.7; do
  160. mv $man pg_$man
  161. done
  162. )
  163. # optionally install pgAccess startup wrapper
  164. %if "%{with_tcl}" == "yes"
  165. ( LD_LIBRARY_PATH=%{l_prefix}/lib:$LD_LIBRARY_PATH
  166. %{l_prefix}/share/postgresql/pgaccess/main.tcl ${1+"$@"}
  167. ) >$RPM_BUILD_ROOT%{l_prefix}/bin/pgaccess
  168. chmod 755 $RPM_BUILD_ROOT%{l_prefix}/bin/pgaccess
  169. %endif
  170. # create additional directories
  171. %{l_shtool} mkdir -f -p -m 755 \
  172. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
  173. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
  174. # install migration utility
  175. %{l_shtool} install -c -m 755 \
  176. -e 's;@l_prefix@;%{l_prefix};g' \
  177. -e 's;@l_rusr@;%{l_rusr};g' \
  178. -e 's;@l_rgrp@;%{l_rgrp};g' \
  179. %{SOURCE pg_migrate} \
  180. $RPM_BUILD_ROOT%{l_prefix}/bin/
  181. # install libpq++ (C++ bindings)
  182. ( cd libpq++-%{V_libpqxx}
  183. %{l_shtool} mkdir -f -p -m 755 \
  184. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++
  185. %{l_shtool} install -c -m 644 \
  186. libpq++.h \
  187. pgconnection.h \
  188. pgdatabase.h \
  189. pgtransdb.h \
  190. pgcursordb.h \
  191. pglobject.h \
  192. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++/
  193. %{l_shtool} install -c -m 644 \
  194. libpq++.a \
  195. $RPM_BUILD_ROOT%{l_prefix}/lib/
  196. )
  197. # install run-command script
  198. %{l_shtool} mkdir -f -p -m 755 \
  199. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  200. %{l_shtool} install -c -m 755 \
  201. -e 's;@l_prefix@;%{l_prefix};g' \
  202. -e 's;@l_rusr@;%{l_rusr};g' \
  203. -e 's;@l_rgrp@;%{l_rgrp};g' \
  204. %{SOURCE rc.postgresql} \
  205. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  206. # determine installation files
  207. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  208. %{l_files_std} \
  209. '%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
  210. '%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
  211. %files -f files
  212. %clean
  213. rm -rf $RPM_BUILD_ROOT
  214. %pre
  215. if [ $1 -eq 1 ]; then
  216. # initial installation
  217. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
  218. -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
  219. # database migration dumping hint
  220. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  221. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  222. v_new_all="%{version}"
  223. v_new_maj=`echo "$v_new_maj" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  224. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  225. if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$PG_MIGRATE" != .ignore ]; then
  226. ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  227. echo "which is a major version change. We expect a database incompatibility,"
  228. echo "so we strongly recommend that you backup your existing database"
  229. echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
  230. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
  231. echo "Alternatively, if you want force this package to be installed without"
  232. echo "performing a database dump, run the following command before upgrading:"
  233. echo " \$ PG_MIGRATE=ignore; export PG_MIGRATE"
  234. ) | %{l_rpmtool} msg -b -t error
  235. exit 1
  236. fi
  237. fi
  238. fi
  239. elif [ $1 -gt 1 ]; then
  240. # upgrading of installation
  241. rm -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART >/dev/null 2>&1 || true
  242. if [ ".`$l_prefix/etc/rc postgresql status 2>&1 | grep 'is running'`" != . ]; then
  243. echo "Shutting down currently running database engine." | %{l_rpmtool} msg -b -t notice
  244. $RPM_INSTALL_PREFIX/etc/rc postgresql stop
  245. touch $RPM_INSTALL_PREFIX/var/posgresql/RESTART
  246. sleep 4
  247. fi
  248. fi
  249. %post
  250. if [ $1 -eq 1 ]; then
  251. # create initial database
  252. su - %{l_rusr} -c \
  253. "LC_CTYPE=C; export LC_CTYPE; umask 022; \
  254. (echo 'postgresql'; echo 'postgresql') |\
  255. $RPM_INSTALL_PREFIX/bin/pg_initdb \
  256. -U postgresql -W -D $RPM_INSTALL_PREFIX/var/postgresql/db" 2>&1 |\
  257. $RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
  258. -p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
  259. # adjust initial authentication configuration
  260. cp $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf \
  261. $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  262. ( cat $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old |\
  263. sed -e 's;^\([^#]\);# \1;' -e 's;^$;#;'
  264. echo ""
  265. echo "# OpenPKG PostgreSQL default access policy"
  266. echo "local all all md5"
  267. echo "host all all 127.0.0.1 255.255.255.255 md5"
  268. echo ""
  269. ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf
  270. rm -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  271. # display information about next steps
  272. ( echo "An initial PostgreSQL DB was created with the two standard"
  273. echo "databases 'template0' and 'template1'. The owner of both"
  274. echo "is the DB user 'postgresql'. Its initial password is 'postgresql'."
  275. echo "After starting PostgreSQL you should change this as quick as"
  276. echo "possible with the following command:"
  277. echo "\$ $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1 \\"
  278. echo " -c \"ALTER USER postgresql WITH PASSWORD '<new-password>'\""
  279. ) | %{l_rpmtool} msg -b -t notice
  280. # optionally link into unixODBC
  281. %if "%{with_odbc}" == "yes"
  282. ( echo "[PostgreSQL]"
  283. echo "Description = PostgreSQL ODBC driver"
  284. echo "Driver = $RPM_INSTALL_PREFIX/lib/libodbcpsql.so"
  285. echo "Setup = $RPM_INSTALL_PREFIX/lib/libodbcpsqlS.so"
  286. echo "Threading = 2"
  287. ) $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r
  288. %endif
  289. elif [ $1 -gt 1 ]; then
  290. if [ -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART ]; then
  291. echo "Starting database engine again." | %{l_rpmtool} msg -b -t notice
  292. $RPM_INSTALL_PREFIX/etc/rc postgresql start
  293. rm -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART >/dev/null 2>&1 || true
  294. sleep 2
  295. fi
  296. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
  297. # database migration restoring hint
  298. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  299. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  300. v_new_all="%{version}"
  301. v_new_maj=`echo "$v_new_maj" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  302. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  303. ( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  304. echo "which is a major version upgrade. We expect a database incompatibility,"
  305. echo "so we strongly recommend you to recreate the existing database under"
  306. echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
  307. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dump restore"
  308. ) | %{l_rpmtool} msg -b -t warn
  309. fi
  310. fi
  311. fi