~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to scripts/g.extension/g.extension

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
 
3
 
############################################################################
4
 
#
5
 
# MODULE:       g.extension
6
 
# AUTHOR(S):    Markus Neteler, Hamish Bowman, and Martin Landa
7
 
# PURPOSE:      Tool to download and install extensions from GRASS Addons SVN into
8
 
#               local GRASS installation
9
 
# COPYRIGHT:    (C) 2009-2012 by Markus Neteler, and the GRASS Development Team
10
 
#
11
 
#               This program is free software under the GNU General Public
12
 
#               License (>=v2). Read the file COPYING that comes with GRASS
13
 
#               for details.
14
 
#
15
 
#############################################################################
16
 
 
17
 
#%Module
18
 
#% label: Tool to maintain GRASS extensions in local GRASS installation.
19
 
#% description: Downloads, installs extensions from GRASS Addons SVN repository into local GRASS installation or removes installed extensions.
20
 
#% keywords: general, extensions
21
 
#%End
22
 
#%option
23
 
#% key: extension
24
 
#% type: string
25
 
#% key_desc: name
26
 
#% description: Name of extension to install/remove
27
 
#% required: no
28
 
#%end
29
 
#%option
30
 
#% key: operation
31
 
#% type: string
32
 
#% key_desc: name
33
 
#% description: Operation to be performed
34
 
#% required: no
35
 
#% options: add,remove
36
 
#% answer: add
37
 
#%end
38
 
#%option
39
 
#% key: svnurl
40
 
#% type: string
41
 
#% key_desc: url
42
 
#% description: SVN Addons repository URL
43
 
#% required: yes
44
 
#% answer: http://svn.osgeo.org/grass/grass-addons/grass6
45
 
#%end
46
 
#%option
47
 
#% key: prefix
48
 
#% type: string
49
 
#% key_desc: path
50
 
#% description: Prefix where to install extension
51
 
#% answer: $GRASS_ADDON_PATH
52
 
#% required: no
53
 
#%end
54
 
#%flag
55
 
#% key: l
56
 
#% description: List available modules in the GRASS Addons SVN repository
57
 
#% guisection: Print
58
 
#%end
59
 
#%flag
60
 
#% key: s
61
 
#% description: Install system-wide (may need system administrator rights)
62
 
#%end
63
 
#%flag
64
 
#% key: u
65
 
#% description: Install system-wide using sudo
66
 
#%end
67
 
 
68
 
 
69
 
if  [ -z "$GISBASE" ] ; then
70
 
    echo "You must be in GRASS GIS to run this program." >&2
71
 
    exit 1
72
 
fi
73
 
 
74
 
if [ "$1" != "@ARGS_PARSED@" ] ; then
75
 
  exec g.parser "$0" "$@"
76
 
fi
77
 
 
78
 
 
79
 
# check if we have the grass include and Make files
80
 
dpkg-query -l grass-dev | grep '^ii' > /dev/null 2> /dev/null
81
 
if [ $? -ne 0 ] ; then
82
 
   g.message -w "This module requires the \"grass-dev\" package"
83
 
fi
84
 
 
85
 
 
86
 
# definitions
87
 
 
88
 
SVNURL_ADDONS="$GIS_OPT_SVNURL"
89
 
MODULE="$GIS_OPT_EXTENSION"
90
 
PREFIX="$GIS_OPT_PREFIX"
91
 
SYSADMIN=0
92
 
 
93
 
#make a temporary directory
94
 
TMPDIR="`g.tempfile pid=$$`"
95
 
if [ $? -ne 0 ] || [ -z "$TMPDIR" ] ; then
96
 
    g.message -e "Unable to create temporary files"
97
 
    exit 1
98
 
fi
99
 
rm -f "$TMPDIR"
100
 
mkdir "$TMPDIR"
101
 
 
102
 
#TODO: combine all these checks into a single for loop
103
 
 
104
 
# check if we have the svn client
105
 
if [ ! -x "`which svn`" ] ; then
106
 
    g.message -e "svn client required. Please install Subversion first."
107
 
    exit 1
108
 
fi
109
 
 
110
 
# check if we have the make program
111
 
if [ ! -x "`which make`" ] ; then
112
 
    g.message -e "The 'make' program is required. Please install first."
113
 
    exit 1
114
 
fi
115
 
 
116
 
# check if we have the "install" program
117
 
if [ ! -x "`which install`" ] ; then
118
 
    g.message -e "The 'install' program is required. Please install first."
119
 
    exit 1
120
 
fi
121
 
 
122
 
# check if we have wget or curl
123
 
if [ ! -x "`which wget`" ] ; then
124
 
    if [ ! -x "`which curl`" ] ; then
125
 
        g.message -e "Either 'wget' or 'curl' is required, please install one first"
126
 
        exit 1
127
 
    else
128
 
        g.message -v "Using CURL for downloading data."
129
 
        USE_CURL=1
130
 
    fi
131
 
else
132
 
    g.message -v "Using WGET for downloading data."
133
 
    USE_WGET=1
134
 
fi
135
 
 
136
 
expand_module_class_name()
137
 
{
138
 
# $1: module class
139
 
 if [ "$1" = "d" ]  ; then
140
 
    echo "display"
141
 
  elif [ "$1" = "db" ] ; then
142
 
    echo "database"
143
 
  elif [ "$1" = "g" ]  ; then
144
 
    echo "general"
145
 
  elif [ "$1" = "i" ]  ; then
146
 
    echo "imagery"
147
 
  elif [ "$1" = "m" ]  ; then
148
 
    echo "misc"
149
 
  elif [ "$1" = "ps" ] ; then
150
 
    echo "postscript"
151
 
#  elif [ "$1" = "p" ]  ; then
152
 
#    echo "paint"
153
 
  elif [ "$1" = "r" ]  ; then
154
 
    echo "raster"
155
 
  elif [ "$1" = "r3" ]  ; then
156
 
    echo "raster3d"
157
 
#  elif [ "$1" = "s" ]  ; then
158
 
#    echo "sites"
159
 
  elif [ "$1" = "v" ]  ; then
160
 
    echo "vector"
161
 
  else
162
 
    echo "$1"
163
 
 fi
164
 
}
165
 
 
166
 
if [ `echo "$MODULE" | grep -c '/'` -eq 0 ] ; then
167
 
   CLASSCHAR=`echo $MODULE | cut -d'.' -f1`
168
 
   MODULECLASS=`expand_module_class_name $CLASSCHAR`
169
 
else
170
 
   # handle vector/adehabitat/ or just vector/v.module ...
171
 
   TOPLEVEL=`echo $MODULE | cut -d'/' -f1`
172
 
   MODULECLASS="$TOPLEVEL"
173
 
   MODULE=`echo "$MODULE" | sed -e "s+^$MODULECLASS/++"`
174
 
fi
175
 
 
176
 
 
177
 
list_available_modules()
178
 
{
179
 
 # a very dirty hack
180
 
 g.message message="Fetching list of modules from GRASS-Addons SVN (be patient)..."
181
 
 for d in d db g i m ps p r r3 v ; do
182
 
     MODCLASS=`expand_module_class_name $d`
183
 
     cd "$TMPDIR"
184
 
     rm -f index.html
185
 
     if [ "$USE_WGET" ] ; then
186
 
        wget --quiet -nv "$SVNURL_ADDONS/$MODCLASS" -O index.html
187
 
     else
188
 
        curl -silent --location "$SVNURL_ADDONS/$MODCLASS" -o index.html
189
 
     fi
190
 
     grep '<li>' index.html 2> /dev/null | grep -v '\.\.' | \
191
 
        cut -d'"' -f2 | sed 's+/$++g' >> list_$$.txt
192
 
     rm -f index.html
193
 
 done
194
 
 grep -v 'Makefile' list_$$.txt
195
 
 rm -f list_$$.txt
196
 
 # so why save to a file at all instead of cat'ing directly?
197
 
}
198
 
 
199
 
##
200
 
cleanup(){
201
 
 if  [ -n "$TMPDIR" ] ; then
202
 
     rm -rf "$TMPDIR"
203
 
 fi
204
 
}
205
 
 
206
 
if [ $GIS_FLAG_L -eq 1 ] ; then
207
 
   list_available_modules
208
 
   rmdir "$TMPDIR"
209
 
   exit 0
210
 
fi
211
 
 
212
 
if [ -z "$GIS_OPT_EXTENSION" -a $GIS_FLAG_L -eq 0 ] ; then
213
 
   g.message message="You need to define an extension name or use -l"
214
 
   exit 1
215
 
fi
216
 
 
217
 
 
218
 
if [ "$PREFIX" = '$GISBASE' ] || [ $GIS_FLAG_S -eq 1 ] || [ $GIS_FLAG_U -eq 1 ] ; then
219
 
   SYSADMIN=1
220
 
   PREFIX="$GISBASE"
221
 
 
222
 
   # just to make later tests happy
223
 
   if [ $GIS_FLAG_S -eq 0 ] && [ $GIS_FLAG_U -eq 1 ] ; then
224
 
      GIS_FLAG_S=1
225
 
   fi
226
 
 
227
 
elif [ "$PREFIX" = '$GRASS_ADDON_PATH' ] ; then 
228
 
    if [ -z "$GRASS_ADDON_PATH" ] ; then 
229
 
        g.message -w message="GRASS_ADDON_PATH is not defined, installing to ~/.grass6/addons/"
230
 
        ADDON_PATH_EMPTY=true
231
 
        #g.message message="Suggest you set GRASS_ADDON_PATH and GRASS_ADDON_ETC to ..."
232
 
        ## will GRASS_ADDON_ETC help for man/ and docs/ ?
233
 
        ## maybe have g.manual search in GRASS_ADDON_ETC/../ ?  :-/
234
 
        mkdir -p ~/.grass6/addons
235
 
        GRASS_ADDON_PATH1=~/.grass6/addons
236
 
    else
237
 
        GRASS_ADDON_PATH1=`echo "$GRASS_ADDON_PATH" | cut -f1 -d:`
238
 
    fi
239
 
    PREFIX="$GRASS_ADDON_PATH1"
240
 
fi
241
 
 
242
 
 
243
 
if [ -d "$PREFIX" ] ; then
244
 
    MYINST_DIR="$PREFIX"
245
 
else
246
 
    g.message -w "'$PREFIX' does not exist. Creating ..."
247
 
    mkdir -p "$PREFIX"
248
 
    if [ $? -ne 0 ] || [ ! -d "$PREFIX" ] ; then
249
 
        g.message -e "Unable to create '$PREFIX' directory"
250
 
        exit 1
251
 
    fi
252
 
    MYINST_DIR="$PREFIX"
253
 
fi
254
 
 
255
 
if [ ! -w "$PREFIX" -a "$SYSADMIN" -ne 1 ] ; then
256
 
    g.message -e "'$PREFIX' is not writable (do you have suitable file-system permissions?)"
257
 
    exit 1
258
 
fi
259
 
 
260
 
# make doesn't like spaces in path names, issue a warning if we see one:
261
 
GLOOM="The build which follows will likely fail."
262
 
if [ `echo "$GISBASE" | grep -c ' '` -gt 0 ] ; then
263
 
    g.message -w "The GRASS program path: [$GISBASE] contains a space. $GLOOM"
264
 
fi
265
 
if [ `echo "$PREFIX" | grep -c ' '` -gt 0 ] ; then
266
 
    g.message -w "The specified install path: [$PREFIX] contains a space. $GLOOM"
267
 
fi
268
 
if [ `echo "$TMPDIR" | grep -c ' '` -gt 0 ] ; then
269
 
    # a problem because $MAPSET/.tmp/ is used as the compile dir
270
 
    g.message -w "The path to your GIS data: [`g.gisenv GISDBASE`] may contain a space. $GLOOM"
271
 
fi
272
 
 
273
 
 
274
 
if [ "$GIS_OPT_OPERATION" = "remove" ] ; then
275
 
   g.message message="Removing <$MODULE>..."
276
 
 
277
 
   if test -f "$MYINST_DIR/bin/$MODULE" ; then
278
 
       rm -f "$MYINST_DIR/bin/$MODULE"
279
 
   fi
280
 
   if test -f "$MYINST_DIR/scripts/$MODULE" ; then
281
 
       rm -f "$MYINST_DIR/scripts/$MODULE"
282
 
   fi
283
 
   if test -e "$MYINST_DIR/$MODULE" ; then
284
 
       rm -f "$MYINST_DIR/$MODULE"
285
 
   fi
286
 
   if test -f "$MYINST_DIR/docs/html/$MODULE.html" ; then
287
 
       rm -f "$MYINST_DIR/docs/html/$MODULE.html"
288
 
       #also html/$MODULE*.jpg, html/$MODULE*.png
289
 
   fi
290
 
   if test -f "$MYINST_DIR/man/man1/$MODULE.1" ; then
291
 
       rm -f "$MYINST_DIR/man/man1/$MODULE.1"
292
 
   fi
293
 
   if test -f "$MYINST_DIR/docs/man/man1/$MODULE.1" ; then
294
 
       rm -f "$MYINST_DIR/docs/man/man1/$MODULE.1"
295
 
   fi
296
 
 
297
 
   exit 0
298
 
fi
299
 
 
300
 
g.message message=""
301
 
g.message -d "svn co [$SVNURL_ADDONS]/[$MODULECLASS]/[$MODULE]"
302
 
 
303
 
cd "$TMPDIR"
304
 
g.message message="Fetching <$MODULE> from GRASS-Addons SVN (be patient)..."
305
 
svn co "$SVNURL_ADDONS/$MODULECLASS/$MODULE"
306
 
 
307
 
if [ $? -ne 0 ] ; then
308
 
   g.message -e message="GRASS Add-on $MODULE not found in repository or no network connection or another problem"
309
 
   exit 1
310
 
fi
311
 
 
312
 
cd "$TMPDIR/$MODULE"
313
 
g.message message="Compiling <$MODULE>..."
314
 
 
315
 
if [ -n "$MACHTYPE" ] ; then
316
 
   DIST_DIR="dist.$MACHTYPE"
317
 
elif [ -x "`which arch`" ] ; then
318
 
   DIST_DIR="dist.`arch`"
319
 
else 
320
 
   DIST_DIR="dist.unknown"
321
 
fi
322
 
 
323
 
# set up a demolocation so --html-description works
324
 
GVER=`echo "$GRASS_VERSION" | cut -f1,2 -d'.' | sed -e 's/\.//'`
325
 
mkdir -p "$TMPDIR/$DIST_DIR/demolocation/PERMANENT"
326
 
cat << EOF > "$TMPDIR/$DIST_DIR/demolocation/.grassrc$GVER"
327
 
GISDBASE: $TMPDIR/$DIST_DIR
328
 
LOCATION_NAME: demolocation
329
 
MAPSET: PERMANENT
330
 
GRASS_DB_ENCODING: utf-8
331
 
DEBUG: 0
332
 
GRASS_GUI: text
333
 
EOF
334
 
 
335
 
# $INST_NOW helps compile and install modules directly into $(INST_DIR)
336
 
# without having to install whole distribution even after modifying only
337
 
# one module. It will update both $(GRASS_HOME)/dist.$(ARCH) and $(INST_DIR).
338
 
#   see $GISBASE/include/Make/Grass.make
339
 
### actually this may not be needed anymore ###
340
 
INST_NOW=true
341
 
export INST_NOW
342
 
 
343
 
make MODULE_TOPDIR="$GISBASE" \
344
 
   ARCH_INC="'-I$GISBASE/include' '-I$MYINST_DIR/include' '-I$TMPDIR/$DIST_DIR/include'" \
345
 
   ARCH_LIBPATH="'-L$GISBASE/lib' '-L$MYINST_DIR/lib' '-L$TMPDIR/$DIST_DIR/lib'" \
346
 
   ARCH_LIBDIR="$GISBASE/lib" \
347
 
   ARCH_DISTDIR="$TMPDIR/$DIST_DIR" \
348
 
   ARCH_BINDIR="$TMPDIR/$DIST_DIR/bin"
349
 
 
350
 
if [ $? -ne 0 ] ; then
351
 
   g.message -e message="Compilation failed, sorry. Please check above error messages."
352
 
   cleanup
353
 
   exit 1
354
 
else
355
 
   g.message message="Installing <$MODULE>..."
356
 
 
357
 
   # is it a script?
358
 
   if [ `grep -c 'default: script' "$TMPDIR/$MODULE/Makefile"` -eq 1 ] ; then
359
 
      PROGTYPE=scripts
360
 
   else
361
 
      PROGTYPE=bin
362
 
   fi
363
 
   # can we write? Install dir present?
364
 
   if test ! -d "$MYINST_DIR" ; then
365
 
      mkdir -p "$MYINST_DIR"
366
 
   fi
367
 
   if test ! -d "$MYINST_DIR/$PROGTYPE" ; then
368
 
      mkdir -p "$MYINST_DIR/$PROGTYPE"
369
 
   fi
370
 
   if test ! -d "$MYINST_DIR/docs/html" ; then
371
 
      mkdir -p "$MYINST_DIR/docs/html"
372
 
   fi
373
 
   if test ! -d "$MYINST_DIR/man/man1" ; then
374
 
      mkdir -p "$MYINST_DIR/man/man1"
375
 
   fi
376
 
 
377
 
   if [ $SYSADMIN -eq 1 ] ; then
378
 
      if test -f "$MYINST_DIR/$PROGTYPE/$MODULE" ; then
379
 
         if [ "$GIS_FLAG_U" -eq 1 ] ; then
380
 
            g.message "You may need to enter your password to remove an earlier copy of $MODULE:"
381
 
            sudo rm -f "$MYINST_DIR/$PROGTYPE/$MODULE"
382
 
         else
383
 
            rm -f "$MYINST_DIR/$PROGTYPE/$MODULE"
384
 
            if [ $? -ne 0 ] ; then
385
 
               g.message -w "Removal failed. Do you have suitable file-system permissions?"
386
 
            fi
387
 
         fi
388
 
      fi
389
 
      if [ $GIS_FLAG_U -eq 1 ] ; then
390
 
         g.message "You may need to enter your password to install $MODULE:"
391
 
 
392
 
         sudo make MODULE_TOPDIR="$GISBASE" \
393
 
             ARCH_DISTDIR="$TMPDIR/$DIST_DIR" \
394
 
             INST_DIR="$MYINST_DIR" install
395
 
      else
396
 
         make MODULE_TOPDIR="$GISBASE" \
397
 
           ARCH_DISTDIR="$TMPDIR/$DIST_DIR" \
398
 
           INST_DIR="$MYINST_DIR" \
399
 
           install
400
 
      fi
401
 
   else
402
 
      if test -f "$MYINST_DIR/$PROGTYPE/$MODULE" ; then
403
 
         g.message -w "Replacing previously built <$MODULE>"
404
 
         rm -f "$MYINST_DIR/$PROGTYPE/$MODULE"
405
 
      fi
406
 
 
407
 
       # ? ETC="$MYINST_DIR/etc"
408
 
      make MODULE_TOPDIR="$GISBASE" \
409
 
           ARCH_DISTDIR="$TMPDIR/$DIST_DIR" \
410
 
           INST_DIR="$MYINST_DIR" install
411
 
   fi
412
 
 
413
 
   if [ $? -ne 0 ] ; then
414
 
      g.message -e message="Installation failed, sorry. Please check above error messages."
415
 
      cleanup
416
 
      exit 1
417
 
   fi
418
 
 
419
 
   # clean up python installs, since PythonScript.make doesn't exist yet
420
 
   if [ -e "$MYINST_DIR/$PROGTYPE/$MODULE.py" ] ; then
421
 
      # drop the .py from python scripts
422
 
      mv "$MYINST_DIR/$PROGTYPE/$MODULE.py" "$MYINST_DIR/$PROGTYPE/$MODULE"
423
 
      mv "$MYINST_DIR/man/man1/$MODULE.py.1" "$MYINST_DIR/man/man1/$MODULE.1"
424
 
      mv "$MYINST_DIR/docs/html/$MODULE.py.html" "$MYINST_DIR/docs/html/$MODULE.html"
425
 
   fi
426
 
 
427
 
   if [ ! -x "$MYINST_DIR/$PROGTYPE/$MODULE" ] ; then
428
 
     g.message -e "Module did not install properly"
429
 
     cleanup
430
 
     exit 1
431
 
   fi
432
 
 
433
 
   if [ "$MYINST_DIR" = "$GRASS_ADDON_PATH1" ] || [ "$MYINST_DIR" = ~/.grass6/addons ] ; then
434
 
        # move bin/ and script/ into ../, then rmdir if they are empty
435
 
        mv "$MYINST_DIR/$PROGTYPE/$MODULE" "$MYINST_DIR/"
436
 
        if [ `ls -a "$MYINST_DIR/$PROGTYPE" | wc -l` -le 2 ] ; then
437
 
           rmdir "$MYINST_DIR/$PROGTYPE"
438
 
        fi
439
 
        # and move the man page into docs/
440
 
        if [ -e "$MYINST_DIR/man/man1/$MODULE.1" ] ; then
441
 
           mkdir -p "$MYINST_DIR/docs/man/man1"
442
 
           mv "$MYINST_DIR/man/man1/$MODULE.1" "$MYINST_DIR/docs/man/man1/"
443
 
           if [ `ls -a "$MYINST_DIR/man/man1" | wc -l` -le 2 ] ; then
444
 
              rmdir "$MYINST_DIR/man/man1"
445
 
              if [ `ls -a "$MYINST_DIR/man" | wc -l` -le 2 ] ; then
446
 
                 rmdir "$MYINST_DIR/man"
447
 
              fi
448
 
           fi
449
 
        fi
450
 
    fi
451
 
fi
452
 
 
453
 
cleanup
454
 
 
455
 
g.message message=""
456
 
g.message message="Installation of <$MODULE> in <$MYINST_DIR> complete."
457
 
 
458
 
if [ -n "$ADDON_PATH_EMPTY" ] && [ "$GIS_FLAG_S" -eq 0 ] ; then
459
 
   g.message message=""
460
 
   g.message -w message='This add-on module will not function until you set the GRASS_ADDON_PATH environment variable (see "g.manual variables")'
461
 
fi
462
 
 
463
 
exit 0