postgresql.spec 15 KB

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