更新双语支持

This commit is contained in:
spiritlhl 2023-06-29 13:41:08 +00:00
parent 1e0123090c
commit d19ee468da
12 changed files with 301 additions and 229 deletions

View file

@ -1,5 +1,9 @@
# 更新日志
2023.06.29
- 修改部分脚本提示避免脚本被小白重复执行
2023.06.26
- 修复ipv6网络是SLAAC动态分配时vmbr0的设置导致宿主机没有V6网络的问题

View file

@ -13,9 +13,9 @@
## 更新
2023.06.28
2023.06.29
- 修改部分脚本提示避免脚本被小白重复执行
- 规整输出,所有输出修改为中英双语
[更新日志](CHANGELOG.md)

View file

@ -1,7 +1,8 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.06.27
# 2023.06.29
# 打印信息
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
@ -20,6 +21,8 @@ else
fi
if [ -f "/root/build_backend_pve.txt" ]; then
_green "You have already executed this script, if you have already rebooted your system, please execute the subsequent script commands to automatically configure the gateway, if you have not rebooted your system, please reboot your system"
_grenn "Do not run this script repeatedly"
_green "你已执行过本脚本,如果已重启过系统,请执行后续的自动配置网关的脚本命令,如果未重启过系统,请重启系统"
_grenn "不要重复运行本脚本"
exit 1

View file

@ -1,7 +1,7 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.06.27
# 2023.06.29
# 打印信息
@ -60,18 +60,18 @@ SUBNET_PREFIX=$(ip -6 addr show | grep -E 'inet6.*global' | awk '{print $2}' | a
ipv6_address=$(ip addr show | awk '/inet6.*scope global/ { print $2 }' | head -n 1)
# 检查是否存在 IPV6
if [ -z "$SUBNET_PREFIX" ] || [ "$SUBNET_PREFIX" = ":0" ]; then
_red "无 IPV6 子网,不进行自动映射"
_red "No IPV6 subnet, no automatic mapping"
_red "无 IPV6 子网,不进行自动映射"
else
_blue "母鸡的IPV6子网前缀为 $SUBNET_PREFIX"
_blue "The IPV6 subnet prefix of the host is $SUBNET_PREFIX"
_blue "母鸡的IPV6子网前缀为 $SUBNET_PREFIX"
fi
if [ -z "$ipv6_address" ]; then
_red "母机无 IPV6 地址,不进行自动映射"
_red "No IPV6 address on the parent machine, no automatic mapping"
_red "母机无 IPV6 地址,不进行自动映射"
else
_blue "母鸡的IPV6地址为 $ipv6_address"
_blue "The IPV6 address of the host is $ipv6_address"
_blue "母鸡的IPV6地址为 $ipv6_address"
fi
# 录入网关
@ -96,17 +96,17 @@ interfaces_file="/etc/network/interfaces"
chattr -i "$interfaces_file"
if ! grep -q "auto lo" "$interfaces_file"; then
# echo "auto lo" >> "$interfaces_file"
echo "Can not find 'auto lo' in ${interfaces_file}"
_blue "Can not find 'auto lo' in ${interfaces_file}"
exit 1
fi
if ! grep -q "iface lo inet loopback" "$interfaces_file"; then
# echo "iface lo inet loopback" >> "$interfaces_file"
echo "Can not find 'iface lo inet loopback' in ${interfaces_file}"
_blue "Can not find 'iface lo inet loopback' in ${interfaces_file}"
exit 1
fi
if grep -q "vmbr0" "$interfaces_file"; then
echo "vmbr0 已存在在 ${interfaces_file}"
echo "vmbr0 already exists in ${interfaces_file}"
_blue "vmbr0 already exists in ${interfaces_file}"
_blue "vmbr0 已存在在 ${interfaces_file}"
else
if [ -z "$SUBNET_PREFIX" ] || [ "$SUBNET_PREFIX" = ":0" ] || [ -z "$ipv6_address" ]; then
cat << EOF | sudo tee -a "$interfaces_file"
@ -148,8 +148,8 @@ EOF
fi
fi
if grep -q "vmbr1" "$interfaces_file"; then
echo "vmbr1 已存在在 ${interfaces_file}"
echo "vmbr1 already exists in ${interfaces_file}"
_blue "vmbr1 already exists in ${interfaces_file}"
_blue "vmbr1 已存在在 ${interfaces_file}"
elif [ -f "/root/iface_auto.txt" ]; then
cat << EOF | sudo tee -a "$interfaces_file"
auto vmbr1

View file

@ -1,7 +1,8 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.06.14
# 2023.06.29
# ./buildct.sh CTID 密码 CPU核数 内存 硬盘 SSH端口 80端口 443端口 外网端口起 外网端口止 系统 存储盘
# ./buildct.sh 102 1234567 1 512 5 20001 20002 20003 30000 30025 debian11 local
@ -14,12 +15,12 @@ _blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
reading(){ read -rp "$(_green "$1")" "$2"; }
utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "UTF-8|utf8")
if [[ -z "$utf8_locale" ]]; then
echo "No UTF-8 locale found"
echo "No UTF-8 locale found"
else
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
echo "Locale set to $utf8_locale"
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
echo "Locale set to $utf8_locale"
fi
cd /root >/dev/null 2>&1
@ -41,23 +42,23 @@ num_system=$(echo "$system_ori" | sed 's/[a-zA-Z]*//g')
system="$en_system-$num_system"
system_name=$(pveam available --section system | grep "$system" | awk '{print $2}' | head -n1)
if ! pveam available --section system | grep "$system" > /dev/null; then
_red "No such system"
exit
_red "No such system"
exit
else
_green "Use $system_name"
_green "Use $system_name"
fi
pveam download local $system_name
check_cdn() {
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" > /dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" > /dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
}
check_cdn_file() {
@ -76,13 +77,13 @@ first_digit=${CTID:0:1}
second_digit=${CTID:1:1}
third_digit=${CTID:2:1}
if [ $first_digit -le 2 ]; then
if [ $second_digit -eq 0 ]; then
num=$third_digit
else
num=$second_digit$third_digit
fi
if [ $second_digit -eq 0 ]; then
num=$third_digit
else
num=$second_digit$third_digit
fi
else
num=$((first_digit - 2))$second_digit$third_digit
num=$((first_digit - 2))$second_digit$third_digit
fi
user_ip="172.16.1.${num}"
pct create $CTID ${storage}:vztmpl/$system_name -cores $core -cpuunits 1024 -memory $memory -swap 128 -rootfs ${storage}:${disk} -onboot 1 -password $password -features nesting=1
@ -121,15 +122,15 @@ iptables-save > /etc/iptables/rules.v4
service netfilter-persistent restart
echo "$CTID $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system_ori $storage" >> "ct${CTID}"
# 容器的相关信息将会存储到对应的容器的NOTE中可在WEB端查看
data=$(echo " CTID root密码 CPU核数 内存 硬盘 SSH端口 80端口 443端口 外网端口起 外网端口止 系统 存储盘")
data=$(echo " CTID root密码-password CPU核数-CPU 内存-memory 硬盘-disk SSH端口 80端口 443端口 外网端口起-port-start 外网端口止-port-end 系统-system 存储盘-storage")
values=$(cat "ct${CTID}")
IFS=' ' read -ra data_array <<< "$data"
IFS=' ' read -ra values_array <<< "$values"
length=${#data_array[@]}
for ((i=0; i<$length; i++))
do
echo "${data_array[$i]} ${values_array[$i]}"
echo ""
echo "${data_array[$i]} ${values_array[$i]}"
echo ""
done > "/tmp/temp${CTID}.txt"
sed -i 's/^/# /' "/tmp/temp${CTID}.txt"
cat "/etc/pve/lxc/${CTID}.conf" >> "/tmp/temp${CTID}.txt"

View file

@ -1,7 +1,8 @@
#!/bin/bash
# from
# from
# https://github.com/spiritLHLS/pve
# 2023.05.29
# 2023.06.29
# ./buildvm.sh VMID 用户名 密码 CPU核数 内存 硬盘 SSH端口 80端口 443端口 外网端口起 外网端口止 系统 存储盘
# ./buildvm.sh 102 test1 1234567 1 512 5 40001 40002 40003 50000 50025 debian11 local
@ -32,24 +33,24 @@ _blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
reading(){ read -rp "$(_green "$1")" "$2"; }
utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "utf8|UTF-8")
if [[ -z "$utf8_locale" ]]; then
_yellow "No UTF-8 locale found"
_yellow "No UTF-8 locale found"
else
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
_green "Locale set to $utf8_locale"
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
_green "Locale set to $utf8_locale"
fi
check_cdn() {
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" > /dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" > /dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
}
check_cdn_file() {
@ -63,40 +64,41 @@ check_cdn_file() {
cdn_urls=("https://cdn.spiritlhl.workers.dev/" "https://cdn3.spiritlhl.net/" "https://cdn1.spiritlhl.net/" "https://ghproxy.com/" "https://cdn2.spiritlhl.net/")
if [ ! -d "qcow" ]; then
mkdir qcow
mkdir qcow
fi
# "centos7" "alpinelinux_v3_15" "alpinelinux_v3_17" "rockylinux8" "QuTScloud_5.0.1"
systems=("debian10" "debian11" "debian9" "ubuntu18" "ubuntu20" "ubuntu22" "archlinux" "centos9-stream" "centos8-stream" "almalinux8" "almalinux9" "fedora33" "fedora34" "opensuse-leap-15")
for sys in ${systems[@]}; do
if [[ "$system" == "$sys" ]]; then
file_path="/root/qcow/${system}.qcow2"
break
fi
if [[ "$system" == "$sys" ]]; then
file_path="/root/qcow/${system}.qcow2"
break
fi
done
if [[ -z "$file_path" ]]; then
# centos9-stream centos8-stream centos7 almalinux8 almalinux9
echo "无法安装对应系统,请查看 https://github.com/spiritLHLS/Images/ 支持的系统镜像 "
exit 1
# centos9-stream centos8-stream centos7 almalinux8 almalinux9
_red "Unable to install corresponding system, please check https://github.com/spiritLHLS/Images/ for supported system images "
_red "无法安装对应系统,请查看 https://github.com/spiritLHLS/Images/ 支持的系统镜像 "
exit 1
fi
if [ ! -f "$file_path" ]; then
# v1.0 基础安装包预安装
# v1.1 增加agent安装包预安装方便在宿主机上看到虚拟机的进程
check_cdn_file
url="${cdn_success_url}https://github.com/spiritLHLS/Images/releases/download/v1.0/${system}.qcow2"
curl -L -o "$file_path" "$url"
# v1.0 基础安装包预安装
# v1.1 增加agent安装包预安装方便在宿主机上看到虚拟机的进程
check_cdn_file
url="${cdn_success_url}https://github.com/spiritLHLS/Images/releases/download/v1.0/${system}.qcow2"
curl -L -o "$file_path" "$url"
fi
first_digit=${vm_num:0:1}
second_digit=${vm_num:1:1}
third_digit=${vm_num:2:1}
if [ $first_digit -le 2 ]; then
if [ $second_digit -eq 0 ]; then
num=$third_digit
else
num=$second_digit$third_digit
fi
if [ $second_digit -eq 0 ]; then
num=$third_digit
else
num=$second_digit$third_digit
fi
else
num=$((first_digit - 2))$second_digit$third_digit
num=$((first_digit - 2))$second_digit$third_digit
fi
qm create $vm_num --agent 1 --scsihw virtio-scsi-single --serial0 socket --cores $core --sockets 1 --cpu host --net0 virtio,bridge=vmbr1,firewall=0
@ -128,15 +130,15 @@ iptables-save > /etc/iptables/rules.v4
service netfilter-persistent restart
echo "$vm_num $user $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system $storage" >> "vm${vm_num}"
# 虚拟机的相关信息将会存储到对应的虚拟机的NOTE中可在WEB端查看
data=$(echo " VMID 用户名 密码 CPU核数 内存 硬盘 SSH端口 80端口 443端口 外网端口起 外网端口止 系统 存储盘")
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk SSH端口 80端口 443端口 外网端口起-port-start 外网端口止-port-end 系统-system 存储盘-storage")
values=$(cat "vm${vm_num}")
IFS=' ' read -ra data_array <<< "$data"
IFS=' ' read -ra values_array <<< "$values"
length=${#data_array[@]}
for ((i=0; i<$length; i++))
do
echo "${data_array[$i]} ${values_array[$i]}"
echo ""
echo "${data_array[$i]} ${values_array[$i]}"
echo ""
done > "/tmp/temp${vm_num}.txt"
sed -i 's/^/# /' "/tmp/temp${vm_num}.txt"
cat "/etc/pve/qemu-server/${vm_num}.conf" >> "/tmp/temp${vm_num}.txt"

View file

@ -1,8 +1,10 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.06.05
# 2023.06.29
# 自动选择要绑定的IPV4地址
# ./buildvm_extraip.sh VMID 用户名 密码 CPU核数 内存 硬盘 系统 存储盘
# ./buildvm_extraip.sh 152 test1 1234567 1 512 5 debian11 local
@ -28,24 +30,24 @@ _blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
reading(){ read -rp "$(_green "$1")" "$2"; }
utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "utf8|UTF-8")
if [[ -z "$utf8_locale" ]]; then
_yellow "No UTF-8 locale found"
_yellow "No UTF-8 locale found"
else
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
_green "Locale set to $utf8_locale"
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
_green "Locale set to $utf8_locale"
fi
check_cdn() {
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" > /dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" > /dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
}
check_cdn_file() {
@ -59,55 +61,56 @@ check_cdn_file() {
cdn_urls=("https://cdn.spiritlhl.workers.dev/" "https://cdn3.spiritlhl.net/" "https://cdn1.spiritlhl.net/" "https://ghproxy.com/" "https://cdn2.spiritlhl.net/")
if [ ! -d "qcow" ]; then
mkdir qcow
mkdir qcow
fi
# "centos7" "alpinelinux_v3_15" "alpinelinux_v3_17" "rockylinux8" "QuTScloud_5.0.1"
systems=("debian10" "debian11" "debian9" "ubuntu18" "ubuntu20" "ubuntu22" "archlinux" "centos9-stream" "centos8-stream" "almalinux8" "almalinux9" "fedora33" "fedora34" "opensuse-leap-15")
for sys in ${systems[@]}; do
if [[ "$system" == "$sys" ]]; then
file_path="/root/qcow/${system}.qcow2"
break
fi
if [[ "$system" == "$sys" ]]; then
file_path="/root/qcow/${system}.qcow2"
break
fi
done
if [[ -z "$file_path" ]]; then
# centos9-stream centos8-stream centos7 almalinux8 almalinux9
echo "无法安装对应系统,请查看 https://github.com/spiritLHLS/Images/ 支持的系统镜像 "
exit 1
_red "Unable to install corresponding system, please check https://github.com/spiritLHLS/Images/ for supported system images "
_red "无法安装对应系统,请查看 https://github.com/spiritLHLS/Images/ 支持的系统镜像 "
exit 1
fi
if [ ! -f "$file_path" ]; then
# v1.0 基础安装包预安装
# v1.1 增加agent安装包预安装方便在宿主机上看到虚拟机的进程
check_cdn_file
url="${cdn_success_url}https://github.com/spiritLHLS/Images/releases/download/v1.1/${system}.qcow2"
curl -L -o "$file_path" "$url"
# v1.0 基础安装包预安装
# v1.1 增加agent安装包预安装方便在宿主机上看到虚拟机的进程
check_cdn_file
url="${cdn_success_url}https://github.com/spiritLHLS/Images/releases/download/v1.1/${system}.qcow2"
curl -L -o "$file_path" "$url"
fi
first_digit=${vm_num:0:1}
second_digit=${vm_num:1:1}
third_digit=${vm_num:2:1}
if [ $first_digit -le 2 ]; then
if [ $second_digit -eq 0 ]; then
num=$third_digit
else
num=$second_digit$third_digit
fi
if [ $second_digit -eq 0 ]; then
num=$third_digit
else
num=$second_digit$third_digit
fi
else
num=$((first_digit - 2))$second_digit$third_digit
num=$((first_digit - 2))$second_digit$third_digit
fi
# 查询信息
if ! command -v lshw > /dev/null 2>&1; then
apt-get install -y lshw
apt-get install -y lshw
fi
if ! command -v ping > /dev/null 2>&1; then
apt-get install -y iputils-ping
apt-get install -y ping
apt-get install -y iputils-ping
apt-get install -y ping
fi
interface=$(lshw -C network | awk '/logical name:/{print $3}' | head -1)
user_main_ip_range=$(grep -A 1 "iface ${interface}" /etc/network/interfaces | grep "address" | awk '{print $2}' | head -n 1)
if [ -z "$user_main_ip_range" ]; then
echo "宿主机可用IP区间查询失败"
exit 1
_red "Host available IP interval query failed"
_red "宿主机可用IP区间查询失败"
exit 1
fi
# 宿主机IP
user_main_ip=$(echo "$user_main_ip_range" | cut -d'/' -f1)
@ -137,19 +140,23 @@ done
# 宿主机的网关
gateway=$(grep -E "iface $interface" -A 3 "/etc/network/interfaces" | grep "gateway" | awk '{print $2}' | head -n 1)
if [ -z "$gateway" ]; then
echo "宿主机网关查询失败"
exit 1
_red "Host gateway query failed"
_red "宿主机网关查询失败"
exit 1
fi
# echo "ip=${user_ip}/${user_ip_range},gw=${gateway}"
# 检查变量是否为空并执行相应操作
if [ -z "$user_ip" ]; then
echo "可使用的IP列表查询失败"
exit 1
_red "The query for the list of available IPs failed"
_red "可使用的IP列表查询失败"
exit 1
fi
if [ -z "$user_ip_range" ]; then
echo "本虚拟机将要绑定的IP选择失败"
exit 1
_red "The selection of the IP to which this virtual machine will bind failed"
_red "本虚拟机将要绑定的IP选择失败"
exit 1
fi
_green "The current IP to which the VM will be bound is: ${user_ip}"
_green "当前虚拟机将绑定的IP为${user_ip}"
qm create $vm_num --agent 1 --scsihw virtio-scsi-single --serial0 socket --cores $core --sockets 1 --cpu host --net0 virtio,bridge=vmbr0,firewall=0
@ -170,7 +177,7 @@ qm start $vm_num
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip" >> "vm${vm_num}"
# 虚拟机的相关信息将会存储到对应的虚拟机的NOTE中可在WEB端查看
data=$(echo " VMID 用户名 密码 CPU核数 内存 硬盘 系统 存储盘 外网IP地址")
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk 系统-system 存储盘-storage 外网IP地址-ipv4")
values=$(cat "vm${vm_num}")
IFS=' ' read -ra data_array <<< "$data"
IFS=' ' read -ra values_array <<< "$values"

View file

@ -1,8 +1,10 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.06.20
# 2023.06.29
# 手动指定要绑定的IPV4地址
# ./buildvm_manual_ip.sh VMID 用户名 密码 CPU核数 内存 硬盘 系统 存储盘 IPV4地址
# ./buildvm_manual_ip.sh 152 test1 1234567 1 512 5 debian11 local a.b.c.d/24
@ -29,12 +31,12 @@ _blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
reading(){ read -rp "$(_green "$1")" "$2"; }
utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "utf8|UTF-8")
if [[ -z "$utf8_locale" ]]; then
_yellow "No UTF-8 locale found"
_yellow "No UTF-8 locale found"
else
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
_green "Locale set to $utf8_locale"
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
_green "Locale set to $utf8_locale"
fi
is_ipv4() {
@ -48,20 +50,20 @@ is_ipv4() {
}
if [[ -z "$extra_ip" ]]; then
_yellow "No IPV4 address is manually assigned"
_yellow "IPV4地址未手动指定"
exit 1
_yellow "No IPV4 address is manually assigned"
_yellow "IPV4地址未手动指定"
exit 1
else
user_ip=$(echo "$extra_ip" | cut -d'/' -f1)
user_ip_range=$(echo "$extra_ip" | cut -d'/' -f2)
if is_ipv4 "$user_ip"; then
_green "This IPV4 address will be used: ${user_ip}"
_green "将使用此IPV4地址: ${user_ip}"
else
_yellow "IPV4 addresses do not conform to the rules"
_yellow "IPV4地址不符合规则"
exit 1
fi
user_ip=$(echo "$extra_ip" | cut -d'/' -f1)
user_ip_range=$(echo "$extra_ip" | cut -d'/' -f2)
if is_ipv4 "$user_ip"; then
_green "This IPV4 address will be used: ${user_ip}"
_green "将使用此IPV4地址: ${user_ip}"
else
_yellow "IPV4 addresses do not conform to the rules"
_yellow "IPV4地址不符合规则"
exit 1
fi
fi
check_cdn() {
@ -92,67 +94,72 @@ fi
# "centos7" "alpinelinux_v3_15" "alpinelinux_v3_17" "rockylinux8" "QuTScloud_5.0.1"
systems=("debian10" "debian11" "debian9" "ubuntu18" "ubuntu20" "ubuntu22" "archlinux" "centos9-stream" "centos8-stream" "almalinux8" "almalinux9" "fedora33" "fedora34" "opensuse-leap-15")
for sys in ${systems[@]}; do
if [[ "$system" == "$sys" ]]; then
file_path="/root/qcow/${system}.qcow2"
break
fi
if [[ "$system" == "$sys" ]]; then
file_path="/root/qcow/${system}.qcow2"
break
fi
done
if [[ -z "$file_path" ]]; then
# centos9-stream centos8-stream centos7 almalinux8 almalinux9
echo "无法安装对应系统,请查看 https://github.com/spiritLHLS/Images/ 支持的系统镜像 "
exit 1
_red "Unable to install corresponding system, please check https://github.com/spiritLHLS/Images/ for supported system images "
_red "无法安装对应系统,请查看 https://github.com/spiritLHLS/Images/ 支持的系统镜像 "
exit 1
fi
if [ ! -f "$file_path" ]; then
# v1.0 基础安装包预安装
# v1.1 增加agent安装包预安装方便在宿主机上看到虚拟机的进程
check_cdn_file
url="${cdn_success_url}https://github.com/spiritLHLS/Images/releases/download/v1.1/${system}.qcow2"
curl -L -o "$file_path" "$url"
# v1.0 基础安装包预安装
# v1.1 增加agent安装包预安装方便在宿主机上看到虚拟机的进程
check_cdn_file
url="${cdn_success_url}https://github.com/spiritLHLS/Images/releases/download/v1.1/${system}.qcow2"
curl -L -o "$file_path" "$url"
fi
first_digit=${vm_num:0:1}
second_digit=${vm_num:1:1}
third_digit=${vm_num:2:1}
if [ $first_digit -le 2 ]; then
if [ $second_digit -eq 0 ]; then
num=$third_digit
else
num=$second_digit$third_digit
fi
if [ $second_digit -eq 0 ]; then
num=$third_digit
else
num=$second_digit$third_digit
fi
else
num=$((first_digit - 2))$second_digit$third_digit
num=$((first_digit - 2))$second_digit$third_digit
fi
# 查询信息
if ! command -v lshw > /dev/null 2>&1; then
apt-get install -y lshw
apt-get install -y lshw
fi
if ! command -v ping > /dev/null 2>&1; then
apt-get install -y iputils-ping
apt-get install -y ping
apt-get install -y iputils-ping
apt-get install -y ping
fi
interface=$(lshw -C network | awk '/logical name:/{print $3}' | head -1)
user_main_ip_range=$(grep -A 1 "iface ${interface}" /etc/network/interfaces | grep "address" | awk '{print $2}' | head -n 1)
if [ -z "$user_main_ip_range" ]; then
echo "宿主机可用IP区间查询失败"
exit 1
_red "Host available IP interval query failed"
_red "宿主机可用IP区间查询失败"
exit 1
fi
# 宿主机的网关
gateway=$(grep -E "iface $interface" -A 3 "/etc/network/interfaces" | grep "gateway" | awk '{print $2}' | head -n 1)
if [ -z "$gateway" ]; then
echo "宿主机网关查询失败"
exit 1
_red "Host gateway query failed"
_red "宿主机网关查询失败"
exit 1
fi
# echo "ip=${user_ip}/${user_ip_range},gw=${gateway}"
# 检查变量是否为空并执行相应操作
if [ -z "$user_ip" ]; then
echo "可使用的IP匹配失败"
exit 1
_red "Available IP match failed"
_red "可使用的IP匹配失败"
exit 1
fi
if [ -z "$user_ip_range" ]; then
echo "可使用的子网大小匹配失败"
exit 1
_red "Available subnet size match failed"
_red "可使用的子网大小匹配失败"
exit 1
fi
_green "The current IP to which the VM will be bound is: ${user_ip}"
_green "当前虚拟机将绑定的IP为${user_ip}"
qm create $vm_num --agent 1 --scsihw virtio-scsi-single --serial0 socket --cores $core --sockets 1 --cpu host --net0 virtio,bridge=vmbr0,firewall=0
@ -173,7 +180,7 @@ qm start $vm_num
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip" >> "vm${vm_num}"
# 虚拟机的相关信息将会存储到对应的虚拟机的NOTE中可在WEB端查看
data=$(echo " VMID 用户名 密码 CPU核数 内存 硬盘 系统 存储盘 外网IP地址")
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk 系统-system 存储盘-storage 外网IP地址-ipv4")
values=$(cat "vm${vm_num}")
IFS=' ' read -ra data_array <<< "$data"
IFS=' ' read -ra values_array <<< "$values"

View file

@ -1,6 +1,8 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.06.29
# 用颜色输出信息
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
@ -19,6 +21,7 @@ else
fi
check_config(){
_green "The machine configuration should meet the minimum requirements of at least 2 cores 2G RAM 20G hard drive"
_green "本机配置应当满足至少2核2G内存20G硬盘的最低要求"
# 检查硬盘大小
@ -26,6 +29,8 @@ check_config(){
total_disk_num=$(echo $total_disk | sed -E 's/([0-9.]+)([GT])/\1 \2/')
total_disk_num=$(awk '{printf "%.0f", $1 * ($2 == "T" ? 1024 : 1)}' <<< "$total_disk_num")
if [ "$total_disk_num" -lt 20 ]; then
_red "The machine configuration does not meet the minimum requirements: at least 20G hard drive"
_red "This machine's hard drive configuration does not allow for the installation of PVE"
_red "本机配置不满足最低要求至少20G硬盘"
_red "本机硬盘配置无法安装PVE"
fi
@ -33,6 +38,8 @@ check_config(){
# 检查CPU核心数
cpu_cores=$(grep -c ^processor /proc/cpuinfo)
if [ "$cpu_cores" -lt 2 ]; then
_red "The local machine configuration does not meet the minimum requirements: at least 2 core CPU"
_red "The number of CPUs on this machine is configured in such a way that PVE cannot be installed"
_red "本机配置不满足最低要求至少2核CPU"
_red "本机CPU数量配置无法安装PVE"
fi
@ -40,6 +47,8 @@ check_config(){
# 检查内存大小
total_mem=$(free -m | awk '/^Mem:/{print $2}')
if [ "$total_mem" -lt 2048 ]; then
_red "The machine configuration does not meet the minimum requirements: at least 2G RAM"
_red "The local memory configuration cannot install PVE (SWAP is not calculated, if the virtual memory of SWAP plus the actual memory of the local machine is greater than 2G please ignore this prompt)"
_red "本机配置不满足最低要求至少2G内存"
_red "本机内存配置无法安装PVE (未计算SWAP如若SWAP的虚拟内存加上本机实际内存大于2G请忽略本提示)"
fi
@ -48,17 +57,21 @@ check_config
# 检查CPU是否支持硬件虚拟化
if [ "$(egrep -c '(vmx|svm)' /proc/cpuinfo)" -eq 0 ]; then
_yellow "CPU does not support hardware virtualization, cannot nest virtualized KVM servers, but can open LXC servers (CT)"
_yellow "CPU不支持硬件虚拟化无法嵌套虚拟化KVM服务器但可以开LXC服务器(CT)"
exit 1
else
_green "The local CPU supports KVM hardware nested virtualization"
_green "本机CPU支持KVM硬件嵌套虚拟化"
fi
# 检查虚拟化选项是否启用
if [ "$(grep -E -c '(vmx|svm)' /proc/cpuinfo)" -eq 0 ]; then
_yellow "Hardware virtualization is not enabled in BIOS, cannot nest virtualized KVM servers, but can open LXC servers (CT)"
_yellow "BIOS中未启用硬件虚拟化无法嵌套虚拟化KVM服务器但可以开LXC服务器(CT)"
exit 1
else
_green "This machine BIOS is enabled to support KVM hardware nested virtualization"
_green "本机BIOS已启用支持KVM硬件嵌套虚拟化"
fi
@ -68,24 +81,30 @@ if [ -e "/sys/module/kvm_intel/parameters/nested" ] && [ "$(cat /sys/module/kvm_
elif [ -e "/sys/module/kvm_amd/parameters/nested" ] && [ "$(cat /sys/module/kvm_amd/parameters/nested | tr '[:upper:]' '[:lower:]')" = "1" ]; then
CPU_TYPE="amd"
else
_yellow "The local system configuration file identifies that KVM hardware nested virtualization is not supported, the KVM server virtualized using PVE may not be able to turn on KVM hardware virtualization in the options, if you have problems using NOVNC remember to turn it off in the open out KVM server options, subject to whether you can actually use it"
_yellow "本机系统配置文件识别到不支持KVM硬件嵌套虚拟化使用PVE虚拟化出来的KVM服务器可能不能在选项中开启KVM硬件虚拟化如果使用NOVNC有问题记得在开出来的KVM服务器选项中关闭以实际能否使用为准"
exit 1
fi
if ! lsmod | grep -q kvm; then
if [ "$CPU_TYPE" = "intel" ]; then
_yellow "KVM模块未加载不能使用PVE虚拟化KVM服务器但可以开LXC服务器(CT)"
elif [ "$CPU_TYPE" = "amd" ]; then
_yellow "KVM模块未加载不能使用PVE虚拟化KVM服务器但可以开LXC服务器(CT)"
fi
if [ "$CPU_TYPE" = "intel" ]; then
_yellow "KVM module not loaded, can't use PVE virtualized KVM server, but can open LXC server (CT)"
_yellow "KVM模块未加载不能使用PVE虚拟化KVM服务器但可以开LXC服务器(CT)"
elif [ "$CPU_TYPE" = "amd" ]; then
_yellow "KVM module not loaded, can't use PVE virtualized KVM server, but can open LXC server (CT)"
_yellow "KVM模块未加载不能使用PVE虚拟化KVM服务器但可以开LXC服务器(CT)"
fi
else
_green "本机符合要求可以使用PVE虚拟化KVM服务器并可以在开出来的KVM服务器选项中开启KVM硬件虚拟化"
_green "This machine meets the requirements: it can use PVE to virtualize the KVM server and can turn on KVM hardware virtualization in the KVM server option that is opened"
_green "本机符合要求可以使用PVE虚拟化KVM服务器并可以在开出来的KVM服务器选项中开启KVM硬件虚拟化"
fi
# 如果KVM模块未加载则加载KVM模块并将其添加到/etc/modules文件中
if ! lsmod | grep -q kvm; then
_yellow "Trying to load KVM module ......"
_yellow "尝试加载KVM模块……"
modprobe kvm
echo "kvm" >> /etc/modules
_green "KVM module has tried to load and add to /etc/modules, you can try to use PVE virtualized KVM server, you can also open LXC server (CT)"
_green "KVM模块已尝试加载并添加到 /etc/modules可以尝试使用PVE虚拟化KVM服务器也可以开LXC服务器(CT)"
fi

View file

@ -1,7 +1,7 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.05.30
# 2023.06.29
# cd /root
@ -47,6 +47,7 @@ check_cdn_file
pre_check(){
home_dir=$(eval echo "~$(whoami)")
if [ "$home_dir" != "/root" ]; then
_red "The script will exit if the current path is not /root."
_red "当前路径不是/root脚本将退出。"
exit 1
fi
@ -70,81 +71,93 @@ pre_check(){
check_info(){
log_file="ctlog"
if [ ! -f "ctlog" ]; then
_yellow "当前目录下不存在ctlog文件"
ct_num=302
web2_port=20003
port_end=30025
_yellow "ctrlog file does not exist in the current directory"
_yellow "当前目录下不存在ctlog文件"
ct_num=302
web2_port=20003
port_end=30025
else
while read line; do
last_line="$line"
done < "$log_file"
last_line_array=($last_line)
ct_num="${last_line_array[0]}"
password="${last_line_array[1]}"
ssh_port="${last_line_array[5]}"
web1_port="${last_line_array[6]}"
web2_port="${last_line_array[7]}"
port_start="${last_line_array[8]}"
port_end="${last_line_array[9]}"
system="${last_line_array[10]}"
storage="${last_line_array[11]}"
_green "当前最后一个NAT服务器对应的信息"
echo "NAT服务器: $ct_num"
# echo "用户名: $user"
# echo "密码: $password"
echo "外网SSH端口: $ssh_port"
echo "外网80端口: $web1_port"
echo "外网443端口: $web2_port"
echo "外网其他端口范围: $port_start-$port_end"
echo "系统:$system"
echo "存储盘:$storage"
while read line; do
last_line="$line"
done < "$log_file"
last_line_array=($last_line)
ct_num="${last_line_array[0]}"
password="${last_line_array[1]}"
ssh_port="${last_line_array[5]}"
web1_port="${last_line_array[6]}"
web2_port="${last_line_array[7]}"
port_start="${last_line_array[8]}"
port_end="${last_line_array[9]}"
system="${last_line_array[10]}"
storage="${last_line_array[11]}"
_green "Information corresponding to the current last NAT container:"
_green "当前最后一个NAT容器对应的信息"
echo "NAT容器(NAT container): $ct_num"
# echo "用户名: $user"
# echo "密码: $password"
echo "外网SSH端口(Extranet SSH port): $ssh_port"
echo "外网80端口(Extranet port 80): $web1_port"
echo "外网443端口(Extranet port 443): $web2_port"
echo "外网其他端口范围(Other port ranges): $port_start-$port_end"
echo "系统(System)$system"
echo "存储盘(Storage Disk)$storage"
fi
}
build_new_cts(){
while true; do
_green "How many more NAT servers need to be generated? (Enter how many new NAT servers to add):"
reading "还需要生成几个NAT服务器(输入新增几个NAT服务器)" new_nums
if [[ "$new_nums" =~ ^[1-9][0-9]*$ ]]; then
break
else
_yellow "Invalid input, please enter a positive integer."
_yellow "输入无效,请输入一个正整数。"
fi
done
while true; do
reading "每个虚拟机分配几个CPU(若每个虚拟机分配1核则输入1)" cpu_nums
_green "How many CPUs are assigned to each container? (Enter 1 if 1 core is assigned to each container):"
reading "每个容器分配几个CPU(若每个容器分配1核则输入1)" cpu_nums
if [[ "$cpu_nums" =~ ^[1-9][0-9]*$ ]]; then
break
else
_yellow "Invalid input, please enter a positive integer."
_yellow "输入无效,请输入一个正整数。"
fi
done
while true; do
reading "每个虚拟机分配多少内存?(若每个虚拟机分配512MB内存则输入512)" memory_nums
_green "How much memory is allocated per container? (If 512 MB of memory is allocated per container, enter 512):"
reading "每个容器分配多少内存?(若每个容器分配512MB内存则输入512)" memory_nums
if [[ "$memory_nums" =~ ^[1-9][0-9]*$ ]]; then
break
else
_yellow "Invalid input, please enter a positive integer."
_yellow "输入无效,请输入一个正整数。"
fi
done
while true; do
reading "虚拟机们开设在哪个存储盘上?(若虚拟机要开设在系统盘上则留空或输入local)" storage
_green "On which storage drive are the containers opened? (Leave blank or enter 'local' if the container is to be opened on the system disk):"
reading "容器们开设在哪个存储盘上?(若容器要开设在系统盘上则留空或输入local)" storage
if [ -z "$storage" ]; then
storage="local"
fi
break
done
while true; do
reading "每个虚拟机分配多少硬盘?(若每个虚拟机分配5G硬盘则输入5)" disk_nums
_green "How many hard disks are allocated per container? (If 5G hard drives are allocated per container, enter 5):"
reading "每个容器分配多少硬盘?(若每个容器分配5G硬盘则输入5)" disk_nums
if [[ "$disk_nums" =~ ^[1-9][0-9]*$ ]]; then
break
else
_yellow "Invalid input, please enter a positive integer."
_yellow "输入无效,请输入一个正整数。"
fi
done
while true; do
reading "每个虚拟机都使用什么系统?(若都使用debian11则留空或输入debian11)" system
_green "What system does each container use? (Leave blank or enter debian11 if all use debian11):"
reading "每个容器都使用什么系统?(若都使用debian11则留空或输入debian11)" system
if [ -z "$system" ]; then
system="debian11"
system="debian11"
fi
# 这块待增加系统列表查询
break

View file

@ -1,7 +1,7 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.05.30
# 2023.06.29
# cd /root
@ -47,6 +47,7 @@ check_cdn_file
pre_check(){
home_dir=$(eval echo "~$(whoami)")
if [ "$home_dir" != "/root" ]; then
_red "The script will exit if the current path is not /root."
_red "当前路径不是/root脚本将退出。"
exit 1
fi
@ -70,6 +71,7 @@ pre_check(){
check_info(){
log_file="vmlog"
if [ ! -f "vmlog" ]; then
_yellow "vmlog file does not exist in the current directory"
_yellow "当前目录下不存在vmlog文件"
vm_num=202
web2_port=40003
@ -89,45 +91,53 @@ check_info(){
port_end="${last_line_array[10]}"
system="${last_line_array[11]}"
storage="${last_line_array[12]}"
_green "Current information corresponding to the last NAT server:"
_green "当前最后一个NAT服务器对应的信息"
echo "NAT服务器: $vm_num"
echo "NAT服务器(NAT Server): $vm_num"
# echo "用户名: $user"
# echo "密码: $password"
echo "外网SSH端口: $ssh_port"
echo "外网80端口: $web1_port"
echo "外网443端口: $web2_port"
echo "外网其他端口范围: $port_start-$port_end"
echo "系统$system"
echo "存储盘$storage"
echo "外网SSH端口(Extranet SSH port): $ssh_port"
echo "外网80端口(Extranet port 80): $web1_port"
echo "外网443端口(Extranet port 443): $web2_port"
echo "外网其他端口范围(Other port ranges): $port_start-$port_end"
echo "系统(System)$system"
echo "存储盘(Storage Disk)$storage"
fi
}
build_new_vms(){
while true; do
_green "How many more NAT servers need to be generated? (Enter how many new NAT servers to add):"
reading "还需要生成几个NAT服务器(输入新增几个NAT服务器)" new_nums
if [[ "$new_nums" =~ ^[1-9][0-9]*$ ]]; then
break
else
_yellow "Invalid input, please enter a positive integer."
_yellow "输入无效,请输入一个正整数。"
fi
done
while true; do
_green "How many CPUs are assigned to each virtual machine? (Enter 1 if 1 core is assigned to each virtual machine):"
reading "每个虚拟机分配几个CPU(若每个虚拟机分配1核则输入1)" cpu_nums
if [[ "$cpu_nums" =~ ^[1-9][0-9]*$ ]]; then
break
else
_yellow "Invalid input, please enter a positive integer."
_yellow "输入无效,请输入一个正整数。"
fi
done
while true; do
_green "How much memory is allocated per virtual machine? (If 512 MB of memory is allocated per virtual machine, enter 512):"
reading "每个虚拟机分配多少内存?(若每个虚拟机分配512MB内存则输入512)" memory_nums
if [[ "$memory_nums" =~ ^[1-9][0-9]*$ ]]; then
break
else
_yellow "Invalid input, please enter a positive integer."
_yellow "输入无效,请输入一个正整数。"
fi
done
while true; do
_green "On which storage drive are the virtual machines opened? (Leave blank or enter 'local' if the virtual machine is to be opened on the system disk):"
reading "虚拟机们开设在哪个存储盘上?(若虚拟机要开设在系统盘上则留空或输入local)" storage
if [ -z "$storage" ]; then
storage="local"
@ -135,15 +145,18 @@ build_new_vms(){
break
done
while true; do
_green "How many hard disks are allocated per virtual machine? (If 5G hard drives are allocated per virtual machine, enter 5):"
reading "每个虚拟机分配多少硬盘?(若每个虚拟机分配5G硬盘则输入5)" disk_nums
if [[ "$disk_nums" =~ ^[1-9][0-9]*$ ]]; then
break
else
_yellow "Invalid input, please enter a positive integer."
_yellow "输入无效,请输入一个正整数。"
fi
done
while true; do
sys_status="false"
_green "What system does each virtual machine use? (Leave blank or enter debian11 if all use debian11):"
reading "每个虚拟机都使用什么系统?(若都使用debian11则留空或输入debian11)" system
if [ -z "$system" ]; then
system="debian11"
@ -156,9 +169,10 @@ build_new_vms(){
fi
done
if [ "$sys_status" = "true" ]; then
break
break
else
_yellow "不支持该系统,请查看 https://github.com/spiritLHLS/Images 支持的系统名字"
_yellow "This system is not supported, please check https://github.com/spiritLHLS/Images for the names of supported systems"
_yellow "不支持该系统,请查看 https://github.com/spiritLHLS/Images 支持的系统名字"
fi
done
for ((i=1; i<=$new_nums; i++)); do

View file

@ -1,7 +1,7 @@
#!/bin/bash
# from
# https://github.com/spiritLHLS/pve
# 2023.06.26
# 2023.06.29
# cd /root >/dev/null 2>&1
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
@ -35,20 +35,20 @@ remove_duplicate_lines() {
install_package() {
package_name=$1
if command -v $package_name > /dev/null 2>&1 ; then
_green "$package_name 已经安装"
_green "$package_name already installed"
_green "$package_name 已经安装"
else
apt-get install -y $package_name
if [ $? -ne 0 ]; then
apt-get install -y $package_name --fix-missing
fi
if [ $? -ne 0 ]; then
_green "$package_name 已尝试安装但失败,退出程序"
_green "$package_name tried to install but failed, exited the program"
_green "$package_name 已尝试安装但失败,退出程序"
exit 1
fi
_green "$package_name 已尝试安装"
_green "$package_name tried to install"
_green "$package_name 已尝试安装"
fi
}
@ -366,8 +366,8 @@ if [ "${hostname}" != "pve" ]; then
# echo "${main_ipv4} ${hostname} ${hostname}" | sudo tee -a /etc/hosts > /dev/null
# _green "已将 ${main_ipv4} ${hostname} ${hostname} 添加到 /etc/hosts 文件中"
else
_blue "已存在 ${main_ipv4} ${hostname} ${hostname} 的记录,无需添加"
_blue "A record for ${main_ipv4} ${hostname} ${hostname} already exists, no need to add it"
_blue "已存在 ${main_ipv4} ${hostname} ${hostname} 的记录,无需添加"
fi
chattr -i /etc/hostname
hostnamectl set-hostname pve
@ -445,6 +445,7 @@ case $version in
# ;;
*)
_red "Error: Unsupported Debian version"
_yellow "Do you want to continue the installation? (Enter to not continue the installation by default) (y/[n])"
reading "是否要继续安装(识别到不是Debian9~Debian12的范围)(回车则默认不继续安装) (y/[n]) " confirm
echo ""
if [ "$confirm" != "y" ]; then
@ -496,6 +497,7 @@ case $version in
;;
*)
_red "Error: Unsupported Debian version"
_yellow "Do you want to continue the installation? (Enter to not continue the installation by default) (y/[n])"
reading "是否要继续安装(识别到不是Debian9~Debian12的范围)(回车则默认不继续安装) (y/[n]) " confirm
echo ""
if [ "$confirm" != "y" ]; then