

# Get the disk layout, and the first disk connected to the system
disk_layout=`/sbin/sysctl -n kern.disks | /usr/bin/sed 's/cd[0-9]//g'`
first_disk="`echo ${disk_layout##*[1-9]} | /usr/bin/cut -d' ' -f1`"
test -z "$first_disk" || echo "First disk: $first_disk"

/root/bin/destroygeom -d $first_disk || exit 1
/root/bin/zfsinstall -d $first_disk -s 2G -u url --url http://mirror.centos.org/centos/7/os/x86_64 || exit 1

cp /etc/resolv.conf /mnt/etc/resolv.conf
mount -t devfs devfs /mnt/dev
fetch -q --no-verify-hostname --no-verify-peer -o /mnt/tmp/finish.sh -d http://foreman.example.com/unattended/finish
chroot /mnt /bin/sh /tmp/finish.sh
rm /mnt/tmp/finish.sh

fetch -q --no-verify-hostname --no-verify-peer -o /dev/null -d http://foreman.example.com/unattended/built
sleep 5
reboot
