#!/bin/bash

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

#DEBHELPER#

case "$1" in
    configure)
        systemctl enable oem-i2c-instantiate-devices.service
        systemctl enable oem-gnss-enablement.service
        update-initramfs -u -k all
        # move grubx64.efi to /boot/efi/EFI/ubuntu/ and then enable shim fallback
        if [ -f "/boot/efi/EFI/boot/grubx64.efi" ] &&
           [ -f "/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed" ] &&
           [ -f "/usr/lib/shim/shimx64.efi.signed" ] &&
           [ -f "/usr/lib/shim/BOOTX64.CSV" ] &&
           [ -f "/usr/lib/shim/mmx64.efi" ] &&
           [ -f "/usr/lib/shim/fbx64.efi" ]; then
            cp /usr/lib/shim/fbx64.efi /boot/efi/EFI/boot/fbx64.efi
            cp /usr/lib/shim/shimx64.efi.signed /boot/efi/EFI/boot/bootx64.efi
            cp /usr/lib/shim/mmx64.efi /boot/efi/EFI/boot/mmx64.efi
            cp /usr/lib/shim/BOOTX64.CSV /boot/efi/EFI/ubuntu/BOOTX64.CSV
            cp /usr/lib/shim/mmx64.efi /boot/efi/EFI/ubuntu/mmx64.efi
            cp /usr/lib/shim/shimx64.efi.signed /boot/efi/EFI/ubuntu/shimx64.efi
            cp /usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed /boot/efi/EFI/ubuntu/grubx64.efi
            rm /boot/efi/EFI/boot/grubx64.efi
        fi
        ;;
esac

exit 0
