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.

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