postgis-9999.ebuild 7.2 KB

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