BASH   43

emc

Guest on 11th July 2022 07:39:54 PM

  1. #!/bin/bash
  2. ################################################################################
  3. # usage: emc [options] [<ini-file>]
  4. #
  5. # options:
  6. #     -v = verbose - prints info as it works
  7. #     -d = echos script commands to screen for debugging
  8. #
  9. # this version calls emc2/tcl/bin/pickconfig.tcl to pick an ini file if one
  10. # is not specified on the command line
  11. #
  12. ################################################################################
  13. # Author:
  14. # License: GPL Version 2
  15. # System: Linux
  16. #    
  17. # Copyright (c) 2004-2009 All rights reserved.
  18. ################################################################################
  19.  
  20. ################################################################################
  21. # 0. Values that come from configure
  22. ################################################################################
  23. prefix=/home/dave/emc2-dev
  24. exec_prefix=${prefix}
  25.  
  26. LSMOD=/sbin/lsmod
  27. PIDOF="/bin/pidof -x"
  28. PS=/bin/ps
  29. AWK=/usr/bin/awk
  30. IPCS=/usr/bin/ipcs
  31. KILL=/bin/kill
  32.  
  33. EMC2_HOME=/home/dave/emc2-dev; export EMC2_HOME
  34.  
  35. EMC2_BIN_DIR=/home/dave/emc2-dev/bin
  36. EMC2_TCL_DIR=/home/dave/emc2-dev/tcl
  37. EMC2_HELP_DIR=/home/dave/emc2-dev/docs/help
  38. EMC2_RTLIB_DIR=/home/dave/emc2-dev/rtlib
  39. EMC2_CONFIG_PATH="~/emc2/configs:/home/dave/emc2-dev/configs"
  40. EMC2_NCFILES_DIR=/home/dave/emc2-dev/nc_files
  41. EMC2_LANG_DIR=/home/dave/emc2-dev/src/objects
  42. REALTIME=/home/dave/emc2-dev/scripts/realtime
  43. EMC2_IMAGEDIR=/home/dave/emc2-dev
  44.  
  45. #put the EMC2_BIN_DIR in PATH
  46. PATH=$EMC2_BIN_DIR:$PATH
  47. #ditto scripts if not RIP
  48. [ -d $EMC2_HOME/scripts ] && PATH=$EMC2_HOME/scripts:$PATH
  49.  
  50. if [ -z "$PYTHONPATH" ]; then
  51.     PYTHONPATH=$EMC2_HOME/lib/python
  52. else
  53.     PYTHONPATH=$EMC2_HOME/lib/python:"$PYTHONPATH"
  54. fi
  55. export PYTHONPATH
  56.  
  57. XFILESEARCHPATH=%D:/home/dave/emc2-dev/%T/%N%C:/home/dave/emc2-dev/%T/%N
  58. export XFILESEARCHPATH
  59.  
  60. MODULE_EXT=.ko # module extension, used when insmod'ing
  61.  
  62. DEBUG_FILE=$(mktemp /tmp/emc.debug.XXXXXX)
  63. PRINT_FILE=$(mktemp /tmp/emc.print.XXXXXX)
  64.  
  65. program_available () {
  66.     type -path "$1" > /dev/null 2>&1
  67. }
  68.  
  69. usage () {
  70.         P=${0##*/}
  71.         cat <<EOF
  72. $P: Run EMC2
  73.  
  74. Usage:
  75.         $P [-d] [-v]
  76.                 Choose the configuration file graphically
  77.  
  78.         $P [-k] [-d] [-v] path/to/your.ini
  79.                 Name the configuration file using its path
  80.  
  81.         $P [-k] [-d] [-v] -l
  82.                 Use the previous configuration file
  83.  
  84.         -d: Turn on "debug" mode
  85.         -v: Turn on "verbose" mode
  86.         -k: Continue in the presence of errors in .hal files
  87. EOF
  88.  
  89. }
  90.  
  91. ################################################################################
  92. # 1.1. strip and process command line options
  93. ################################################################################
  94. while getopts "dvlhk" opt
  95. do
  96.         case "$opt" in
  97.         d)
  98.                 # enable echoing of script and command output
  99.                 if tty -s; then
  100.                     DEBUG_FILE=/dev/fd/2
  101.                     echo "Debug mode on" >$DEBUG_FILE
  102.                 fi
  103.                 set -x;;
  104.         v)
  105.                 # enable printing of verbose messages
  106.                 if tty -s; then
  107.                     PRINT_FILE=/dev/fd/1
  108.                     echo "Verbose mode on" >$PRINT_FILE
  109.                 fi;;
  110.         l)
  111.                 USE_LAST_INIFILE=1;;
  112.         k)      DASHK=-k;;
  113.         h)
  114.                 usage
  115.                 exit 0;;
  116.         *)
  117.                 usage
  118.                 exit 1
  119.         esac
  120. done
  121. shift $(($OPTIND-1))
  122.  
  123. case "2.6.24-16-rtai" in
  124. "") ;;
  125. *)
  126.     if [ `uname -r` != "2.6.24-16-rtai" ]; then
  127.         if tty -s; then
  128.             echo "EMC2 requires the real-time kernel 2.6.24-16-rtai to run."
  129.             echo "Before running EMC2, reboot and choose this kernel at the boot menu."
  130.         else
  131.             /usr/bin/wish8.4 <<EOF
  132.                 wm wi .
  133.                 tk_messageBox -type ok \
  134.                     -title EMC2 -icon error -title "Realtime Kernel Required" \
  135.                     -message {EMC2 requires the real-time kernel 2.6.24-16-rtai to run.  Before running EMC2, reboot and choose this kernel at the boot menu.}
  136.                 exit
  137. EOF
  138.         fi
  139.         exit
  140.     fi
  141. esac
  142.  
  143. if ! tty -s; then
  144.     exec 2>> $DEBUG_FILE
  145.     exec >> $PRINT_FILE
  146. fi
  147.  
  148. function ErrorCheck () {
  149.     result=$?
  150.     if [ ! -z "$DISPLAY" ]; then
  151.         echo "catch {send -async popimage destroy .}; destroy ." | /usr/bin/wish8.4
  152.     fi
  153.  
  154.     if [ $result -ne 0 ]; then
  155.         if tty -s || [ -z "$DISPLAY" ] ; then
  156.             if [ -f $DEBUG_FILE ]; then
  157.                 cp $DEBUG_FILE $HOME/emc_debug.txt
  158.             else
  159.                 echo "(debug information was sent to stderr)" \
  160.                     > $HOME/emc_debug.txt
  161.             fi
  162.  
  163.             if [ -f $PRINT_FILE ]; then
  164.                 cp $PRINT_FILE $HOME/emc_print.txt
  165.             else
  166.                 echo "(print information was sent to stdout)" \
  167.                     > $HOME/emc_print.txt
  168.             fi
  169.  
  170.             echo "\
  171. EMC terminated with an error.  You can find more information in the log:
  172.    $HOME/emc_debug.txt
  173. and
  174.    $HOME/emc_print.txt
  175. as well as in the output of the shell command 'dmesg' and in the terminal"
  176.         else
  177.             /usr/bin/wish8.4 $EMC2_TCL_DIR/show_errors.tcl $DEBUG_FILE $PRINT_FILE
  178.         fi
  179.     fi
  180.     rm -f $DEBUG_FILE $PRINT_FILE 2>/dev/null
  181.     exit $result
  182. }
  183.  
  184. trap ErrorCheck EXIT
  185.  
  186. ################################################################################
  187. # 1.3. INIFILE                           find inifile to use                   #
  188. ################################################################################
  189.  
  190. if [ ! -z "$1" ]; then
  191.     case "$1" in
  192.       -)  USE_LAST_INIFILE=1;;
  193.       /*) INIFILE="$1" ;;
  194.       *)  INIFILE="`pwd`/$1";;
  195.     esac
  196.     shift
  197. fi
  198. EXTRA_ARGS="$@"
  199.  
  200. # 1.3.1. Determine if we have run-in place or installed system
  201. RUN_IN_PLACE=yes
  202. echo RUN_IN_PLACE=$RUN_IN_PLACE >>$PRINT_FILE
  203.  
  204. EMC2VERSION="2.4.0~pre"; export EMC2VERSION
  205.  
  206. # common from here..
  207. INIVAR=inivar
  208. HALCMD="halcmd $DASHK"
  209. PICKCONFIG="/usr/bin/wish8.4 $EMC2_TCL_DIR/bin/pickconfig.tcl"
  210. EMC2_EMCSH=/usr/bin/wish8.4
  211.  
  212. echo EMC2_DIR=$EMC2_DIR >>$PRINT_FILE
  213. echo EMC2_BIN_DIR=$EMC2_BIN_DIR >>$PRINT_FILE
  214. echo EMC2_TCL_DIR=$EMC2_TCL_DIR >>$PRINT_FILE
  215. echo EMC2_SCRIPT_DIR=$EMC2_SCRIPT_DIR >>$PRINT_FILE
  216. echo EMC2_RTLIB_DIR=$EMC2_RTLIB_DIR >>$PRINT_FILE
  217. echo EMC2_CONFIG_DIR=$EMC2_CONFIG_DIR >>$PRINT_FILE
  218. echo EMC2_LANG_DIR=$EMC2_LANG_DIR >>$PRINT_FILE
  219. echo INIVAR=$INIVAR >>$PRINT_FILE
  220. echo HALCMD=$HALCMD >>$PRINT_FILE
  221. echo EMC2_EMCSH=$EMC2_EMCSH >>$PRINT_FILE
  222.  
  223. echo "EMC2 - $EMC2VERSION"
  224.  
  225. # was an inifile specified on the command line?
  226. if [ ! -z "$USE_LAST_INIFILE" ]; then
  227.     INIFILE=$($INIVAR -ini ~/.emcrc -var LAST_CONFIG -sec PICKCONFIG 2>>$DEBUG_FILE)
  228.     echo "Using previous inifile: $INIFILE" >> $PRINT_FILE
  229. fi
  230.  
  231. if [ ! -n "$INIFILE" ] ; then
  232.     # nothing specified, get from the user
  233.     INIFILE=$($PICKCONFIG "$EMC2_CONFIG_PATH")
  234.     # it returns either a path, or nothing at all
  235. fi
  236.  
  237. if [ ! -n "$INIFILE" ] ; then
  238.     # still nothing specified, exit
  239.     exit 0
  240. fi
  241.  
  242. # delete directories from path, save name only
  243. INI_NAME="${INIFILE##*/}"
  244. INI_DIR="${INIFILE%/*}"
  245.  
  246. echo "Machine configuration directory is '$INI_DIR'"
  247. echo "Machine configuration file is '$INI_NAME'"
  248.  
  249. # make sure ini file exists (the tcl script just did this, so we could
  250. # eliminate this test, but it does no harm)
  251.  
  252. if [ ! -f "$INIFILE" ] ; then
  253.     echo "Could not find ini file '$INIFILE'"
  254.     trap '' EXIT
  255.     exit -1
  256. fi
  257. echo INIFILE=$INIFILE >>$PRINT_FILE
  258.  
  259. ################################################################################
  260. # 2.  extract info from the ini file that we will need later
  261. ################################################################################
  262. retval=
  263.  
  264. # 2.1. define helper function
  265. function GetFromIniQuiet {
  266.     #$1 var name   $2 - section name
  267.     name=$1
  268.     retval=`$INIVAR -ini "$INIFILE" -var $1 -sec $2 2> /dev/null`
  269.     if [ ! -n "$1" ] ; then
  270.         exit -1
  271.     fi
  272.     echo "$name=$retval" >>$PRINT_FILE
  273. }
  274.  
  275. function GetFromIni {
  276.     #$1 var name   $2 - section name
  277.     name=$1
  278.     retval=`$INIVAR -ini "$INIFILE" -var $1 -sec $2 2>>$DEBUG_FILE`
  279.     if [ ! -n "$1" ] ; then
  280.         echo "Can't find variable $1 in section [$2] of file $INIFILE."
  281.         exit -1
  282.     fi
  283.     echo "$name=$retval" >>$PRINT_FILE
  284. }
  285. # 2.2. get param file
  286. GetFromIni PARAMETER_FILE RS274NGC
  287. RS274NGC_PARAMFILE=$retval
  288.  
  289. # 2.3. get emcmot information
  290. GetFromIni EMCMOT EMCMOT
  291. EMCMOT=$retval$MODULE_EXT # add module extension
  292.  
  293. # 2.4. get emcio information
  294. GetFromIni EMCIO EMCIO
  295. EMCIO=$retval
  296.  
  297. # 2.5. get emctask information
  298. GetFromIni TASK TASK
  299. EMCTASK=$retval
  300.  
  301. # 2.6. we know the emc server name, change if needed
  302. # emcsvr now holds/creates all the NML channels,
  303. # so it needs to start by default, as the first process
  304. EMCSERVER=emcsvr
  305.  
  306. # 2.7. get halui information
  307. GetFromIniQuiet HALUI HAL
  308. HALUI=$retval
  309.  
  310. # 2.9. get display information
  311. GetFromIni DISPLAY DISPLAY
  312. EMCDISPLAY=`(set -- $retval ; echo $1 )`
  313. EMCDISPLAYARGS=`(set -- $retval ; shift ; echo $* )`
  314.  
  315. # 2.10. get NML config information
  316. GetFromIni NML_FILE EMC
  317. NMLFILE=$retval
  318. if [ -z "$NMLFILE" ]; then NMLFILE=/home/dave/emc2-dev/configs/common/emc.nml; fi
  319.  
  320. ################################################################################
  321. # 3. Done gathering information, define a few functions
  322. # Execution resumes after function definitions...
  323. ################################################################################
  324.  
  325. KILL_TASK=
  326. KILL_TIMEOUT=20
  327.  
  328. ################################################################################
  329. # 3.1. Kills a list of tasks with timeout
  330. # if it doesn't work, kill -9 is used
  331. ################################################################################
  332. function KillTaskWithTimeout() {
  333.     if [ ! -n "$KILL_PIDS" ] ; then
  334.         KILL_PIDS=`$PIDOF $KILL_TASK`
  335.     fi
  336.     if [ ! -n "$KILL_PIDS" ] ; then
  337.         echo "Could not find pid(s) for task $KILL_TASK"
  338.         return -1
  339.     fi
  340.     for KILL_PID in $KILL_PIDS ; do
  341.         echo "Killing task $KILL_TASK, PID=$KILL_PID" >>$PRINT_FILE
  342.         # first a "gentle" kill with signal TERM
  343.         $KILL $KILL_PID
  344.         WAIT=$KILL_TIMEOUT
  345.         # wait and see if it dissappears
  346.         while [ $WAIT -gt 1 ] ; do
  347.             # see if it's still alive
  348.             if $PS $KILL_PID >>$DEBUG_FILE ; then
  349.                 WAIT=$(($WAIT-1))
  350.                 sleep .1
  351.             else
  352.                 WAIT=0
  353.             fi
  354.         done
  355.         if [ $WAIT -gt 0 ] ; then
  356.             # gentle didn't work, get serious
  357.             echo "Timeout, trying kill -9" >>$PRINT_FILE
  358.             $KILL -9 $KILL_PID
  359.             WAIT=$KILL_TIMEOUT
  360.             # wait and see if it dissappears
  361.             while [ $WAIT -gt 1 ] ; do
  362.                 # see if it's still alive
  363.                 if $PS $KILL_PID >>$DEBUG_FILE ; then
  364.                     WAIT=$(($WAIT-1))
  365.                     sleep .1
  366.                 else
  367.                     WAIT=0
  368.                 fi
  369.             done
  370.         fi
  371.         if [ $WAIT -gt 0 ] ; then
  372.             echo "Could not kill task $KILL_TASK, PID=$KILL_PID"
  373.         fi
  374.         KILL_PIDS=
  375.         KILL_TASK=
  376.     done
  377. }
  378.  
  379.  
  380. ################################################################################
  381. # 3.2. define the cleanup function
  382. #
  383. # this cleanup function doesn't know or care what was actually
  384. # loaded - it simply kills _any_ processes in it's list of emc
  385. # components
  386. ################################################################################
  387. function Cleanup() {
  388.  
  389.     echo "Shutting down and cleaning up EMC2..."
  390.     # Kill displays first - that should cause an orderly
  391.     #   shutdown of the rest of emc2
  392.     for KILL_TASK in xemc yemc emcpanel keystick iosh emcsh emcrsh emctop mdi debuglevel; do
  393.         if $PIDOF $KILL_TASK >>$DEBUG_FILE ; then
  394.             KillTaskWithTimeout
  395.         fi
  396.     done
  397.  
  398.     if program_available axis-remote ; then
  399.         if [ ! -z "$DISPLAY" ]; then
  400.             axis-remote --ping && axis-remote --quit
  401.         fi
  402.     fi
  403.  
  404.     if [ "$1" = "other" ]; then
  405.         echo -n "Waiting for other session to finish exiting..."
  406.         WAIT=$KILL_TIMEOUT
  407.         while [ $WAIT -gt 1 ]; do
  408.             if ! [ -f $LOCKFILE ]; then
  409.                 echo " Ok"
  410.                 return 0
  411.             fi
  412.             WAIT=$(($WAIT-1))
  413.             sleep .1
  414.         done
  415.         echo "lockfile still not removed"
  416.     fi
  417.  
  418.     SHUTDOWN=`$INIVAR -ini "$INIFILE" -var SHUTDOWN -sec HAL 2> /dev/null`
  419.     if [ -n "$SHUTDOWN" ]; then
  420.         echo "Running HAL shutdown script"
  421.         $HALCMD -f $SHUTDOWN
  422.     fi
  423.  
  424.     # now kill all the other user space components of emc
  425.     for KILL_TASK in emcsvr milltask; do
  426.         if $PIDOF $KILL_TASK >>$DEBUG_FILE ; then
  427.             KillTaskWithTimeout
  428.         fi
  429.     done
  430.  
  431.     echo "Stopping realtime threads" >> $DEBUG_FILE
  432.     $HALCMD stop
  433.     echo "Unloading hal components" >> $DEBUG_FILE
  434.     $HALCMD unload all
  435.  
  436.     for i in `seq 10`; do
  437.         # (the one component is the halcmd itself)
  438.         if [ `$HALCMD list comp | wc -w` = 1 ]; then break; fi
  439.         sleep .2
  440.     done
  441.  
  442.     echo "Removing HAL_LIB, RTAPI, and Real Time OS modules" >>$PRINT_FILE
  443.     $REALTIME stop
  444.  
  445.     echo "Removing NML shared memory segments" >> $PRINT_FILE
  446.     while read b x t x x x x x x m x; do
  447.         case $b$t in
  448.             BSHMEM) ipcrm -M $m 2>/dev/null;;
  449.         esac
  450.     done < $NMLFILE
  451.  
  452.  
  453.     # remove lock file
  454.     if [ -f $LOCKFILE ] ; then
  455.         rm $LOCKFILE
  456.     fi
  457.  
  458.     echo "Cleanup done"
  459. }
  460.  
  461.  
  462.  
  463. ################################################################################
  464. # 4. done with function definitions, execution resumes here
  465. ################################################################################
  466.  
  467. # Name of lock file to check for that signifies that EMC is up,
  468. # to prevent multiple copies of controller
  469. LOCKFILE=/tmp/emc.lock
  470.  
  471. # Check for lock file
  472. if [ -f $LOCKFILE ]; then
  473.   if tty -s; then
  474.     echo -n "EMC2 is still running.  Restart it? [Y/n] "
  475.     read input; [ -z $input ] && input=y
  476.   else
  477.     input=$(/usr/bin/wish8.4 <<EOF
  478. wm wi .
  479. puts [tk_messageBox -title EMC2 -message "EMC2 is still running.  Restart it?" -type yesno]
  480. exit
  481. EOF
  482. )
  483.   fi
  484.   case $input in
  485.     y|Y|yes)
  486.       echo Cleaning up old EMC2...
  487.       Cleanup other
  488.     ;;
  489.     *)
  490.       echo Not starting new EMC2
  491.       exit 0
  492.     ;;
  493.   esac
  494. fi
  495. echo Starting EMC2...
  496.  
  497. # trap ^C so that it's called if user interrupts script
  498. trap 'Cleanup ; exit 0' SIGINT SIGTERM
  499.  
  500. # go to the dir where the ini file is
  501. # either configs/<specific-config> when run-in-place, or
  502. # /usr/local/share/emc/configs/<specific-config> (wherever it was installed)
  503. cd "$INI_DIR"
  504.  
  505. # Create the lock file
  506. touch $LOCKFILE
  507.  
  508. ################################################################################
  509. # 4.1. pop up intro graphic
  510. ################################################################################
  511. img=`$INIVAR -ini "$INIFILE" -var INTRO_GRAPHIC -sec DISPLAY 2>>$DEBUG_FILE`
  512. imgtime=`$INIVAR -ini "$INIFILE" -var INTRO_TIME -sec DISPLAY 2>>$DEBUG_FILE`
  513. if [ "$imgtime" = "" ] ; then
  514.   imgtime=5
  515. fi
  516. if [ "$img" != "" ] ; then
  517.   if [ -e "$img" ]; then
  518.     true
  519.   elif [ -e "$INI_DIR/$img" ]; then
  520.     img="$INI_DIR/$img"
  521.   elif [ -e "$EMC2_IMAGEDIR/$img" ]; then
  522.     img="$EMC2_IMAGEDIR/$img"
  523.   else
  524.     img=
  525.   fi
  526. fi
  527. if [ "$img" != "" ] ; then
  528.     if [ -x $EMC2_TCL_DIR/bin/popimage ] ; then
  529.         $EMC2_TCL_DIR/bin/popimage $img $imgtime &
  530.     fi
  531. fi
  532.  
  533. ################################################################################
  534. # 4.2. Now we can finally start loading EMC
  535. ################################################################################
  536.  
  537. # 4.3.1. Run emcserver in background, always (it owns/creates the NML buffers)
  538. echo "Starting EMC2 server program: $EMCSERVER" >>$PRINT_FILE
  539. if ! program_available $EMCSERVER; then
  540.     echo "Can't execute server program $EMCSERVER"
  541.     Cleanup
  542.     exit 1
  543. fi
  544. export INI_FILE_NAME="$INIFILE"
  545. $EMCSERVER -ini "$INIFILE" &
  546. sleep 1
  547.  
  548. # 4.3.2. Start REALTIME
  549. echo "Loading Real Time OS, RTAPI, and HAL_LIB modules" >>$PRINT_FILE
  550. if ! $REALTIME start ; then
  551.     echo "Realtime system did not load"
  552.     Cleanup
  553.     exit -1
  554. fi
  555.  
  556. # 4.3.3. export the location of the HAL realtime modules so that
  557. # "halcmd loadrt" can find them
  558. export HAL_RTMOD_DIR=$EMC2_RTLIB_DIR
  559.  
  560. # 4.3.4. Run emcio in background
  561. echo "Starting EMC2 IO program: $EMCIO" >>$PRINT_FILE
  562. if ! program_available $EMCIO ; then
  563.     echo "Can't execute IO program $EMCIO"
  564.     Cleanup
  565.     exit 1
  566. fi
  567. $HALCMD loadusr -Wn iocontrol $EMCIO -ini "$INIFILE"
  568.  
  569. # 4.3.5. Run halui in background, if necessary
  570. if [ -n "$HALUI" ] ; then
  571.     echo "Starting HAL User Interface program: $HALUI" >>$PRINT_FILE
  572.     if ! program_available $HALUI ; then
  573.         echo "Can't execute halui program $HALUI"
  574.         Cleanup
  575.         exit 1
  576.     fi
  577.     $HALCMD loadusr -Wn halui $HALUI -ini "$INIFILE"
  578. fi
  579.  
  580. # 4.3.6. execute HALCMD config files (if any)
  581. # get first config file name from ini file
  582. NUM=1
  583. CFGFILE=`$INIVAR -ini "$INIFILE" -var HALFILE -sec HAL -num $NUM 2> /dev/null`
  584. while [ -n "$CFGFILE" ] ; do
  585.     case $CFGFILE in
  586.     *.tcl)
  587.         if ! haltcl -ini "$INIFILE" $CFGFILE && [ "$DASHK" = "" ]; then
  588.             Cleanup
  589.             exit -1
  590.         fi
  591.     ;;
  592.     *)
  593.         if ! $HALCMD -i "$INIFILE" -f $CFGFILE && [ "$DASHK" = "" ]; then
  594.             Cleanup
  595.             exit -1
  596.         fi
  597.     esac
  598.     # get next config file name from ini file
  599.     NUM=$(($NUM+1))
  600.     CFGFILE=`$INIVAR -ini "$INIFILE" -var HALFILE -sec HAL -num $NUM 2> /dev/null`
  601. done
  602.  
  603. # 4.3.7. execute discrete HAL commands from ini file (if any)
  604. # get first command from ini file
  605. NUM=1
  606. HALCOMMAND=`$INIVAR -ini "$INIFILE" -var HALCMD -sec HAL -num $NUM 2> /dev/null`
  607. while [ -n "$HALCOMMAND" ] ; do
  608.     if [ -n "$HALCOMMAND" ] ; then
  609.         echo "Running HAL command: $HALCOMMAND" >>$PRINT_FILE
  610.         if ! $HALCMD $HALCOMMAND && [ "$DASHK" = "" ]; then
  611.             echo "ini file HAL command $HALCOMMAND failed."
  612.             Cleanup
  613.             exit -1
  614.         fi
  615.     fi
  616.     # get next command from ini file
  617.     NUM=$(($NUM+1))
  618.     HALCOMMAND=`$INIVAR -ini "$INIFILE" -var HALCMD -sec HAL -num $NUM 2> /dev/null`
  619. done
  620.  
  621. # 4.3.8. start the realtime stuff ticking
  622. $HALCMD start
  623.  
  624. # 4.3.9. Run emctask in background
  625. echo "Starting EMC2 TASK program: $EMCTASK" >>$PRINT_FILE
  626. if ! program_available $EMCTASK ; then
  627.     echo "Can't execute TASK program $EMCTASK"
  628.     Cleanup
  629.     exit 1
  630. fi
  631. $EMCTASK -ini "$INIFILE" &
  632.  
  633. #export some common directories, used by some of the GUI's
  634. export EMC2_TCL_DIR
  635. export EMC2_EMCSH
  636. export EMC2_HELP_DIR
  637. export EMC2_LANG_DIR
  638. export REALTIME
  639. export HALCMD
  640. export NMLFILE
  641.  
  642. # 4.3.10. Run display in foreground
  643. echo "Starting EMC2 DISPLAY program: $EMCDISPLAY" >>$PRINT_FILE
  644. result=0
  645. case $EMCDISPLAY in
  646.   tkemc|mini)
  647.     # tkemc and mini are in the tcl directory, not the bin directory
  648.     if [ ! -x $EMC2_TCL_DIR/$EMCDISPLAY.tcl ] ; then
  649.         echo "Can't execute DISPLAY program $EMC2_TCL_DIR/$EMCDISPLAY.tcl $EMCDISPLAYARGS"
  650.         Cleanup
  651.         exit 1
  652.     fi
  653.     $EMC2_TCL_DIR/$EMCDISPLAY.tcl -ini "$INIFILE" $EMCDISPLAYARGS
  654.     result=$?
  655.   ;;
  656.   dummy)
  657.     # dummy display just waits for <ENTER>
  658.     echo "DUMMY DISPLAY MODULE, press <ENTER> to continue."
  659.     read foo;
  660.   ;;
  661.   keystick)
  662.     if ! program_available keystick ; then
  663.         echo "Can't execute DISPLAY program $EMCDISPLAY $EMCDISPLAYARGS $EXTRA_ARGS"
  664.         Cleanup
  665.         exit 1
  666.     fi
  667.     if [ ! -z "$DISPLAY" ]; then
  668.         xterm -xrm 'XTerm*metaSendsEscape:false' -ls -e keystick -ini "$INIFILE"
  669.     else
  670.         keystick -ini "$INIFILE"
  671.     fi
  672.     result=$?
  673.   ;;
  674.   *)
  675.     # all other displays are assumed to be commands on the PATH
  676.     if ! program_available $EMCDISPLAY; then
  677.         echo "Can't execute DISPLAY program $EMCDISPLAY $EMCDISPLAYARGS $EXTRA_ARGS"
  678.         Cleanup
  679.         exit 1
  680.     fi
  681.     $EMCDISPLAY -ini "$INIFILE" $EMCDISPLAYARGS $EXTRA_ARGS
  682.     result=$?
  683.   ;;
  684. esac
  685.  
  686. # the display won't return until you shut it down,
  687. # so when you get here it's time to clean up
  688. Cleanup
  689.  
  690. exit $result

Raw Paste


Login or Register to edit or fork this paste. It's free.