#!/bin/sh

echo "FixBootloader $@"

. /lib/deepin-recovery-gui/scripts/functions

# boot分区
# 根分区
# 默认引导项

_boot=$1
_system=$2
_data=$3
_default_entry=$4

boot=$(resolv_device ${_boot})
system=$(resolv_device ${_system})
data=$(resolv_device ${_data})

mkdir /target

mount ${system} /target
mount ${boot} /target/boot
mount ${data} /target/data

cd /target

mount --bind /dev dev
mount --bind /proc proc
mount -t sysfs sysfs /target/sys
mount --bind /target/data/var /target/var

sed -i "s|.*GRUB_DEFAULT.*|GRUB_DEFAULT=$_default_entry|" /target/etc/default/grub

chroot /target grub-mkconfig -o /boot/grub/grub.cfg

cd /

umount /target/boot || exit -1
umount /target/var || exit -1
umount /target/data || exit -1
umount /target/sys || exit -1
umount -R /target || exit -1

rm -rf /target

lsblk
