#!/bin/sh
# -*- mode: sh; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-

ROLE=toxcore
prog=$(basename $0 .bash)

KEY=0x066DAFCB81E42C40
TIMEO=15
WARGS="-v -S --dns-timeout $TIMEO --connect-timeout $TIMEO --read-timeout $TIMEO"

. /usr/local/bin/proxy_export.bash

if [ is = dead ] ; then
# URL="http://hkps.pool.sks-keyservers.net:80/pks/lookup?op=get&options=mr&search=$KEY"
URL="http://pgp.mit.edu:80/pks/lookup?op=get&options=mr&search=$KEY"
DBUG wget $URL
wget $WARGS  -o /tmp/2$$.log -O /tmp/2$$.html $URL || {
    ERROR retval=$? ; cat /tmp/2$$.log; exit 2 ;
}
grep -q -e '-----BEGIN PGP PUBLIC KEY BLOCK' /tmp/2$$.html || exit 210
grep -q 'HTTP/1.1 200 OK' /tmp/2$$.log || exit 220
fi

URL="http://keyserver.ubuntu.com:80/pks/lookup?op=get&options=mr&search=$KEY"
DBUG wget $URL
wget $WARGS  -o /tmp/3$$.log -O /tmp/3$$.html $URL || {
    ERROR retval=$? /tmp/3$$.log
    exit 3
}
grep -q -e '-----BEGIN PGP PUBLIC KEY BLOCK' /tmp/3$$.html || {
    ERROR  '-----BEGIN PGP PUBLIC KEY BLOCK' /tmp/3$$.html
    exit 310
}
grep -q 'HTTP/1.1 200 OK' /tmp/3$$.log || {
    ERROR NO 'HTTP/1.1 200 OK' /tmp/3$$.log 
    exit 320
}

exit 0
