mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-31 10:58:06 +08:00
core: 不重要的优化
This commit is contained in:
parent
bde9108d08
commit
934800799d
@ -15,10 +15,12 @@ get_all_disks() {
|
||||
}
|
||||
|
||||
get_xda() {
|
||||
# 如果没找到 main_disk 或 xda
|
||||
# 返回假的值,防止意外地格式化全部盘
|
||||
main_disk="$(grep -o 'extra\.main_disk=[^ ]*' /proc/cmdline | cut -d= -f2)"
|
||||
|
||||
# 防止 $main_disk 为空
|
||||
if [ -z "$main_disk" ]; then
|
||||
echo 'MAIN_DISK_NOT_FOUND'
|
||||
return 1
|
||||
fi
|
||||
|
||||
@ -29,8 +31,7 @@ get_xda() {
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果没找到,返回假的值,防止意外地格式化全部盘
|
||||
echo 'FAKE_DISK'
|
||||
echo 'XDA_NOT_FOUND'
|
||||
return 1
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,8 @@ if not exist %tmp% (
|
||||
|
||||
rem 检查是否国内
|
||||
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
|
||||
if !errorlevel! == 0 (
|
||||
|
@ -74,9 +74,8 @@ curl() {
|
||||
|
||||
is_in_china() {
|
||||
if [ -z $_is_in_china ]; then
|
||||
# https://geoip.fedoraproject.org/city # 不支持 ipv6
|
||||
# https://geoip.ubuntu.com/lookup # 不支持 ipv6
|
||||
curl -L http://www.cloudflare.com/cdn-cgi/trace |
|
||||
# 部分地区 www.cloudflare.com 被墙
|
||||
curl -L http://dash.cloudflare.com/cdn-cgi/trace |
|
||||
grep -qx 'loc=CN' && _is_in_china=true ||
|
||||
_is_in_china=false
|
||||
fi
|
||||
@ -912,7 +911,9 @@ find_main_disk() {
|
||||
|
||||
# 可以用 dd 找出 guid?
|
||||
|
||||
# centos7 blkid lsblk 不显示 PTUUID
|
||||
# centos7 sfdisk 不显示 Disk identifier
|
||||
# alpine blkid 不显示 gpt 分区表的 PTUUID
|
||||
# 因此用 fdisk
|
||||
|
||||
# Disk identifier: 0x36778223 # gnu fdisk + mbr
|
||||
@ -1744,7 +1745,7 @@ if is_use_grub; then
|
||||
if [ -d /boot/loader/entries/ ]; then
|
||||
entries="/boot/loader/entries/"
|
||||
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
|
||||
fi
|
||||
fi
|
||||
|
35
trans.sh
35
trans.sh
@ -217,23 +217,38 @@ find_xda() {
|
||||
fi
|
||||
|
||||
# busybox fdisk 不显示 mbr 分区表 id
|
||||
# 可用以下工具:
|
||||
# fdisk 在 util-linux-misc 里面,占用大
|
||||
# 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
|
||||
if sfdisk --disk-id "/dev/$disk" | sed 's/0x//' | grep -ix "$main_disk"; then
|
||||
xda=$disk
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
# lsblk
|
||||
xda=$(lsblk --nodeps -rno NAME,PTUUID | grep -iw "$main_disk" | awk '{print $1}')
|
||||
fi
|
||||
|
||||
if [ -z "$xda" ]; then
|
||||
error_and_exit "Could not find xda: $main_disk"
|
||||
fi
|
||||
|
||||
apk del sfdisk
|
||||
if $need_install_tool; then
|
||||
apk del $tool
|
||||
fi
|
||||
}
|
||||
|
||||
get_all_disks() {
|
||||
@ -1647,7 +1662,7 @@ install_qcow_el() {
|
||||
|
||||
# fstab 删除 boot 分区
|
||||
# alma/rocky 镜像本身有boot分区,但我们不需要
|
||||
sed -i '/[[:blank:]]\/boot[[:blank:]]/d' /os/etc/fstab
|
||||
sed -i '/[[:space:]]\/boot[[:space:]]/d' /os/etc/fstab
|
||||
|
||||
# fstab 添加 efi 分区
|
||||
if is_efi; then
|
||||
@ -1658,7 +1673,7 @@ install_qcow_el() {
|
||||
fi
|
||||
else
|
||||
# 删除 efi 条目
|
||||
sed -i '/[[:blank:]]\/boot\/efi[[:blank:]]/d' /os/etc/fstab
|
||||
sed -i '/[[:space:]]\/boot\/efi[[:space:]]/d' /os/etc/fstab
|
||||
fi
|
||||
|
||||
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)
|
||||
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
|
||||
# 否则改成正确的大小写
|
||||
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
|
||||
echo "Image Name: $image_name"
|
||||
|
||||
@ -2263,9 +2278,13 @@ download_netboot_xyz_efi() {
|
||||
}
|
||||
|
||||
refind_main_disk() {
|
||||
if true; then
|
||||
apk add sfdisk
|
||||
main_disk="$(sfdisk --disk-id "/dev/$xda" | sed 's/0x//')"
|
||||
apk del sfdisk
|
||||
main_disk=$(sfdisk --disk-id /dev/$xda | sed 's/0x//')
|
||||
else
|
||||
apk add lsblk
|
||||
main_disk=$(lsblk --nodeps -rno PTUUID /dev/$xda)
|
||||
fi
|
||||
}
|
||||
|
||||
install_redhat_ubuntu() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user