postgresql.spec 12 KB

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