#!/bin/sh

set -eu

retry() {
    for i in 1 2 3; do
        if "$@"; then
            return 0
        else
            echo "try again: $i"
            sleep 0.5
        fi
    done
    return 1
}
. config/chroot_local-includes/etc/default/htpdate.pools
err=0
for url in $(echo "$HTP_POOL_1" "$HTP_POOL_2" "$HTP_POOL_3" | tr ',' ' ')
do
    echo "$url"
    if ! retry ./https-get-expired -reject-expired "https://$url"; then
        echo "ERROR on $url"
        err=1
    fi
done
exit $err
