#!/usr/bin/env dmm-perform-recipe
###
# DMM Recipe to build AIMS Desktop
# You can get the latest version of this file at:
# https://git.aims.ac.za/aims-desktop/aims-debmower/aims-desktop-2020-amd64.dmm
###

#TODO:
# Remove build files like dpkg options
# write a final sources.list
# perform md5sum tests
# report with debsums and sizes

module_path:
- local

global_settings:
    name: &name AIMS Desktop
    version: &version "2020.2"
    description: &description Live installer image
    chroot: &chroot /tmp/debmower/disk
    live-media-path: &live-media-path /tmp/debmower/live-media
    squashfs: &squashfs /tmp/debmower/filesystem.squashfs
    architecture: &architecture amd64
    workspace: /tmp/debmower/
    release: &release buster
    additional_modules: /usr/local/example/path


recipe:
    install_debian:
        module: debootstrap
        destination: *chroot
        release:  buster
        mirror: http://deb.debian.org/debian
        debootstrapopts: ''
    setup_network:
        module: networking
        chroot: *chroot
        hostname: live
    dpkg_setup:
        module: dpkgsetup
        chroot: *chroot
        dpkg-options: |
            Dpkg::Options {
               "--force-confdef";
               "--force-confold";
               "--force-unsafe-io";
            }
        options-file: /etc/apt/apt.conf.d/buildoptions
    apt_setup:
        module: aptsetup
        chroot: *chroot
        sources-list: |
            deb http://deb.debian.org/debian buster main contrib non-free
            deb http://deb.debian.org/debian buster-updates main contrib non-free
            deb http://deb.debian.org/debian buster-backports main contrib non-free
            deb http://security.debian.org/debian buster-updates main contrib non-free
            deb [trusted=yes] http://ppa.aims.ac.za/aims-ppa buster main
        sources-file: /etc/apt/sources.list
        update-sources: True
    setup_bind_mounts:
        module: mountfs
        partitions:
            - dev:
              source: /dev
              mountpoint: /tmp/debmower/disk/dev
              mountopts: ''
              fstype: devtmpfs
            - proc:
              source: /proc
              mountpoint: /tmp/debmower/disk/proc
              mountopts: ''
              fstype: proc
            - sys:
              source: /sys
              mountpoint: /tmp/debmower/disk/sys
              mountopts: ''
              fstype: sysfs
    install_main_meta:
        module: aptpkg
        action: install
        packages: aims-desktop gnome grub-efi-amd64-bin esmtp antiword- catdoc- cython-doc- docutils-doc- ecl-doc- gmp-doc- mercurial- sagetex-doc- sphinx-doc- texlive-fonts-extra-doc- texlive-latex-base-doc- texlive-latex-recommended-doc- texlive-latex-extra-doc- texlive-pictures-doc- texlive-pstricks-doc- texlive-publishers-doc- texlive-science-doc- qmail-
        clean_cache: True
        download_only: False
    setup_live_packages:
        module: aptpkg
        action: install
        packages: aims-live
        clean_cache: True
        download_only: False
    install_linux:
        module: linux
        chroot: *chroot
        package: linux-image-amd64 linux-headers-amd64
    download_pool_packages:
        module: aptpkg
        action: install
        packages: grub-efi efibootmgr grub-efi-amd64 grub-efi-amd64-bin grub-pc-bin
        clean_cache: False
        download_only: True
    setup_package_pool:
        module: reprepro
        prepend_path: *chroot
        package_path: /var/cache/apt/archives
        architectures: *architecture
        description: *description
        components: main
        live-media-path: *live-media-path
        clean_package_path: True
    #clean_apt:
    #    module: aptsetup
    #    chroot: *chroot
    #    sources-list: ''
    #    sources-file: /etc/apt/sources.list
    #    update-sources: True
    unmount_filesystems:
        module: umountfs
        mounts:
            - proc:
              mountpoint: /tmp/debmower/disk/proc
            - sys:
              mountpoint: /tmp/debmower/disk/sys
            - dev:
              mountpoint: /tmp/debmower/disk/dev
    make_squashfs:
        module: squashfs
        action: make-squashfs
        blocksize: 1048576
        compression-method: zstd
        source: *chroot
        destination: *squashfs
        options: -noappend
    prepare_live_environment:
        module: livedisk
        template_dir: './live_template'
        update-initramfs: False
    generate_readme:
        module: readme
        template: ./live_template/README.txt
        destination: *live-media-path
        filename: README.txt
        name: *name
        version: *version
    generate_checksums:
        module: checksums
        checksum_binary: md5sum
        checksum_path: *live-media-path
        checksum_output: /tmp/debmower/live-media/md5sums.txt
        cut: *live-media-path
    make_iso_fs:
        module: grub
        action: mkrescue

