#!/bin/bash

targetdir=/srv/repos/pool/focal/zoom

newest=$(timeout 30 curl -v -s https://zoom.us/client/latest/zoom_amd64.deb 2>&1 | awk 'BEGIN {FS="/"} /location:/ {print $5}')

if [ -z "$newest" ]
then
	exit 0
fi

if [ ! -f "${targetdir}/zoom_${newest}_amd64.deb" ]
then
	wget -q -P ${targetdir} https://zoom.us/client/latest/zoom_amd64.deb
	mv ${targetdir}/zoom_amd64.deb ${targetdir}/$(bash /srv/repos/scripts/debgetrealname.bash ${targetdir}/zoom_amd64.deb)
	bash /srv/repos/scripts/update-packages focal zoom &>/dev/null
	bash /srv/repos/scripts/update-release focal &>/dev/null
fi
