postgresql.spec 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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
  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: 20021219
  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
  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. %build
  96. # configure package
  97. CC="%{l_cc}"; export CC
  98. CFLAGS="%{l_cflags -O}"; export CFLAGS
  99. CPPFLAGS="%{l_cppflags}"; export CPPFLAGS
  100. LDFLAGS="%{l_ldflags}"; export LDFLAGS
  101. %if "%{with_odbc}" == "yes"
  102. %endif
  103. %if "%{with_tcl}" == "yes"
  104. CFLAGS="$CFLAGS -I%{l_prefix}/include/tcl"
  105. LDFLAGS="$LDFLAGS -L%{l_prefix}/lib"
  106. %endif
  107. ./configure \
  108. --prefix=%{l_prefix} \
  109. %if "%{with_openssl}" == "yes"
  110. --with-openssl=%{l_prefix} \
  111. %endif
  112. %if "%{with_odbc}" == "yes"
  113. --enable-odbc \
  114. --with-unixodbc \
  115. --with-odbcinst=%{l_prefix}/etc/unixodbc \
  116. %endif
  117. %if "%{with_perl}" == "yes"
  118. --with-perl \
  119. %endif
  120. %if "%{with_tcl}" == "yes"
  121. --with-tcl \
  122. %endif
  123. --without-CXX \
  124. --disable-syslog
  125. # build package
  126. %{l_make} %{l_mflags -O}
  127. # build libpq++ (C++ bindings)
  128. ( cd libpq++-%{V_libpqxx}
  129. CXX="%{l_cxx}"
  130. CFLAGS="%{l_cflags -O}"
  131. CPPFLAGS="-DHAVE_NAMESPACE_STD -DHAVE_CXX_STRING_HEADER -DDLLIMPORT= "
  132. CPPFLAGS="$CPPFLAGS -I. -I../src/interfaces -I../src/interfaces/libpq "
  133. CPPFLAGS="$CPPFLAGS %{l_cppflags}"
  134. LDFLAGS="%{l_ldflags}"
  135. OBJS="pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o"
  136. for o in $OBJS; do
  137. $CXX $CFLAGS $CPPFLAGS $LDFLAGS -c -o $o `echo $o | sed -e 's;\.o$;.cc;'`
  138. done
  139. rm -f libpq++.a
  140. ar rc libpq++.a $OBJS
  141. )
  142. %install
  143. rm -rf $RPM_BUILD_ROOT
  144. # perform standard installation procedure
  145. %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
  146. # strip down installation
  147. rm -rf $RPM_BUILD_ROOT%{l_prefix}/doc
  148. strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
  149. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgaccess.1
  150. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtclsh.1
  151. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/pgtksh.1
  152. rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/lib*.so*
  153. # namespace adjustments to installation
  154. for prog in \
  155. createdb createlang createuser dropdb droplang \
  156. dropuser initdb initlocation ipcclean vacuumdb; do
  157. mv $RPM_BUILD_ROOT%{l_prefix}/bin/$prog \
  158. $RPM_BUILD_ROOT%{l_prefix}/bin/pg_$prog
  159. mv $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prog.1 \
  160. $RPM_BUILD_ROOT%{l_prefix}/man/man1/pg_$prog.1
  161. done
  162. ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man7
  163. for man in *.7; do
  164. mv $man pg_$man
  165. done
  166. )
  167. # optionally install pgAccess startup wrapper
  168. %if "%{with_tcl}" == "yes"
  169. ( LD_LIBRARY_PATH=%{l_prefix}/lib:$LD_LIBRARY_PATH
  170. %{l_prefix}/share/postgresql/pgaccess/main.tcl ${1+"$@"}
  171. ) >$RPM_BUILD_ROOT%{l_prefix}/bin/pgaccess
  172. chmod 755 $RPM_BUILD_ROOT%{l_prefix}/bin/pgaccess
  173. %endif
  174. # create additional directories
  175. %{l_shtool} mkdir -f -p -m 755 \
  176. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/db \
  177. $RPM_BUILD_ROOT%{l_prefix}/var/postgresql/run
  178. # install migration utility
  179. %{l_shtool} install -c -m 755 \
  180. -e 's;@l_prefix@;%{l_prefix};g' \
  181. -e 's;@l_rusr@;%{l_rusr};g' \
  182. -e 's;@l_rgrp@;%{l_rgrp};g' \
  183. %{SOURCE pg_migrate} \
  184. $RPM_BUILD_ROOT%{l_prefix}/bin/
  185. # install libpq++ (C++ bindings)
  186. ( cd libpq++-%{V_libpqxx}
  187. %{l_shtool} mkdir -f -p -m 755 \
  188. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++
  189. %{l_shtool} install -c -m 644 \
  190. libpq++.h pgconnection.h pgdatabase.h pgtransdb.h pgcursordb.h pglobject.h \
  191. $RPM_BUILD_ROOT%{l_prefix}/include/libpq++/
  192. %{l_shtool} install -c -m 644 \
  193. libpq++.a \
  194. $RPM_BUILD_ROOT%{l_prefix}/lib/
  195. )
  196. # install run-command script
  197. %{l_shtool} mkdir -f -p -m 755 \
  198. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  199. %{l_shtool} install -c -m 755 \
  200. -e 's;@l_prefix@;%{l_prefix};g' \
  201. -e 's;@l_rusr@;%{l_rusr};g' \
  202. -e 's;@l_rgrp@;%{l_rgrp};g' \
  203. %{SOURCE rc.postgresql} \
  204. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  205. # determine installation files
  206. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  207. %{l_files_std} \
  208. '%attr(700,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/db' \
  209. '%attr(755,%{l_rusr},%{l_rgrp}) %dir %{l_prefix}/var/postgresql/run'
  210. %files -f files
  211. %clean
  212. rm -rf $RPM_BUILD_ROOT
  213. %pre
  214. if [ $1 -eq 1 ]; then
  215. # initial installation
  216. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
  217. -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
  218. # database migration dumping hint
  219. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  220. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  221. v_new_all="%{V_postgresql}"
  222. v_new_maj=`echo "$v_new_maj" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  223. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  224. if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$PG_MIGRATE" != .ignore ]; then
  225. ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  226. echo "which is a major version change. We expect a database incompatibility,"
  227. echo "so we strongly recommend that you backup your existing database"
  228. echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
  229. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
  230. echo "Alternatively, if you want force this package to be installed without"
  231. echo "performing a database dump, run the following command before upgrading:"
  232. echo " \$ PG_MIGRATE=ignore; export PG_MIGRATE"
  233. ) | %{l_rpmtool} msg -b -t error
  234. exit 1
  235. fi
  236. fi
  237. fi
  238. elif [ $1 -gt 1 ]; then
  239. # upgrading of installation
  240. rm -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART >/dev/null 2>&1 || true
  241. if [ ".`$l_prefix/etc/rc postgresql status 2>&1 | grep 'is running'`" != . ]; then
  242. echo "Shutting down currently running database engine." | %{l_rpmtool} msg -b -t notice
  243. $RPM_INSTALL_PREFIX/etc/rc postgresql stop
  244. touch $RPM_INSTALL_PREFIX/var/posgresql/RESTART
  245. sleep 4
  246. fi
  247. fi
  248. %post
  249. if [ $1 -eq 1 ]; then
  250. # create initial database
  251. su - %{l_rusr} -c \
  252. "LC_CTYPE=C; export LC_CTYPE; umask 022; \
  253. (echo 'postgresql'; echo 'postgresql') |\
  254. $RPM_INSTALL_PREFIX/bin/pg_initdb \
  255. -U postgresql -W -D $RPM_INSTALL_PREFIX/var/postgresql/db" 2>&1 |\
  256. $RPM_INSTALL_PREFIX/lib/openpkg/shtool prop \
  257. -p "Creating initial PostgreSQL DB in $RPM_INSTALL_PREFIX/var/postgresql/db"
  258. # adjust initial authentication configuration
  259. cp $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf \
  260. $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  261. ( cat $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old |\
  262. sed -e 's;^\([^#]\);# \1;' -e 's;^$;#;'
  263. echo ""
  264. echo "# OpenPKG PostgreSQL default access policy"
  265. echo "local all all md5"
  266. echo "host all all 127.0.0.1 255.255.255.255 md5"
  267. echo ""
  268. ) >$RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf
  269. rm -f $RPM_INSTALL_PREFIX/var/postgresql/db/pg_hba.conf.old
  270. # display information about next steps
  271. ( echo "An initial PostgreSQL DB was created with the two standard"
  272. echo "databases 'template0' and 'template1'. The owner of both"
  273. echo "is the DB user 'postgresql'. Its initial password is 'postgresql'."
  274. echo "After starting PostgreSQL you should change this as quick as"
  275. echo "possible with the following command:"
  276. echo "\$ $RPM_INSTALL_PREFIX/bin/psql -U postgresql -d template1 \\"
  277. echo " -c \"ALTER USER postgresql WITH PASSWORD '<new-password>'\""
  278. ) | %{l_rpmtool} msg -b -t notice
  279. # optionally link into unixODBC
  280. %if "%{with_odbc}" == "yes"
  281. ( echo "[PostgreSQL]"
  282. echo "Description = PostgreSQL ODBC driver"
  283. echo "Driver = $RPM_INSTALL_PREFIX/lib/libodbcpsql.so"
  284. echo "Setup = $RPM_INSTALL_PREFIX/lib/libodbcpsqlS.so"
  285. echo "Threading = 2"
  286. ) $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r
  287. %endif
  288. elif [ $1 -gt 1 ]; then
  289. if [ -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART ]; then
  290. echo "Starting database engine again." | %{l_rpmtool} msg -b -t notice
  291. $RPM_INSTALL_PREFIX/etc/rc postgresql start
  292. rm -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART >/dev/null 2>&1 || true
  293. sleep 2
  294. fi
  295. if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
  296. # database migration restoring hint
  297. v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
  298. v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  299. v_new_all="%{V_postgresql}"
  300. v_new_maj=`echo "$v_new_maj" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
  301. if [ ".$v_old_maj" != ".$v_new_maj" ]; then
  302. ( echo "You upgraded from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
  303. echo "which is a major version upgrade. We expect a database incompatibility,"
  304. echo "so we strongly recommend you to recreate the existing database under"
  305. echo "$RPM_INSTALL_PREFIX/var/postgresql/db/ by running the following command:"
  306. echo " \$ $RPM_INSTALL_PREFIX/bin/pg_dump restore"
  307. ) | %{l_rpmtool} msg -b -t warn
  308. fi
  309. fi
  310. fi