# chk_t.sh
# Usage: sh chk_t.sh
# http://sourceforge.jp/projects/aalaya
# $Id: chk_t.sh,v 1.1 2010/09/26 15:13:18 nakamkaz Exp $

TARGET=$1

CMDS='
sh
sed
which
chmod
'
for command in ${CMDS}
do
WHICH=`which $command`
if [ $? == 0 ]
then
echo "  ${WHICH} .. OK"
else 
echo "  $command is required. bye"
exit 1
fi
done

if [ ! -z ${TARGET} ]
then
USESH=`which sh` 
USESHB=`echo ${USESH} | sed s/\\\//@@@/g`
  if [ ! -e ${TARGET} -a ! -e ${TARGET}.def ]
  then
    sed s/__SHELL__/${USESHB}/ ${TARGET}.def | sed s/@@@/\\\//g >  ${TARGET}
    chmod u+x ${TARGET}
    ${USESH} ${TARGET} 

    echo "[OK] script successfully"
    exit 0
  else 
    echo "FAILED:"
    echo "${TARGET}.def exists? if it exists,"
    echo "please specify not ${TARGET}.def but ${TARGET}, without suffix .def"
    exit 1
  fi
fi 
