postgresql.spec 15 KB

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