OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
2.8 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde
  6. # Copyright (C) 2006 - 2010 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. set -e
  16. # stand-alone simplified minimal functions
  17. #
  18. echo_info() {
  19. echo "-> $@" >&2
  20. }
  21. echo_abort() {
  22. local errno="$1"; shift
  23. echo "!> ERROR: $@" >&2
  24. exit "$errno"
  25. }
  26. # Early checking of the system
  27. #
  28. if ! type readlink > /dev/null 2>&1; then
  29. echo_abort 1 '`readlink` tool not found'
  30. fi
  31. readlink -f /bin/sh 2>&1 > /dev/null
  32. [ $? -eq 0 ] ||
  33. echo_abort 1 '`readlink` doesnt support -f, please update it.'
  34. if [ "x-x" = "x${1:-}" ]; then
  35. XTRACE=yes
  36. PS4='+${BASH_SOURCE:+$BASH_SOURCE:}$LINENO> '
  37. shift
  38. set -x
  39. else
  40. XTRACE=
  41. fi
  42. # find libsde.in
  43. #
  44. if [ -z "$SDEROOT" ]; then
  45. # finding the root of the tree where we are stand
  46. #
  47. SDEROOT=$( pwd -P )
  48. while [ "$SDEROOT" -a ! -r "$SDEROOT/lib/libsde.in" ]; do
  49. SDEROOT="${SDEROOT%/*}"
  50. done
  51. fi
  52. # if libsde.in was not found, try a fallback
  53. #
  54. if [ ! -r "$SDEROOT/lib/libsde.in" ]; then
  55. SDEROOT="$( readlink -f "$0" )"; SDEROOT="${SDEROOT%/bin/sde}"
  56. [ -r "$SDEROOT/lib/libsde.in" ] ||
  57. echo_abort 1 'SDEROOT not found.'
  58. fi
  59. # switching to the right sde wrapper (SDEROOT specific)
  60. #
  61. if [ "$( readlink -f "$0" )" != "$SDEROOT/bin/sde" ]; then
  62. if [ "--loop" = "${1:-}" ]; then
  63. echo_abort 2 'loop detected, abort.'
  64. fi
  65. set -- ${XTRACE:+-x }--loop "$@"
  66. if [ -x "$SDEROOT/run.sh" ]; then
  67. exec "$SDEROOT/run.sh" sde --run-loop "$@"
  68. else
  69. exec "$SDEROOT/bin/sde" "$@"
  70. fi
  71. elif [ -x "$SDEROOT/run.sh" ]; then
  72. if [ "yes" = "${SDE_VIA_RUN_SH:-}" ]; then
  73. # good
  74. while [ $# -gt 0 ]; do
  75. case "$1" in
  76. --run-loop|--loop)
  77. ;;
  78. *)
  79. break ;;
  80. esac
  81. shift
  82. done
  83. elif [ "--run-loop" = "${1:-}" ]; then
  84. echo_abort 2 'loop detected, abort.'
  85. else
  86. if [ "--loop" = "${1:-}" ]; then
  87. shift
  88. fi
  89. exec "$SDEROOT/run.sh" sde ${XTRACE:+-x }--run-loop "$@"
  90. fi
  91. elif [ "--loop" = "${1:-}" ]; then
  92. shift
  93. fi
  94. # load corresponding library for sh scripts
  95. #
  96. . "$SDEROOT/lib/libsde.in"
  97. . "$SDEROOT/lib/sde-wrapper-command.in"
  98. if [ $# -eq 0 -o "$1" = "--help" ]; then
  99. sde_wrapper_command_help
  100. else
  101. command="$( sde_wrapper_command "$1" )"
  102. if [ -z "$command" ]; then
  103. # unknown command
  104. echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood."
  105. sde_wrapper_command_help
  106. else
  107. shift;
  108. [ -x "$SDEROOT/bin/sde-$command" ] ||
  109. echo_abort 2 "Can't execute '$COLOR_INFO$SDEROOT/bin/sde-$command$COLOR_NORMAL', sorry."
  110. exec "$SDEROOT/bin/sde-$command" "$@"
  111. fi
  112. fi
  113. exit 1