postgresql.spec 13 KB

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