# How this snap is prepared (to be turned into snapcraft.yaml eventually):

sudo apt install shim-signed grub-pc-bin grub-efi-amd64-signed
cp /usr/lib/shim/shim.efi.signed shim.efi.signed
cp /usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed grubx64.efi

cp /usr/lib/grub/i386-pc/boot.img pc-boot.img
echo -n -e '\x90\x90' | dd of=pc-boot.img seek=102 bs=1 conv=notrunc

NONSNAP_GRUB_MODULES="
	btrfs
	hfsplus
	iso9660
	part_apple
	part_msdos
	password_pbkdf2
	zfs
	zfscrypt
	zfsinfo
	lvm
	mdraid09
	mdraid1x
	raid5rec
	raid6rec
	"

# filtered list of modules included in the signed EFI grub image, excluding
# ones that we don't think are useful in snappy.
GRUB_MODULES="
	all_video
	biosdisk
	boot
	cat
	chain
	configfile
	echo
	ext2
	fat
	font
	gettext
	gfxmenu
	gfxterm
	gfxterm_background
	gzio
	halt
	jpeg
	keystatus
	loadenv
	loopback
	linux
	memdisk
	minicmd
	normal
	part_gpt
	png
	reboot
	search
	search_fs_uuid
	search_fs_file
	search_label
	sleep
	squash4
	test
	true
	video
	"
grub-mkimage -O i386-pc -o pc-core.img -p '(,gpt2)/EFI/ubuntu' $GRUB_MODULES
# The first sector of the core image requires an absolute pointer to the
# second sector of the image.  Since this is always hard-coded, it means our
# BIOS boot partition must be defined with an absolute offset.  The
# particular value here is 2049, or 0x01 0x08 0x00 0x00 in little-endian.
echo -n -e '\x01\x08' | dd of=pc-core.img seek=500 bs=1 conv=notrunc
