TFTP upload script with menu

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload
Author Message
inetquestion
DD-WRT Novice


Joined: 24 Sep 2015
Posts: 20

PostPosted: Thu Jun 25, 2020 14:51    Post subject: TFTP upload script with menu Reply with quote
Used this on a Mac, should be portable across multiple *nix flavors. Looks like the spacing gets garbled, when posting within CODE blocks. Should still work...

-Inet



[code]
#!/bin/ksh

##############################
## CONFIG
##############################

FILE=$1
HOST=192.168.1.1
CONFIG="binary\nrexmt 1\ntimeout 60\ntrace\nput"
CONFIG="binary\nrexmt 1\ntimeout 60\nput"

##############################
## Subroutine
##############################

doUsage()
{
clear
cat <<EOM
Displays a menu of firmware files to be uploaded via TFTP to a router.
The computer must be on the same network as the router: ($HOST).

Usage: $0
$0 [<firmware filename>]

Running the script with no arguments shows a menu of available files for
use. Optionally passing the firmware filename as an argument skips the
menu altogether.

As soon as this script is able to successfully ping the router, TFTP of
the selected firmware will begin.

<ENTER> to continue...

EOM
}

doListChoices()
{
clear
set -A ARRAY `ls $1`
echo "Showing firmware files of type: $*"
echo
i=0
for item in ${ARRAY[*]};
do
i=$((i=$i+1))
echo "$i) `basename $item`"
done
echo "h) help"
echo "x) exit"
}


doChooseFile()
{
until [[ -r ${ARRAY[$file]} && $selection -gt 0 && $selection -le ${#ARRAY[*]} ]];do
FILE=""; file=""
doListChoices '*.bin *.trx *.SSA'
print -n "\nChoose file to upload: "
read selection
if [[ $selection = *([0-9]) ]]; then
if [[ $selection -gt 0 ]]; then
file=$(($selection-1))
fi
FILE="${ARRAY[$file]}"
elif [[ $selection == "h" ]]; then
doUsage
selection=""
read
elif [[ $selection == "x" ]]; then
break
else
selection=""
fi
done
}

##############################
## Main
##############################

if [[ ! -r $FILE ]]; then
doChooseFile
fi

RC=1
if [[ -r $FILE ]]; then
until [[ $RC -eq 0 ]]; do
ping -c 1 -t 1 ${HOST} >/dev/null 2>&1
RC=$?
echo "Waiting for host: ${HOST} ..."
sleep 1
done

echo "********* Startign TFTP *********"
echo -e "${CONFIG} ${FILE}\n" | tftp ${HOST}
else
echo
fi
[/code]
Sponsor
inetquestion
DD-WRT Novice


Joined: 24 Sep 2015
Posts: 20

PostPosted: Thu Jun 25, 2020 15:00    Post subject: Reply with quote
attaching script...
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum