[GRASS-SVN] r43734 - grass/branches/develbranch_6/scripts/g.extension

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 30 01:41:40 EDT 2010


Author: hamish
Date: 2010-09-30 05:41:40 +0000 (Thu, 30 Sep 2010)
New Revision: 43734

Modified:
   grass/branches/develbranch_6/scripts/g.extension/g.extension
Log:
somewhat experimental attempt at fixing #1180:
 - default install back to GRASS_ADDON_PATH
 - make a GRASS_ADDON_PATH if needed
 - symlink binary into ADDON_PATH if that's the destination
 - minor cosmetics
 - test if install dir is writable
 - also remove if in scripts/ or base dir


Modified: grass/branches/develbranch_6/scripts/g.extension/g.extension
===================================================================
--- grass/branches/develbranch_6/scripts/g.extension/g.extension	2010-09-30 02:30:42 UTC (rev 43733)
+++ grass/branches/develbranch_6/scripts/g.extension/g.extension	2010-09-30 05:41:40 UTC (rev 43734)
@@ -50,14 +50,18 @@
 #% type: string
 #% key_desc: path
 #% description: Prefix where to install extension
-#% answer: $GISBASE
-#% required: yes
+#% answer: $GRASS_ADDON_PATH
+#% required: no
 #%end
 #%flag
 #% key: l
 #% description: List available modules in the GRASS Addons SVN repository
 #% guisection: Print
 #%end
+#%flag
+#% key: s
+#% description: Install system-wide (may need system administrator rights)
+#%end
 
 
 if  [ -z "$GISBASE" ] ; then
@@ -199,10 +203,22 @@
    exit 1
 fi
 
-if [ "$PREFIX" = '$GISBASE' ] ; then
+
+if [ "$PREFIX" == '$GRASS_ADDON_PATH' ] ; then 
+    if [ -z "$GRASS_ADDON_PATH" ] ; then 
+        g.message -w message="GRASS_ADDON_PATH is not defined, installing to ~/.grass6/addons/" 
+        #g.message message="Suggest you set GRASS_ADDON_PATH and GRASS_ADDON_ETC to ..."
+        ## will GRASS_ADDON_ETC help for man/ and docs/ ?
+	## maybe have g.manual search in GRASS_ADDON_ETC/../ ?  :-/
+        mkdir -p ~/.grass6/addons
+        GRASS_ADDON_PATH=~/.grass6/addons
+    fi
+    PREFIX="$GRASS_ADDON_PATH"
+elif [ "$PREFIX" = '$GISBASE' ] || [ $GIS_FLAG_S -eq 1 ] ; then
    PREFIX="$GISBASE"
 fi
 
+
 if [ -d "$PREFIX" ] ; then
     MYINST_DIR="$PREFIX"
 else
@@ -210,14 +226,27 @@
     exit 1
 fi
 
+if [ ! -w "$PREFIX" ] ; then
+    g.message -e "'$PREFIX' is not writable (are you logged in as the system administator?)"
+    exit 1
+fi
+
+
 if [ "$GIS_OPT_OPERATION" = "remove" ] ; then
    g.message message="Removing <$MODULE>..."
 
    if test -f "${MYINST_DIR}/bin/${MODULE}" ; then
        rm -f "${MYINST_DIR}/bin/${MODULE}"
    fi
+   if test -f "$MYINST_DIR/scripts/$MODULE" ; then
+       rm -f "$MYINST_DIR/scripts/$MODULE"
+   fi
+   if test -f "$MYINST_DIR/$MODULE" ; then
+       rm -f "$MYINST_DIR/$MODULE"
+   fi
    if test -f "${MYINST_DIR}/docs/html/${MODULE}.html" ; then
        rm -f "${MYINST_DIR}/docs/html/${MODULE}.html"
+       #also html/$MODULE*.jpg, html/$MODULE*.png
    fi
    if test -f "${MYINST_DIR}/man/man1/${MODULE}.1" ; then
        rm -f "${MYINST_DIR}/man/man1/${MODULE}.1"
@@ -233,22 +262,22 @@
 svn co "${SVNURL_ADDONS}/${MODULECLASS}/${MODULE}"
 
 if [ $? -ne 0 ] ; then
-   g.message -e message="GRASS Addon ${MODULE} not found in repository or no network connection or another problem"
+   g.message -e message="GRASS Add-on $MODULE not found in repository or no network connection or another problem"
    exit 1
 fi
 
 cd "$TMPDIR/$MODULE"
-g.message message="Compiling <${MODULE}>..."
+g.message message="Compiling <$MODULE>..."
 make MODULE_TOPDIR="$GISBASE"
 if [ $? -ne 0 ] ; then
    g.message -e message="Compilation failed, sorry. Please check above error messages."
    cleanup
    exit 1
 else
-   g.message message="Installing ${MODULE}..."
+   g.message message="Installing <$MODULE>..."
 
    # is it a script?
-   grep "default: script" "$TMPDIR/$MODULE/Makefile" 2>&1 >/dev/null
+   grep "default: script" "$TMPDIR/$MODULE/Makefile" 2>&1 > /dev/null
    if [ $? -eq 0 ] ; then
       PROGTYPE=scripts
    else
@@ -267,27 +296,36 @@
    if test ! -d "${MYINST_DIR}/man/man1" ; then
       mkdir -p "${MYINST_DIR}/man/man1"
    fi
+
+   # use `test -w` instead of touch?
    touch "${MYINST_DIR}/`basename $0`.$$"
    if [ $? -ne 0 ] ; then
       g.message -e message="Cannot write to <$MYINST_DIR>, installation failed"
       exit 1
-   else
-      rm -f "${MYINST_DIR}/`basename $0`.$$"
-      if test -f "${MYINST_DIR}/$PROGTYPE/${MODULE}" ; then
-         rm -f "${MYINST_DIR}/$PROGTYPE/${MODULE}"
-      fi
-      make MODULE_TOPDIR="$GISBASE" INST_DIR="$MYINST_DIR" install
-      if [ $? -ne 0 ] ; then
-         g.message -e message="Installation failed, sorry. Please check above error messages."
-         cleanup
-         exit 1
-      fi
-      if [ ! -x "${MYINST_DIR}/$PROGTYPE/${MODULE}" ] ; then
-	g.message -e "Module did not install properly"
-	cleanup
-	exit 1
-      fi
    fi
+   rm -f "${MYINST_DIR}/`basename $0`.$$"
+
+   if test -f "${MYINST_DIR}/$PROGTYPE/${MODULE}" ; then
+      rm -f "${MYINST_DIR}/$PROGTYPE/${MODULE}"
+   fi
+
+   make MODULE_TOPDIR="$GISBASE" INST_DIR="$MYINST_DIR" install
+   if [ $? -ne 0 ] ; then
+      g.message -e message="Installation failed, sorry. Please check above error messages."
+      cleanup
+      exit 1
+   fi
+
+   if [ ! -x "${MYINST_DIR}/$PROGTYPE/${MODULE}" ] ; then
+     g.message -e "Module did not install properly"
+     cleanup
+     exit 1
+   fi
+
+   if [ "$MYINST_DIR" = "$GRASS_ADDON_PATH" ] ; then
+      # symlink into path which is actually in the $PATH
+      ln -s "$MYINST_DIR/$PROGTYPE/$MODULE" "$MYINST_DIR/"
+   fi
 fi
 
 cleanup



More information about the grass-commit mailing list