core: 重构,拆分方法

This commit is contained in:
bin456789 2023-10-22 18:50:54 +08:00
parent e5efd0adc9
commit dbb73f0733
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -1080,16 +1080,16 @@ disable_selinux_kdump() {
rm -rf $os_dir/etc/systemd/system/multi-user.target.wants/kdump.service
}
install_cloud_image() {
download_qcow() {
apk add qemu-img lsblk
mkdir -p /installer
mount /dev/disk/by-label/installer /installer
qcow_file=/installer/cloud_image.qcow2
download $img $qcow_file
}
# centos/alma/rocky cloud image系统分区是8~9g xfs而我们的目标是能在5g硬盘上运行因此改成复制系统文件
if [ "$distro" = "centos" ] || [ "$distro" = "alma" ] || [ "$distro" = "rocky" ]; then
install_qcow_el() {
yum() {
if [ "$releasever" = 7 ]; then
chroot /os/ yum -y --disablerepo=* --enablerepo=base,updates "$@"
@ -1260,9 +1260,9 @@ EOF
swapoff -a
umount /installer
parted /dev/$xda -s rm 3
}
else
# debian ubuntu arch opensuse gentoo
dd_qcow() {
if true; then
modprobe nbd
qemu_nbd -c /dev/nbd0 $qcow_file
@ -1342,6 +1342,9 @@ EOF
dd if=/first-1M of=/dev/$xda
update_part /dev/$xda
}
resize_after_install_cloud_image() {
# 提前扩容
# 1 修复 vultr 512m debian 10/11 generic/genericcloud 首次启动 kernel panic
# 2 修复 gentoo websync 时空间不足
@ -1361,12 +1364,9 @@ EOF
fi
fi
fi
modify_dd_os
fi
}
mount_part() {
mount_part_for_install_mode() {
# 挂载主分区
mkdir -p /os
mount /dev/disk/by-label/os /os
@ -1866,21 +1866,39 @@ if [ "$distro" != "alpine" ]; then
setup_nginx_if_enough_ram
fi
# shellcheck disable=SC2154
# dd qemu 切换成云镜像模式,暂时没用到
if [ "$distro" = "dd" ] && [ "$img_type" = "qemu" ]; then
cloud_image=1
fi
if [ "$distro" = "alpine" ]; then
install_alpine
elif [ "$distro" = "dd" ]; then
install_dd
elif [ "$distro" = "dd" ] && [ "$img_type" != "qemu" ]; then
dd_gzip_xz
modify_os_on_disk
elif is_use_cloud_image; then
if [ "$img_type" = "xz" ] || [ "$img_type" = "gzip" ]; then
install_cloud_image_by_dd
else
if [ "$img_type" = "qemu" ]; then
create_part
install_cloud_image
download_qcow
# 这几个系统云镜像系统盘是8~9g xfs而我们的目标是能在5g硬盘上运行因此改成复制系统文件
if [ "$distro" = centos ] || [ "$distro" = alma ] || [ "$distro" = rocky ]; then
install_qcow_el
else
# debian ubuntu fedora opensuse arch gentoo
dd_qcow
resize_after_install_cloud_image
modify_os_on_disk
fi
else
# gzip xz 格式的云镜像,暂时没用到
dd_gzip_xz
resize_after_install_cloud_image
modify_os_on_disk
fi
else
# 安装模式: windows windows ubuntu 红帽
create_part
mount_part
mount_part_for_install_mode
if [ "$distro" = "windows" ]; then
install_windows
else