{{ $architecture := or .architecture "amd64" }}
{{ $type := or .type "minimal" }}
{{ $suite := or .suite "v2019dev0" }}
{{ $image := or .image (printf "apertis-ostree-%s-%s-%s" $suite  $type $architecture) }}

{{ $board := or .board "uefi" }}
{{ $repourl := or .repourl "https://images.apertis.org/ostree/repo" }}
{{ $osname := or .osname "apertis" }}
{{ $branch := or .branch (printf "%s/%s/%s-%s/%s" $osname $suite $architecture $board $type) }}
{{ $ostree := or .ostree "repo" }}

{{ $cmdline := or .cmdline "console=tty0 console=ttyS0,115200n8 rootwait rw quiet splash plymouth.ignore-serial-consoles fsck.mode=auto fsck.repair=yes" }}

{{ $demopack := or .demopack "disabled" }}

architecture: {{ $architecture }}

actions:
  - action: image-partition
    imagename: {{ $image }}.img
{{ if eq $type "minimal" }}
    imagesize: 7G
{{end}}
{{ if eq $type "target" "development" }}
    imagesize: 15G
{{end}}
    partitiontype: gpt

    mountpoints:
      - mountpoint: /
        partition: system
      - mountpoint: /boot
        partition: boot
      - mountpoint: /boot/efi
        partition: EFI
      - mountpoint: /home
        partition: general_storage

    partitions:
      - name: EFI
        fs: vfat
        start: 6176s
        end: 512M
        flags: [ boot ]
      - name: boot
        fs: ext4
        start: 512M
        end: 1024M
      - name: system
        fs: ext4
        start: 1024M
        end: 4096M
      - name: general_storage
        fs: btrfs
        start: 4096M
        end: 100%

  - action: ostree-deploy
    description: Deploying ostree onto image
    repository: {{ $ostree }}
    remote_repository: {{ $repourl }}
    branch: {{ $branch }}
    os: {{ $osname }}
    append-kernel-cmdline: {{ $cmdline }}
    {{ if .collection_id }}
    collection-id: {{ .collection_id }}
    {{ end }}

  # Add multimedia demo pack
  # Provide URL via '-t demopack:"https://images.apertis.org/media/multimedia-demo.tar.gz"'
  # to add multimedia demo files
  {{ if ne $demopack "disabled" }}
  - action: download
    url: {{ $demopack }}
    name: mediademo

  - action: unpack
    origin: mediademo
  {{ end }}

  - action: run
    description: Install UEFI bootloader
    chroot: false
    script: scripts/setup-uefi-bootloader.sh {{ $osname }}

  - action: run
    description: List files on {{ $image }}
    chroot: false
    script: scripts/list-files "$ROOTDIR" | gzip > "${ARTIFACTDIR}/{{ $image }}.filelist.gz"

  - action: run
    description: Create block map for {{ $image }}.img
    postprocess: true
    command: bmaptool create {{ $image }}.img > {{ $image }}.img.bmap

  - action: run
    description: Compress {{ $image }}.img
    postprocess: true
    command: gzip -f {{ $image }}.img

  - action: run
    description: Checksum for {{ $image }}.img.gz
    postprocess: true
    command: sha256sum {{ $image }}.img.gz > {{ $image }}.img.gz.sha256
