#!/bin/bash
echo "=============================="
echo $1
echo $2
echo $3
echo $4
echo $5

echo 'Change DNS resolving in unbound'

splitip () {
    local IFS
    IFS=.
    set -- $*
    echo "ec2-$1-$2-$3-$4.compute-1.amazonaws.com"
}

DNS_ADDR=$(splitip $1)

sudo sed -i "2i\\\tlocal-zone: \"$DNS_ADDR\" static" /etc/unbound/unbound.conf
sudo sed -i "3i\\\tlocal-data: \"$DNS_ADDR A $4\"" /etc/unbound/unbound.conf

sudo /etc/init.d/unbound restart