diff --git a/roles/routeros_firmware/files/download-routeros-firmware.sh b/roles/routeros_firmware/files/download-routeros-firmware.sh index 8f199f0..4691f9e 100644 --- a/roles/routeros_firmware/files/download-routeros-firmware.sh +++ b/roles/routeros_firmware/files/download-routeros-firmware.sh @@ -17,8 +17,19 @@ if [ $# -gt 0 ]; then exit 1 fi -packageurl="$(curl -sSf "https://mikrotik.com/download" | \ - sed -n 's/.* ].*/\1/p')" +packageinfo=$(curl -sSf "https://mikrotik.com/download" | awk -F '"' ' + { + if (!url && $0 ~ /routeros-[0-9\.]+-arm.npk/) { + url=$2 + } else if (!found && url && $0 ~ /data-checksum-sha256/) { + print url " " $6 + found = 1 + } + } + ') + +packageurl="$(echo "$packageinfo" | cut -d " " -f 1)" +checksum="$(echo "$packageinfo" | cut -d " " -f 2)" if [ -z "$packageurl" ]; then echo "ERR: Got empty package URL, exiting" 1>&2 exit 1 @@ -29,8 +40,6 @@ if [ -f "$packagename" ]; then exit 0 fi -checksum="$(curl -sSf "https://mikrotik.com/download" | \ - sed -n 's/.*routeros-[0-9\.]*-arm\.npk<\/td>.*SHA256<\/td>\(.*\)<\/td>.*/\1/p')" if [ -z "$checksum" ]; then echo "ERR: Failed to determine package checksum" 1>&2 exit 1