ungleich-tools/openwrt/viirb-1-firmware-upgrade.sh

68 lines
1.4 KiB
Bash
Raw Normal View History

2020-06-14 21:01:16 +00:00
#!/bin/sh
# 2020-06-13, Nico Schottelius
# See https://ungleich.ch/u/products/viirb-ipv6-box/
if [ $# -ne 1 ]; then
echo "$0 address"
echo " address: connect to this address"
2020-06-14 21:01:16 +00:00
exit 1
fi
set -x
viirb_ip=$1; shift
2020-06-14 21:01:16 +00:00
# openwrt
version=19.07.7
2020-06-14 21:01:16 +00:00
filename=openwrt-${version}-ramips-mt76x8-vocore2-squashfs-sysupgrade.bin
# don't care about other/old known_host entries
ssh-keygen -R ${viirb_ip}
2020-08-01 14:21:33 +00:00
while ! ping -c1 ${viirb_ip}; do
echo "Cannot ping $viirb_ip yet - waiting"
sleep 1
done
2020-06-14 21:01:16 +00:00
cat ~/.ssh/id_rsa.pub | ssh root@${viirb_ip} "cat > /etc/dropbear/authorized_keys"
# Don't re-download if we already have it
wget -c http://downloads.openwrt.org/releases/${version}/targets/ramips/mt76x8/${filename}
if echo $viirb_ip | grep -q :; then
scp_ip="[$viirb_ip]"
else
scp_ip="$viirb_ip"
fi
2020-10-08 09:52:31 +00:00
scp ${filename} root@${scp_ip}:/tmp
ssh root@${viirb_ip} "sysupgrade -n /tmp/*.bin"
2020-06-14 21:01:16 +00:00
# It still pings for some time - wait for the reboot to happen
2020-08-01 15:08:44 +00:00
echo "Waiting for VIIRB to really disappear"
2020-06-14 21:01:16 +00:00
sleep 15
wait=0
found=""
while [ $wait -lt 180 ]; do
ping -c1 ${viirb_ip} >/dev/null
if [ $? -eq 0 ]; then
found=yes
# wait for ssh to come up
sleep 10
break
fi
sleep 1
wait=$((wait+1))
done
if [ ! "$found" ]; then
echo "Did not find updated viirb - debug / restart it"
exit 1
fi
echo "VIIRB successfully updated to ${version}"