postgis-2.1.8-r1.ebuild 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="5"
  4. POSTGRES_COMPAT=( 9.{1,2,3,4,5} )
  5. inherit autotools eutils versionator
  6. MY_PV=$(replace_version_separator 3 '')
  7. MY_P="${PN}-${MY_PV}"
  8. S="${WORKDIR}/${MY_P}"
  9. DESCRIPTION="Geographic Objects for PostgreSQL"
  10. HOMEPAGE="http://postgis.net"
  11. SRC_URI="http://download.osgeo.org/postgis/source/${MY_P}.tar.gz"
  12. LICENSE="GPL-2"
  13. SLOT="0"
  14. KEYWORDS="amd64 ppc x86 ~amd64-linux ~x86-linux"
  15. IUSE="doc gtk static-libs test"
  16. RDEPEND="
  17. || (
  18. dev-db/postgresql:9.4[server]
  19. dev-db/postgresql:9.3[server]
  20. dev-db/postgresql:9.2[server]
  21. dev-db/postgresql:9.1[server]
  22. )
  23. dev-libs/json-c
  24. dev-libs/libxml2:2
  25. >=sci-libs/geos-3.4.2
  26. >=sci-libs/proj-4.6.0
  27. >=sci-libs/gdal-1.10.0:=
  28. gtk? ( x11-libs/gtk+:2 )
  29. "
  30. DEPEND="${RDEPEND}
  31. doc? (
  32. app-text/docbook-xsl-stylesheets
  33. app-text/docbook-xml-dtd:4.5
  34. dev-libs/libxslt
  35. virtual/imagemagick-tools[png]
  36. )
  37. virtual/pkgconfig
  38. test? ( dev-util/cunit )
  39. "
  40. PGIS="$(get_version_component_range 1-2)"
  41. REQUIRED_USE="test? ( doc )"
  42. # Needs a running psql instance, doesn't work out of the box
  43. RESTRICT="test"
  44. MAKEOPTS+=' -j1'
  45. # These modules are built using the same *FLAGS that were used to build
  46. # dev-db/postgresql. The right thing to do is to ignore the current
  47. # *FLAGS settings.
  48. QA_FLAGS_IGNORED="usr/lib(64)?/(rt)?postgis-${PGIS}\.so"
  49. postgres_check_slot() {
  50. if ! declare -p POSTGRES_COMPAT &>/dev/null; then
  51. die 'POSTGRES_COMPAT not declared.'
  52. fi
  53. # Don't die because we can't run postgresql-config during pretend.
  54. [[ "$EBUILD_PHASE" = "pretend" \
  55. && -z "$(which postgresql-config 2> /dev/null)" ]] && return 0
  56. local res=$(echo ${POSTGRES_COMPAT[@]} \
  57. | grep -c $(postgresql-config show 2> /dev/null) 2> /dev/null)
  58. if [[ "$res" -eq "0" ]] ; then
  59. eerror "PostgreSQL slot must be set to one of: "
  60. eerror " ${POSTGRES_COMPAT[@]}"
  61. return 1
  62. fi
  63. return 0
  64. }
  65. pkg_setup() {
  66. postgres_check_slot || die
  67. export PGSLOT="$(postgresql-config show)"
  68. }
  69. src_prepare() {
  70. epatch "${FILESDIR}/${PN}-2.1-ldflags.patch" \
  71. "${FILESDIR}/${PN}-2.0-arflags.patch" \
  72. "${FILESDIR}/${PN}-2.1.4-pkgconfig-json.patch"
  73. local AT_M4DIR="macros"
  74. eautoreconf
  75. }
  76. src_configure() {
  77. local myargs=""
  78. use gtk && myargs+=" --with-gui"
  79. econf \
  80. --with-pgconfig="/usr/lib/postgresql-${PGSLOT}/bin/pg_config" \
  81. ${myargs}
  82. }
  83. src_compile() {
  84. emake
  85. emake -C topology
  86. if use doc ; then
  87. emake comments
  88. emake cheatsheets
  89. emake -C doc html
  90. fi
  91. }
  92. src_install() {
  93. emake DESTDIR="${D}" install
  94. use doc && emake DESTDIR="${D}" comments-install
  95. emake -C topology DESTDIR="${D}" install
  96. dobin ./utils/postgis_restore.pl
  97. dodoc CREDITS TODO loader/README.* doc/*txt
  98. use doc && dohtml -r doc/html/*
  99. docinto topology
  100. dodoc topology/{TODO,README}
  101. insinto /etc
  102. doins "${FILESDIR}/postgis_dbs"
  103. use static-libs || find "${ED}" -name '*.a' -delete
  104. }
  105. pkg_postinst() {
  106. postgresql-config update
  107. elog "To finish installing or updating PostGIS edit:"
  108. elog " ${EROOT%/}/etc/postgis_dbs"
  109. elog
  110. elog "Then, run:"
  111. elog " emerge --config =${CATEGORY}/${PF}"
  112. }
  113. pkg_config(){
  114. source "${EROOT%/}/etc/conf.d/postgresql-${PGSLOT}"
  115. source "${EROOT%/}/etc/postgis_dbs"
  116. local postgis_path="${EROOT%/}/usr/share/postgresql-${PGSLOT}/contrib/postgis-${PGIS}"
  117. if [[ -n ${configured} ]] ; then
  118. einfon "Password for PostgreSQL user '${pguser}': "
  119. read -s PGPASSWORD
  120. export PGPASSWORD
  121. echo
  122. else
  123. eerror "You must edit:"
  124. eerror " ${EROOT%/}/etc/postgis_dbs"
  125. eerror "Before running 'emerge --config =${CATEGORY}/${PF}'"
  126. eerror
  127. die "Edit postgis_dbs"
  128. fi
  129. # The server we work with must be the same slot we built against.
  130. local server_match
  131. server_match=$(psql -U ${pguser} -d postgres -p ${PGPORT} \
  132. -Aqwtc 'SELECT version()' 2> /dev/null | grep -c "PostgreSQL ${PGSLOT}")
  133. if [[ $? = 0 ]] ; then
  134. if [[ $server_match -ne 1 ]] ; then
  135. unset PGPASSWORD
  136. eerror "Server version must be ${PGSLOT}.x"
  137. die "Server version isn't ${PGSLOT}.x"
  138. fi
  139. else
  140. unset PGPASSWORD
  141. eerror "Is the server running?"
  142. die "Couldn't connect to server."
  143. fi
  144. local retval
  145. safe_exit() {
  146. unset PGPASSWORD
  147. sed -e 's/\(configured\)/#\1/' -i "${EROOT%/}/etc/postgis_dbs"
  148. eend $retval
  149. eerror "All actions could not be performed."
  150. eerror "Read above to see what failed."
  151. eerror "Once you fix the issue, you'll need to edit:"
  152. eerror " ${EROOT%/}/etc/postgis_dbs"
  153. eerror "As some things may have succeeded."
  154. eerror
  155. die "All actions could not be performed"
  156. }
  157. local db
  158. for db in ${databases[@]} ; do
  159. ebegin "Performing CREATE LANGUAGE on ${db}"
  160. createlang -U ${pguser} -p ${PGPORT} plpgsql ${db}
  161. retval=$?
  162. # In this case, only error code 1 is fatal
  163. [[ $retval == 1 ]] && safe_exit || eend 0
  164. ebegin "Enabling PostGIS on ${db}"
  165. psql -q -U ${pguser} -p ${PGPORT} -d ${db} \
  166. -f "${postgis_path}/postgis.sql"
  167. retval=$?
  168. [[ $retval == 0 ]] && eend 0 || safe_exit
  169. done
  170. for db in ${templates[@]} ; do
  171. ebegin "Creating template database '${db}'"
  172. createdb -p ${PGPORT} -U ${pguser} -O ${pguser} -T ${from_template} \
  173. ${db} "PostGIS Template"
  174. retval=$?
  175. [[ $retval != 0 ]] && safe_exit
  176. psql -q -U ${pguser} -p ${PGPORT} -c \
  177. "UPDATE pg_database \
  178. SET datistemplate = TRUE, datallowconn = TRUE \
  179. WHERE datname = '${db}'"
  180. retval=$?
  181. [[ $retval != 0 ]] && safe_exit
  182. createlang -U ${pguser} -p ${PGPORT} plpgsql ${db}
  183. retval=$?
  184. # In this case, only error code 1 is fatal
  185. [[ $retval == 1 ]] && safe_exit
  186. psql -q -U ${pguser} -p ${PGPORT} -d ${db} \
  187. -f "${postgis_path}/postgis.sql"
  188. retval=$?
  189. [[ $retval == 0 ]] && eend 0 || safe_exit
  190. done
  191. for db in ${epsg_databases[@]} ; do
  192. ebegin "Adding EPSG to ${db}"
  193. psql -q -U ${pguser} -p ${PGPORT} -d ${db} \
  194. -f "${postgis_path}/spatial_ref_sys.sql"
  195. retval=$?
  196. [[ $retval == 0 ]] && eend 0 || safe_exit
  197. done
  198. for db in ${comment_databases[@]} ; do
  199. ebegin "Adding comments on ${db}"
  200. local comment_file
  201. for comment_file in "${postgis_path}"/*_comments.sql ; do
  202. psql -q -U ${pguser} -p ${PGPORT} -d ${db} -f "${comment_file}"
  203. retval=$?
  204. [[ $retval == 0 ]] && continue || safe_exit
  205. done
  206. eend 0
  207. done
  208. for db in ${upgrade_from_1_3[@]} ; do
  209. ebegin "Upgrading from PostGIS 1.3 to ${PGIS} on ${db}"
  210. psql -q -U ${pguser} -p ${PGPORT} -d ${db} \
  211. -f "${postgis_path}/postgis_upgrade_13_to_${PGIS//.}.sql"
  212. retval=$?
  213. [[ $retval == 0 ]] && eend 0 || safe_exit
  214. done
  215. for db in ${upgrade_from_1_4[@]} ; do
  216. ebegin "Upgrading from PostGIS 1.4 to ${PGIS} on ${db}"
  217. psql -q -U ${pguser} -p ${PGPORT} -d ${db} \
  218. -f "${postgis_path}/postgis_upgrade_14_to_${PGIS//.}.sql"
  219. retval=$?
  220. [[ $retval == 0 ]] && eend 0 || safe_exit
  221. done
  222. for db in ${upgrade_from_1_5[@]} ; do
  223. ebegin "Minor upgrade for PostGIS ${PGIS} on ${db}"
  224. psql -q -U ${pguser} -p ${PGPORT} -d ${db} \
  225. -f "${postgis_path}/postgis_upgrade_${PGIS//.}_minor.sql"
  226. retval=$?
  227. [[ $retval == 0 ]] && eend 0 || safe_exit
  228. done
  229. # Clean up and make it so the user has to edit postgis_dbs again that
  230. # way this script won't step on any toes due to user error.
  231. unset PGPASSWORD
  232. sed -e 's/\(configured\)/#\1/' -i "${EROOT%/}/etc/postgis_dbs"
  233. einfo "PostgreSQL ${PGSLOT} is now PostGIS enabled."
  234. einfo
  235. einfo "Currently, only one PostgreSQL slot at a time can be PostGIS enabled."
  236. }