#!/bin/ash
#
#
#
 if [ x$1 = x ]; then
   exit
 fi
 if [ ! -e $1 ]; then
   exit
 fi
 if [ ! -e /sys/firmware/efi ]; then
   exit
 fi
 if [ -h $1 ]; then
   ROOTFS=$(readlink $1)
   else
   ROOTFS=$1
 fi
 partprobe /dev/sda
 fdisk -l /dev/sda | grep EFI | cut -c 6,7,8,9,10 >/tmp/efi.tmp
 if [ -s /tmp/efi.tmp ]; then
   EFI=$(cat /tmp/efi.tmp)
   umount /dev/$EFI 2>/dev/null
   mkdir /boot/efi 2>/dev/null
   mount /dev/$EFI /boot/efi
   rmdir /mnt/$EFI 2>/dev/null
   else
   echo "Error: I cannot find your ESP partition."
   rm /tmp/*.tmp
   exit
 fi
 tar -xvf /usr/share/grub/mini/addon_grub-mini.tar.xz -C /
 if [ x$TARGET = x ]; then
   TARGET=..
 fi
 cp /mnt/$TARGET/boot/bzImage /boot/efi/boot
 echo clear > /boot/efi/boot/grub/grub.cfg
 . /usr/share/grub/mini/getname.sh
 echo "echo Loading $NAME. Please wait..." >> /boot/efi/boot/grub/grub.cfg
 echo "linux /boot/bzImage root=$ROOTFS" >> /boot/efi/boot/grub/grub.cfg
 echo boot >> /boot/efi/boot/grub/grub.cfg
