build_gui_user_menu.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. # Build addon menu files, from the global /Library/GRASS/$GRASS_MMVER/Modules
  3. # and the user's $HOME/Library/GRASS/$GRASS_MMVER/Modules.
  4. # test files to make sure they are appropriate for adding to the GUI menu.
  5. # Using 'file', assume executable binaries OK. Check scripts to see if they
  6. # have GRASS options configured - a simple grep for #%Module.
  7. # Other script languages may need their own test.
  8. # addon commands can't have spaces in them or sh for loop messes up.
  9. # may be my limited knowledge of sh scripting and there could be a way.
  10. GRASS_MMVER=`cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER"`
  11. BINDIR="$GISBASE_USER/Modules/bin"
  12. BINDIRG="$GISBASE_SYSTEM/Modules/bin"
  13. MENUDIR="$GISBASE_USER/Modules/etc"
  14. echo "Rebuilding Addon menu..."
  15. # just to make sure (startup should have created it)
  16. mkdir -p "$MENUDIR"
  17. echo "# generated by grass startup" > "$MENUDIR/xtnmenu.dat"
  18. # global addons:
  19. if [ -d "$BINDIRG" ] ; then
  20. cd "$BINDIRG"
  21. CMDLISTG=`ls -1 2> /dev/null | sort -u`
  22. else
  23. CMDLISTG=""
  24. fi
  25. CMDGFOUND=""
  26. if [ "$CMDLISTG" != "" ] ; then
  27. for i in $CMDLISTG
  28. do
  29. ftype="`file "$BINDIRG/$i"`"
  30. if [ "`echo $ftype | grep 'Mach-O'`" ] || [ "`grep '#% *Module' "$BINDIRG/$i"`" ] ; then
  31. echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat"
  32. CMDGFOUND="1"
  33. fi
  34. done
  35. fi
  36. # user addons:
  37. CMDFIRST="1"
  38. cd "$BINDIR"
  39. CMDLIST=`ls -1 2> /dev/null | sort -u`
  40. if [ "$CMDLIST" != "" ] ; then
  41. for i in $CMDLIST
  42. do
  43. ftype="`file "$BINDIR/$i"`"
  44. if [ "`echo $ftype | grep 'Mach-O'`" ] || [ "`grep '#% *Module' "$BINDIR/$i"`" ] ; then
  45. if [ "$CMDFIRST" ] && [ "$CMDGFOUND" ] ; then
  46. echo "separator" >> "$MENUDIR/xtnmenu.dat"
  47. CMDFIRST=""
  48. fi
  49. echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat"
  50. fi
  51. done
  52. fi