# ==============================================================================
# FreeBSD bsdinstall Scripting Configuration
# ==============================================================================

# 1. System & Partitioning Defaults
KEYMAP="us.kbd"
HOSTNAME="freebsd"
DISTRIBUTIONS="kernel.txz base.txz"

# Guided ZFS Installation Parameters
ZFSBOOT_DISKS="da0"
ZFSBOOT_VDEV_TYPE="stripe"
ZFSBOOT_CONFIRM_POOL_CREATE="YES"

# Timezone Configuration (US/Eastern)
TIMEZONE="America/New_York"

# Enabling Services (local_unbound, sshd, etc.)
# Maps to your service choices during setup
bsdinstall_services="sshd local_unbound"


# ==============================================================================
# Post-Installation Shell Script (Runs automatically in chroot)
# ==============================================================================
#!/bin/sh

# Network configuration for the installed system
echo 'ifconfig_DEFAULT="DHCP"' >> /etc/rc.conf

# Set Root Password ('packer')
echo "packer" | pw usermod root -h 0

# Create 'xadmin' user in 'wheel' group with password 'packer'
echo "packer" | pw useradd xadmin \
  -c "Remote admin user" \
  -g wheel \
  -m \
  -s /bin/sh \
  -h 0

# Install Packages (qemu-guest-agent, sudo)
# ASSUMPTION: The system has internet access during post-install
env ASSUME_ALWAYS_YES=YES pkg install -y qemu-guest-agent sudo

# Sudoers configuration for xadmin
mkdir -p /usr/local/etc/sudoers.d
echo 'xadmin ALL=(ALL:ALL) NOPASSWD:ALL' > /usr/local/etc/sudoers.d/xadmin
chmod 0440 /usr/local/etc/sudoers.d/xadmin

# Enable QEMU Guest Agent service
sysrc qemu_guest_agent_enable="YES"

# Finalize and reboot system
reboot