#!/bin/sh # --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: bin/sde # Copyright (C) 2006 - 2007 The OpenSDE Project # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END --- set -e # stand-alone simplified minimal functions # echo_info() { echo "-> $@" >&2 } echo_abort() { local errno="$1"; shift echo -e "!> ERROR: $@" >&2 exit "$errno" } # Early checking of the system # [ -n "$( type -p readlink )" ] || echo_abort 1 '`readlink` tool not found' readlink -f /bin/sh 2>&1 > /dev/null [ $? -eq 0 ] || echo_abort 1 '`readlink` doesnt support -f, please update it.' # find libsde.in # if [ -z "$SDEROOT" ]; then # finding the root of the tree where we are stand # SDEROOT=$( pwd -P ) while [ "$SDEROOT" -a ! -r "$SDEROOT/lib/libsde.in" ]; do SDEROOT="${SDEROOT%/*}" done fi # if libsde.in was not found, try a fallback # if [ ! -r "$SDEROOT/lib/libsde.in" ]; then SDEROOT="$( readlink -f "$0" )"; SDEROOT="${SDEROOT%/bin/sde}" [ -r "$SDEROOT/lib/libsde.in" ] || echo_abort 1 'SDEROOT not found.' fi # switching to the right sde wrapper (SDEROOT specific) # if [ "$( readlink -f "$0" )" != "$SDEROOT/bin/sde" ]; then if [ "$1" == "--loop" ]; then echo_abort 2 'loop detected, abort.' else exec "$SDEROOT/bin/sde" --loop "$@" fi elif [ "$1" == "--loop" ]; then shift fi # load corresponding library for sh scripts # . "$SDEROOT/lib/libsde.in" if [ $# -eq 0 ]; then command="help" elif [ -x "$SDEROOT/bin/sde-$1" ]; then command="$1"; shift elif grep -q "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null; then # use alias command="$( grep -l "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null | head -n 1 | sed -e 's,.*/sde-,,' )" shift else # unknown command echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood." # call help without arguments set -- command="help" fi [ -x "$SDEROOT/bin/sde-$command" ] || echo_abort 2 "Can't execute '$COLOR_INFO$SDEROOT/bin/sde-$command$COLOR_NORMAL', sorry." exec "$SDEROOT/bin/sde-$command" "$@"