# Preconfiguration file for Debian unattended installation

# Enable auto mode
d-i auto-install/enable boolean true
d-i debconf/priority select critical

# Set language, country and locale
d-i debian-installer/language string en
d-i debian-installer/country string GB
d-i debian-installer/locale string en_GB.UTF-8
d-i keyboard-configuration/xkb-keymap select us

# Set clock and timezone
d-i clock-setup/utc boolean true
d-i time/zone select Europe/London

# Skip installing recommended packages
d-i base-installer/install-recommends boolean false

# Set user and password
d-i passwd/root-login boolean false
d-i passwd/user-fullname string user
d-i passwd/username string user
d-i passwd/user-password password unsafe
d-i passwd/user-password-again password unsafe

# Disable CD-ROM and set mirror
d-i apt-setup/cdrom/set-first boolean false
d-i mirror/country string manual NO
d-i mirror/http/proxy string

# Disable mirror selection
d-i apt-setup/no_mirror boolean true
d-i popularity-contest/participate boolean false

# Skip package selection and upgrades
d-i pkgsel/run_tasksel boolean false
d-i pkgsel/upgrade select none

# Ensure the 'dbus' package is installed
d-i pkgsel/include string dbus

# Set host and domain names
d-i netcfg/get_hostname string debtest
d-i netcfg/get_domain string unassigned-domain

# Partitioning
d-i partman-auto/disk string /dev/vda
d-i partman-auto/init_automatically_partition select Guided - use entire disk
d-i partman-auto/choose_recipe select All files in one partition (recommended for new users)
d-i partman-auto/method string regular
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

# Install GRUB bootloader
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/vda
d-i grub-installer/bootloader-id string debian
d-i grub-installer/efi-directory string /boot/efi

# Handle errors automatically
d-i debian-installer/exit-on-error boolean true

# Late command to install GRUB and finalize boot setup
d-i preseed/late_command string \
    mount /dev/vda1 /target/boot/efi || true; \
    in-target mkdir -p /boot/efi/EFI/boot || true; \
    in-target grub-install --target=arm64-efi --efi-directory=/boot/efi --bootloader-id=debian --removable || true; \
    in-target update-grub || true; \
    umount /target/boot/efi || true

# Reboot after installation
d-i finish-install/reboot_in_progress note
