blob: 5f40120191f6fd0df0ab76b1e83dc7933d9239c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/dev-db/postgis/postgis-1.2.1.ebuild,v 1.3 2009/03/07 06:27:50 zmedico Exp $
inherit autotools eutils versionator
KEYWORDS="~x86 ~ppc ~amd64"
DESCRIPTION="Geographic Objects for PostgreSQL"
HOMEPAGE="http://postgis.refractions.net"
SRC_URI="http://www.postgis.org/download/${P}.tar.gz"
LICENSE="GPL-2"
SLOT="0"
IUSE="geos proj doc"
RDEPEND=">=virtual/postgresql-server-7.4
geos? ( sci-libs/geos )
proj? ( sci-libs/proj )"
DEPEND="${RDEPEND}
doc? ( app-text/docbook-xsl-stylesheets )"
RESTRICT="test"
pkg_setup(){
local tmp
tmp="$(portageq match / ${CATEGORY}/${PN} | cut -d'.' -f2)"
if [ "${tmp}" != "$(get_version_component_range 2)" ]; then
elog "You must soft upgrade your existing postgis enabled databases"
elog "using 'emerge --config postgis'."
require_soft_upgrade="1"
ebeep 2
fi
}
src_unpack(){
unpack ${A}
cd "${S}"
epatch "${FILESDIR}/${PN}_xsl.patch"
eautoconf
}
src_compile(){
local myconf
if use geos; then
myconf="--with-geos"
fi
if use doc;then
myconf="${myconf} --with-xsl=$(ls "${ROOT}"usr/share/sgml/docbook/* | \
grep xsl\- | cut -d':' -f1)"
fi
econf --enable-autoconf \
--datadir=/usr/share/postgresql/contrib/ \
--libdir=/usr/$(get_libdir)/postgresql/ \
--with-docdir=/usr/share/doc/${PF}/html/ \
${myconf} \
$(use_with proj) ||\
die "Error: econf failed"
emake || die "Error: emake failed"
cd topology/
emake || die "Unable to build topology sql file"
if use doc ; then
cd "${S}"
emake docs || die "Unable to build documentation"
fi
}
src_install(){
dodir /usr/$(get_libdir)/postgresql /usr/share/postgresql/contrib/
emake DESTDIR="${D}" install || die "emake install failed"
cd "${S}/topology/"
emake DESTDIR="${D}" install || die "emake install topology failed"
cd "${S}"
dodoc Changelog CREDITS TODO loader/README.* doc/*txt
docinto topology
dodoc topology/{TODO,README}
dobin ./utils/postgis_restore.pl
cd "${S}"
if use doc; then
emake DESTDIR="${D}" docs-install || die "emake install docs failed"
fi
if [ ! -z "${require_soft_upgrade}" ]; then
grep "'C'" -B 4 "${D}"usr/share/postgresql/contrib/lwpostgis.sql |\
grep -v "'sql'" > \
"${D}"usr/share/postgresql/contrib/load_before_upgrade.sql
fi
}
pkg_postinst() {
elog "To create new spatial database use 'emerge --config ${PN}.'"
}
pkg_config(){
PGUSER="${PGUSER:-postgres}"
PGDATABASE="${PGDATABASE:-template_postgis}"
is_template=false
if [ "${PGDATABASE:0:8}" == "template" ];then
is_template=true
mytype="template database"
else
mytype="database"
fi
einfo "Create or upgrade a spatial template and database."
einfo "Using the user ${PGUSER} and the ${PGDATABASE} ${mytype}."
einfo "Please do 'export PGUSER=...' to use another user."
einfo "Please do 'export PGDATABASE=...' to set another template/database"
einfo "name (templates name have to be prefixed with 'template')."
logfile=$(mktemp "${ROOT}tmp/error.log.XXXXXX")
safe_exit(){
eerror "Removing created ${mydb} ${mytype}"
dropdb -q || (eerror "${1}"
die "Removing old db failed, you must do it manually")
eerror "Please see ${logfile} for more information."
die "${1}"
}
# if there is not a table or a template existing with the same name, create.
psql -ql 2> ${logfile}
if [ "$?" == 2 ];then
die "Unable to access databases server using the ${PGUSER} user"
fi
PGDBS="$(psql template1 -Atc \
'select 1 from pg_tables where tablename=${PGDATABASE};')"
if [ "$(psql -l | grep "${PGDATABASE}")" != 1 ]; then
einfo
einfo "Please hit ENTER if you want to create the ${PGDATABASE}"
einfo "${mytype} as "${PGUSER}" user, or Control-C to abort now..."
read
einfo "Creating the ${mytype} ${PGDATABASE}."
createdb -q -O ${PGUSER} ||\
die "Unable to create the ${mydb} ${mytype} as ${myuser}"
createlang plpgsql
if [ "$?" == 2 ]; then
safe_exit "${myuser} not allowed to createlang plpgsql ${mydb}."
fi
einfo "Loading PostGIS files into ${PGDATABASE}."
(psql -q -f \
"${ROOT}"usr/share/postgresql/contrib/lwpostgis.sql &&
psql -q -f \
"${ROOT}"usr/share/postgresql/contrib/spatial_ref_sys.sql) 2>\
"${logfile}"
if [ "$(grep -c ERROR "${logfile}")" \> 0 ]; then
safe_exit "Unable to load the sql files."
fi
if ${is_template}; then
einfo "Configure ${PGDATABASE} as a ${mytype}"
psql -q -c \
"UPDATE pg_database SET datistemplate=TRUE, datallowconn=FALSE
WHERE datname = '${PGDATABASE}';
VACUUM FREEZE;" || die "Unable to create ${mydb}"
fi
else
einfo
einfo "Please hit ENTER if you want to upgrade the ${mydb}"
einfo "${mytype} as ${myuser} user, or Control-C to abort now..."
read
if [ -e "${ROOT}"usr/share/postgresql/contrib/load_before_upgrade.sql ];
then
einfo "Updating the dynamic library references"
psql -q -f \
"${ROOT}"usr/share/postgresql/contrib/load_before_upgrade.sql\
2> "${logfile}"
if [ "$(grep -c ERROR "${logfile}")" \> 0 ]; then
safe_exit "Unable to update references."
fi
fi
if [ -e "${ROOT}"usr/share/postgresql/contrib/lwpostgis_upgrade.sql ];
then
einfo "Running soft upgrade"
psql -q -f \
"${ROOT}"usr/share/postgresql/contrib/lwpostgis_upgrade.sql 2>\
"${logfile}"
if [ "$(grep -c ERROR "${logfile}")" \> 0 ]; then
safe_exit "Unable to run soft upgrade."
fi
fi
fi
if ${is_template}; then
einfo "You can now create a spatial database using :"
einfo "createdb -T ${PGDATABASE} <db_name>"
fi
}
|