{{- $architecture := or .architecture "amd64" }}
{{- $type := or .type "basesdk" -}}
{{- $mirror := or .mirror "https://repositories.apertis.org/apertis/" -}}
{{- $suite := or .suite "v2019dev0" -}}
{{- $timestamp := or .timestamp "" -}}
{{- $ospack := or .ospack (printf "ospack_%s-%s-%s" $suite $architecture $type) -}}

architecture: {{ $architecture }}

actions:
  - action: debootstrap
    suite: {{ $suite }}
    components:
      - target
    mirror: {{ $mirror }}
    variant: minbase
    keyring-package: apertis-archive-keyring
    keyring-file: keyring/apertis-archive-keyring.gpg
    merged-usr: false

  # Add image version information
  - action: run
    description: "Setting up image version metadata"
    chroot: true
    script: scripts/setup_image_version.sh apertis {{ $suite }} '{{ $timestamp }}' collabora {{ $type }}

  - action: run
    description: "Add extra apt sources"
    chroot: true
    script: scripts/apt_source.sh -m {{ $mirror }} -r {{ $suite }} hmi helper-libs development sdk

  - action: run
    description: "Switch to the latest coreutils package (GPLv3)"
    chroot: true
    script: scripts/replace-tar-coreutils-for-build.sh

  - action: apt
    description: "Core packages"
    packages:
      - sudo
      - apt-transport-https
      - initramfs-tools
      # - apertis-customizations

  - action: apt
    description: "Base packages"
    packages:
      - busybox
      - dbus-user-session

  - action: apt
    description: "Networking packages"
    packages:
      - connman
      - wpasupplicant

  - action: apt
    description: "AppArmor packages"
    packages:
      - apparmor
      - chaiwala-apparmor-profiles

  - action: apt
    description: "Test environment packages"
    packages:
      - net-tools
      - openssh-client
      - openssh-server
      - vim.tiny

  - action: apt
    description: "Target packages"
    packages:
      - adduser
      - apertis-archive-keyring
      - apparmor
      - apparmor-profiles
      - apt
      - apt-transport-https
      - apt-utils
      - auditd
      - avahi-daemon
      - bluez
      - bluez-obexd
      - btrfs-tools
      - bzip2
      - ca-certificates
      - connman
      - debconf-i18n
      - evolution-data-server
      - file
      - fonts-dejavu-extra
      - gnupg
      - gstreamer1.0-plugins-good
      - gstreamer1.0-pulseaudio
      - gvfs
      - initramfs-tools
      - iproute2
      - iptables
      - kmod
      - libgupnp-1.0-4
      - liblockfile-bin
      - libnss-myhostname
      #- libproxy1-pacrunner
      - libwebkit2gtk-4.0-37
      - locales
      - lsb-base
      - lzma
      - mawk
      - mobile-broadband-provider-info
      #- mutter
      - net-tools
      - netbase
      - openssh-client
      - openssh-server
      #- pacrunner
      - plymouth
      - plymouth-themes
      - policykit-1
      - pulseaudio
      - pulseaudio-module-bluetooth
      - pulseaudio-utils
      - sudo
      - systemd-sysv
      # - tcmmd
      - tracker
      - tracker-miner-fs
      - tumbler
      - tumbler-plugins-extra
      - udev
      - usb-modeswitch
      - vim-tiny
      - whiptail
      - wpasupplicant
      - xauth
      - xdg-user-dirs
      - xwayland

  - action: apt
    description: "Development packages"
    packages:
      - apparmor-utils
      - automake
      - autopoint
      - autotools-dev
      - bash
      - bison
      - build-essential
      - bustle-pcap
      - chrpath
      - cmake
      - cmake-data
      #- connman-tests
      - d-feet
      - debhelper
      - dosfstools
      - evolution-data-server-dbgsym
      - evolution-data-server-dev
      - fakeroot
      - flex
      - gawk
      - gcc
      - gdb
      - gdbserver
      - gir1.2-secret-1
      - git
      - gperf
      - gstreamer1.0-tools
      - gtk-doc-tools
      - iputils-ping
      - less
      - libasound2-dev
      - libbluetooth-dev
      - libcurl4-nss-dev
      - libenchant-dev
      - libffi-dev
      - libgirepository1.0-dev
      - libglib2.0-0-dbgsym
      - libglib2.0-dev
      - libgstreamer-plugins-base1.0-dev
      - libgstreamer1.0-dev
      - libgtk2.0-dev
      - libgtk-3-0-dbgsym
      - libgudev-1.0-dev
      - libgupnp-1.0-dev
      - libhyphen-dev
      - libicu-dev
      - libjpeg-dev
      - libjsoncpp1
      # - libmutter-dev
      #- libmx-2.0-0-dev
      - libnotify-dev
      - libpango1.0-dev
      - libpng-dev
      - libpoppler-glib-dev
      - libproxy-dev
      - libpulse-dev
      - libsecret-1-0
      - libsecret-1-dev
      - libsecret-common
      - libsoup2.4-dev
      - libsqlite3-dev
      - libtool
      - libtracker-control-2.0-dev
      - libtracker-miner-2.0-dev
      - libtracker-sparql-2.0-dev
      - libwebkit2gtk-4.0-dev
      - libwebp-dev
      - libwnck-3-dev
      - libxslt1-dev
      - libxt-dev
  {{ if eq $architecture "armhf" }}
      - linux-headers-armmp
  {{ else }}
      - linux-headers-{{$architecture}}
  {{ end }}
      - lsb-release
      - ltrace
      - openssh-client
      - openssh-server
      - pavucontrol
      - pkg-config
      - python-pkg-resources
      - python-ply
      - ruby
      - slimit
      - strace
      - symlinks
      - syncevolution-dbgsym
      - valgrind
      - wget
      - xinput

  - action: apt
    description: "SDK packages"
    packages:
      - adduser
      - apertis-archive-keyring
      #- apertis-customizations
      - apertis-dev-tools
      #- apertis-docs
      - apparmor
      - apparmor-profiles
      - apparmor-utils
      - apt
      - apt-transport-https
      - apt-utils
      - auditd
      - automake
      - autopoint
      - autotools-dev
      - avahi-daemon
      - bash
      - bison
      - blueman
      - bluez
      - bluez-obexd
      - bmap-tools
      - btrfs-tools
      - build-essential
      - bustle
      - bustle-pcap
      - bzip2
      - ca-certificates
      - ccache
      #- chaiwala-sdk-default-settings
      - chrpath
      - clang
      - cmake
      - cntlm
      - connman
      #- connman-tests
      - d-feet
      - dbus-user-session
      - debconf-i18n
      - debhelper
      - devhelp
      - devilspie
      - devscripts
      - dh-autoreconf
      - dh-exec
      - dosfstools
      - evince
      - evolution-data-server
      - evolution-data-server-dbgsym
      - evolution-data-server-dev
      - evolution-data-server-doc
      - fakeroot
      - file
      - firefox-esr
      - flex
      - g++-aarch64-linux-gnu
      - g++-arm-linux-gnueabihf
      - gawk
      - gcc
      - gcc-aarch64-linux-gnu
      - gcc-arm-linux-gnueabihf
      - gdb
      #- gdb-doc
      - gdb-multiarch
      - gdbserver
      - gettext-doc
      - gir1.2-secret-1
      - git
      - glibc-doc
      - gnome-desktop-testing
      - gnome-devel-docs
      - gnome-icon-theme
      - gnupg
      - gperf
      - gstreamer1.0-doc
      - gstreamer1.0-plugins-good
      - gstreamer1.0-pulseaudio
      - gstreamer1.0-tools
      - gtk-doc-tools
      - hotdoc
      - hotdoc-c-extension
      - hotdoc-dbus-extension
      - ibus-doc
      - initramfs-tools
      - iproute2
      - iptables
      - iputils-ping
      - kmod
      - lcov
      - less
      - libasound2-dev
      - libbluetooth-dev
      - libcairo2-doc
      - libcurl4-nss-dev
      - libelf-dev
      - libenchant-dev
      - libffi-dev
      - libgdata-doc
      - libgirepository1.0-dev
      - libglib2.0-dev
      - libgstreamer-plugins-base1.0-dev
      - libgstreamer1.0-dev
      - libgupnp-1.0-4
      - libgupnp-1.0-dev
      - libgupnp-doc
      - libicu-dev
      - libjpeg-dev
      - libjson-glib-doc
      - liblockfile-bin
      # - libmutter-dev
      #- libmx-2.0-0-dev
      #- libmx-2.0-doc
      - libnss-myhostname
      - libpango1.0-dev
      - libpng-dev
      - libpoppler-glib-dev
      - libproxy-dev
      # - libproxy1-pacrunner
      - libpulse-dev
      - libsecret-1-0
      - libsecret-1-dev
      - libsecret-common
      - libsoup2.4-dev
      - libsoup2.4-doc
      - libsqlite3-dev
      - libtool
      - libtracker-control-2.0-dev
      - libtracker-control-doc
      - libtracker-miner-2.0-dev
      - libtracker-miner-doc
      - libtracker-sparql-2.0-dev
      - libtracker-sparql-doc
      - libwebp-dev
      - libwnck-3-dev
      - libxml2-doc
      - libxml2-utils
      - libxslt1-dev
      - libxt-dev
      - lightdm
      #- linux-firmware
      - linux-perf
      - locales
      - lsb-base
      - lsb-release
      - ltrace
      - lzma
      - mawk
      - mousepad
      - murrine-themes
      # - mutter
      - net-tools
      - netbase
      - openssh-client
      - openssh-server
      - osc
      # - pacrunner
      - pavucontrol
      - pkg-config
      #- pkg-config-aarch64-linux-gnu
      #- pkg-config-arm-linux-gnueabihf
      #- pkg-config-x86-64-linux-gnu
      - plymouth
      - plymouth-themes
      - policykit-1
      - pristine-tar
      - pulseaudio
      - pulseaudio-module-bluetooth
      - pulseaudio-utils
      - python-gobject
      - python3-debian
      - qemu-user-static
      - rtkit
      - ruby
      - screen
      - splint
      - splint-doc-html
      - strace
      - sudo
      - symlinks
      - syncevolution
      - syncevolution-dbgsym
      - sysprof
      - systemd-sysv
      - systemtap
      - systemtap-client
      - systemtap-server
      - tar
      #- tartan
      #- tcmmd
      - tracker
      - tracker-miner-fs
      - tumbler
      - tumbler-plugins-extra
      - udev
      - usb-modeswitch
      - usbutils
      - valgrind
      - vim-tiny
      - wget
      - whiptail
      - wpasupplicant
      - xauth
      - xdg-user-dirs
      - xfce4
      - xfce4-terminal
      - xinput
      - xserver-xephyr
      - xserver-xorg
      - xserver-xorg-input-evdev
      - xserver-xorg-video-fbdev
      - xserver-xorg-video-intel
      - xserver-xorg-video-vesa
      # needed by the VirtualBox extensions for xrandr. (Apertis:T4485)
      - x11-xserver-utils
      - yelp
      - yelp-tools

  - action: overlay
    source: overlays/hostname

  - action: overlay
    source: overlays/default-hosts

  - action: overlay
    source: overlays/loopback-interface

  - action: overlay
    source: overlays/media-tmpfs

  - action: overlay
    source: overlays/create-homedir

  - action: overlay
    source: overlays/sudo-fqdn

  - action: overlay
    source: overlays/default-locale-c-utf8

  - action: overlay
    source: overlays/supported-locales

  - action: overlay
    source: overlays/initramfs-modules-amd64

  - action: overlay
    source: overlays/sdk-vboxvideo-workaround

  - action: overlay
    source: overlays/sdk-lightdm-autologin

  - action: overlay
    source: overlays/sdk-mount-opt-sysroot

  - action: overlay
    source: overlays/sdk-xfce-theme

  - action: overlay
    source: overlays/sdk-desktop-icon-devhelp/

  - action: run
    chroot: true
    script: scripts/add-xdg-user-metadata.sh

  - action: run
    chroot: true
    script: scripts/create-mtab-symlink.hook.sh

  - action: run
    chroot: true
    script: scripts/setup_user.sh

  - action: run
    chroot: true
    description: "Force homedir creation so sample-applications can be cloned in"
    command: /usr/sbin/apertis-create-homedir-if-needed 1000

  - action: run
    chroot: true
    description: "Creating mount point /Applications"
    command: install -d -m 0755 /Applications

  - action: run
    description: "Setting up sysroot storage"
    chroot: true
    command: install -d -m 0755 -o user -g user /home/sysroot

  - action: run
    description: "disable deprecated gnome-vfs-2.0 documentation"
    chroot: true
    script: scripts/disable-deprecated-gnome-vfs-2.0.sh

  - action: run
    chroot: true
    script: scripts/add_user_to_groups.sh

  - action: run
    chroot: true
    script: scripts/check_sudoers_for_admin.sh

  - action: run
    chroot: true
    script: scripts/generate_openssh_keys.sh

  - action: run
    chroot: true
    script: scripts/add-initramfs-modules.sh

  - action: run
    description: "Generate locales"
    chroot: true
    script: scripts/generate_locales.sh

  - action: run
    description: Switch the logind AppArmor profile to complain mode
    chroot: false
    script: scripts/apparmor-profile-switch-to-complain.sh ${ROOTDIR}/etc/apparmor.d/lib.systemd.systemd-logind

  # work around the Debos isssue in https://phabricator.apertis.org/T4308
  - action: run
    chroot: false
    description: "Drop resolv.conf so the appropriate one gets created at runtime"
    command: rm "${ROOTDIR}/etc/resolv.conf"

  - action: run
    description: "Save installed package status"
    chroot: false
    command: gzip -c "${ROOTDIR}/var/lib/dpkg/status" > "${ARTIFACTDIR}/{{ $ospack }}.pkglist.gz"

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

  - action: pack
    compression: gz
    file: {{ $ospack }}.tar.gz
