|
|
|
@ -13,7 +13,7 @@ |
|
|
|
|
|
|
|
|
|
show_help() { |
|
|
|
|
cat <<EOT |
|
|
|
|
Usage: ${0##*/} [-options...] hostname user1.bin user2.bin |
|
|
|
|
Usage: ${0##*/} [-options...] hostname user1.bin user2.bin [espfs.img] |
|
|
|
|
Flash the esp8266 running esphttpd at <hostname> with either <user1.bin> or <user2.bin> |
|
|
|
|
depending on its current state. Reboot the esp8266 after flashing and wait for it to come |
|
|
|
|
up again. |
|
|
|
@ -25,6 +25,30 @@ Example: ${0##*/} -v esp8266 firmware/user1.bin firmware/user2.bin |
|
|
|
|
EOT |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_response() { |
|
|
|
|
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"` |
|
|
|
|
[[ -n "$verbose" ]] && echo "got: $next2" |
|
|
|
|
re='user[12]\.bin' |
|
|
|
|
if [[ "$next2" =~ $re ]]; then |
|
|
|
|
if [[ "$next2" != "$next" ]]; then |
|
|
|
|
sec=$(( `date +%s` - $start )) |
|
|
|
|
echo "Success, took $sec seconds" >&2 |
|
|
|
|
break |
|
|
|
|
else |
|
|
|
|
echo "Flashing seems to have failed and it reverted to the old firmware?" >&2 |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
sleep 1 |
|
|
|
|
done |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ! which curl >/dev/null; then |
|
|
|
|
echo "ERROR: Cannot find curl: it is required for this script." >&2 |
|
|
|
|
exit 1 |
|
|
|
@ -49,13 +73,15 @@ done |
|
|
|
|
shift "$((OPTIND-1))" |
|
|
|
|
|
|
|
|
|
# Get the fixed arguments |
|
|
|
|
if [[ $# != 3 ]]; then |
|
|
|
|
# only 3 or 4 are accepted |
|
|
|
|
if [[ $# < 3 || $# > 4 ]]; then |
|
|
|
|
show_help >&2 |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
hostname=$1 |
|
|
|
|
user1=$2 |
|
|
|
|
user2=$3 |
|
|
|
|
espfs=$4 |
|
|
|
|
|
|
|
|
|
re='[-A-Za-z0-9.]+' |
|
|
|
|
if [[ ! "$hostname" =~ $re ]]; then |
|
|
|
@ -112,22 +138,29 @@ sleep 2 |
|
|
|
|
echo "Rebooting into new firmware" >&2 |
|
|
|
|
curl -m 10 -s "http://$hostname/flash/reboot" |
|
|
|
|
|
|
|
|
|
check_response |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# everything is done, if no ESP FS image file was spezified |
|
|
|
|
if [ ! "$espfs" ]; then |
|
|
|
|
exit 0 |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
if [[ ! -r "$espfs" ]]; then |
|
|
|
|
echo "ERROR: cannot read ESP FS image file ($espfs)" >&2 |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
echo "Uploading ESP FS image" >&2 |
|
|
|
|
res=`curl $silent -XPOST --data-binary "@$espfs" "http://$hostname/flash/upload"` |
|
|
|
|
if [[ $? != 0 ]]; then |
|
|
|
|
echo "Error uploading $espfs" >&2 |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"` |
|
|
|
|
[[ -n "$verbose" ]] && echo "got: $next2" |
|
|
|
|
re='user[12]\.bin' |
|
|
|
|
if [[ "$next2" =~ $re ]]; then |
|
|
|
|
if [[ "$next2" != "$next" ]]; then |
|
|
|
|
sec=$(( `date +%s` - $start )) |
|
|
|
|
echo "Success, took $sec seconds" >&2 |
|
|
|
|
exit 0 |
|
|
|
|
else |
|
|
|
|
echo "Flashing seems to have failed and it reverted to the old firmware?" >&2 |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
sleep 1 |
|
|
|
|
done |
|
|
|
|
echo "Reseting to load new ESP FS image" >&2 |
|
|
|
|
curl -m 10 -s "http://$hostname/log/reset" |
|
|
|
|
|
|
|
|
|
check_response |
|
|
|
|