-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_postgis.sh
executable file
·85 lines (72 loc) · 2.76 KB
/
install_postgis.sh
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
#!/bin/bash
DB_NAME=geodb
GEOSVERSION=3.3.8
POSTGIS_VERSION=$POSTGIS_VERSION
PG_VERSION=9.1
GDAL_VERSION=1.9.2
SRC_DIR=/home/gregs/projects/geodjangosetup
sudo /etc/init.d/postgresql stop
function upgrade_postgis{
# PostGIS 1.5.2 and its dependencies were installed already, so I
# removed them
sudo aptitude remove postgis postgresql-9.1-postgis \
libgdal1-dev libgdal1-1.7.0 gdal-bin python-gdal \
libspatialite2 libspatialite3 libgeos-dev libgeos-c1
# install any missing prerequisites
sudo aptitude install gdebi build-essential checkinstall postgresql \
postgresql-server-dev-9.1 libjson0-dev libxml2-dev libproj-dev \
python2.7-dev swig binutils
mkdir -p $SRC_DIR
echo "Downloading and compiloing GEOS"
# download and compile geos in /opt/geos
cd $SRC_DIR
wget http://download.osgeo.org/geos/geos-$GEOSVERSION.tar.bz2
tar xvjf geos-$GEOSVERSION.tar.bz2
cd geos-$GEOSVERSION/
./configure --prefix=/opt/geos --enable-python
make -j2
sudo checkinstall # uninstall with: dpkg -r geos
sudo gdebi geos_$GEOSVERSION-1_amd64.deb
echo "Downloading and compiloing GDAL"
# download and compile gdal in /opt/gdal
cd $SRC_DIR
wget http://download.osgeo.org/gdal/gdal-$GDALVERSION.tar.gz
tar xvzf gdal-$GDALVERSION.tar.gz
cd gdal-$GDALVERSION/
./configure --prefix=/opt/gdal --with-geos=/opt/geos/bin/geos-config \
--with-pg=/usr/lib/postgresql/9.1/bin/pg_config --with-python
make -j2
sudo checkinstall # uninstall with: dpkg -r gdal
sudo gdebi gdal_$GDAL_VERSION-1_amd64.deb
echo "Downloading and compiloing PostGIS"
# download and compile postgis 2 in default location
cd $SRC_DIR
wget http://www.postgis.org/download/postgis-$POSTGIS_VERSION.tar.gz
tar xvzf postgis-$POSTGIS_VERSION.tar.gz
cd postgis-$POSTGIS_VERSION/
./configure --with-geosconfig=/opt/geos/bin/geos-config \
--with-gdalconfig=/opt/gdal/bin/gdal-config
make -j2
sudo checkinstall # uninstall with: dpkg -r postgis
sudo gdebi postgis_$POSTGIS_VERSION-1_amd64
# for command-line tools, append this line to .profile/.bashrc/etc.
export PATH=$PATH:/opt/geos/bin:/opt/gdal/bin
# so libraries are found, create /etc/ld.so.conf.d/geolibs.conf
# with these two lines:
echo "/opt/geos/lib
/opt/gdal/lib" >> geolibs.conf
# then
sudo ldconfig
sudo /etc/init.d/postgresql start
}
function restore_postgisDB{
# Migrate a previous PostGIS DB into the newly installed version
# supply the DB name to be used for the latest postgis DB and
# a file path to the pg_dump -Fc backup from an earlier PostGIS version
echo 'create database -E UTF8 $DB_NAME;' | sudo -u postgres psql
echo 'create extension postgis; create extension postgis_topology;' \
| sudo -u postgres psql -d $DB_NAME
/usr/share/postgresql/$PG_VERSION/contrib/postgis-$PG_VERSION/postgis_restore.pl \
/path/to/mydb.dump \
| sudo -u postgres psql -d $DB_NAME
}