From 0e425eff6eeb5000a6a9d381a48460a04384d1cd Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Sun, 31 Dec 2023 09:20:23 +0000 Subject: [PATCH] 2023.12.31 --- CHANGELOG.md | 4 +++ README.md | 5 ++-- scripts/create_ct.sh | 5 +++- scripts/create_vm.sh | 7 +++-- scripts/pve_delete.sh | 65 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 scripts/pve_delete.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 50e9ec4..cb3fcb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新日志 +2023.12.27 + +- 修复部分宿主机安装过程中可能存在```firmware-ath9k-htc```需要移除的情况 + 2023.12.21 - 修复部分宿主机和LXC容器不含定时任务机制的问题 diff --git a/README.md b/README.md index f1b944f..b812da2 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,10 @@ ## 更新 -2023.12.27 +2023.12.31 -- 修复部分宿主机安装过程中可能存在```firmware-ath9k-htc```需要移除的情况 +- 增加一个删除对应容器/虚拟机的脚本,避免在删除过程中删除了非对应的映射规则 +- 修复批量开设时最后一个循环后续没有要等待的内容还去等待的问题 [更新日志](CHANGELOG.md) diff --git a/scripts/create_ct.sh b/scripts/create_ct.sh index 74c790a..12ea4e4 100644 --- a/scripts/create_ct.sh +++ b/scripts/create_ct.sh @@ -1,7 +1,7 @@ #!/bin/bash # from # https://github.com/spiritLHLS/pve -# 2023.07.31 +# 2023.12.31 # cd /root @@ -204,6 +204,9 @@ build_new_cts() { ./buildct.sh $ct_num $password $cpu_nums $memory_nums $disk_nums $ssh_port $web1_port $web2_port $port_start $port_end $system $storage $independent_ipv6 cat "ct$ct_num" >>ctlog rm -rf "ct$ct_num" + if [ "$i" = "$new_nums" ]; then + break + fi sleep 30 done } diff --git a/scripts/create_vm.sh b/scripts/create_vm.sh index ad7f918..a457c90 100644 --- a/scripts/create_vm.sh +++ b/scripts/create_vm.sh @@ -1,7 +1,7 @@ #!/bin/bash # from # https://github.com/spiritLHLS/pve -# 2023.07.31 +# 2023.12.31 # cd /root @@ -242,7 +242,10 @@ build_new_vms() { ./buildvm.sh $vm_num $user $password $cpu_nums $memory_nums $disk_nums $ssh_port $web1_port $web2_port $port_start $port_end $system $storage $independent_ipv6 cat "vm$vm_num" >>vmlog rm -rf "vm$vm_num" - sleep 60 + if [ "$i" = "$new_nums" ]; then + break + fi + sleep 30 done } diff --git a/scripts/pve_delete.sh b/scripts/pve_delete.sh new file mode 100644 index 0000000..22150aa --- /dev/null +++ b/scripts/pve_delete.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# from +# https://github.com/spiritLHLS/pve +# 2023.12.31 +# ./pve_delete.sh arg1 arg2 +# arg 可填入虚拟机/容器的序号,可以有任意多个 + +# 输入解析 +args=("$@") +num_args=${#args[@]} + +# 虚拟机操作 +vmids=$(qm list | awk '{if(NR>1)print $1}') +if [ -n "$vmids" ]; then + # 遍历每个VMID的config,提取ip=到/24之间的内容 + for vmid in $vmids; do + ip_address=$(qm config $vmid | grep -oP 'ip=\K[0-9.]+') + if [ ! -z "$ip_address" ]; then + vmip_array["$vmid"]=$ip_address + fi + done + for key_1 in "${!vmip_array[@]}"; do + for key_2 in "${args[@]}"; do + if [ "$key_1" = "$key_2" ]; then + ip_address="${vmip_array[$key_1]}" + echo "Delete VMID $key_1 IP Address $ip_address Mapping" + sed -i "/$ip_address:/d" /etc/iptables/rules.v4 + qm stop $vmid + qm destroy $vmid + rm -rf /var/lib/vz/images/$vmid* + rm -rf vm"$key_1" + fi + done + done +fi + +# 容器操作 +ctids=$(pct list | awk '{if(NR>1)print $1}') +if [ -n "$ctids" ]; then + # 遍历每个CTID的config,提取ip=到/24之间的内容 + for ctid in $ctids; do + ip_address=$(pct config $ctid | grep -oP 'ip=\K[0-9.]+') + if [ ! -z "$ip_address" ]; then + ctip_array["$ctid"]=$ip_address + fi + done + for key_1 in "${!ctip_array[@]}"; do + for key_2 in "${args[@]}"; do + if [ "$key_1" = "$key_2" ]; then + ip_address="${ctip_array[$key_1]}" + echo "Delete CTID $key_1 IP Address $ip_address Mapping" + sed -i "/$ip_address:/d" /etc/iptables/rules.v4 + pct stop "$key_1" + pct destroy "$key_1" + rm -rf ct"$key_1" + fi + done + done +fi + +# 其他相关操作 +cat /etc/iptables/rules.v4 | iptables-restore +service networking restart +systemctl restart networking.service +systemctl restart ndpresponder.service \ No newline at end of file