From e349ee449e5cf8a625a332e23426628f5343e9f9 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 21 Dec 2020 19:55:04 +0100 Subject: [PATCH] [vigir] add firmware update script --- openwrt/vigir-1-firmware-upgrade.sh | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 openwrt/vigir-1-firmware-upgrade.sh diff --git a/openwrt/vigir-1-firmware-upgrade.sh b/openwrt/vigir-1-firmware-upgrade.sh new file mode 100755 index 0000000..e192bc9 --- /dev/null +++ b/openwrt/vigir-1-firmware-upgrade.sh @@ -0,0 +1,85 @@ +#!/bin/sh +# 2020-06-13, Nico Schottelius +# See https://ungleich.ch/u/products/viirb-ipv6-box/ + +if [ $# -lt 1 ]; then + echo "$0 interface [address]" + echo " interface to add the config ip address to" + echo " address: connect to this address, ignore the interface" + exit 1 +fi + +set -x +dev=$1; shift + +# $# = 2 +# shift -> remove the first argument +# $# = 1 + +if [ $# -ge 1 ]; then + vigir_ip=$1; shift + dev="" +else + vigir_ip=192.168.8.1 +fi + +# openwrt +version=19.07.5 +filename=openwrt-${version}-ramips-mt7621-zbt-wg3526-16M-squashfs-sysupgrade.bin + +# IP address for setting it up initially + +if [ "$dev" ]; then + sudo ip addr del 192.168.8.2/24 dev "$dev" 2>/dev/null || true + sudo ip addr add 192.168.8.2/24 dev "$dev" +fi + +# don't care about other/old known_host entries +ssh-keygen -R ${vigir_ip} + +while ! ping -c1 ${vigir_ip}; do + echo "Cannot ping $vigir_ip yet - waiting" + sleep 1 +done + +cat ~/.ssh/id_rsa.pub | ssh root@${vigir_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/mt7621/${filename} + +if echo $vigir_ip | grep -q :; then + scp_ip="[$vigir_ip]" +else + scp_ip="$vigir_ip" +fi + +scp ${filename} root@${scp_ip}:/tmp +ssh root@${vigir_ip} "sysupgrade -n /tmp/*.bin" + +# It still pings for some time - wait for the reboot to happen +echo "Waiting for vigir to really disappear" +sleep 15 + +wait=0 +found="" + +while [ $wait -lt 180 ]; do + ping -c1 ${vigir_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 vigir - debug / restart it" + exit 1 +fi + +echo "vigir successfully updated to ${version}"