/ scripts / rip-environment.in
rip-environment.in
  1  #!/bin/bash
  2  # Execute this file in the context of your shell, such as with
  3  #  . @EMC2_HOME@/scripts/rip-environment
  4  # and your shell environment will be properly configured to run commands like
  5  # halcompile, halcmd, halrun, iosh, and python with the emc modules available.
  6  #
  7  # Alternately, use it as a wrapper to invoke a linuxcnc command that requires
  8  # the environment to be set:
  9  #  @EMC2_HOME@/scripts/rip-environment latency-test
 10  #
 11  #    Copyright 2006, 2007, 2008, 2009, 2014 Jeff Epler <jepler@unpythonic.net>
 12  #
 13  #    This program is free software; you can redistribute it and/or modify
 14  #    it under the terms of the GNU General Public License as published by
 15  #    the Free Software Foundation; either version 2 of the License, or
 16  #    (at your option) any later version.
 17  #
 18  #    This program is distributed in the hope that it will be useful,
 19  #    but WITHOUT ANY WARRANTY; without even the implied warranty of
 20  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21  #    GNU General Public License for more details.
 22  #
 23  #    You should have received a copy of the GNU General Public License
 24  #    along with this program; if not, write to the Free Software
 25  #    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 26  
 27  case "$0" in
 28      rip-environment|*/rip-environment)
 29          as_command=true
 30          if [ $# -eq 0 ]; then
 31                  cat <<-EOF
 32  			This script can be used in one of two ways.
 33  
 34  			It can be loaded in the context of your shell, by executing
 35  			    . $0
 36  			after this, commands like 'linuxcnc', 'halrun' and so on refer to the
 37  			version in this directory, instead of to an installed version of
 38  			linuxcnc (if any)
 39  
 40  			Second, it can be used to run a command in this directory without
 41  			modifying the environment of the calling shell:
 42  			    $0 command...
 43  			such as
 44  			    $0 halrun foo.hal
 45  			    $0 linuxcnc configs/.../foo.ini
 46  		EOF
 47  	exit 1
 48          fi ;;
 49      *) as_command=false
 50  esac
 51  
 52  if ! test "xyes" = "x@RUN_IN_PLACE@"; then
 53      echo "This script is only useful on run-in-place systems."
 54      return
 55  fi
 56  
 57  case "$PATH" in
 58      @EMC2_BIN_DIR@:*|*:@EMC2_BIN_DIR@:*)
 59          if ! $as_command; then
 60              echo "This script only needs to be run once per shell session."
 61              return
 62          fi ;;
 63  esac
 64  
 65  EMC2_HOME=@EMC2_HOME@; export EMC2_HOME
 66  EMC2VERSION="@EMC2VERSION@"; export EMC2VERSION
 67  LINUXCNCVERSION="@EMC2VERSION@"; export LINUXCNCVERSION
 68  LINUXCNC_NCFILES_DIR="@EMC2_NCFILES_DIR@"; export LINUXCNC_NCFILES_DIR
 69  LINUXCNC_EMCSH=@WISH@; export LINUXCNC_EMCSH
 70  PATH=@EMC2_BIN_DIR@:$EMC2_HOME/scripts:$EMC2_HOME/tcl:"$PATH"
 71  
 72  if [ -z "$TCLLIBPATH" ]; then
 73      TCLLIBPATH=$EMC2_HOME/tcl
 74  else
 75      TCLLIBPATH=$EMC2_HOME/tcl:$TCLLIBPATH
 76  fi
 77  
 78  if [ -z "$LD_LIBRARY_PATH" ]; then
 79      LD_LIBRARY_PATH=$EMC2_HOME/lib
 80  else
 81      LD_LIBRARY_PATH=$EMC2_HOME/lib:"$LD_LIBRARY_PATH"
 82  fi
 83  
 84  if [ -z "$PYTHONPATH" ]; then
 85      PYTHONPATH=$EMC2_HOME/lib/python
 86  else
 87      PYTHONPATH=$EMC2_HOME/lib/python:"$PYTHONPATH"
 88  fi
 89  
 90  if [ -z "$MANPATH" ]; then
 91      if type -path manpath > /dev/null 2>&1; then
 92  	MANPATH=$EMC2_HOME/docs/man:"$(manpath)"
 93      else
 94  	MANPATH=$EMC2_HOME/docs/man:/usr/local/man:/usr/local/share/man:/usr/share/man
 95      fi
 96  else
 97      MANPATH=$EMC2_HOME/docs/man:"$MANPATH"
 98  fi
 99  
100  if [ -z "$GLADE_CATALOG_PATH" ]; then
101      GLADE_CATALOG_PATH=$EMC2_HOME/lib/python/gladevcp
102  else
103      GLADE_CATALOG_PATH=$EMC2_HOME/lib/python/gladevcp:"$GLADE_CATALOG_PATH"
104  fi
105  
106  if ! $as_command; then
107      # TODO: if these completion directives give trouble for any versions
108      # of bash actively in use, protect them with checks of BASH_VERSINFO
109      if [ $BASH_VERSINFO -eq 2 ]; then
110          complete -o dirnames -f -X '!*.ini' emc axis mdi
111          complete -o dirnames -f -X '!*.hal' halrun halcmd
112          complete -W 'start stop restart status' realtime
113          complete -C "halcmd -C" halcmd
114      else
115          _iningc () {
116              case "$3" in
117              *.ini) COMPREPLY=($(compgen -o plusdirs -f -X '!*.ngc' -- "$2")) ;;
118              *) COMPREPLY=($(compgen -o plusdirs -f -X '!*.ini' -- "$2"))
119              esac
120          }
121          complete -o plusdirs -F _iningc emc axis
122          complete -o plusdirs -f -X '!*.ini' mdi
123          complete -o plusdirs -f -X '!*.hal' halrun halcmd
124          complete -W 'start stop restart status' realtime
125          complete -C "halcmd -C" halcmd
126      fi
127  
128      if [ -f $EMC2_HOME/src/Makefile ]; then
129          build () { make -C $EMC2_HOME/src "$@"; }
130      fi
131  fi
132  
133  export PYTHONPATH MANPATH LD_LIBRARY_PATH TCLLIBPATH GLADE_CATALOG_PATH
134  
135  if $as_command; then exec "$@"; fi