Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Postgres 9.1, PostGIS and create PostGIS template on Ubuntu 12.04 Precise Pangolin box (as ROOT)
#!/bin/bash
#
# Install Postgres 9.1, PostGIS and create PostGIS template on a clean Ubuntu 12.04 Precise Pangolin box (as ROOT)
# TaskRabbit
# add the ubuntu gis ppa
# sudo apt-get -y install python-software-properties
# sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
# sudo apt-get update
# the big list of apt dependencies to check we have installed
sudo apt-get -y install postgis postgresql-9.1 postgresql-server-dev-9.1 postgresql-contrib-9.1 postgis gdal-bin binutils libgeos-3.2.2 libgeos-c1 libgeos-dev libgdal1-dev libxml2 libxml2-dev libxml2-dev checkinstall proj libpq-dev postgresql-9.1-postgis
# sudo mkdir -p '/usr/share/postgresql/9.1/contrib/postgis-1.5'
# fetch, compile and install PostGIS
# wget http://postgis.refractions.net/download/postgis-1.5.3.tar.gz
# tar zxvf postgis-1.5.3.tar.gz && cd postgis-1.5.3/
# sudo ./configure && sudo make && sudo checkinstall --pkgname postgis-1.5.3 --pkgversion 1.5.3-src --default
# now create the test_gis database template
export POSTGIS_SQL_PATH=/usr/share/postgresql/9.1/contrib/
su postgres -c 'createdb -E UTF8 -U postgres test_gis'
su postgres -c 'createlang -d test_gis plpgsql;'
su postgres -c 'psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='test_gis';"'
su postgres -c 'psql -U postgres -d test_gis -c "CREATE EXTENSION hstore;"'
su postgres -c 'psql -U postgres -d test_gis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql'
su postgres -c 'psql -U postgres -d test_gis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql'
su postgres -c 'psql -U postgres -d test_gis -c "select postgis_lib_version();"'
su postgres -c 'psql -U postgres -d test_gis -c "GRANT ALL ON geometry_columns TO PUBLIC;"'
su postgres -c 'psql -U postgres -d test_gis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"'
su postgres -c 'psql -U postgres -d test_gis -c "GRANT ALL ON geography_columns TO PUBLIC;"'
su postgres -c 'psql -U postgres -d test_gis -c "VACUUM FULL;"'
su postgres -c 'psql -U postgres -d test_gis -c "VACUUM FREEZE;"'
echo "Done!"
# Allows non-superusers the ability to create from this template.
#su postgres -c 'psql -U postgres -d test_gis -c "UPDATE pg_database SET datistemplate='true' WHERE datname='test_gis';"
#su postgres -c 'psql -U postgres -d test_gis -c "UPDATE pg_database SET datallowconn='false' WHERE datname='test_gis';"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment