#!/bin/sh

DBNAME=$1
USER=\"$2\"
[ ! "$USER" -o ! "$DBNAME" ] && exit

psql $DBNAME <<End
create user "$USER";
grant select on geometry_columns to $USER;
grant select on spatial_ref_sys to $USER;
End

while read table; do
    echo "grant select on ${table%%@*} to $USER;" | psql $DBNAME
done

