#!/bin/sh

arg_num=$#

usage(){
   echo "Usage: `basename $0` (clear|configure)"
}

if [ ${arg_num} = 0 ]; then
   usage 
   exit 0
fi

opt=$1

if [ "x${opt}" = "xclear" ]; then
   if [ -f /boot/efi/EFI/BOOT/OSLoader.cfg ]; then
     rm /boot/efi/EFI/BOOT/OSLoader.cfg
   fi

   if [ -f /boot/efi/EFI/BOOT/kernel ]; then
     rm /boot/efi/EFI/BOOT/kernel
   fi

   rm -f /boot/efi/EFI/BOOT/initrd*

   rm -f /etc/initramfs/post-update.d/fstart_copy_initrd
   rm -f /etc/grub.d/16_fstart
   echo "cleared!!!"
fi


if [ "x${opt}" = "xconfigure" ]; then
   boot_partion=
   if [ ! -w "/boot" ]; then
      boot_partion=`lsblk | grep part | grep -v "/boot/efi" | grep "/boot" | awk '{print $7}'`
      if [ "x${boot_partion}" != "x" ]; then
         mount -o rw,remount /boot
      fi
   fi
   update-grub
   echo "configured!!!"
fi

exit 0
