ungleich-tools/mikrotik-update.sh
Nico Schottelius 0875392098 +mod
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
2020-10-12 18:53:48 +02:00

54 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
# Nico Schottelius, 2019-12-02
# Update mikrotik routers to the latest package
set -e
if [ $# -lt 2 ]; then
echo "$0 <version> <arch> router [router...]"
cat <<EOF
Version:
- the package version as found on https://mikrotik.com/download
Arch:
- rb4011: arm
- crs326: arm
- hapac: mipsbe
router:
- The hostname(s) or IP(v6) addresses of the routers you want to update
EOF
exit 1
fi
version=$1; shift
arch=$1; shift
file=all_packages-${arch}-${version}.zip
url=https://download.mikrotik.com/routeros/${version}/${file}
tmp=$(mktemp -d)
cd "$tmp"
wget "${url}"
unzip "${file}"
pkg_list="dhcp ipv6 lcd lte multicast ppp routing security system user-manager wireless"
while [ $# -ge 1 ]; do
target=$1; shift
# Escape literal IPv6 addresses
if echo $target | grep ':'; then
target_scp="[$target]"
else
target_scp="$target"
fi
echo "Updating ${target}"
for pkg in $pkg_list; do
scp ${pkg}-${version}-${arch}.npk "admin@${target_scp}:"
done
ssh admin@${target} "/system reboot"
done
rm -rf "${tmp}"!