--- /dev/null
+include ../../Makefile.config
+
+#
+# PostGIS template_gis Makefile
+#
+
+SCRIPTS_IN:=$(wildcard *.in)
+SCRIPTS:=$(SCRIPTS_IN:.in=)
+PUBLIC_SCRIPTS:=mktemplate_gis rmtemplate_gis createdb.postgis
+
+SUBSTITUTE=-e s:@bindir@:$(bindir):g \
+ -e s:@datadir@:$(datadir):g \
+ -e s:@prefix@:$(prefix):g
+SCRIPT_PREPARE=cat $(SCRIPT).in | sed $(SUBSTITUTE) > $(SCRIPT)
+SCRIPT_TARGET=$(DESTDIR)$(bindir)/$(SCRIPT)
+SCRIPT_INSTALL=$(INSTALL_BIN) $(SCRIPT) $(SCRIPT_TARGET)
+SCRIPT_LINK=$(DESTDIR)$(prefix)/bin/$(SCRIPT)
+SCRIPT_DOLINK=rm -f $(SCRIPT_LINK); \
+ $(LN_S) -T $(SCRIPT_TARGET) $(SCRIPT_LINK)
+SCRIPT_UNINSTALL=rm -f $(SCRIPT_TARGET)
+SCRIPT_UNLINK=rm -f $(SCRIPT_LINK)
+DEFAULTS_DIR=$(DESTDIR)/etc/default
+SCRIPT_DEFAULTS=$(DEFAULTS_DIR)/postgis
+
+all: $(SCRIPTS_IN)
+ $(foreach SCRIPT, $(SCRIPTS), $(SCRIPT_PREPARE);)
+
+install: all
+ @mkdir -p $(DESTDIR)$(bindir)
+ @mkdir -p $(DESTDIR)$(prefix)/bin
+ $(foreach SCRIPT, $(SCRIPTS), $(SCRIPT_INSTALL);)
+ $(foreach SCRIPT, $(PUBLIC_SCRIPTS), $(SCRIPT_DOLINK);)
+ @mkdir -p $(DEFAULTS_DIR)
+ cp profile $(SCRIPT_DEFAULTS)
+
+uninstall:
+ $(foreach SCRIPT, $(PUBLIC_SCRIPTS), $(SCRIPT_UNLINK);)
+ $(foreach SCRIPT, $(SCRIPTS), $(SCRIPT_UNINSTALL);)
+
+purge: uninstall
+ rm -f $(SCRIPT_DEFAULTS)
+
+clean distclean:
+ rm -f $(SCRIPTS)
--- /dev/null
+
+This program suite create a template database for working with Postgis geometries.
+
+It requires to be run by root, or by PostgreSQL superuser (DBA), or by the
+cluster owner, but once created, any user with createdb permissions can create
+spatial enabled databases with createdb.postgis.
+The privileges on the initial objects in the created databases will be granted
+to the user defined upon the template creation.
+
+For usage, see manual pages mktemplate_gis, rmtemplate_gis, and createdb.postgis
+
+AUTHORS:
+Alex Bodnaru <alexbodn@012.net.il>, Roberto Boati <roberto.boati@gmail.com>
--- /dev/null
+.TH "createdb.postgis" "1" "" "Roberto Boati" "Postgis utilities"
+.SH "NAME"
+.LP
+createdb.postgis \- Create Postgis database in a PostgreSQL server.
+.SH "SYNTAX"
+.LP
+createdb.postgis [\fIoptions\fP] \fIdatabase_name\fP
+.SH "DESCRIPTION"
+.LP
+This program create a database for working with Postgis geometries.
+.br
+Using this program any user with createdb permissions can create a spatial enabled database.
+.SH "OPTIONS"
+.LP
+.TP
+<\fIdatabase_name\fP>
+Database to be created.
+.TP
+<\fIoptions\fP>
+All options from createdb(1), except choice of template database, can be used here.
+Specifying an owner here will not be able to set ownership to the tables originating
+from the template database used, unless the template owner, that is calling this
+script, is dba. Otherwise, you could only build databases owned by the
+template owner.
+.TP
+The most significant option would be \fI\-\-template\fP below.
+.TP
+\fB\-\-template=\fR<\fItemplatedb\fP>
+Set template name to be <\fItemplatedb\fP>
+.TP
+Environment variable: \fITEMPLATEDB\fR.
+.TP
+.TP
+\fB\-\-help\fR
+Output help information and exit.
+.SH "ENVIRONMENT"
+.TP
+.B TEMPLATEDB
+If
+.RB $ TEMPLATEDB
+is set, its value is used as the default template name.
+.SH "FILES"
+.LP
+The environment variables for template_gis creation, removal and usage may be stored in files, as follows:
+.TP
+.B /etc/default/postgis
+will designate default values for the whole system.
+.TP
+.B $HOME/.postgis/profile
+will designate the values used by the current user by default.
+Beware, this is the current SYSTEM user, not the dba or the database owner to
+become. As those values are more user specific, they supersede the ones in the
+system default file for the current user.
+.SH "NOTES"
+.LP
+The order of precedence of the variables definition:
+.TP
+.B 1.
+Command line options.
+.TP
+.B 2.
+Environment variables.
+.TP
+.B 3.
+The user specific profile file.
+.TP
+.B 4.
+The system wide default file.
+.TP
+.B The builtin (hardwired) values are not a good choice.
+.SH "EXAMPLES"
+.LP
+To run this program you can simply type:
+.LP
+# \fBcreatedb.postgis mypostgis\fR
+.SH "AUTHORS"
+.LP
+Alex Bodnaru <alexbodn@012.net.il>
+.br
+Roberto Boati <roberto.boati@gmail.com>
+.SH "SEE ALSO"
+.LP
+createdb.postgis(1), createdb(1), dropdb(1)
--- /dev/null
+#!/bin/sh
+
+# create a database using the given template
+# other parameters are passed to createdb,
+# but the specified owner will not have
+# extra privileges on objects in the template. see createdb.postgis(1)
+
+source @bindir@/postgis_env.sh
+
+for ARGVN in $1 $2 ; do
+ if [ `expr substr $ARGVN 1 11` = "--template=" ]; then
+ TDB=`echo $ARGVN | sed -e s/^--template=//`
+ elif [ `expr substr $ARGVN 1 6` = "--help" ]; then
+ echo "Usage of `basename $0`"
+ echo "Supply arguments as follows"
+ echo "--template=templatename of the template to use"
+ echo "Other arguments will be passed verbatim to createdb,"
+ echo "and it may return additional messages."
+ echo "You must usually have createdb privileges"
+ echo "in order to use `basename $0`"
+ exit 1
+ fi
+done
+
+PWD1=`pwd`
+
+cd /tmp
+
+exec createdb -T $TDB "$@"
+
+cd $PWD1
--- /dev/null
+.TH "mktemplate_gis" "1" "" "Roberto Boati" "Postgis utilities"
+.SH "NAME"
+.LP
+mktemplate_gis \- Create Postgis template in a PostgreSQL server.
+.SH "SYNTAX"
+.LP
+mktemplate_gis [\fIoptions\fP]
+.SH "DESCRIPTION"
+.LP
+This program create a template database for working with Postgis geometries.
+.br
+It requires to be run by root, or by PostgreSQL superuser (DBA), or by the
+cluster owner, but once the template created, any user with createdb permissions
+can create a spatial enabled database with \fBcreatedb.postgis\fR.
+The privileges on the initial objects in the created databases will be granted
+to the user defined here (see \fIGRUSER\fR below).
+.br
+PostgreSQL should be running.
+.SH "OPTIONS"
+.LP
+.TP
+For default values see below.
+.TP
+\fB\-\-user=\fR<\fIdbowner\fP>
+Creates a database template owned by <\fIdbowner\fP>.
+If normal user, \fIdbowner\fR will own the template database,
+else if it's a group or public,
+\fIdbowner\fR will have full rights to the objects in the template database.
+The rights granted here will also hols for new databases created from this
+template, even by non-dba and non-cluster owning users.
+.TP
+Environment variable: \fIGRUSER\fR.
+.TP
+\fB\-\-template=\fR<\fItemplatedb\fP>
+Set template name to be <\fItemplatedb\fP>
+.TP
+Environment variable: \fITEMPLATEDB\fR.
+.TP
+\fB\-\-dba=\fR<\fIdba_name\fP>
+DBA is required to perform template database building.
+.TP
+Environment variable: \fIDBAUSER\fR.
+.TP
+\fB\-\-script=\fR<\fIpgis_script\fP>
+pgis_script is the sql script containing the postgis functions for the template database.
+If no directory name will be given, the script will be taken from /usr/share/postgresql/\fI$CLUSTERVER\fP/contrib.
+.TP
+Environment variable: \fIPGISSCRIPT\fR.
+.TP
+\fB\-\-no\-srs\fP
+this argument will suppress loading of the huge spatial_ref_sys in the database template.
+the table will be created anyway.
+.TP
+Environment variable: \fINO_SRS=true\fR.
+.TP
+\fB\-\-no\-topo\fP
+this argument will suppress loading of the topology functionality in the database template.
+.TP
+Environment variable: \fINO_TOPO=true\fR.
+.TP
+\fB\-\-help\fR
+Output help information and exit.
+.SH "ENVIRONMENT"
+.TP
+.B TEMPLATEDB
+If
+.RB $ TEMPLATEDB
+is set, its value is used as the default template name.
+.TP
+.B GRUSER
+If
+.RB $ GRUSER
+is set, its value is used as the default user to own the template. This user
+will naturally have default rights to databases created with this template.
+.TP
+.B DBAUSER
+If
+.RB $ DBAUSER
+is set, its value is used as the default DBA for building the template. Else,
+the cluster owner and postgres are the next candidates.
+.TP
+.B PGISSCRIPT
+If
+.RB $ PGISSCRIPT
+is set, its value is used as the default postgis sql script for the template.
+If a directory will not be specified, the file will be taken from the default
+scripts/contrib directory for this postgresql version.
+.SH "FILES"
+.LP
+The environment variables for template_gis creation, removal and usage may be stored in files, as follows:
+.TP
+.B /etc/default/postgis
+will designate default values for the whole system.
+.TP
+.B $HOME/.postgis/profile
+will designate the values used by the current user by default.
+Beware, this is the current SYSTEM user, not the dba or the database owner to
+become. As those values are more user specific, they supersede the ones in the
+system default file for the current user.
+.SH "NOTES"
+.LP
+The order of precedence of the variables definition:
+.TP
+.B 1.
+Command line options.
+.TP
+.B 2.
+Environment variables.
+.TP
+.B 3.
+The user specific profile file.
+.TP
+.B 4.
+The system wide default file.
+.TP
+.B The builtin (hardwired) values are not a good choice.
+.SH "EXAMPLES"
+.LP
+To run this program the standard way, you can simply type:
+.LP
+# \fBmktemplate\_gis\fR
+.LP
+Alternatively you can specify also a template name to create and the database superuser:
+.LP
+# \fBmktemplate\_gis \-\-user=postgres \-\-template=template\_postgis\fR
+.SH "AUTHORS"
+.LP
+Alex Bodnaru <alexbodn@012.net.il>
+.br
+Roberto Boati <roberto.boati@gmail.com>
+.SH "SEE ALSO"
+.LP
+createdb.postgis(1), rmtemplate_gis(1)
--- /dev/null
+#!/bin/sh
+
+#create a template database, named template_gis by default,
+#and grant ownership or full privileges to the postgis tables to a user, postgres by default
+
+source @bindir@/postgis_env.sh
+
+for ARGVN in $1 $2 $3 $4 $5 $6 ; do
+ if [ `expr substr $ARGVN 1 7` = "--user=" ]; then
+ GRUSER=`echo $ARGVN | sed -e s/^--user=//`
+ elif [ `expr substr $ARGVN 1 11` = "--template=" ]; then
+ TDB=`echo $ARGVN | sed -e s/^--template=//`
+ elif [ `expr substr $ARGVN 1 6` = "--dba=" ]; then
+ DBAUSER=`echo $ARGVN | sed -e s/^--dba=//`
+ elif [ `expr substr $ARGVN 1 9` = "--script=" ]; then
+ PGISSCRIPT=`echo $ARGVN | sed -e s/^--script=//`
+ elif [ "$ARGVN" = "--no-srs" ]; then
+ NO_SRS="true"
+ elif [ "$ARGVN" = "--no-topo" ]; then
+ NO_TOPO="true"
+ elif [ -n $ARGVN ]; then
+ echo "Usage of `basename $0`"
+ echo "Supply arguments as follows"
+ echo "--user=username to own or be grant privileges on databases"
+ echo " created from template"
+ echo "--template=templatename of the template to create"
+ echo "--dba=dbaname of the dba to run administrational programs as"
+ echo "--script=script to load postgis functions in the database"
+ echo " if no directory given, default is @datadir@/"
+ echo "--no-srs: use this option to not load the huge spatial_ref_sys.sql"
+ echo "--no-topo: use this option to not load the topology functionality"
+ echo "You must usually be either root, or a postgresql dba or the"
+ echo "cluster owner in order to use `basename $0`"
+ exit 1
+ fi
+done
+
+if [ -z "`echo $PGISSCRIPT | grep /`" ]; then
+ PGISSCRIPT="@datadir@/${PGISSCRIPT}"
+fi
+
+GRTABLES="geometry_columns"
+GRSCHEMAS=""
+SCRIPTS=$PGISSCRIPT
+
+if [ ! "$NO_SRS" = "true" ]; then
+ GRTABLES="${GRTABLES} spatial_ref_sys"
+ SCRIPTS="${SCRIPTS} @datadir@/spatial_ref_sys.sql"
+fi
+if [ ! "$NO_TOPO" = "true" ]; then
+ GRTABLES="${GRTABLES} topology.topology topology.layer topology.topology_id_seq"
+ GRSCHEMAS="${GRSCHEMAS} topology"
+ TMPTOPO=/tmp/topology_$$.sql
+ cat @datadir@/topology.sql | awk -v GRUSER=$GRUSER \
+ '{ \
+ if (tolower($1)=="create" && tolower($2)=="schema" && match(tolower($3),"topology;?")) \
+ {print "create schema topology authorization "GRUSER";"}else print; \
+ }' > ${TMPTOPO}
+ SCRIPTS="${SCRIPTS} ${TMPTOPO}"
+fi
+
+source @bindir@/postgres_lib.sh
+
+sudo_dba DBAUSER
+
+export SCRIPTS GRTABLES GRSCHEMAS GRUSER DBAUSER TDB
+$SUDO -c "@bindir@/mktemplate_gis.sh"
--- /dev/null
+#!/bin/sh
+
+#this script should be run as $DBAUSER
+
+PWD1=`pwd`
+
+cd /tmp
+
+source @bindir@/postgres_lib.sh
+
+check_dba $DBAUSER
+template_rm $TDB
+template_mk $TDB $GRUSER
+
+cd $PWD1
--- /dev/null
+#!/bin/sh
+
+# environment variables for postgis
+
+#read optional configuration files. last prevails
+for file in "/etc/default/postgis" "$HOME/.postgis/profile" ; do
+ if [ -f "$file" ]; then
+ tmpval=`grep "^TEMPLATEDB=" $file | cut -d= -f2`
+ if [ -n "$tmpval" ]; then
+ TEMPLATEDB1=$tmpval
+ fi
+ tmpval=`grep "^GRUSER=" $file | cut -d= -f2`
+ if [ -n "$tmpval" ]; then
+ GRUSER1=$tmpval
+ fi
+ tmpval=`grep "^DBAUSER=" $file | cut -d= -f2`
+ if [ -n "$tmpval" ]; then
+ DBAUSER1=$tmpval
+ fi
+ tmpval=`grep "^PGISSCRIPT=" $file | cut -d= -f2`
+ if [ -n "$tmpval" ]; then
+ PGISSCRIPT1=$tmpval
+ fi
+ fi
+done
+
+#cluster information should be set separately
+if [ -x @prefix@/bin/pg_lsclusters ]; then
+# PGCLUSTER=`pg_lsclusters | awk '{if ($3 == ENVIRON["PGPORT"]) {print $1"/"$2;}}'`
+# export PGCLUSTER
+#
+ if [ -z $DBAUSER ]; then
+ DBAUSER=`pg_lsclusters | awk '{if ($3 == ENVIRON["PGPORT"]) {print $5;}}'`
+ fi
+fi
+
+if [ -z "$TEMPLATEDB" ]; then
+ if [ -n "$TEMPLATEDB1" ]; then
+ TEMPLATEDB="$TEMPLATEDB1"
+ else
+ TEMPLATEDB="template_gis"
+ fi
+fi
+if [ -z "$GRUSER" ]; then
+ if [ -n "$GRUSER1" ]; then
+ GRUSER="$GRUSER1"
+ else
+ GRUSER="postgres"
+ fi
+fi
+if [ -z "$DBAUSER" ]; then
+ if [ -n "$DBAUSER1" ]; then
+ DBAUSER="$DBAUSER1"
+ else
+ DBAUSER="postgres"
+ fi
+fi
+if [ -z "$PGISSCRIPT" ]; then
+ if [ -n "$PGISSCRIPT1" ]; then
+ PGISSCRIPT="$PGISSCRIPT1"
+ else
+ PGISSCRIPT="postgis.sql"
+ fi
+fi
+
+TDB=$TEMPLATEDB
--- /dev/null
+#!/bin/sh
+
+SUDO_OTHERUSER="su $DBAUSER"
+SUDO_SAMEUSER="$SHELL"
+
+function sudo_dba()
+{
+ if [ "$USER" != "$DBAUSER" ]; then
+ ISDBASYSUSER=`cat /etc/passwd | awk -F : '{print $1}' | grep ^$DBAUSER$`
+ if [ ! "$ISDBASYSUSER" = "$DBAUSER" ]; then
+ echo "$DBAUSER is not a system user on `hostname`."
+ echo "support for remote servers not implemented yet."
+ exit 1
+ fi
+ SUDO=$SUDO_OTHERUSER
+ if [ ! "$USER" = "root" ]; then
+ echo "you will be prompted for the system password for $DBAUSER,"
+ echo "even more than once."
+ fi
+ else
+ SUDO=$SUDO_SAMEUSER
+ fi
+}
+
+function wrong_cluster()
+{
+ if [ -n "`dpkg-query -W postgresql-common`" ]; then
+ echo "in case you meant another cluster, please specify it explicitly."
+ echo "see pwrapper(1)."
+ fi
+}
+
+#for the following functions, $USER is expected to be $DBAUSER, as set before
+function check_dba()
+{
+ DBAUSER=$1
+ if [ ! "$DBAUSER" = "$USER" ]; then
+ echo "you are not working as $DBAUSER".
+ echo "you may be not allowed to do so (maybe wrong password)."
+ exit 1
+ fi
+ ISDBAPGUSER=`psql -At -d template1 -c "select usename from pg_user where usesuper = true and usename = '$DBAUSER';" 2>&1`
+ if [ ! "$ISDBAPGUSER" = "$DBAUSER" ]; then
+ MAYPOSTGRES=`psql -l`
+ if [ -z "$MAYPOSTGRES" ]; then
+ echo "either postgresql $PGCLUSTER is not running,"
+ echo "or $DBAUSER doesn't have privileges on cluster $PGCLUSTER."
+ wrong_cluster
+ exit 1
+ fi
+ echo "dba or cluster $PGCLUSTER owner privileges are needed for this operation."
+ echo "$DBAUSER doesn't have dba or cluster $PGCLUSTER owner privileges."
+ echo "you may specify a dba that you are allowed to use his/her name (try --help)."
+ wrong_cluster
+ exit 1
+ fi
+}
+
+function template_rm()
+{
+ TDB=$1
+ db_update=`psql -d template1 -c "UPDATE pg_database SET datistemplate = FALSE WHERE datname = '$TDB';" 2>&1`
+ if [ "$db_update" = "UPDATE 1" ]; then
+ dropdb $TDB 2>&1 | cat > /dev/null
+ else
+ echo "$TDB could not be accessed. it may not exist"
+ fi
+}
+
+#environment variables used:
+#$SCRIPTS=spaces separated list of sql scripts to load into new template db
+#$GRTABLES=spaces separated list of tables to be granted access to $GRUSER
+function template_mk()
+{
+ TDB=$1
+ GRUSER=$2
+ #of course it could be better to create as the $GRUSER where system user
+ db_create=`createdb $TDB 2>&1`
+ if [ "$db_create" = "CREATE DATABASE" ]; then
+ GRID=`psql -d template1 -At -c "select usesysid from pg_user where usename='$GRUSER';"`
+ if [ -n "$GRID" ]; then
+ psql -d $TDB -c "UPDATE pg_database SET datdba = $GRID WHERE datname = '$TDB';" 2>&1 | cat > /dev/null
+ fi
+ if [ -x @bindir@/createlang ]; then
+ @bindir@/createlang plpgsql $TDB 2>&1 | cat > /dev/null
+ fi
+ for script in $SCRIPTS ; do
+ psql -d $TDB -f $script 2>&1 | cat > /dev/null
+ done
+ #pseudo tables for postgresql 7.2 and 7.4. feel free to add more, for other postgresql versions
+ PSEUDO_TABLES="'pg_xactlock', 'sql_features', 'sql_implementation_info', 'sql_languages',
+ 'sql_packages', 'sql_sizing', 'sql_sizing_profiles'"
+ TABLES=`psql -d $TDB -At -c "select tablename from pg_tables where tablename not in ($PSEUDO_TABLES);"`
+ if [ -n "$GRID" ]; then
+ for table in $TABLES ; do
+ psql -d $TDB -c "alter table $table owner to $GRUSER;" 2>&1 | cat > /dev/null
+ done
+ psql -d $TDB -c "update pg_class set relowner=$GRID where relkind = 'S';" 2>&1 | cat > /dev/null
+ else #maybe public, or group
+ for grtable in $GRTABLES ; do
+ psql -d $TDB -c "grant all privileges on table $grtable to $GRUSER;" 2>&1 | cat > /dev/null
+ done
+ fi
+ for grschema in $GRSCHEMAS ; do
+ psql -d $TDB -c "alter schema $grschema owner to $GRUSER;" 2>&1 | cat > /dev/null
+ psql -d $TDB -c "grant all privileges on schema $grschema to $GRUSER;" 2>&1 | cat > /dev/null
+ STABLES=`psql -d $TDB -At -c "select tablename from pg_tables where schemaname = '$grschema';"`
+ if [ -n "$GRID" ]; then
+ for table in $STABLES ; do
+ psql -d $TDB -c "alter table $grschema.$table owner to $GRUSER;" 2>&1 | cat > /dev/null
+ done
+ else #maybe public, or group
+ for grtable in $GRTABLES ; do #contain specific schema
+ psql -d $TDB -c "grant all privileges on table $grtable to $GRUSER;" 2>&1 | cat > /dev/null
+ done
+ fi
+ done
+ psql -d $TDB -c "VACUUM FULL;" 2>&1 | cat > /dev/null
+ psql -d $TDB -c "VACUUM FREEZE;" 2>&1 | cat > /dev/null
+ psql -d $TDB -c "UPDATE pg_database SET datistemplate = TRUE WHERE datname = '$TDB';" 2>&1 | cat > /dev/null
+ psql -d $TDB -c "UPDATE pg_database SET datallowconn = FALSE WHERE datname = '$TDB';" 2>&1 | cat > /dev/null
+ else
+ echo "$db_create"
+ fi
+}
--- /dev/null
+
+#those are the default variables for postgresql-postgis.
+#this file will be scanned from /etc/default/postgis,
+#and then from $HOME/postgis/profile
+
+#values should NOT be in quotes
+
+#the name of the template database to create
+TEMPLATEDB=template_gis
+
+#the user/group to be granted maximum rights to the template.
+#public/groups are ok, but cannot be owners, so cannot grant
+#privileges on databases created from this template.
+GRUSER=postgres
+
+#name of the user the template script will be created/removed as.
+#should be either dba, or the database cluster owner.
+#defaults to the cluster owner, and if none, to postgres.
+DBAUSER=postgres
+
+#this is the postgis functionality loader script.
+#as it contains the name of the postgresql-postgis library, this
+#file will designate which postgis version to use.
+PGISSCRIPT=postgis#SONAME#.sql
+
+#set this to true not to load huge spatial_ref_sys table in the template.
+#NO_SRS=true
+
+#set this to true not to load topology functionality in the template.
+#NO_TOPO=true
--- /dev/null
+.TH "rmtemplate_gis" "1" "" "Roberto Boati" "Postgis utilities"
+.SH "NAME"
+.LP
+rmtemplate_gis \- Delete Postgis template in a PostgreSQL server.
+.SH "SYNTAX"
+.LP
+rmtemplate_gis [\fIoption\fP]
+.SH "DESCRIPTION"
+.LP
+This program deletes a template database Postgis.
+.br
+It requires to be run by root, or by PostgreSQL superuser (postgres),
+or by a dba, or by the cluster owner, or by the database owner.
+.br
+PostgreSQL should be running.
+.SH "OPTIONS"
+.LP
+.TP
+For default values see below.
+.TP
+\fB\-\-template=\fR<\fItemplatedb\fP>
+Set template name to be <\fItemplatedb\fP>
+.TP
+Envirunment variable: \fITEMPLATEDB\fR.
+.TP
+\fB\-\-dba=\fR<\fIdba_name\fP>
+DBA is required to perform template database building.
+.TP
+Envirunment variable: \fIDBAUSER\fR.
+.TP
+\fB\-\-help\fR
+Output help information and exit.
+.SH "ENVIRONMENT"
+.TP
+.B TEMPLATEDB
+If
+.RB $ TEMPLATEDB
+is set, its value is used as the default template name.
+.TP
+.B DBAUSER
+If
+.RB $ DBAUSER
+is set, its value is used as the default DBA for removing the template.
+.SH "FILES"
+.LP
+The environment variables for template_gis creation, removal and usage may be stored in files, as follows:
+.TP
+.B /etc/default/postgis
+will designate default values for the whole system.
+.TP
+.B $HOME/.postgis/profile
+will designate the values used by the current user by default.
+Beware, this is the current SYSTEM user, not the dba or the database owner to
+become. As those values are more user specific, they supersede the ones in the
+system default file for the current user.
+.SH "NOTES"
+.LP
+The order of precedence of the variables definition:
+.TP
+.B 1.
+Command line options.
+.TP
+.B 2.
+Environment variables.
+.TP
+.B 3.
+The user specific profile file.
+.TP
+.B 4.
+The system wide default file.
+.TP
+.B The builtin (hardwired) values are not a good choice.
+.SH "EXAMPLES"
+.LP
+To run this program the standard way, you can simply type:
+.LP
+# \fBrmtemplate\_gis\fR
+.LP
+Alternatively you can specify also a template name to delete:
+.LP
+# \fBrmtemplate\_gis \-\-template=template\_postgis\fR
+.SH "AUTHORS"
+.LP
+Alex Bodnaru <alexbodn@012.net.il>
+.br
+Roberto Boati <roberto.boati@gmail.com>
+.SH "SEE ALSO"
+.LP
+createdb.postgis(1), mktemplate_gis(1)
--- /dev/null
+#!/bin/sh
+
+#drop template_gis
+#it may be used to drop any postgresql template, by supplying argument
+
+source @bindir@/postgis_env.sh
+
+for ARGVN in $1 $2 $3 $4 ; do
+ if [ `expr substr $ARGVN 1 11` = "--template=" ]; then
+ TDB=`echo $ARGVN | sed -e s/^--template=//`
+ elif [ `expr substr $ARGVN 1 6` = "--dba=" ]; then
+ DBAUSER=`echo $ARGVN | sed -e s/^--dba=//`
+ elif [ -n $ARGVN ]; then
+ echo "Usage of `basename $0`"
+ echo "Supply arguments as follows"
+ echo "--template=templatename of the template to remove"
+ echo "--dba=dbaname of the dba to run administrational programs as"
+ echo "You must usually be either root, or a postgresql dba in order"
+ echo "to use `basename $0`"
+ exit 1
+ fi
+done
+
+source @bindir@/postgres_lib.sh
+
+sudo_dba $DBAUSER
+
+export DBAUSER TDB
+$SUDO -c "@bindir@/rmtemplate_gis.sh"
--- /dev/null
+#!/bin/sh
+
+#this script should be run as $DBAUSER
+
+PWD1=`pwd`
+
+cd /tmp
+
+source @bindir@/postgres_lib.sh
+
+check_dba $DBAUSER
+template_rm $TDB
+
+cd $PWD1