#!/bin/sh #------------------------------------------------------------------------------ # /opt/etc/usb.startup # By Francesco Luminaria - http://www.luminaria.cc # # V. 1.1 - 2011/02/01 # - Moved file from /opt to /opt/etc # - Run only executable "startup" and "stop" scripts # # Based on the standard dd-wrt startup script for Samba3 # from the "Kong Mod" for Netgear WNR3500L # # startup script for dd-wrt on Netgear WNR3500L #------------------------------------------------------------------------------ # turn the WPS light ON gpio enable 1 # set path to include optware binaries echo "export PATH=$PATH:/opt/bin:/opt/sbin" > /tmp/root/.profile export PATH=$PATH:/opt/bin:/opt/sbin # run optware startup scripts for I in `/bin/ls /opt/etc/config/*.startup` do if [ -x "$I" ]; then sh $I fi done # check if temp config directory exists or create it if [ ! -d /tmp/etc/config ]; then mkdir -p /tmp/etc/config fi # create the usbunplug.sesbutton script in /tmp/etc/config USB_OFF=$( cat </dev/null if [ "\$?" -eq "0" ]; then # mounted return 1 else # not mounted return 0 fi } echo "creating lock file..." # check if the same script is already running if [ -e /tmp/unplug_ses_running ]; then exit fi touch /tmp/unplug_ses_running echo "stopping optware services..." # run optware stop scripts for I in \`/bin/ls /opt/etc/config/*.stop\` do if [ -x "\$I" ]; then echo "stopping \$I" sh \$I _blink 2 fi done _blink 5 check_opt='/opt' test_opt=1 check_mnt='/mnt' test_mnt=1 retries=1 while [ \$retries -le 10 ] do echo "unmount loop n. \$retries" _blink 2 echo "unmounting /mnt" umount /mnt echo "unmounting /opt" umount -rl /opt _blink 5 _check \$check_opt test_opt=\$? _check \$check_mnt test_mnt=\$? if [ "\$test_opt" -eq "1" ]; then # /opt is still mounted echo "/opt still mounted" _blink 3 retries=\`expr \$retries + 1\` elif [ "\$test_mnt" -eq "1" ]; then # /mnt is still mounted echo "/mnt still mounted" _blink 3 retries=\`expr \$retries + 1\` else # everything is unmounted echo "unmount finished" _blink 3 gpio disable 1 echo "removing lock file" rm /tmp/unplug_ses_running echo "end" # end the script exit fi _blink 5 done # usb unmount failed echo "usb unmount failed" gpio enable 1 echo "removing lock file" rm /tmp/unplug_ses_running echo "end" EOF ) echo "$USB_OFF" > /tmp/etc/config/usbunplug.sesbutton # sesbutton script must be executable by everyone chmod 777 /tmp/etc/config/usbunplug.sesbutton