#================#
#INIT_USB_AUTORUN#
#================#
#===================================================================
wait_for_remove()
#===================================================================
{
# echo ${FTP}${fundstelle}${HOME_DIR}${STOP_FILE} #*#
if [ -e ${FTP}${fundstelle}${HOME_DIR}${STOP_FILE} ]
then
cp ${FTP}${fundstelle}${HOME_DIR}${STOP_FILE} /var/tmp/${STOP_FILE}
chmod +x /var/tmp/${STOP_FILE}
while [ 1 = 1 ]
do
if [ ! -e ${FTP}${fundstelle}${HOME_DIR}${START_FILE} ]
then
echo 7,2 >/var/led
sleep $SIGNAL_TIME
/var/tmp/${STOP_FILE}
echo 7,3 >/var/led
continue
fi
sleep $WAIT_TIME
#echo 7,1 >/var/led
done
echo 7,1 >/var/led
fi
}
#===================================================================
run_init()
#===================================================================
{
if [ -e "${1}" ]
then
echo 7,3 >/var/led
# echo "** Autorun found **"
# echo executing Autorun $1 #*#
$1 &
sleep $SIGNAL_TIME
echo 7,1 >/var/led
wait_for_remove
fi
}
#===================================================================
usb_autostart()
#===================================================================
{
LIMIT=0 # how many tries? 0 for unlimited
HOME_DIR=/fritzbox/start/ # directory where to find the file on the
# stick, must end with /
START_FILE=fbfautorun.sh #the file to look for
FTP=/var/media/ftp/ #location of the ftp-folder
WAIT_TIME=10 # seconds in between two tries
SIGNAL_TIME=10 #Time in s how long the INFO-LED shall blink
STOP_FILE=fbfstop.sh #will be executed when USB-Stick (/start-file
#is removed)
found_files=0
i=0;
#echo "Looking for the first autorun-file (${HOME_DIR}{$START_FILE}) on any USB-Stick partitions"
#echo "in scripts you can use the right dir of usb-stick e.g. "
#echo "cat /var/flash/debug.cfg > /var/media/ftp/\`cat /var/tmp/autorun_disk_name\`/debug.backup"
#echo "(with \`\`)"
rm /var/tmp/autorun_disk_name 2>/dev/null
while [ $found_files = 0 ]
do
#-------------------------------
for fundstelle in `ls ${FTP} 2>/dev/null`;
do
# echo ${FTP}${fundstelle}${HOME_DIR}${START_FILE} #*#
if [ -e ${FTP}${fundstelle}${HOME_DIR}${START_FILE} ];
then
if [ ${found_files} = 0 ]
then
# echo "Autorun file found on: $fundstelle" #*#
found_files=$(($found_files+1))
touch /var/tmp/autorun_disk_name
echo ${fundstelle}>/var/tmp/autorun_disk_name
#write this dir to file for script
run_init ${FTP}${fundstelle}${HOME_DIR}${START_FILE}
fi
continue
fi;
done
#--------------------------------
sleep $WAIT_TIME
i=$(($i+1))
if [ $i -gt $LIMIT ]
then
if [ ! $LIMIT -lt 1 ]
then
break
fi
fi
done
}
#===================================================================
#echo "my name:" ${0}
log="/dev/null"
#log="/var/tmp/autorun.log"
#log="/dev/tty"
echo "${log}">/var/tmp/log_file
#cat ${0}|grep -v DO_NOT_INSERT_THIS_LINE_INTO_DEBUG_CFG >/var/flash/debug.cfg ##rewrite debug.cfg
usb_autostart > $log &
#=================#
#/INIT_USB_AUTORUN#
#=================#