#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL

# The working dir for the binary hook is the working dir, not in the chroot.
# Put grub2 efi boot loader
# The name server is deconfigured, we have to enable it so the apt-get will work in ocs-gen-grub2-efi-bldr.
# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions

chroot chroot mkdir -p /EFI/boot
# Find the distribution for the chroot environment
[ -e chroot/etc/lsb-release ] && . chroot/etc/lsb-release
if [ "$DISTRIB_ID" = "Ubuntu" ] ;then
  # Ubuntu linux. Use the signed boot loader (shim+grub) so it can be used in uEFI secure boot.
  # //NOTE// This command is not run in all chroot environment, instead part of its content is run in chroot dir
  ocs-put-signed-grub2-efi-bldr -c chroot chroot/EFI/boot
else
  # Debian linux
  chroot chroot /bin/bash ocs-gen-grub2-efi-bldr /EFI/boot
fi
rm -rf ./binary/EFI
mv chroot/EFI ./binary/

### THE END ###
# DO NOT PUT ANY SCRIPT AFTHER THIS!!!
rm -rf ./binary/live-binary-hook-dir/
