requires:
- name: "{{.Values.name}}"
  category: "distro-kernels"
  version: ">=0"

copy:
# The toolkit is required in module-setup and embedded in the initramfs. 
- package:
    category: "system"
    name: "kairos-agent"
    version: ">=0"
  source: "/usr/bin/kairos-agent"
  destination: "/usr/bin/kairos-agent"
- package:
    category: "system"
    name: "immucore"
    version: ">=0"
  source: "/usr/bin/immucore"
  destination: "/usr/bin/immucore"
- package: 
    category: "dracut"
    name: "immucore"
    version: ">=0"
  source: "/package/."
  destination: "/"
{{ if or ( eq .Values.name "opensuse" ) }}
- package: 
    category: "dracut"
    name: "sysext"
    version: ">=0"
  source: "/package/."
  destination: "/"
{{ end }}
#{{ if and ( ne .Values.name "ubuntu-20-lts" ) ( ne .Values.name "ubuntu" ) ( ne .Values.name "ubuntu-22-lts" ) }}
#- package: 
#    category: "dracut"
#    name: "systemd-resolved"
#    version: ">=0"
#  source: "/package/."
#  destination: "/"
#{{ end }}

# Use network-legacy until https://github.com/dracutdevs/dracut/issues/1822 is fixed
{{ if and ( ne .Values.name "ubuntu-20-lts" ) ( ne .Values.name "ubuntu" ) ( ne .Values.name "ubuntu-22-lts" ) }}
- package: 
    category: "dracut"
    name: "network-legacy"
    version: ">=0"
  source: "/package/."
  destination: "/"
{{ else }}
- package: 
    category: "dracut"
    name: "network-legacy-compat"
    version: ">=0"
  source: "/package/."
  destination: "/"
{{ end }}
- package:
    category: "system"
    name: "kcrypt"
    version: ">=0"
  source: "/usr/bin/kcrypt"
  destination: "/usr/bin/kcrypt"
prelude:
# remove if any
- rm -rf /boot/initrd || true
includes:
- ^/boot|^/boot/.*
steps:
# Create initrd
- |
    kernel=$(ls /lib/modules | head -n1) && \
    dracut -f "/boot/initrd-${kernel}" "${kernel}" && \
    ln -sf "initrd-${kernel}" /boot/initrd
