create_template_postgis-debian.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. GEOGRAPHY=0
  3. POSTGIS_SQL=postgis.sql
  4. # For Ubuntu 10.04
  5. if [ -d "/usr/share/postgresql/8.4/contrib" ]
  6. then
  7. POSTGIS_SQL_PATH=/usr/share/postgresql/8.4/contrib
  8. fi
  9. # For Ubuntu 10.10 (with PostGIS 1.5)
  10. if [ -d "/usr/share/postgresql/8.4/contrib/postgis-1.5" ]
  11. then
  12. POSTGIS_SQL_PATH=/usr/share/postgresql/8.4/contrib/postgis-1.5
  13. GEOGRAPHY=1
  14. fi
  15. # For Ubuntu 11.10 / Linux Mint 12 (with PostGIS 1.5)
  16. if [ -d "/usr/share/postgresql/9.1/contrib/postgis-1.5" ]
  17. then
  18. POSTGIS_SQL_PATH=/usr/share/postgresql/9.1/contrib/postgis-1.5
  19. GEOGRAPHY=1
  20. fi
  21. createdb -E UTF8 template_postgis && \
  22. ( createlang -d template_postgis -l | grep plpgsql || createlang -d template_postgis plpgsql ) && \
  23. psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';" && \
  24. psql -d template_postgis -f $POSTGIS_SQL_PATH/$POSTGIS_SQL && \
  25. psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql && \
  26. psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;" && \
  27. psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
  28. if [ $GEOGRAPHY -eq 1 ]
  29. then
  30. psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
  31. fi