#!/usr/bin/env nix-shell
#! nix-shell -i bash -p bash curl

function header {
    echo =============================================
    echo "$1"
    echo =============================================
}

function update {
    hostname=@
    domain=$1
    password=$2
    ip=$3
    base="https://dynamicdns.park-your-domain.com/update"

    if host "$domain" 1.1.1.1 | grep "has address" | grep "$ip"; then
        echo "$domain is currently set to $ip; no changes needed"
        exit
    fi
    echo updating "$domain"
    host="host=$hostname"
    domain="domain=$domain"
    password="password=$password"
    curl "$base?$host&$domain&$password&ip=$ip"
    echo
}

ip=$(curl -s -X GET https://checkip.amazonaws.com)
header "$ip"
header NAMECHEAP
update servidos.lat "$PASSSERVIDOS" "$ip"
update rotehaare.art "$PASSROTE" "$ip"
update danilo-reyes.com "$PASSDANILO" "$ip"
update wedsgk5ac2qcaf9yb.click "$PASSSECRET" "$ip"
