From f60ec31e48cd1f06f805d889373ab8fd841f7507 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Wed, 8 May 2024 22:17:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 29 ++++++++++++++++++++--------- trans.sh | 16 +++++++++++----- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index 9cbd48f..91dd1a5 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -165,7 +165,8 @@ is_have_initrd() { } is_use_firmware() { - [ "$distro" = debian ] && ! is_virt + # shellcheck disable=SC2154 + [ "$nextos_distro" = debian ] && ! is_virt } get_host_by_url() { @@ -1074,7 +1075,7 @@ setos() { eval ${step}_distro=$distro eval ${step}_releasever=$releasever - if is_distro_like_redhat $distro && ! [ "$distro" = oracle ]; then + if is_distro_like_redhat && ! [ "$distro" = oracle ]; then setos_redhat else setos_$distro @@ -1088,11 +1089,21 @@ setos() { } is_distro_like_redhat() { - [ "$distro" = centos ] || [ "$distro" = alma ] || [ "$distro" = rocky ] || [ "$distro" = fedora ] || [ "$distro" = oracle ] + if [ -n "$1" ]; then + _distro=$1 + else + _distro=$distro + fi + [ "$_distro" = centos ] || [ "$_distro" = alma ] || [ "$_distro" = rocky ] || [ "$_distro" = fedora ] || [ "$_distro" = oracle ] } is_distro_like_debian() { - [ "$distro" = debian ] || [ "$distro" = kali ] + if [ -n "$1" ]; then + _distro=$1 + else + _distro=$distro + fi + [ "$_distro" = debian ] || [ "$_distro" = kali ] } # 检查是否为正确的系统名 @@ -1874,7 +1885,7 @@ get_entry_name() { build_nextos_cmdline() { if [ $nextos_distro = alpine ]; then nextos_cmdline="alpine_repo=$nextos_repo modloop=$nextos_modloop" - elif is_distro_like_debian; then + elif is_distro_like_debian $nextos_distro; then nextos_cmdline="lowmem/low=1 auto=true priority=critical" nextos_cmdline+=" url=$nextos_ks" nextos_cmdline+=" mirror/http/hostname=$nextos_deb_hostname" @@ -1884,12 +1895,12 @@ build_nextos_cmdline() { if [ "$nextos_distro" = kali ]; then nextos_cmdline+=" net.ifnames=0" fi - elif is_distro_like_redhat; then + elif is_distro_like_redhat $nextos_distro; then # redhat nextos_cmdline="root=live:$nextos_squashfs inst.ks=$nextos_ks" fi - if is_distro_like_debian; then + if is_distro_like_debian $nextos_distro; then if [ "$basearch" = "x86_64" ]; then # debian 安装界面不遵循最后一个 tty 为主 tty 的规则 # 设置ttyS0,tty0,安装界面还是显示在ttyS0 @@ -2366,7 +2377,7 @@ mod_initrd() { curl -Lo $tmp_dir/trans.sh $confhome/trans.sh curl -Lo $tmp_dir/alpine-network.sh $confhome/alpine-network.sh - if is_distro_like_debian; then + if is_distro_like_debian $nextos_distro; then mod_initrd_debian else mod_initrd_$nextos_distro @@ -2659,7 +2670,7 @@ else fi # 修改 alpine debian kali initrd -if [ "$nextos_distro" = alpine ] || is_distro_like_debian; then +if [ "$nextos_distro" = alpine ] || is_distro_like_debian "$nextos_distro"; then mod_initrd fi diff --git a/trans.sh b/trans.sh index 32841c5..d06b753 100644 --- a/trans.sh +++ b/trans.sh @@ -401,6 +401,12 @@ get_netconf_to() { eval "$1='$res'" } +is_ipv4_has_internet() { + get_netconf_to ipv4_has_internet + # shellcheck disable=SC2154 + [ "$ipv4_has_internet" = 1 ] +} + is_in_china() { get_netconf_to is_in_china # shellcheck disable=SC2154 @@ -1057,8 +1063,8 @@ EOF git_uri=https://mirrors.tuna.tsinghua.edu.cn/git/gentoo-portage.git else # github 不支持 ipv6 - # git_uri=https://github.com/gentoo-mirror/gentoo.git - git_uri=https://anongit.gentoo.org/git/repo/gentoo.git + is_ipv4_has_internet && git_uri=https://github.com/gentoo-mirror/gentoo.git || + git_uri=https://anongit.gentoo.org/git/repo/gentoo.git fi mkdir -p $os_dir/etc/portage/repos.conf @@ -1734,7 +1740,7 @@ EOF # debian 网络问题 # 注意 ubuntu 也有 /etc/debian_version - if false && [ "$distro" = debian ]; then + if [ "$distro" = debian ]; then # 修复 onlink 网关 add_onlink_script_if_need @@ -1852,7 +1858,7 @@ modify_os_on_disk() { mkdir -p /os # 按分区容量大到小,依次寻找系统分区 - for part in $(lsblk /dev/$xda --sort SIZE -no NAME | sed '$d' | tac); do + for part in $(lsblk /dev/$xda*[0-9] --sort SIZE -no NAME | tac); do # btrfs挂载的是默认子卷,如果没有默认子卷,挂载的是根目录 # fedora 云镜像没有默认子卷,且系统在root子卷中 if mount -o ro /dev/$part /os; then @@ -2039,7 +2045,7 @@ install_qcow_by_copy() { # 镜像分区格式 # centos/rocky/alma: xfs # oracle x86_64: lvm + xfs - # oracle aarch64 cloud: ext4 + # oracle aarch64 cloud: xfs if lsblk -f /dev/nbd0p* | grep LVM2_member; then apk add lvm2 lvscan