#!/bin/bash -l

gen_etc_hosts() {
	host=$(cat /etc/hostname)
	echo 127.0.0.1 localhost $host $host.local type type.local help help.local
	echo 192.168.1.1 server server.local control control.local
	echo 138.68.125.63 bastion artix.techlitafrica.org
	echo

	(
		cd "/srv/secure/hosts"
		for name in *; do
			ipv4=$(grep ipv4 "$name" | cut -d' ' -f2)
			echo $ipv4 $name $name.local
		done
	)
}

HOSTS="$(mktemp)"
gen_etc_hosts > "$HOSTS"
sudo cp "$HOSTS" "/etc/hosts"
