run-linuxcnc-demo.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. die()
  3. {
  4. echo "$*" >&2
  5. exit 1
  6. }
  7. usage()
  8. {
  9. echo "Usage: run-linuxcnc-demo.sh [/path/to/linuxcnc]"
  10. echo
  11. echo " /path/to/linuxcnc: Path to 'linuxcnc' start script"
  12. }
  13. if [ $# -ge 1 ] && [ "$1" = "-h" -o "$1" = "--help" ]; then
  14. usage
  15. exit 0
  16. fi
  17. if [ $# -eq 0 ]; then
  18. linuxcnc="linuxcnc"
  19. elif [ $# -eq 1 ]; then
  20. linuxcnc="$1"
  21. else
  22. usage
  23. exit 1
  24. fi
  25. # basedir = directory where this script lives in
  26. basedir="$(dirname "$0")"
  27. [ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"
  28. # rootdir = root of the pyprofibus repository
  29. rootdir="$basedir/.."
  30. [ -x "$rootdir/pyprofibus-linuxcnc-hal" ] || die "pyprofibus-linuxcnc-hal not found"
  31. cleanup()
  32. {
  33. rm -f "/tmp/linuxcnc-demo.ngc"
  34. }
  35. cleanup
  36. trap cleanup EXIT
  37. cp "$basedir/linuxcnc-demo.ngc" /tmp/ || die "Failed to copy linuxcnc-demo.ngc"
  38. # Start LinuxCNC
  39. (
  40. cd "$basedir" || die "Failed to 'cd $basedir'"
  41. PATH="$rootdir/:$PATH"\
  42. PYTHONPATH="$rootdir/:$PYTHONPATH"\
  43. "$linuxcnc" "$basedir/linuxcnc-demo.ini" ||\
  44. die "LinuxCNC exited with an error"
  45. )