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.

101 lines
2.5 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 - 2007 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 -e "!> ERROR: $@" >&2
  24. exit "$errno"
  25. }
  26. # Early checking of the system
  27. #
  28. [ -n "$( type -p readlink )" ] ||
  29. echo_abort 1 '`readlink` tool not found'
  30. readlink -f /bin/sh 2>&1 > /dev/null
  31. [ $? -eq 0 ] ||
  32. echo_abort 1 '`readlink` doesnt support -f, please update it.'
  33. # find libsde.in
  34. #
  35. if [ -z "$SDEROOT" ]; then
  36. # finding the root of the tree where we are stand
  37. #
  38. SDEROOT=$( pwd -P )
  39. while [ "$SDEROOT" -a ! -r "$SDEROOT/lib/libsde.in" ]; do
  40. SDEROOT="${SDEROOT%/*}"
  41. done
  42. fi
  43. # if libsde.in was not found, try a fallback
  44. #
  45. if [ ! -r "$SDEROOT/lib/libsde.in" ]; then
  46. SDEROOT="$( readlink -f "$0" )"; SDEROOT="${SDEROOT%/bin/sde}"
  47. [ -r "$SDEROOT/lib/libsde.in" ] ||
  48. echo_abort 1 'SDEROOT not found.'
  49. fi
  50. # switching to the right sde wrapper (SDEROOT specific)
  51. #
  52. if [ "$( readlink -f "$0" )" != "$SDEROOT/bin/sde" ]; then
  53. if [ "$1" == "--loop" ]; then
  54. echo_abort 2 'loop detected, abort.'
  55. else
  56. exec "$SDEROOT/bin/sde" --loop "$@"
  57. fi
  58. elif [ "$1" == "--loop" ]; then
  59. shift
  60. fi
  61. # load corresponding library for sh scripts
  62. #
  63. . "$SDEROOT/lib/libsde.in"
  64. if [ $# -eq 0 ]; then
  65. command="help"
  66. elif [ "$1" != "${1%-*}" ]; then
  67. # unknown command
  68. echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood."
  69. # call help without arguments
  70. set --
  71. command="help"
  72. elif [ -x "$SDEROOT/bin/sde-$1" ]; then
  73. command="$1"; shift
  74. elif grep -q "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null; then
  75. # use alias
  76. command="$( grep -l "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null |
  77. head -n 1 | sed -e 's,.*/sde-,,' )"
  78. shift
  79. else
  80. # unknown command
  81. echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood."
  82. # call help without arguments
  83. set --
  84. command="help"
  85. fi
  86. [ -x "$SDEROOT/bin/sde-$command" ] ||
  87. echo_abort 2 "Can't execute '$COLOR_INFO$SDEROOT/bin/sde-$command$COLOR_NORMAL', sorry."
  88. exec "$SDEROOT/bin/sde-$command" "$@"