core: 不重要的优化

This commit is contained in:
bin456789 2024-03-01 22:01:22 +08:00
parent bde9108d08
commit 934800799d
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
4 changed files with 45 additions and 23 deletions

View File

@ -15,10 +15,12 @@ get_all_disks() {
} }
get_xda() { get_xda() {
# 如果没找到 main_disk 或 xda
# 返回假的值,防止意外地格式化全部盘
main_disk="$(grep -o 'extra\.main_disk=[^ ]*' /proc/cmdline | cut -d= -f2)" main_disk="$(grep -o 'extra\.main_disk=[^ ]*' /proc/cmdline | cut -d= -f2)"
# 防止 $main_disk 为空
if [ -z "$main_disk" ]; then if [ -z "$main_disk" ]; then
echo 'MAIN_DISK_NOT_FOUND'
return 1 return 1
fi fi
@ -29,8 +31,7 @@ get_xda() {
fi fi
done done
# 如果没找到,返回假的值,防止意外地格式化全部盘 echo 'XDA_NOT_FOUND'
echo 'FAKE_DISK'
return 1 return 1
} }

View File

@ -28,7 +28,8 @@ if not exist %tmp% (
rem 检查是否国内 rem 检查是否国内
if not exist %tmp%\geoip ( if not exist %tmp%\geoip (
call :download http://www.cloudflare.com/cdn-cgi/trace %tmp%\geoip rem 部分地区 www.cloudflare.com 被墙
call :download http://dash.cloudflare.com/cdn-cgi/trace %tmp%\geoip
) )
findstr /c:"loc=CN" %tmp%\geoip >nul findstr /c:"loc=CN" %tmp%\geoip >nul
if !errorlevel! == 0 ( if !errorlevel! == 0 (

View File

@ -74,9 +74,8 @@ curl() {
is_in_china() { is_in_china() {
if [ -z $_is_in_china ]; then if [ -z $_is_in_china ]; then
# https://geoip.fedoraproject.org/city # 不支持 ipv6 # 部分地区 www.cloudflare.com 被墙
# https://geoip.ubuntu.com/lookup # 不支持 ipv6 curl -L http://dash.cloudflare.com/cdn-cgi/trace |
curl -L http://www.cloudflare.com/cdn-cgi/trace |
grep -qx 'loc=CN' && _is_in_china=true || grep -qx 'loc=CN' && _is_in_china=true ||
_is_in_china=false _is_in_china=false
fi fi
@ -912,7 +911,9 @@ find_main_disk() {
# 可以用 dd 找出 guid? # 可以用 dd 找出 guid?
# centos7 blkid lsblk 不显示 PTUUID
# centos7 sfdisk 不显示 Disk identifier # centos7 sfdisk 不显示 Disk identifier
# alpine blkid 不显示 gpt 分区表的 PTUUID
# 因此用 fdisk # 因此用 fdisk
# Disk identifier: 0x36778223 # gnu fdisk + mbr # Disk identifier: 0x36778223 # gnu fdisk + mbr
@ -1744,7 +1745,7 @@ if is_use_grub; then
if [ -d /boot/loader/entries/ ]; then if [ -d /boot/loader/entries/ ]; then
entries="/boot/loader/entries/" entries="/boot/loader/entries/"
fi fi
if grep -q -r -E '^[[:blank:]]*linuxefi[[:blank:]]' $grub_cfg $entries; then if grep -q -r -E '^[[:space:]]*linuxefi[[:space:]]' $grub_cfg $entries; then
efi=efi efi=efi
fi fi
fi fi

View File

@ -217,23 +217,38 @@ find_xda() {
fi fi
# busybox fdisk 不显示 mbr 分区表 id # busybox fdisk 不显示 mbr 分区表 id
# 可用以下工具:
# fdisk 在 util-linux-misc 里面,占用大 # fdisk 在 util-linux-misc 里面,占用大
# sfdisk 占用小 # sfdisk 占用小
# lsblk
apk add sfdisk tool=sfdisk
is_have_cmd $tool && need_install_tool=false || need_install_tool=true
if $need_install_tool; then
apk add $tool
fi
if [ "$tool" = sfdisk ]; then
# sfdisk
for disk in $(get_all_disks); do for disk in $(get_all_disks); do
if sfdisk --disk-id "/dev/$disk" | sed 's/0x//' | grep -ix "$main_disk"; then if sfdisk --disk-id "/dev/$disk" | sed 's/0x//' | grep -ix "$main_disk"; then
xda=$disk xda=$disk
break break
fi fi
done done
else
# lsblk
xda=$(lsblk --nodeps -rno NAME,PTUUID | grep -iw "$main_disk" | awk '{print $1}')
fi
if [ -z "$xda" ]; then if [ -z "$xda" ]; then
error_and_exit "Could not find xda: $main_disk" error_and_exit "Could not find xda: $main_disk"
fi fi
apk del sfdisk if $need_install_tool; then
apk del $tool
fi
} }
get_all_disks() { get_all_disks() {
@ -1647,7 +1662,7 @@ install_qcow_el() {
# fstab 删除 boot 分区 # fstab 删除 boot 分区
# alma/rocky 镜像本身有boot分区但我们不需要 # alma/rocky 镜像本身有boot分区但我们不需要
sed -i '/[[:blank:]]\/boot[[:blank:]]/d' /os/etc/fstab sed -i '/[[:space:]]\/boot[[:space:]]/d' /os/etc/fstab
# fstab 添加 efi 分区 # fstab 添加 efi 分区
if is_efi; then if is_efi; then
@ -1658,7 +1673,7 @@ install_qcow_el() {
fi fi
else else
# 删除 efi 条目 # 删除 efi 条目
sed -i '/[[:blank:]]\/boot\/efi[[:blank:]]/d' /os/etc/fstab sed -i '/[[:space:]]\/boot\/efi[[:space:]]/d' /os/etc/fstab
fi fi
distro_full=$(awk -F: '{ print $3 }' </os/etc/system-release-cpe) distro_full=$(awk -F: '{ print $3 }' </os/etc/system-release-cpe)
@ -1948,10 +1963,10 @@ install_windows() {
image_count=$(wiminfo $install_wim | grep "Image Count:" | cut -d: -f2 | xargs) image_count=$(wiminfo $install_wim | grep "Image Count:" | cut -d: -f2 | xargs)
if [ "$image_count" = 1 ]; then if [ "$image_count" = 1 ]; then
# 只有一个版本就使用第一个版本 # 只有一个版本就使用第一个版本
image_name=$(wiminfo $install_wim | grep -ix "Name:[[:blank:]]*.*" | cut -d: -f2 | xargs) image_name=$(wiminfo $install_wim | grep -ix "Name:[[:space:]]*.*" | cut -d: -f2 | xargs)
else else
# 否则改成正确的大小写 # 否则改成正确的大小写
image_name=$(wiminfo $install_wim | grep -ix "Name:[[:blank:]]*$image_name" | cut -d: -f2 | xargs) image_name=$(wiminfo $install_wim | grep -ix "Name:[[:space:]]*$image_name" | cut -d: -f2 | xargs)
fi fi
echo "Image Name: $image_name" echo "Image Name: $image_name"
@ -2263,9 +2278,13 @@ download_netboot_xyz_efi() {
} }
refind_main_disk() { refind_main_disk() {
if true; then
apk add sfdisk apk add sfdisk
main_disk="$(sfdisk --disk-id "/dev/$xda" | sed 's/0x//')" main_disk=$(sfdisk --disk-id /dev/$xda | sed 's/0x//')
apk del sfdisk else
apk add lsblk
main_disk=$(lsblk --nodeps -rno PTUUID /dev/$xda)
fi
} }
install_redhat_ubuntu() { install_redhat_ubuntu() {