release 1

This commit is contained in:
2026-04-27 22:10:41 +08:00
parent ce7e78a96b
commit 653251cfff
6 changed files with 282 additions and 308 deletions

View File

@@ -1,254 +0,0 @@
#!/bin/bash
get_disk_priority() {
local disk=$1
local disk_name=$(basename $disk)
if [[ $disk_name == nvme* ]]; then
echo 1
return
fi
local rotational=$(cat /sys/block/$disk/queue/rotational 2>/dev/null)
if [[ $rotational -eq 0 ]]; then
echo 2
return
fi
local transport=$(lsblk -d -o NAME,TRAN /dev/$disk 2>/dev/null | grep $disk | awk '{print $2}')
if [[ $transport == "sas" ]]; then
echo 3
else
echo 4 # SATA OR OTHER
fi
}
get_disk_size() {
local disk=$1
cat /sys/block/$disk/size 2>/dev/null
}
is_installed_node() {
local disks=$(lsblk -d -n -o NAME,TYPE | grep disk | awk '{print $1}')
for disk in $disks; do
local partitions=$(lsblk -n -o NAME /dev/$disk | grep -E "^${disk}p?[0-9]+" || true)
for part in $partitions; do
local mount_point="/mnt/tmp_${part}"
mkdir -p $mount_point 2>/dev/null
if mount -t ext4 -o ro /dev/$part $mount_point 2>/dev/null || \
mount -t xfs -o ro /dev/$part $mount_point 2>/dev/null; then
if [[ -f $mount_point/.sunhpc-release ]]; then
umount $mount_point
rmdir $mount_point 2>/dev/null
echo "yes"
return 0
fi
umount $mount_point
fi
rmdir $mount_point 2>/dev/null
done
done
echo "no"
}
select_best_disk() {
local disks=()
for disk in /sys/block/*; do
local disk_name=$(basename $disk)
if [[ $disk_name =~ ^(loop|zram|ram|sr|fd|dm-) ]]; then
continue
fi
if [[ -e /dev/$disk_name ]] && [[ $(cat /sys/block/$disk_name/removable 2>/dev/null) -eq 0 ]]; then
disks+=($disk_name)
fi
done
if [[ ${#disks[@]} -eq 0 ]]; then
echo ""
return 1
fi
declare -A disk_priority
declare -A disk_size
for disk in "${disks[@]}"; do
disk_priority[$disk]=$(get_disk_priority $disk)
disk_size[$disk]=$(get_disk_size $disk)
done
local sorted_disks=($(for disk in "${disks[@]}"; do
echo "${disk_priority[$disk]}:${disk_size[$disk]}:$disk"
done | sort -n -t: -k1,1 -k2,2rn | cut -d: -f3))
echo "${sorted_disks[0]}"
}
# 智能计算 Root 分区大小
# 参数: $1 = 磁盘总大小(GB), $2 = 期望的默认大小(GB)
# 返回: 合适的 root 分区大小(GB)
calculate_root_size() {
local disk_total_gb=$1
local default_root_gb=${2:-70}
local min_root_gb=30
local max_root_gb=100
# 如果磁盘总容量小于最小要求70GB + boot + swap = 约75GB
if [[ $disk_total_gb -lt 75 ]]; then
# 磁盘太小,使用最小 root 分区
echo $min_root_gb
elif [[ $disk_total_gb -lt 100 ]]; then
# 磁盘在 75-100GB 之间,使用 40-50GB
echo $((disk_total_gb - 45)) # 预留 boot+swap+state 空间
elif [[ $disk_total_gb -lt 150 ]]; then
# 磁盘在 100-150GB 之间,使用 60GB
echo 60
elif [[ $disk_total_gb -lt 250 ]]; then
# 磁盘在 150-250GB 之间,使用默认 70GB
echo $default_root_gb
else
# 大磁盘,限制最大 100GB
echo $max_root_gb
fi
}
calculate_state_size() {
local disk_total_sectors=$1
local root_size_sectors=$2
echo $((disk_total_sectors - root_size_sectors))
}
get_disk_size_gb() {
local disk=$1
local total_sectors=$(cat /sys/block/$disk/size 2>/dev/null)
local total_gb=$((total_sectors * 512 / 1024 / 1024 / 1024))
echo $total_gb
}
get_disk_type() {
local disk=$1
if [[ $disk == nvme* ]]; then
echo "NVMe"
elif [[ $(cat /sys/block/$disk/queue/rotational 2>/dev/null) -eq 0 ]]; then
echo "SSD"
else
local transport=$(lsblk -d -o NAME,TRAN /dev/$disk 2>/dev/null | grep $disk | awk '{print $2}')
if [[ $transport == "sas" ]]; then
echo "SAS"
else
echo "SATA"
fi
fi
}
generate_ks_partition() {
local disk=$1
local is_upgrade=$2
# 获取磁盘总容量扇区和GB
local total_sectors=$(cat /sys/block/$disk/size)
local total_gb=$(get_disk_size_gb $disk)
local disk_type=$(get_disk_type $disk)
# 智能计算 root 分区大小
local root_gb=$(calculate_root_size $total_gb 70)
local root_size_sectors=$((root_gb * 1024 * 1024 * 1024 / 512))
# 计算剩余空间给 state 分区
local remaining_sectors=$((total_sectors - root_size_sectors))
local remaining_gb=$((remaining_sectors * 512 / 1024 / 1024 / 1024))
# 计算 boot 和 swap 预留空间
local boot_gb=1
local swap_gb=4
local reserved_gb=$((boot_gb + swap_gb))
cat << EOF
# ==================================================
# Disk Partition Information
# ==================================================
# Installation Type : $([ "$is_upgrade" == "yes" ] && echo "Upgrade" || echo "Fresh") Installation
# Disk Device : /dev/$disk
# Disk Type : $disk_type
# Disk Total : $total_gb GB ($total_sectors sectors)
#
# Partition Plan:
# - /boot : ${boot_gb}GB (reserved)
# - swap : ${swap_gb}GB (reserved)
# - / : ${root_gb}GB ($root_size_sectors sectors)
# - /state : ${remaining_gb}GB ($remaining_sectors sectors)
# ==================================================
EOF
cat << EOF
zerombr
ignoredisk --only-use=$disk
clearpart --all --initlabel
part /boot --fstype="xfs" --size=1024 --ondisk=$disk
part swap --fstype="swap" --size=4096 --ondisk=$disk
part / --fstype="xfs" --size=$((root_gb * 1024)) --ondisk=$disk
EOF
if [[ $is_upgrade == "yes" ]]; then
cat << EOF
part /state/partition1 --fstype=xfs --size=1 --grow --ondisk=$disk
EOF
fi
}
main() {
local is_installed=$(is_installed_node)
if [[ $is_installed == "yes" ]]; then
echo "# Detected: Already installed node (found .sunhpc-release)"
local found_disk=""
local disks=$(lsblk -d -n -o NAME,TYPE | grep disk | awk '{print $1}')
for disk in $disks; do
local partitions=$(lsblk -n -o NAME /dev/$disk | grep -E "^${disk}p?[0-9]+" || true)
for part in $partitions; do
local mount_point="/mnt/tmp_${part}"
mkdir -p $mount_point 2>/dev/null
if mount -t ext4 -o ro /dev/$part $mount_point 2>/dev/null || \
mount -t xfs -o ro /dev/$part $mount_point 2>/dev/null; then
if [[ -f $mount_point/.sunhpc-release ]]; then
found_disk=$disk
umount $mount_point
rmdir $mount_point 2>/dev/null
break 2
fi
umount $mount_point
fi
rmdir $mount_point 2>/dev/null
done
done
if [[ -n $found_disk ]]; then
echo "# Found existing installation on disk: /dev/$found_disk"
generate_ks_partition $found_disk "yes"
else
echo "# ERROR: Cannot find disk with .sunhpc-release, using default"
local best_disk=$(select_best_disk)
generate_ks_partition $best_disk "yes"
fi
else
echo "# Detected: Fresh installation"
local best_disk=$(select_best_disk)
if [[ -z $best_disk ]]; then
echo "# ERROR: No disk found"
exit 1
fi
echo "# Selected best disk: /dev/$best_disk"
generate_ks_partition $best_disk "no"
fi
}
main

View File

@@ -12,8 +12,8 @@ choose --default @osname@ --timeout 5000 selected || goto local
echo Booting @osrels@ from networking
kernel @vmlinuz@ \
@kargs@ \
@repos@ \
@ksarg@
inst.repo=@repos@ \
inst.ks=@ksarg@
initrd @initrds@
boot

View File

@@ -16,7 +16,13 @@ network --bootproto=dhcp --device=link --ipv6=auto --activate
# part swap --fstype="swap" --ondisk=sda --size=4096
# part / --fstype="xfs" --ondisk=sda --size=97278
# part /home --fstype="xfs" --ondisk=sda --size=20480
# autopart --type=lvm
# autopart --type=plain
# autopart --nohome
# autopart --noswap
%include /tmp/diskinfo
%packages
@@ -32,14 +38,34 @@ nfs4-acl-tools
sssd-nfs-idmap
%end
rootpw --plaintext admin_b101
user --name=dell --plaintext admin_b101 --gecos="dell"
sshpw --username=root
rootpw --plaintext "admin_b101"
user --name=dell --plaintext --password="admin_b101" --gecos="dell"
reboot
%pre --interpreter=/bin/bash
curl -o /tmp/dfmt.sh @dfmt@
chmod +x /tmp/dfmt.sh
/tmp/dfmt.sh > /tmp/diskinfo
if [ -d /sys/firmware/efi ]; then
cat > /tmp/diskinfo <<EOF
clearpart --all --initlabel
part /boot/efi --fstype=efi --size=600 --fsoptions="umask=0077,shortname=uefi"
part /boot --fstype=xfs --size=1024
part pv.01 --size=1 --grow
volgroup vg_sys pv.01
logvol / --fstype=xfs --name=root --vgname=vg_sys --size=51200
logvol swap --fstype=swap --name=swap --vgname=vg_sys --size=4096
logvol /data --fstype=xfs --name=data --vgname=vg_sys --size=1 --grow
EOF
else
cat > /tmp/diskinfo <<EOF
clearpart --all --initlabel
part /boot --fstype=xfs --size=1024 --asprimary
part pv.01 --size=1 --grow
volgroup vg_sys pv.01
logvol / --fstype=xfs --name=root --vgname=vg_sys --size=51200
logvol swap --fstype=swap --name=swap --vgname=vg_sys --size=4096
logvol /data --fstype=xfs --name=data --vgname=vg_sys --size=1 --grow
EOF
fi
%end
%post

Binary file not shown.

296
sunhpc
View File

@@ -6,7 +6,7 @@ R='\e[1;31m'
AR='\e[0;31m'
G='\e[1;92m'
AG='\e[0;92m'
AG='\e[0;32m'
C='\e[1;36m' # 亮青色
AC='\e[0;36m' # 暗青色
@@ -109,6 +109,25 @@ load_conf_envs() {
done < "$config_file"
}
human_size() {
local bytes=$1
local unit="B"
local value=$bytes
if [[ $bytes -ge 1073741824 ]]; then
value=$(echo "scale=2; $bytes / 1073741824" | bc)
unit="GB"
elif [[ $bytes -ge 1048576 ]]; then
value=$(echo "scale=2; $bytes / 1048576" | bc)
unit="MB"
elif [[ $bytes -ge 1024 ]]; then
value=$(echo "scale=2; $bytes / 1024" | bc)
unit="KB"
fi
echo "${value} ${unit}"
}
parse_treeinfo() {
local treeinfo_file="${1:-.treeinfo}"
local current_section=""
@@ -218,6 +237,106 @@ getArgs() {
fi
}
service() {
local service_name=$1
local action=${2:-start} # 默认动作为 start
case $action in
start)
systemctl daemon-reload
if systemctl start "$service_name" 2>/dev/null; then
info "✓ $service_name 启动成功"
return 0
else
warn "✗ $service_name 启动失败"
systemctl status "$service_name" --no-pager -l
return 1
fi
;;
stop)
if systemctl stop "$service_name" 2>/dev/null; then
info "✓ $service_name 停止成功"
return 0
else
warn "✗ $service_name 停止失败"
return 1
fi
;;
restart)
systemctl daemon-reload
if systemctl restart "$service_name" 2>/dev/null; then
info "✓ $service_name 重启成功"
return 0
else
warn "✗ $service_name 重启失败"
systemctl status "$service_name" --no-pager -l
return 1
fi
;;
status)
if systemctl is-active --quiet "$service_name"; then
info "✓ $service_name 运行中"
return 0
else
warn "✗ $service_name 未运行"
return 1
fi
;;
*)
warn "Example: service <srv name> [start|stop|restart|status]"
warn "Default: start"
return 1
;;
esac
}
iptables_srv() {
# iptables-srv 80
# iptables-srv 80,90
# iptables-srv 80,90/tcp
# iptables-srv 80-90/tcp
local target="$1"
local srvname="sunhpc"
if [[ $EUID -ne 0 ]]; then
error "ERROR: Require root perms, Please use sudo execute."
fi
if ! systemctl is-active --quiet firewalld; then
error "ERROR: Firewalld is not running..."
fi
if ! firewall-cmd --get-services |grep -qw "$srvname"; then
info "Create firewall service : $srvname"
firewall-cmd --permanent --new-service=$srvname &>/dev/null
firewall-cmd --permanent --quiet --service=$srvname --set-short="$srvname cluster"
firewall-cmd --permanent --quiet --service=$srvname --set-description="Ports used by $srvname service"
firewall-cmd --reload --quiet
firewall-cmd --permanent --quiet --add-service=$srvname
firewall-cmd --reload --quiet
fi
# 判断输入端口是单个还是多个,使用逗号分割
IFS=',' read -ra port_array <<< "$target"
for port in "${port_array[@]}"; do
if firewall-cmd --service=$srvname --list-ports| grep -q $port ; then
info "Already added: $port"
else
info "Ports added: $port"
firewall-cmd --permanent --quiet --service=$srvname --add-port=$port
fi
done
firewall-cmd --quiet --reload
ports=($(firewall-cmd --service=$srvname --list-ports))
info "FW Service: $srvname"
for port in "${ports[@]}"; do
info "Port is open: $port"
done
info "$SSEP"
}
# ============================================================
# 辅助函数:打印所有环境变量(调试用)
# ============================================================
@@ -376,10 +495,7 @@ get_subnet_address() {
}
# ====================== pxe server functions ====================
build_httpd_srv() {
log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}"
log_debug "私有参数:${PRIVATE_ARGS[*]}"
wwwroot=${1:-/var/www/html/linux}
nopkgs=()
pkgs=("httpd")
@@ -394,12 +510,12 @@ build_httpd_srv() {
custom_conf="$http_root_conf/conf.d/sunhpc.conf"
{
echo 'Alias /linux /var/www/html/linux'
echo "Alias /linux $wwwroot"
echo ''
echo 'UseCanonicalName Off'
echo "ServerName `hostname -f`"
echo ''
echo '<Directory "/var/www/html/linux">'
echo "<Directory \"$wwwroot\">"
echo " Options Indexes FollowSymLinks"
echo " AllowOverride None"
echo " Require all granted"
@@ -408,10 +524,7 @@ build_httpd_srv() {
echo "</Directory>"
} > ${custom_conf}
#systemctl daemon-reload && systemctl restart httpd
#systemctl is-enabled httpd &>/dev/null || systemctl enable httpd &>/dev/null
systemctl is-enabled httpd &>/dev/null || systemctl enable httpd &>/dev/null
if systemctl is-active httpd &>/dev/null ; then
info "HTTP 服务部署成功"
info "HTTP 服务端口: 80,443"
@@ -802,6 +915,25 @@ check_node_status() {
fi
}
check_download() {
local url="$1"
local result
result=$(curl -o /dev/null -s -w '%{http_code}|%{speed_download}|%{time_total}|%{size_download}' "$url")
IFS='|' read -r http_code speed_download time_total size_download <<< "$result"
local speed_mb=$(human_size $speed_download)
local file_size=$(human_size $size_download)
local time_fmt=$(printf "%.4f" "$time_total")
info "CHECk File: ${url}"
info "HTTPs Code: ${http_code}"
info "Files Size: ${file_size}"
info "Speed Down: ${speed_mb}/s"
info "Total Time: ${time_fmt} Second"
[[ $http_code -eq 200 ]] && return 0 || return 1
}
show_nodes() {
echo "$SSEP"
printf "${G}%-12s %-15s %-8s %s${NC}\n" "Nodename" "Status" "Port" "Days"
@@ -1039,6 +1171,7 @@ rsync_sync_file() {
info " 源路径: $source"
info " 目标路径: $destination"
info " rsync 选项: $rsync_opts"
info ""
rsync $rsync_opts "$rsync_source" "$destination"
exit_code=$?
@@ -1062,6 +1195,7 @@ rsync_sync_file() {
return $exit_code
}
info "$SSEP"
}
# ====================== 帮助文档 ======================
show_help() {
@@ -1185,6 +1319,8 @@ init_run() {
getArgs interface iface e "必须指定一个网络接口,例如: -i/--interface eth1"
getArgs mntroot mntroot e "必须指定 mnt 路径,例如: -m/--mntroot /mnt/cdrom"
[[ -z ${global_env[${iface}_ip]} ]] && error "ERROR: no ip address for ${iface}"
treeinfo=$(find -L $mntroot -name ".treeinfo")
parse_treeinfo $treeinfo
@@ -1195,62 +1331,85 @@ init_run() {
[[ -z "$treeinfo" ]] && warn "提供的 $mntroot 目录为空,或是不被支持的系统."
nopkgs=()
pkgs=("ipxe-bootimgs")
pkgs=("ipxe-bootimgs git rsync vim createrepo_c httpd \
make bc wget curl syslinux dnsmasq dnsmasq-utils ipxe-bootimgs")
filter_pkgs pkgs nopkgs
local cmd=("dnf -y install ${nopkgs[*]}")
[[ -z ${nopkgs[@]} ]] || run_with_progress "DNF Install ipxe tools..." "$cmd" "$log_file"
srv_root="/srv"
repos_root="$srv_root/repos"
kernel_path="${global_treeinfo[images-x86_64.kernel]}"
initrd_path="${global_treeinfo[images-x86_64.initrd]}"
sys_os_rels="${global_treeinfo[general.family]}" # RockyLinux
sys_os_vers="${global_treeinfo[general.version]}" # 9.7
url_os_path="$sys_os_rels/$sys_os_vers" # http://ip/ 后面系统路径 rockylinux/9.7
ipaddr=${global_env[${iface}_ip]}
netcidr=${global_env[${iface}_mask]}
netmask=$(cidr_to_netmask 24)
subnet=$(get_subnet_address $ipaddr $netmask)
dnsip="233.5.5.5"
IFS=. read -r i1 i2 i3 i4 <<< "$ipaddr"
start_ip="$i1.$i2.$i3.10"
ender_ip="$i1.$i2.$i3.90"
mnt_dst="$repos_root/$url_os_path"
rsync_sync_file $mntroot $mnt_dst
lsrv_root="/srv"
lrepo_name="$sys_os_rels/$sys_os_vers" # rockylinux/9.7
lrepo_root="$lsrv_root/repos" # /srv/repos
lrepo_path="$lrepo_root/$sys_os_rels" # /srv/repos/rockylinux
lrepo_vers="$lrepo_root/$lrepo_name" # /srv/repos/rockylinux/9.7
lrepo_path="$repos_root/$sys_os_rels"
rsync_sync_file $mntroot $lrepo_vers
lrepo_file="/etc/yum.repos.d/sunhpc.repo"
{
echo "[sunhpc-baseos]"
echo "name=SunHPC Local Repos ${sys_os_rels^} ${sys_os_vers} - BaseOS"
echo "baseurl=file://$lrepo_vers/BaseOS"
echo "gpgcheck=1"
echo "enabled=1"
echo "[sunhpc-AppStream]"
echo "name=SunHPC Local Repos ${sys_os_rels^} ${sys_os_vers} - AppStream"
echo "baseurl=file://$lrepo_vers/AppStream"
echo "gpgcheck=1"
echo "enabled=1"
} > $lrepo_file
wwwroot="/var/www/html/linux"
linksrc="$lrepo_root/$sys_os_rels" # /srv/repos/rockylinux
linkdst="$wwwroot/$sys_os_rels" # /var/www/html/linux/rockylinux
[[ -e $wwwroot ]] || mkdir -p $wwwroot
[[ -e $linkdst ]] || ln -s $linksrc $linkdst
ks_src="$PWD/pkgs/"
ks_dst="$srv_root/htool/pkgs/"
[[ -e $ks_src ]] && rsync_sync_file $ks_src $ks_dst
# Copy pkgs file to /srv/repos/tools/pkgs
pkgs_src="$PWD/pkgs/"
pkgs_dst="$lrepo_root/pkgs/" # /srv/repos/pkgs/
[[ -e $pkgs_src ]] && rsync_sync_file $pkgs_src $pkgs_dst
tftpboot="/srv/pxelinux/tftpboot"
lkickstart="$lrepo_root/pkgs/ks" # /srv/repos/pkgs/ks
dkickstart="${wwwroot}/" # /var/www/html/linux/
[[ -e $wwwroot/ks ]] || ln -s $lkickstart $dkickstart &>/dev/null
efi_src="$mnt_dst/EFI/BOOT/BOOTX64.EFI"
[[ -e $efi_src ]] && rsync_sync_file $efi_src $tftpboot/bootx64.efi \
|| warn "UEFI Boot file no found: $efi_src"
ltftpboot="${pkgs_src}pxelinux/tftpboot/" # $PWD/pkgs/pxelinux/tftpboot/
dtftpboot="/srv/pxelinux/tftpboot" # /srv/pxelinux/tftpboot
rsync_sync_file $ltftpboot $dtftpboot/
ipxe_src="/usr/share/ipxe/undionly.kpxe"
[[ -e $ipxe_src ]] && rsync_sync_file $ipxe_src $tftpboot/boot/ \
|| warn "iPXE Boot file no found: $ipxe_tools"
chmod -R 755 $dtftpboot
getent passwd dnsmasq &>/dev/null && chown -R dnsmasq:dnsmasq $dtftpboot
ks_args="net.ifnames=0 biosdevname=0"
ks_args="net.ifnames=0 biosdevname=0 inst.sshd"
ks_rhel="http://$ipaddr/linux/ks/rhel.ks"
ks_dfmt="http://$ipaddr/linux/ks/dfmt.sh"
ks_ipxe="http://$ipaddr/linux/ks/ipxe.sh"
ks_init="http://$ipaddr/linux/ks/init.sh"
ks_repo="http://$ipaddr/linux/$url_os_path"
vmlinuz="http://$ipaddr/linux/$url_os_path/$kernel_path"
initrds="http://$ipaddr/linux/$url_os_path/$initrd_path"
ks_repo="http://$ipaddr/linux/$lrepo_name"
vmlinuz="http://$ipaddr/linux/$lrepo_name/$kernel_path"
initrds="http://$ipaddr/linux/$lrepo_name/$initrd_path"
biosboot="$dtftpboot/boot/undionly.kpxe"
uefiboot="$dtftpboot/boot/bootx64.efi"
ipxeboot="$dtftpboot/boot/ipxe.efi"
{
echo "# ===================================================="
echo "# Generated by htool commands"
@@ -1258,19 +1417,20 @@ init_run() {
echo ""
echo "interface $iface"
echo "server $ipaddr"
echo "pkgsroot $ks_dst"
echo "pkgssrc $pkgs_src"
echo "pkgsdst $pkgs_dst"
echo "wwwroot $wwwroot"
echo "tftpboot $tftpboot"
echo "tftpboot $dtftpboot"
echo "startip $start_ip"
echo "endip $ender_ip"
echo "dns 223.5.5.5"
echo "dns $dnsip"
echo "osname $sys_os_rels"
echo "osvers $sys_os_vers"
echo "ospath $url_os_path"
echo "ospath $lrepo_name"
echo "lrepo $lrepo_path"
echo "bios $tftpboot/boot/undionly.kpxe"
echo "uefi $tftpboot/boot/bootx64.efi"
echo "dfmt $ks_dfmt"
echo "bios $biosboot"
echo "uefi $uefiboot"
echo "ipxe $ipxeboot"
echo "ksaddr $ks_rhel"
echo "ipxeboot $ks_ipxe"
echo "repos $ks_repo"
@@ -1278,7 +1438,39 @@ init_run() {
echo "initrd $initrds"
} > $config_file
pkgs_ipxe="$srv_root/htool/pkgs/ks/ipxe.sh"
biosboot="${biosboot#$dtftpboot/}"
uefiboot="${uefiboot#$dtftpboot/}"
ipxeboot="${ipxeboot#$dtftpboot/}"
dnsmasq_conf="/etc/dnsmasq.d/sunhpc.conf"
{
echo "interface=$iface"
echo "bind-interfaces"
echo "port=0"
echo ""
echo "enable-tftp"
echo "tftp-root=${dtftpboot}"
echo ""
echo "# Gateway:3, DNS:6"
echo "dhcp-range=$start_ip,$ender_ip,12h"
echo "dhcp-option=3,${ipaddr}"
echo "dhcp-option=6,$dnsip"
echo ""
echo "dhcp-match=set:ipxe,175"
echo "dhcp-match=set:bios,option:client-arch,0"
echo "dhcp-match=set:uefi,option:client-arch,7"
echo "dhcp-match=set:uefi,option:client-arch,9"
echo "dhcp-match=set:ipxe,option:user-class,ipxe"
echo ""
echo "dhcp-boot=tag:bios,tag:!ipxe,$biosboot"
echo "dhcp-boot=tag:uefi,tag:!ipxe,$uefiboot"
echo "dhcp-boot=tag:ipxe,$ks_ipxe"
} > ${dnsmasq_conf}
if ! service dnsmasq start; then
service dnsmasq restart
fi
iptables_srv "53/tcp,53/udp,67-69/udp"
pkgs_ipxe="$pkgs_dst/ks/ipxe.sh"
sed -i "s|@osname@|$sys_os_rels|" $pkgs_ipxe
sed -i "s|@osrels@|"${sys_os_rels^}"|" $pkgs_ipxe
sed -i "s|@osvers@|$sys_os_vers|" $pkgs_ipxe
@@ -1288,17 +1480,24 @@ init_run() {
sed -i "s|@repos@|$ks_repo|" $pkgs_ipxe
sed -i "s|@ksarg@|$ks_rhel|" $pkgs_ipxe
pkgs_rhel="$srv_root/htool/pkgs/ks/rhel.ks"
pkgs_rhel="$pkgs_dst/ks/rhel.ks"
sed -i "s|@url@|$ks_repo|" $pkgs_rhel
sed -i "s|@dfmt@|$ks_dfmt|" $pkgs_rhel
sed -i "s|@init@|$ks_init|" $pkgs_rhel
pkgs_init="${ks_dst}ks/init.sh"
pkgs_init="${pkgs_dst}ks/init.sh"
sed -i "s|@osipaddr@|$ipaddr|" $pkgs_init
sed -i "s|@ospath@|$url_os_path|" $pkgs_init
}
sed -i "s|@ospath@|$lrepo_name|" $pkgs_init
build_httpd_srv $wwwroot
if ! service httpd start; then
service httpd restart
fi
iptables_srv "80/tcp,80/udp,443/tcp,443/udp"
check_download "$ks_repo/.treeinfo"
#check_download "$ks_repo/images/install.img"
}
# -----------------------------------------------------------------------------------------------------------------
exec_run() {
log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}"
@@ -1499,4 +1698,7 @@ main() {
dispatch
}
info "$DSEP"
main "$@"
info "$DSEP"
echo ""