#!/bin/sh
set -e

###sw架构特殊处理
###不能insmod以及主题显示,grub,cfg文件中删除字段
if [ "x`archdetect`" = "xsw64/generic" ];then
   if [ -f /etc/grub.d/06_ubuntukylin_theme ];then 
      rm /etc/grub.d/06_ubuntukylin_theme
   fi	
fi

if [ "x`archdetect`" = "xarm64/efi" ];then
  update-grub-ftefi
  if [ -d "/boot/grub" ]; then
    cp /boot/efi/boot/grub/grub.cfg /boot/grub/grub.cfg
  else
    mkdir -p /boot/grub
    cp /boot/efi/boot/grub/grub.cfg /boot/grub/grub.cfg
  fi

elif [ "x`archdetect`" = "xloongarch64/generic" ];then
  update-grub-loongsonefi
  if [ -d "/boot/grub" ]; then
    cp /boot/efi/boot/EFI/grub.cfg /boot/grub/grub.cfg
  else
    mkdir -p /boot/grub
    cp /boot/efi/boot/EFI/grub.cfg /boot/grub/grub.cfg
  fi

else
  update-grub-st
fi

if [ "x`archdetect`" != "xloongarch64/generic" ] && [ "x`archdetect`" != "xsw64/generic" ];then
  grub-measurelist-init
  grub-measureconf-init
fi

if [ "x`archdetect`" = "xsw64/generic" ];then
 sed -i '/recordfail/d' /boot/grub/grub.cfg
 sed -i '/insmod/d' /boot/grub/grub.cfg
fi
