#_preseed_V1
#### Contents of the preconfiguration file (for trixie)
### Localization
# Preseeding only locale sets language, country and locale.
d-i debian-installer/locale string en_US.UTF-8

# Keyboard selection.
d-i keyboard-configuration/xkb-keymap select us
# d-i keyboard-configuration/toggle select No toggling

# netcfg will choose an interface that has link if possible. This makes it
# skip displaying a list if there is more than one interface.
d-i netcfg/choose_interface select auto

# To set a different link detection timeout (default is 3 seconds).
# Values are interpreted as seconds.
d-i netcfg/link_wait_timeout string 30

# If you have a slow dhcp server and the installer times out waiting for
# it, this might be useful.
d-i netcfg/dhcp_timeout string 90
d-i netcfg/dhcpv6_timeout string 90

# Any hostname and domain names assigned from dhcp take precedence over
# values set here. However, setting the values still prevents the questions
# from being shown, even if values come from dhcp.
d-i netcfg/get_hostname string debian-1
d-i netcfg/get_domain string

# Mirror protocol:
d-i mirror/country string manual
d-i mirror/http/hostname string deb.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# Skip creation of a root account (normal user account will be able to
# use sudo).
d-i passwd/root-login boolean false

# To create a normal user account.
d-i passwd/user-fullname string vsoc 01
d-i passwd/username string vsoc-01
# Normal user's password, either in clear text
d-i passwd/user-password password cuttlefish
d-i passwd/user-password-again password cuttlefish

# Controls whether or not the hardware clock is set to UTC.
d-i clock-setup/utc boolean true

# You may set this to any valid setting for $TZ; see the contents of
# /usr/share/zoneinfo/ for valid values.
d-i time/zone string US/Eastern

# Controls whether to use NTP to set the clock during the install
d-i clock-setup/ntp boolean true

# Choose disk
d-i partman/early_command string \
  VGNAME="$(debconf-get partman-auto-lvm/new_vg_name)"; \
  NUMOFPARTITIONS=$(list-devices partition | wc -l); \
  COUNTER=0; \
  while [ "$COUNTER" -lt "$NUMOFPARTITIONS" ]; do \
    COUNTER=$((COUNTER+1)); \
    if [ "$COUNTER" -eq 1 ]; then \
      PARTITION1=$(list-devices partition|head -n1); \
    else \
      PARTITION1=$(list-devices partition|head -n$COUNTER|tail -1); \
    fi; \
    if blkid "${PARTITION1}" | grep 'LABEL="Debian arm64' | grep 'TYPE="iso9660"'; then \
      INSTALLER_PARTITION=${PARTITION1}; \
      break; \
    elif blkid "${PARTITION1}" | grep 'LABEL="ISOIMAGE"' | grep 'TYPE="iso9660"'; then \
      INSTALLER_PARTITION=${PARTITION1}; \
      break; \
    elif blkid "${PARTITION1}" | grep 'PARTLABEL="debdilnr"'; then \
      INSTALLER_PARTITION=${PARTITION1}; \
      break; \
    fi; \
  done; \
  NUMOFDISKS=$(list-devices disk | wc -l); \
  COUNTER=0; \
  while [ "$COUNTER" -lt "$NUMOFDISKS" ]; do \
    COUNTER=$((COUNTER+1)); \
    if [ "$COUNTER" -eq 1 ]; then \
      DISK1=$(list-devices disk|head -n1); \
    else \
      DISK1=$(list-devices disk|head -n$COUNTER|tail -1); \
    fi; \
    if [[ x"${INSTALLER_PARTITION}" == x"${DISK1}*" ]]; then \
      INSTALLER_DISK=${DISK1}; \
      break; \
    fi; \
  done; \
  NUMOFLV=$(lvdisplay -C -o lv_path --readonly | wc -l); \
  LVS=$(lvdisplay -C -o lv_path --readonly); \
  for LV1 in ${LVS}; do \
    if [ x"${LV1}" = x"Path" ]; then \
      continue; \
    fi; \
    lvremove "${LV1}" -f -y; \
  done; \
  NUMOFVG=$(vgdisplay -C -o vg_name --readonly | wc -l); \
  VGS=$(vgdisplay -C -o vg_name --readonly); \
  for VG1 in ${VGS}; do \
    if [ x"${VG1}" = x"VG" ]; then \
      continue; \
    fi; \
    vgremove "${VG1}" -f -y; \
  done; \
  NUMOFPV=$(pvdisplay -C -o pv_name --readonly | wc -l); \
  PVS=$(pvdisplay -C -o pv_name --readonly); \
  for PV1 in ${PVS}; do \
    if [ x"${PV1}" = x"PV" ]; then \
      continue; \
    fi; \
    if [[ x"${PV1}" == x"${INSTALLER_DISK}*" ]]; then \
      continue; \
    fi; \
    pvremove "${PV1}" -f -y; \
  done; \
  NUMOFDISKS=$(list-devices disk | wc -l); \
  for DISK2 in "/dev/nvme0n1" "/dev/sda" "/dev/vda"; do \
    if [ x"${DISK2}" = x"${INSTALLER_DISK}" ]; then \
      continue; \
    fi; \
    COUNTER=0; \
    FOUNDFLAG=0; \
    while [ "$COUNTER" -lt "$NUMOFDISKS" ]; do \
      COUNTER=$((COUNTER+1)); \
      if [ "$COUNTER" -eq 1 ]; then \
        DISK1=$(list-devices disk|head -n1); \
      else \
        DISK1=$(list-devices disk|head -n$COUNTER|tail -1); \
      fi; \
      if [ x"${DISK1}" = x"${DISK2}" ]; then \
        FOUNDFLAG=1; \
        break; \
      fi; \
    done; \
    if [ "${FOUNDFLAG}" -eq 1 ]; then \
      MAIN_DISK="${DISK2}"; \
      break; \
    fi; \
  done; \
  COUNTER=0; \
  if [ x"$MAIN_DISK" != x ]; then \
    FINAL_DISKS="$MAIN_DISK"; \
  fi; \
  if [ x"$MAIN_DISK" != x ]; then \
    RECIPE_PART1="$(debconf-get partman-auto/expert_recipe_linaro_lvm_nopv)"; \
    FINAL_RECIPE="${RECIPE_PART1} 4096 8192 1000000000 \$default_filesystem \$defaultignore{ } \$primary{ } method{ lvm } device{ ${MAIN_DISK} } vg_name{ ${VGNAME} } ."; \
  fi; \
  if [ x"$MAIN_DISK" != x ]; then \
    COUNTER=0; \
    while [ "$COUNTER" -lt "$NUMOFDISKS" ]; do \
      COUNTER=$((COUNTER+1)); \
      if [ "$COUNTER" -eq 1 ]; then \
        DISK1=$(list-devices disk|head -n1); \
      else \
        DISK1=$(list-devices disk|head -n$COUNTER|tail -1); \
      fi; \
      if [ x"$DISK1" = x"$MAIN_DISK" ]; then \
        continue; \
      elif [ x"$DISK1" = x"$INSTALLER_DISK" ]; then \
        continue; \
      elif [[ x"$DISK1" == x"/dev/nvme*" ]]; then \
        FINAL_DISKS="${FINAL_DISKS} ${DISK1}"; \
        FINAL_RECIPE="${FINAL_RECIPE} 128 8192 1000000000 \$default_filesystem \$defaultignore{ } \$primary{ } method{ lvm } device{ ${DISK1} } vg_name{ ${VGNAME} } ."; \
      elif [[ x"$DISK1" == x"/dev/vd*" ]]; then \
        FINAL_DISKS="${FINAL_DISKS} ${DISK1}"; \
        FINAL_RECIPE="${FINAL_RECIPE} 128 8192 1000000000 \$default_filesystem \$defaultignore{ } \$primary{ } method{ lvm } device{ ${DISK1} } vg_name{ ${VGNAME} } ."; \
      fi; \
    done; \
  fi; \
  if [ x"$FINAL_DISKS" != x ]; then \
    debconf-set partman-auto/disk "$FINAL_DISKS"; \
  fi; \
  if [ x"$FINAL_RECIPE" != x ]; then \
    debconf-set partman-auto/expert_recipe "${FINAL_RECIPE}"; \
  fi;

# Set the disk to install. If not set, select Guided -> select device.
#d-i partman-auto/disk string /dev/vda
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/device_remove_lvm_span boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-auto-lvm/new_vg_name string vglinarogigamprootfs
d-i partman/alignment string "optimal"
d-i partman-auto-lvm/guided_size string max
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true

d-i partman-auto/expert_recipe_linaro_lvm_nopv string         \
      linaroefiroot ::                                        \
              128 256 512 fat32                               \
                      $iflabel{ gpt }                         \
                      $primary{ }                             \
                      $reusemethod{ }                         \
                      method{ efi } format{ }                 \
                      label { esp }                           \
              .                                               \
              512 2048 4096 ext4                              \
                      $primary{ }                             \
                      $bootable{ }                            \
                      method{ format }                        \
                      format{ }                               \
                      use_filesystem{ }                       \
                      filesystem{ ext4 }                      \
                      mountpoint{ /boot }                     \
              .                                               \
              4096 8192 -1 ext4                               \
                      $lvmok{}                                \
                      lv_name{ lvlinarogigamprootfs }         \
                      in_vg{ vglinarogigamprootfs }           \
                      method{ format } format{ }              \
                      use_filesystem{ }                       \
                      filesystem{ ext4 }                      \
                      mountpoint{ / }                         \
              .

d-i partman-auto/expert_recipe_linaro_root string             \
      linaroefiroot ::                                        \
              128 256 512 fat32                               \
                      $iflabel{ gpt }                         \
                      $reusemethod{ }                         \
                      method{ efi } format{ }                 \
              .                                               \
              4096 8192 1000000000 ext4                       \
                      method{ format } format{ }              \
                      use_filesystem{ }                       \
                      filesystem{ ext4 }                      \
                      mountpoint{ / }                         \
              .

d-i partman-auto/expert_recipe_linaro_home_format string      \
      linaroefiroot ::                                        \
              128 256 512 fat32                               \
                      $iflabel{ gpt }                         \
                      $reusemethod{ }                         \
                      method{ efi } format{ }                 \
              .                                               \
              8192 71680 143360 ext4                          \
                      method{ format } format{ }              \
                      use_filesystem{ }                       \
                      filesystem{ ext4 }                      \
                      mountpoint{ / }                         \
              .                                               \
              4096 71680 1000000000 ext4                      \
                      method{ format } format{ }              \
                      use_filesystem{ }                       \
                      filesystem{ ext4 }                      \
                      mountpoint{ /home }                     \
              .

d-i partman-auto/expert_recipe_linaro_home string             \
      linaroefiroot ::                                        \
              128 256 512 fat32                               \
                      $iflabel{ gpt }                         \
                      $reusemethod{ }                         \
                      method{ efi } format{ }                 \
              .                                               \
              8192 71680 143360 ext4                          \
                      method{ format } format{ }              \
                      use_filesystem{ }                       \
                      filesystem{ ext4 }                      \
                      mountpoint{ / }                         \
              .                                               \
              4096 71680 1000000000 ext4                      \
                      method{ keep }                          \
                      use_filesystem{ }                       \
                      filesystem{ ext4 }                      \
                      mountpoint{ /home }                     \
              .

# 
d-i partman-auto/choose_recipe select linaroefiroot
d-i partman-basicfilesystems/no_swap boolean false

# Don't punt for no-method filesystems.  Another undocumented option.
d-i partman-basicmethods/method_only boolean false

# This makes partman automatically partition without confirmation, provided
# that you told it what to do using one of the methods above.
d-i partman-partitioning/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

# Force UEFI booting ('BIOS compatibility' will be lost). Default: false.
d-i partman-efi/non_efi_system boolean true

# Ensure the partition table is GPT - this is required for EFI
d-i partman-partitioning/choose_label select gpt
d-i partman-partitioning/default_label string gpt

# Choose, if you want to scan additional installation media
# (default: false).
d-i apt-setup/cdrom/set-first boolean false
# Backport selection
# d-i apt-setup/services-select multiselect backports
# You can choose to install non-free firmware.
d-i apt-setup/non-free-firmware boolean true
# You can choose to install non-free and contrib software.
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true

tasksel tasksel/first multiselect standard, ssh-server

popularity-contest popularity-contest/participate boolean false

grub-efi-arm64 grub2/linux_cmdline_default string quiet amdgpu.runpm=0 amdgpu.dc=0

# This is fairly safe to set, it makes grub install automatically to the UEFI
# partition/boot record if no other operating system is detected on the machine.
d-i grub-installer/only_debian boolean true
d-i grub-installer/force-efi-extra-removable boolean true
d-i grub-installer/update-nvram boolean false

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note

d-i preseed/late_command string \
  mkdir -p /target/root/debian-snapshot && \
  cp -f /debian-snapshot.list /target/root/debian-snapshot/ && \
  cp -f /after_install_1.sh /target/root && \
  in-target /bin/sh /root/after_install_1.sh;

