postgresql.spec 13 KB

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