#!/bin/sh
# Create the jail with dhcp on
iocage create -r 14.1-RELEASE --name $1 dhcp=on boot=on

# Install mdnsd and .local DNS
iocage exec -f $1 "pkg install -y python311 openmdns && sysrc mdnsd_enable="YES" && sysrc mdnsd_flags=epair0b && service mdnsd start"

# Copy our jail public key to allow login
mkdir /tank/iocage/jails/$1/root/root/.ssh
cp /home/powellc/.ssh/jails.pub /tank/iocage/jails/$1/root/root/.ssh/authorized_keys

# Allow root login and start SSH
iocage exec -f $1 "echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && sysrc sshd_enable="YES" && service sshd start"

# Add our new IP address to our unbound local zone
#ip_address=$(iocage exec $1 ifconfig epair0b | grep 'inet ' | awk '{print $2}')
#echo 'local-data: "'$1'.service	IN	A	'$ip_address'"' >> /tank/iocage/jails/dns/root/var/unbound/service.zones
#iocage exec dns service unbound restart
