Improve syncrepo-template.sh to allow rsync for lastupdate check
As suggested in https://bugs.archlinux.org/task/71617. I'm transferring the suggestion here as it's more relevant to keep track of the code changes via GitLab issues.
It also allows tagging the change to a recorded issue here.
https://gitlab.archlinux.org/archlinux/infrastructure/-/blob/master/roles/syncrepo/files/syncrepo-template.sh currently requires a http/https URL to enable lastupdate awareness.
Nikke suggests to enhance the script to allow using rsync to check lastupdate freshness.
With a reasonably modern rsync, this is IMHO easiest done with something similar to:
needupd="$(rsync -n -R -t --no-motd --out-format='%n' --timeout=60 rsync://source.site/lastupdate /destination/dir/)"
if [ $? = 0 -a -z "$needupd" ]; then
echo "Up 2 date, only rsync lastsync"
else
echo "Need update, do full rsync"
fi
Granted, it doesn't do the full compare of the lastupdate content, but it's good enough as a freshness check in the general use case.
With this addition, the script would work out of the box by only supplying it with an rsync URL making setup easier for mirror admins, and removes the requirement that the master site provides lastupdate via http/https. While the latter might not be stricly needed as the Arch Linux master provides it via http(s), it might help lastupdate/lastsync adoption by other projects which would be a Good Thing for us mirror admins.