el: 优化判断系统是否为 el7 家族

This commit is contained in:
bin456789 2024-11-26 21:20:09 +08:00
parent 34f64e31db
commit 72383f46b2
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -3146,6 +3146,11 @@ del_default_user() {
done < <(grep -v nologin$ "$os_dir/etc/passwd" | cut -d: -f1 | grep -v root) done < <(grep -v nologin$ "$os_dir/etc/passwd" | cut -d: -f1 | grep -v root)
} }
is_el7_family() {
is_have_cmd_on_disk "$1" yum &&
! is_have_cmd_on_disk "$1" dnf
}
install_qcow_by_copy() { install_qcow_by_copy() {
info "Install qcow2 by copy" info "Install qcow2 by copy"
@ -3307,26 +3312,31 @@ install_qcow_by_copy() {
# selinux kdump # selinux kdump
disable_selinux_kdump /os disable_selinux_kdump /os
# centos7 删除 machine-id 后不会自动重建 # el7 删除 machine-id 后不会自动重建
clear_machine_id /os clear_machine_id /os
# el7 yum 可能会使用 ipv6即使没有 ipv6 网络 # el7 forks 特殊处理
if [ "$releasever" = 7 ]; then if is_el7_family /os; then
# centos 7 eol 换源
if [ -f /os/etc/yum.repos.d/CentOS-Base.repo ]; then
# 保持默认的 http 因为自带的 ssl 证书可能过期
if is_in_china; then
mirror=mirror.nju.edu.cn/centos-vault
else
mirror=vault.centos.org
fi
sed -Ei -e 's,(mirrorlist=),#\1,' \
-e "s,#(baseurl=http://)mirror.centos.org,\1$mirror," /os/etc/yum.repos.d/CentOS-Base.repo
fi
# el7 yum 可能会使用 ipv6即使没有 ipv6 网络
if [ "$(cat /dev/netconf/eth*/ipv6_has_internet | sort -u)" = 0 ]; then if [ "$(cat /dev/netconf/eth*/ipv6_has_internet | sort -u)" = 0 ]; then
echo 'ip_resolve=4' >>/os/etc/yum.conf echo 'ip_resolve=4' >>/os/etc/yum.conf
fi fi
fi
# centos 7 eol 特殊处理 # el7 安装 NetworkManager
if [ "$releasever" = 7 ] && [ -f /os/etc/yum.repos.d/CentOS-Base.repo ]; then # anolis 7 镜像自带 NetworkManager
# 保持默认的 http 因为自带的 ssl 证书可能过期 chroot_dnf install NetworkManager
if is_in_china; then
mirror=mirror.nju.edu.cn/centos-vault
else
mirror=vault.centos.org
fi
sed -Ei -e 's,(mirrorlist=),#\1,' \
-e "s,#(baseurl=http://)mirror.centos.org,\1$mirror," /os/etc/yum.repos.d/CentOS-Base.repo
fi fi
# firmware + microcode # firmware + microcode
@ -3335,12 +3345,6 @@ install_qcow_by_copy() {
chroot_dnf install $(get_ucode_firmware_pkgs) chroot_dnf install $(get_ucode_firmware_pkgs)
fi fi
# centos 7 安装 NetworkManager
if [ "$releasever" = 7 ]; then
chroot_dnf install NetworkManager
fi
# anolis 7 镜像自带 nm
# 删除云镜像自带的 dhcp 配置,防止歧义 # 删除云镜像自带的 dhcp 配置,防止歧义
# clout-init 网络配置在 /etc/sysconfig/network-scripts/ # clout-init 网络配置在 /etc/sysconfig/network-scripts/
rm -rf /os/etc/NetworkManager/system-connections/*.nmconnection rm -rf /os/etc/NetworkManager/system-connections/*.nmconnection