requires:
- category: "base-image"
  version: ">=0"
  name: "{{.Values.name}}"

steps:
{{ if .Values.distribution }}
{{if eq .Values.distribution "opensuse" }}
- zypper in -y --no-recommends {{.Values.packages}}
{{ if .Values.arch }}
  {{ if eq .Values.arch "arm64" }}
- zypper in -y {{.Values.packages_arm}}
  {{ end }}
{{ end }}
- zypper cc
{{ if .Values.arch }}
  {{ if eq .Values.arch "arm64" }}
# aarch64 has an uncompressed kernel so we need to link it to vmlinuz
- |
    kernel=$(ls /boot/Image-* | head -n1) && \
    ln -sf "${kernel#/boot/}" /boot/vmlinuz
  {{ end }}
{{ end }}
{{else if eq .Values.distribution "fedora" }}
- dnf install -y {{.Values.packages}}
- dnf clean all
- |
    kernel=$(ls /boot/vmlinuz-* | head -n1) && \
    ln -sf "${kernel#/boot/}" /boot/vmlinuz
{{else if eq .Values.distribution "ubuntu" }}
# Note for future issues with grub: https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1879558 https://github.com/rancher-sandbox/cOS-toolkit/pull/101#discussion_r621929109
- apt-get update
{{ if .Values.arch }}
  {{ if eq .Values.arch "arm64" }}
- DEBIAN_FRONTEND=noninteractive apt-get install -y {{.Values.packages_arm}}
  {{ else }}
- DEBIAN_FRONTEND=noninteractive apt-get install -y {{.Values.packages}}
  {{ end }}
{{ end }}
- apt-get clean
- |
    kernel=$(ls /boot/vmlinuz-* | head -n1) && \
    ln -sf "${kernel#/boot/}" /boot/vmlinuz
{{end}}
{{end}}
- kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}"
{{if eq .Values.distribution "ubuntu" }}
- mkdir -p /package/boot
- mkdir -p /package/lib/modules
- mkdir -p /package/lib/firmware
- cp -rfv /boot/* /package/boot
- cp -rfv /lib/modules/* /package/lib/modules
- cp -rfv /lib/firmware/* /package/lib/firmware
- rm -rf /package/boot/grub2 || true
- rm -rf /package/boot/grub || true
- rm -rf /package/boot/initrd  || true
- rm -rf /package/boot/initrd.*  || true
package_dir: "/package"
{{ else }}

includes:
- ^/boot|^/boot/.*
# TODO: Shall we have separate packages for modules/firwmare?
- ^/lib/modules|^/lib/modules.*
- ^/lib/firmware|^/lib/firmware.*

excludes:
- ^/boot/grub2
- ^/boot/initrd
unpack: true

{{end}}
