#!/bin/sh

mount | grep -i '/boot type' | grep -i ro
IS_READONLY=$?

mount -o remount,rw /boot

set -e

install -Dm644 /boot/vmlinuz-$(uname -r) /boot/recovery/vmlinuz
cd /usr/lib/deepin-recovery/mkinitramfs; ./mkinitramfs -s /usr/lib/deepin-recovery/rootfs.cpio.gz -o /boot/recovery/rootfs.cpio.gz $(uname -r)

install -Dm755 /usr/lib/deepin-recovery/grub.d/01_live /etc/grub.d/01_live
install -Dm755 /usr/lib/deepin-recovery/grub.d/15_linux_recovery /etc/grub.d/15_linux_recovery


if [ -x /usr/sbin/update-grub ]
then
    /usr/sbin/update-grub || echo "update-grub failed! Ignore..." >&2
fi

if [ ${IS_READONLY} -eq 0 ];then
    mount -o remount,ro /boot
fi

exit 0
