From 926409f676bee4ce88448a5e9e1fdb98c14012dc Mon Sep 17 00:00:00 2001 From: Ivan Susanin Date: Sun, 27 Sep 2015 22:11:56 +0300 Subject: [PATCH] Allow update over WiFi when password is set. Use as 'AUTH=user:pass ./wiflash ' --- wiflash | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wiflash b/wiflash index d8c12ea..5c33a32 100755 --- a/wiflash +++ b/wiflash @@ -25,6 +25,8 @@ Example: ${0##*/} -v esp8266 firmware/user1.bin firmware/user2.bin EOT } +[ -z "$DEBUG" ] || set -x + if ! which curl >/dev/null; then echo "ERROR: Cannot find curl: it is required for this script." >&2 exit 1 @@ -56,6 +58,8 @@ fi hostname=$1 user1=$2 user2=$3 +test -n "$AUTH" && PASSADD="-u $AUTH" + re='[-A-Za-z0-9.]+' if [[ ! "$hostname" =~ $re ]]; then @@ -79,7 +83,7 @@ fw= while true; do [[ -n "$verbose" ]] && echo "Fetching http://$hostname/flash/next" >&2 v=; [[ -n "$verbose" ]] && v=-v - next=`curl -m 10 $v -s "http://$hostname/flash/next"` + next=`curl -m 10 $v $PASSADD -s "http://$hostname/flash/next"` if [[ $? != 0 ]]; then echo "Error retrieving http://$hostname/flash/next" >&2 exit 1 @@ -102,7 +106,7 @@ done #silent=-s [[ -n "$verbose" ]] && silent= -res=`curl $silent -XPOST --data-binary "@$fw" "http://$hostname/flash/upload"` +res=`curl $silent $PASSADD -XPOST --data-binary "@$fw" "http://$hostname/flash/upload"` if [[ $? != 0 ]]; then echo "Error flashing $fw" >&2 exit 1 @@ -110,13 +114,13 @@ fi sleep 2 echo "Rebooting into new firmware" >&2 -curl -m 10 -s "http://$hostname/flash/reboot" +curl -m 10 $PASSADD -s "http://$hostname/flash/reboot" sleep 2 echo "Waiting for ESP8266 to come back" while true; do [[ -n "$verbose" ]] && echo "Fetching http://$hostname/flash/next" >&2 - next2=`curl -m 10 $v -s "http://$hostname/flash/next"` + next2=`curl -m 10 $v $PASSADD -s "http://$hostname/flash/next"` [[ -n "$verbose" ]] && echo "got: $next2" re='user[12]\.bin' if [[ "$next2" =~ $re ]]; then