#!/bin/bash

set -e


if [[ -f /lib/cryptsetup/scripts/set_cryptsetup_lang ]]; then
	bash /lib/cryptsetup/scripts/set_cryptsetup_lang || echo "set_cryptsetup_lang is failed"
fi

if [[ $(uname -m) =~ 'sw_64' ]]; then
    if [[ -f /usr/sbin/update-initramfs ]]; then
    	msg "更新 initramfs"
	apt purge -y casper || echo "卸载casper包失败"
    	update-initramfs -u
    	sync
    fi
    if [[ -f /usr/sbin/update-grub ]]; then
    	update-grub
    fi
    return 0
fi

#if grep -q 'zh_CN' /etc/default/locale; then
#    touch /usr/share/initramfs-tools/scripts/lang_is_zh
#else
#    rm -f /usr/share/initramfs-tools/scripts/lang_is_zh || true
#fi

if [[ -f /usr/sbin/update-initramfs ]]; then

    if egrep -qi '3A5000' /proc/cpuinfo; then
	echo "this is 3A5000,update-initramfs in the after apt purge casper"	
    else
    	msg "更新 initramfs"
	apt purge -y casper || echo "卸载casper包失败"
    	update-initramfs -u
    	sync
    fi
fi

if [[ -f /usr/sbin/update-grub ]]; then
    update-grub
fi

#
if [[ "x`archdetect`" = "xloongarch64/generic" ]] && [[ -f /usr/sbin/grub-install ]]; then
    grub-install || true
fi

