#!/bin/bash

modprobe efivars

cp /etc/default/grub /etc/default/grub.pre-uefi
groovix-auto-apt-get remove --purge grub-pc grub-gfxpayload-lists

# can these be pre-installed?  if not update debs to latest
#dpkg -i /var/lib/groovix/debs/uefi-install/*.deb
#groovix-apt-dpkg-fixer

cp /etc/default/grub /etc/default/grub.uefi-defaults
#/etc/default/grub got purged, have to restore, ideally these should be variables
bashconfset.pl GRUB_CMDLINE_LINUX_DEFAULT "" /etc/default/grub
bashconfset.pl GRUB_CMDLINE_LINUX "net.ifnames=0 biosdevname=0" /etc/default/grub
bashconfset.pl GRUB_TIMEOUT 5 /etc/default/grub
bashconfset.pl GRUB_DEFAULT saved /etc/default/grub

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy --debug
update-grub
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy --debug
update-grub

#for buggy old bioses
#mkdir /boot/efi/EFI/Microsoft/
#mkdir /boot/efi/EFI/Microsoft/Boot/
#cp /boot/efi/EFI/ubuntu/grubx64.efi  /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi
#take files from 1804 which works for more bioses , has shim and fallback
mv /boot/efi/EFI /boot/efi/EFI.default
rsync -a /usr/share/groovix-installer/templates/EFI/ /boot/efi/EFI
cp /boot/efi/EFI.default/ubuntu/grub.cfg /boot/efi/EFI/ubuntu/grub.cfg
touch /boot/efi/gxuefip.here

echo waiting 30 seconds to see eufi install messages
sleep 30
