#!/bin/bash

set -e
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

case "$1" in
    configure)
        # If network-manager is installed, the default networkd should be masked.
        nm_status=$(dpkg -l network-manager | grep ii)
        if [ -n "$nm_status" ]; then
            systemctl mask systemd-networkd.socket
            systemctl mask systemd-networkd
            systemctl mask systemd-networkd-wait-online
            systemctl mask networkd-dispatcher
        fi

        if [ ! -d /boot/grub ]; then
            mkdir -p /boot/grub
        fi
        update-grub
        if ischroot; then
            echo "chroot detected; skipping postinst"
            exit 0
        fi
        target=x86_64-efi
        if ! test -e /boot/grub/$target/core.efi; then
            grub-install -v --boot-directory=/boot \
                            --efi-directory=/boot/efi \
                            --target=$target \
                            --uefi-secure-boot \
                            --no-nvram
        fi
    ;;
esac

exit 0
