优化代码

This commit is contained in:
bin456789 2024-05-08 22:17:33 +08:00
parent 75881a09d0
commit f60ec31e48
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
2 changed files with 31 additions and 14 deletions

View File

@ -165,7 +165,8 @@ is_have_initrd() {
} }
is_use_firmware() { is_use_firmware() {
[ "$distro" = debian ] && ! is_virt # shellcheck disable=SC2154
[ "$nextos_distro" = debian ] && ! is_virt
} }
get_host_by_url() { get_host_by_url() {
@ -1074,7 +1075,7 @@ setos() {
eval ${step}_distro=$distro eval ${step}_distro=$distro
eval ${step}_releasever=$releasever eval ${step}_releasever=$releasever
if is_distro_like_redhat $distro && ! [ "$distro" = oracle ]; then if is_distro_like_redhat && ! [ "$distro" = oracle ]; then
setos_redhat setos_redhat
else else
setos_$distro setos_$distro
@ -1088,11 +1089,21 @@ setos() {
} }
is_distro_like_redhat() { 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() { 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() { build_nextos_cmdline() {
if [ $nextos_distro = alpine ]; then if [ $nextos_distro = alpine ]; then
nextos_cmdline="alpine_repo=$nextos_repo modloop=$nextos_modloop" 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="lowmem/low=1 auto=true priority=critical"
nextos_cmdline+=" url=$nextos_ks" nextos_cmdline+=" url=$nextos_ks"
nextos_cmdline+=" mirror/http/hostname=$nextos_deb_hostname" nextos_cmdline+=" mirror/http/hostname=$nextos_deb_hostname"
@ -1884,12 +1895,12 @@ build_nextos_cmdline() {
if [ "$nextos_distro" = kali ]; then if [ "$nextos_distro" = kali ]; then
nextos_cmdline+=" net.ifnames=0" nextos_cmdline+=" net.ifnames=0"
fi fi
elif is_distro_like_redhat; then elif is_distro_like_redhat $nextos_distro; then
# redhat # redhat
nextos_cmdline="root=live:$nextos_squashfs inst.ks=$nextos_ks" nextos_cmdline="root=live:$nextos_squashfs inst.ks=$nextos_ks"
fi fi
if is_distro_like_debian; then if is_distro_like_debian $nextos_distro; then
if [ "$basearch" = "x86_64" ]; then if [ "$basearch" = "x86_64" ]; then
# debian 安装界面不遵循最后一个 tty 为主 tty 的规则 # debian 安装界面不遵循最后一个 tty 为主 tty 的规则
# 设置ttyS0,tty0,安装界面还是显示在ttyS0 # 设置ttyS0,tty0,安装界面还是显示在ttyS0
@ -2366,7 +2377,7 @@ mod_initrd() {
curl -Lo $tmp_dir/trans.sh $confhome/trans.sh curl -Lo $tmp_dir/trans.sh $confhome/trans.sh
curl -Lo $tmp_dir/alpine-network.sh $confhome/alpine-network.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 mod_initrd_debian
else else
mod_initrd_$nextos_distro mod_initrd_$nextos_distro
@ -2659,7 +2670,7 @@ else
fi fi
# 修改 alpine debian kali initrd # 修改 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 mod_initrd
fi fi

View File

@ -401,6 +401,12 @@ get_netconf_to() {
eval "$1='$res'" eval "$1='$res'"
} }
is_ipv4_has_internet() {
get_netconf_to ipv4_has_internet
# shellcheck disable=SC2154
[ "$ipv4_has_internet" = 1 ]
}
is_in_china() { is_in_china() {
get_netconf_to is_in_china get_netconf_to is_in_china
# shellcheck disable=SC2154 # shellcheck disable=SC2154
@ -1057,7 +1063,7 @@ EOF
git_uri=https://mirrors.tuna.tsinghua.edu.cn/git/gentoo-portage.git git_uri=https://mirrors.tuna.tsinghua.edu.cn/git/gentoo-portage.git
else else
# github 不支持 ipv6 # github 不支持 ipv6
# git_uri=https://github.com/gentoo-mirror/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 git_uri=https://anongit.gentoo.org/git/repo/gentoo.git
fi fi
@ -1734,7 +1740,7 @@ EOF
# debian 网络问题 # debian 网络问题
# 注意 ubuntu 也有 /etc/debian_version # 注意 ubuntu 也有 /etc/debian_version
if false && [ "$distro" = debian ]; then if [ "$distro" = debian ]; then
# 修复 onlink 网关 # 修复 onlink 网关
add_onlink_script_if_need add_onlink_script_if_need
@ -1852,7 +1858,7 @@ modify_os_on_disk() {
mkdir -p /os 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挂载的是默认子卷如果没有默认子卷挂载的是根目录 # btrfs挂载的是默认子卷如果没有默认子卷挂载的是根目录
# fedora 云镜像没有默认子卷且系统在root子卷中 # fedora 云镜像没有默认子卷且系统在root子卷中
if mount -o ro /dev/$part /os; then if mount -o ro /dev/$part /os; then
@ -2039,7 +2045,7 @@ install_qcow_by_copy() {
# 镜像分区格式 # 镜像分区格式
# centos/rocky/alma: xfs # centos/rocky/alma: xfs
# oracle x86_64: lvm + xfs # oracle x86_64: lvm + xfs
# oracle aarch64 cloud: ext4 # oracle aarch64 cloud: xfs
if lsblk -f /dev/nbd0p* | grep LVM2_member; then if lsblk -f /dev/nbd0p* | grep LVM2_member; then
apk add lvm2 apk add lvm2
lvscan lvscan