postgresql.spec 16 KB

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