#cloud-config
autoinstall:
  # version is an Autoinstall required field.
  version: 1

  # This adds the default ubuntu-desktop packages to the system.
  # Any desired additional packages may also be listed here.
  packages:
    - ubuntu-desktop
    #- plymouth-theme-ubuntu-logo
    #- grub-gfxpayload-lists
    #- gnome-shell-extensions
    #- adwaita-icon-theme-full

  #proxy: http://store00.science.uoit.ca:3142
  shutdown: poweroff
  apt:
    preserve_sources_list: false
    mirror-selection:
      primary:
        - uri: http://mirror.science.uoit.ca/ubuntu/
        #- uri: http://199.212.32.27/ubuntu/

  # This adds the default snaps found on a 22.04 Ubuntu Desktop system.
  # Any desired additional snaps may also be listed here.
  snaps:
    - name: firefox
    #- name: gnome-3-38-2004
    #- name: gtk-common-themes
    - name: snap-store
    - name: snapd-desktop-integration
    - name: slack
    - name: spotify
    - name: code
      classic: true

  ssh:
    allow-pw: true
    install-server: true

  refresh-installer:
    update: yes

  locale: en_CA.UTF8
  timezone: America/Toronto
  updates: all

  codecs:
    install: yes

  drivers:
    install: yes

  # User creation can occur in one of 3 ways:
  # 1. Create a user using this `identity` section.
  # 2. Create users as documented in cloud-init inside the user-data section,
  #    which means this single-user identity section may be removed.
  # 3. Prompt for user configuration on first boot.  Remove this identity
  #    section and see the "Installation without a default user" section.
  identity:
    realname: 'Science Administrator'
    username: science
    # A password hash is needed. `mkpasswd --method=SHA-512` can help.
    # mkpasswd can be found in the package 'whois'
    password: '$5$CCOAg23FpFu6zLTR$IdcNjm1BErAfFEIm7Rf18rdLcr.nZy0m5wpRn5zCtC5'
    hostname: mcs11

  # Default to LVM on an SSD
  storage:
    version: 1
    config:
      #- {type: disk, ptable: gpt, match: {ssd: yes}, wipe: superblock-recursive, preserve: false, id: disk-sda}
      - {type: disk, ptable: gpt, match: {largest: yes}, wipe: superblock-recursive, preserve: false, id: disk-sda}
      - {type: partition, number: 1, flag: boot, size: 1G, device: disk-sda, id: part-sda1, grub_device: true, offset 1048576, partition_type: c12a7328-f81f-11d2-ba4b-00a0c93ec93b}
      - {type: format, fstype: vfat, label: ESP, volume: part-sda1, id: format-part-sda1}
      - {type: mount, device: format-part-sda1, path: /boot/efi, id: mount-part-sda1}
      - {type: partition, number: 2, flag: linux, size: -1, device: disk-sda, id: part-sda2}
      - {type: lvm_volgroup, name: vg0, devices: [part-sda2], id: lvm-volgroup-vg0}
      - {type: lvm_partition, volgroup: lvm-volgroup-vg0, name: root, size: 100G, id: lvm-part-lvroot}
      - {type: format, fstype: ext4, volume: lvm-part-lvroot, id: format-root}
      - {type: mount, device: format-root, path: /, id: mount-root}
      - {type: lvm_partition, volgroup: lvm-volgroup-vg0, name: home, size: -1, id: lvm-part-lvhome}
      - {type: format, fstype: ext4, volume: lvm-part-lvhome, id: format-home}
      - {type: mount, device: format-home, path: /home, id: mount-home}
      #- {id: disk-sda, type: disk, ptable: gpt, match: {ssd: yes}, wipe: superblock-recursive, preserve: false}
      #- {id: part-sda1, type: partition, size: 1G, device: disk-sda, grub_device: true, flag: boot, offset: 1048576, number: 1, partition_type: c12a7328-f81f-11d2-ba4b-00a0c93ec93b}
      #- {id: format-part-sda1, type: format, fstype: vfat, label: ESP, volume: part-sda1}
      #- {id: mount-part-sda1, type: mount, device: format-part-sda1, path: /boot/efi}
      #- {id: part-sda2, type: partition, size: -1, device: disk-sda, flag: linux, number: 2}
      #- {id: lvm-volgroup-vg0, name: vg0, type: lvm_volgroup, devices: [part-sda2]}
      #- {id: lvm-part-lvroot, type: lvm_partition, name: root, size: 100G, volgroup: lvm-volgroup-vg0}
      #- {id: format-root, type: format, fstype: ext4, volume: lvm-part-lvroot, preserve: false}
      #- {id: mount-root, type: mount, device: format-root, path: /}
      #- {id: lvm-part-lvhome, type: lvm_partition, name: home, size: -1, volgroup: lvm-volgroup-vg0}
      #- {id: format-home, type: format, fstype: ext4, volume: lvm-part-lvhome}
      #- {id: mount-home, type: mount, device: format-home, path: /home}

  # Ubuntu Desktop uses the hwe flavor kernel by default.
  early-commands:
    - echo 'linux-generic-hwe-22.04' > /run/kernel-meta-package

  # The live-server ISO does not contain some of the required packages,
  # such as ubuntu-desktop or the hwe kernel (or most of their depdendencies).
  # The system being installed will need some sort of apt access.
  # proxy: http://192.168.0.1:3142

  late-commands:
    # Enable the boot splash
    - >-
      curtin in-target --
      sed -i /etc/default/grub -e
      's/GRUB_CMDLINE_LINUX_DEFAULT=".*/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/'
    # Disable GRUB menu (RECORDFAIL method required for EFI with LVM layouts)
    # https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1918736
    - >-
      curtin in-target --
      sed -i /etc/default/grub -e
      '9aGRUB_RECORDFAIL_TIMEOUT=0'
    - curtin in-target -- update-grub
    # - curtin in-target --target=/target -- sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT=""/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/' /etc/default/grub

    # Let NetworkManager handle network
    - rm /target/etc/netplan/00-installer-config*yaml
    - >-
      printf "network:\n  version: 2\n  renderer: NetworkManager"
      > /target/etc/netplan/01-network-manager-all.yaml

    # Remove other packages present by default in Ubuntu Server but not
    # normally present in Ubuntu Desktop.
    #- >-
    #  curtin in-target -- apt-get remove -y mdadm
    #  ubuntu-server ubuntu-server-minimal binutils byobu dmeventd finalrd gawk
    #  kpartx open-iscsi sg3-utils ssh-import-id sosreport screen open-vm-tools
    #  lxd-agent-loader landscape-common fonts-ubuntu-console

    # Keep cloud-init, as it performs some of the installation on first boot.
    #- curtin in-target -- apt-get install -y cloud-init

    # Finally, remove things only installed as dependencies of other things
    # we have already removed.
    - curtin in-target -- apt-get autoremove -y

    # A postinstall script may optionally be used for further install
    # customization. Deploy this postinstall.sh script on the webserver.
    # - wget -O /target/postinstall.sh http://192.168.0.2/postinstall.sh
    # - curtin in-target -- bash /postinstall.sh
    # - rm /target/postinstall.sh

  # Additional cloud-init configuration affecting the target
  # system can be supplied underneath a user-data section inside of
  # autoinstall.
  # user-data:
  #   …
