#!/bin/bash # This file is part of the PyOWS-WMS-Server package (= program). # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # author(s): Sebastian Holler # # Copyright (c)2008 by Sebastian Holler # for document references, used in this source code: see # use: listing all vector and raster layers from the current location # run this script in GRASS environment !! LD_checkLocationAccess () { if touch "$LOCATION/testfile_${PYWMS_TMP_PREFIX}$$" 2>/dev/null ; then rm "$LOCATION/testfile_${PYWMS_TMP_PREFIX}$$" return 0 else return -1 fi } LD_checkName () { # filter directory names with the following special characters: #: *+?,@#:; if [ $(echo $1 | grep '[\*\+\?\,\@\#\:\;\ ]') ]; then return -1 else return 0 fi } LD_checkMapsetName () { # see LD_checkName; additional: # filter temporary mapsets, created by the WMS server if [[ $(echo $1 | grep '[\*\+\?\,\@\#\:\;\ ]') || \ $(echo $1 | grep "${PYWMS_TMP_PREFIX}") ]]; then return -1 else return 0 fi } if [ -z "$GISBASE" ] ; then echo "You must be in GRASS GIS to run this program." 1>&2 return -1 fi GISDBASE=$(g.gisenv GISDBASE) # set IFS due to possible space characters in file names: ORIG_IFS=$IFS IFS=" " # if DEFAULT_WIND in mapset PERMANENT is found, and the remote user has # write access in this directory, it is supposed to be a valid GRASS LOCATION if [ -f "${LOCATION}/PERMANENT/DEFAULT_WIND" ] && \ LD_checkName ${LOCATION} && LD_checkLocationAccess ; then for LD_GRASSMSET in $(find $LOCATION -mindepth 1 \ -maxdepth 1 -type d -printf %f\\n 2>/dev/null) do if [ -f "${LOCATION}/$LD_GRASSMSET/WIND" ] && \ LD_checkMapsetName ${LD_GRASSMSET}; then echo ${LD_GRASSMSET} for LD_GRASSLYR in $(find ${LOCATION}/${LD_GRASSMSET}/vector \ -mindepth 1 -maxdepth 1 -type d -printf %f\\n 2>/dev/null) do if [ -f "${LOCATION}/$LD_GRASSMSET/vector/\ ${LD_GRASSLYR}/head" ] && LD_checkName ${LD_GRASSLYR}; then echo "v.${LD_GRASSLYR}@${LD_GRASSMSET}" fi done for LD_GRASSLYR in \ $(find ${LOCATION}/${LD_GRASSMSET}/cell \ -mindepth 1 -maxdepth 1 -type f -printf %f\\n 2>/dev/null) do if [ -f "${LOCATION}/$LD_GRASSMSET/cellhd/\ ${LD_GRASSLYR}" ] && LD_checkName ${LD_GRASSLYR}; then echo "r.${LD_GRASSLYR}@${LD_GRASSMSET}" fi done fi done else # print error message echo "location $LOCATION is not usable (invalid / not accessible?)." 1>&2 fi IFS=$ORIG_IFS