#!/bin/bash

SRV="${1:?Need a current server fqdn}"
ZONE="linuxforward.com"
TTL=1800

SRV_IP=$( host "${SRV}" | awk '!/:/ { print $NF }' )
SUB_DOMAIN_1="$( awk '$0 ~ /^\w{5}$/ { print tolower($1) }' /usr/share/dict/words | sort -n | uniq | shuf -n 1 )"
SUB_DOMAIN_2="$( awk '$0 ~ /^\w{5}$/ { print tolower($1) }' /usr/share/dict/words | sort -n | uniq | shuf -n 1 )"

HTTP_PAYLOAD='{ "fieldType": "A", "subDomain": "'${SUB_DOMAIN_1}-${SUB_DOMAIN_2}'", "target": "'${SRV_IP}'", "ttl": '${TTL}' }'

./ovh-bash post "domain/zone/${ZONE}/record" "${HTTP_PAYLOAD}"

exit $?
