ubuntu: 修复删除 grub-pc 时报错

fixes #304
This commit is contained in:
bin456789 2025-04-02 19:22:49 +08:00
parent 06559947e3
commit b664df17e8
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -3870,16 +3870,21 @@ chroot_dnf() {
fi fi
} }
chroot_apt_install() { chroot_apt_update() {
os_dir=$1 os_dir=$1
shift
current_hash=$(cat $os_dir/etc/apt/sources.list $os_dir/etc/apt/sources.list.d/*.sources 2>/dev/null | md5sum) current_hash=$(cat $os_dir/etc/apt/sources.list $os_dir/etc/apt/sources.list.d/*.sources 2>/dev/null | md5sum)
if ! [ "$saved_hash" = "$current_hash" ]; then if ! [ "$saved_hash" = "$current_hash" ]; then
chroot $os_dir apt-get update chroot $os_dir apt-get update
saved_hash="$current_hash" saved_hash="$current_hash"
fi fi
}
chroot_apt_install() {
os_dir=$1
shift
chroot_apt_update $os_dir
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get install -y "$@" DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get install -y "$@"
} }
@ -3887,6 +3892,10 @@ chroot_apt_remove() {
os_dir=$1 os_dir=$1
shift shift
# minimal 镜像 删除 grub-pc 时会安装 grub-efi-amd64
# 因此需要先更新索引
chroot_apt_update $os_dir
# 不能用 apt remove --purge -y xxx yyy # 不能用 apt remove --purge -y xxx yyy
# 因为如果索引里没有其中一个,会报错,另一个也不会删除 # 因为如果索引里没有其中一个,会报错,另一个也不会删除
local pkgs= local pkgs=