diff --git a/get-xda.sh b/get-xda.sh index 5419428..10e960c 100644 --- a/get-xda.sh +++ b/get-xda.sh @@ -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 } diff --git a/reinstall.bat b/reinstall.bat index 14446df..feadea5 100644 --- a/reinstall.bat +++ b/reinstall.bat @@ -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 ( diff --git a/reinstall.sh b/reinstall.sh index d125d0c..5a4d86d 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -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 diff --git a/trans.sh b/trans.sh index 639aff9..65e9101 100644 --- a/trans.sh +++ b/trans.sh @@ -217,23 +217,38 @@ find_xda() { fi # busybox fdisk 不显示 mbr 分区表 id + # 可用以下工具: # fdisk 在 util-linux-misc 里面,占用大 # sfdisk 占用小 + # lsblk - apk add sfdisk + tool=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 + 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 }'