#!/bin/sh
VERSION=251218
SCRIPT=$(readlink -f $0)
SCRIPTNAME=$(basename $SCRIPT)
SCRIPTDIR=$(dirname $SCRIPT)
if [ "$1" = "-v" ] ; then echo "$VERSION $SCRIPTNAME $SCRIPTDIR";exit 0; fi
if [ -e "$SCRIPTDIR/esc.sh" ] ; then . "$SCRIPTDIR/esc.sh"; fi
LOG=$LOGDIR/log-$SCRIPTNAME.log

# boot autostart control file
bac=/etc/rc.local.d/esc.sh

if [ "$1" == "edit" ] ; then
        vi $bac
        exit
fi

if [ ! -e "$bac" ] ; then
        touch $bac
        echo "#!/bin/sh">>$bac
        chmod +x $bac
        echo "$ts $SCRIPTNAME created boot autostart control file:$bac" | tee -a $LOG
fi

if [ -e "$bac" ] ; then
        echo -n "$ts $SCRIPTNAME call:$@ state:" | tee -a $LOG
        grep "$@" $bac
        if [ $? == 0 ] ; then
                echo "exists" | tee -a $LOG
        else
                echo "added" | tee -a $LOG
                echo "$@" >> $bac
        fi
else
        echo "autostart-file:$bac could not be created" | tee -a $LOG
fi

