#!/bin/sh -
#
# Pull down latest FreeBSD ports of the rpki.net tools, drop them into
# /usr/ports/net, and turn portmaster loose on them to do whatever
# needs doing.

# Warn users about programs we're going to need.
if ! test -x /usr/local/bin/curl -a -x /usr/local/sbin/portmaster
then
    echo 1>&2 "This script requires curl and portmaster."
    echo 1>&2 "See /usr/ports/ftp/curl and /usr/ports/ports-mgmt/portmaster."
    exit 1
fi

# Whence to fetch the port tarballs

url=https://download.rpki.net/FreeBSD_Packages

# Drop this stuff in /usr/ports/net

cd /usr/ports/net

# Download fresh copies of the ports

for port in rpki-rp rpki-ca
do
    /bin/rm -rf ${port}
    /usr/local/bin/curl --tlsv1 ${url}/${port}-port.tgz |
    /usr/bin/tar xvvf - ${port}
done

# And build whatever needs building

/usr/local/sbin/portmaster -vd --update-if-newer net/rpki-rp net/rpki-ca
