mirror of
https://github.com/thelittlerocket/pve.git
synced 2024-09-20 06:46:09 +08:00
update
This commit is contained in:
parent
e2a0a82519
commit
eea44a5657
|
@ -1,33 +1,31 @@
|
|||
FROM debian:11
|
||||
|
||||
# Set official Debian sources
|
||||
RUN rm /etc/apt/sources.list && \
|
||||
echo "deb http://deb.debian.org/debian/ bullseye main contrib non-free" >> /etc/apt/sources.list && \
|
||||
echo "deb http://deb.debian.org/debian/ bullseye-updates main contrib non-free" >> /etc/apt/sources.list && \
|
||||
echo "deb http://deb.debian.org/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list && \
|
||||
echo "deb http://security.debian.org/debian-security bullseye-security main contrib" >> /etc/apt/sources.list
|
||||
RUN rm /etc/apt/sources.list &&
|
||||
echo "deb http://deb.debian.org/debian/ bullseye main contrib non-free" >>/etc/apt/sources.list &&
|
||||
echo "deb http://deb.debian.org/debian/ bullseye-updates main contrib non-free" >>/etc/apt/sources.list &&
|
||||
echo "deb http://deb.debian.org/debian/ bullseye-backports main contrib non-free" >>/etc/apt/sources.list &&
|
||||
echo "deb http://security.debian.org/debian-security bullseye-security main contrib" >>/etc/apt/sources.list
|
||||
|
||||
# Install base packages
|
||||
RUN apt-get update && \
|
||||
RUN apt-get update &&
|
||||
apt-get install wget systemd nano vim curl gnupg ca-certificates -y
|
||||
|
||||
#add proxmox repo
|
||||
#use jiangcuo_proxmox_arm64 https://github.com/jiangcuo/Proxmox-Arm64
|
||||
RUN echo "deb https://global.mirrors.apqa.cn/proxmox/ pvearm main">/etc/apt/sources.list.d/foxi.list && \
|
||||
wget --no-check-certificate https://global.mirrors.apqa.cn/proxmox/gpg.key -O /etc/apt/trusted.gpg.d/gpg.key && \
|
||||
RUN echo "deb https://global.mirrors.apqa.cn/proxmox/ pvearm main" >/etc/apt/sources.list.d/foxi.list &&
|
||||
wget --no-check-certificate https://global.mirrors.apqa.cn/proxmox/gpg.key -O /etc/apt/trusted.gpg.d/gpg.key &&
|
||||
chmod +r /etc/apt/trusted.gpg.d/gpg.key
|
||||
|
||||
|
||||
#intall proxmox-ve without recommends.
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND=noninteractiv apt-get -y --no-install-recommends install proxmox-ve || echo ok
|
||||
|
||||
#intall proxmox-ve without recommends.
|
||||
RUN apt-get update &&
|
||||
DEBIAN_FRONTEND=noninteractiv apt-get -y --no-install-recommends install proxmox-ve || echo ok
|
||||
|
||||
#set passwd for root
|
||||
RUN echo "root:root"|chpasswd
|
||||
RUN echo "root:root" | chpasswd
|
||||
|
||||
#clean
|
||||
RUN rm -rf /var/lib/apt/lists/* /*.deb
|
||||
RUN rm -rf /var/lib/apt/lists/* /*.deb
|
||||
|
||||
#use setup.sh to start proxmox service
|
||||
STOPSIGNAL SIGINT
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
FROM debian:11
|
||||
|
||||
# Set official Debian sources
|
||||
RUN rm /etc/apt/sources.list && \
|
||||
echo "deb http://deb.debian.org/debian/ bullseye main contrib non-free" >> /etc/apt/sources.list && \
|
||||
echo "deb http://deb.debian.org/debian/ bullseye-updates main contrib non-free" >> /etc/apt/sources.list && \
|
||||
echo "deb http://deb.debian.org/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list && \
|
||||
echo "deb http://security.debian.org/debian-security bullseye-security main contrib" >> /etc/apt/sources.list
|
||||
RUN rm /etc/apt/sources.list &&
|
||||
echo "deb http://deb.debian.org/debian/ bullseye main contrib non-free" >>/etc/apt/sources.list &&
|
||||
echo "deb http://deb.debian.org/debian/ bullseye-updates main contrib non-free" >>/etc/apt/sources.list &&
|
||||
echo "deb http://deb.debian.org/debian/ bullseye-backports main contrib non-free" >>/etc/apt/sources.list &&
|
||||
echo "deb http://security.debian.org/debian-security bullseye-security main contrib" >>/etc/apt/sources.list
|
||||
|
||||
# Install base packages
|
||||
RUN apt-get update && \
|
||||
RUN apt-get update &&
|
||||
apt-get install wget systemd nano vim curl gnupg ca-certificates -y
|
||||
|
||||
#add proxmox repo
|
||||
RUN echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/ bullseye pve-no-subscription" >>/etc/apt/sources.list && \
|
||||
wget --no-check-certificate https://mirrors.ustc.edu.cn/proxmox/debian/proxmox-release-bullseye.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg && \
|
||||
RUN echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/ bullseye pve-no-subscription" >>/etc/apt/sources.list &&
|
||||
wget --no-check-certificate https://mirrors.ustc.edu.cn/proxmox/debian/proxmox-release-bullseye.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg &&
|
||||
chmod +r /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg
|
||||
|
||||
#repacked proxmox-ve
|
||||
RUN wget https://mirrors.ustc.edu.cn/proxmox/debian/dists/bullseye/pve-no-subscription/binary-amd64/proxmox-ve_7.2-1_all.deb && \
|
||||
mkdir /tmp/pve && \
|
||||
dpkg -X proxmox-ve_7.2-1_all.deb /tmp/pve/ && \
|
||||
dpkg -e proxmox-ve_7.2-1_all.deb /tmp/pve/DEBIAN && \
|
||||
sed -i "s/pve-kernel-helper,//g" /tmp/pve/DEBIAN/control && \
|
||||
sed -i "s/pve-kernel-5.15,//g" /tmp/pve/DEBIAN/control && \
|
||||
dpkg-deb -Zxz -b /tmp/pve/ /tmp/
|
||||
RUN wget https://mirrors.ustc.edu.cn/proxmox/debian/dists/bullseye/pve-no-subscription/binary-amd64/proxmox-ve_7.2-1_all.deb &&
|
||||
mkdir /tmp/pve &&
|
||||
dpkg -X proxmox-ve_7.2-1_all.deb /tmp/pve/ &&
|
||||
dpkg -e proxmox-ve_7.2-1_all.deb /tmp/pve/DEBIAN &&
|
||||
sed -i "s/pve-kernel-helper,//g" /tmp/pve/DEBIAN/control &&
|
||||
sed -i "s/pve-kernel-5.15,//g" /tmp/pve/DEBIAN/control &&
|
||||
dpkg-deb -Zxz -b /tmp/pve/ /tmp/
|
||||
|
||||
#repacked pve-manager
|
||||
RUN wget https://mirrors.ustc.edu.cn/proxmox/debian/dists/bullseye/pve-no-subscription/binary-amd64/pve-manager_7.2-7_amd64.deb && \
|
||||
mkdir /tmp/pve-manager && \
|
||||
dpkg -X pve-manager_7.2-7_amd64.deb /tmp/pve-manager/ && \
|
||||
dpkg -e pve-manager_7.2-7_amd64.deb /tmp/pve-manager/DEBIAN && \
|
||||
sed -i "s/ifupdown2 (>= 2.0.1-1+pve8) | ifenslave (>= 2.6),//g" /tmp/pve-manager/DEBIAN/control && \
|
||||
dpkg-deb -Zxz -b /tmp/pve-manager/ /tmp
|
||||
RUN wget https://mirrors.ustc.edu.cn/proxmox/debian/dists/bullseye/pve-no-subscription/binary-amd64/pve-manager_7.2-7_amd64.deb &&
|
||||
mkdir /tmp/pve-manager &&
|
||||
dpkg -X pve-manager_7.2-7_amd64.deb /tmp/pve-manager/ &&
|
||||
dpkg -e pve-manager_7.2-7_amd64.deb /tmp/pve-manager/DEBIAN &&
|
||||
sed -i "s/ifupdown2 (>= 2.0.1-1+pve8) | ifenslave (>= 2.6),//g" /tmp/pve-manager/DEBIAN/control &&
|
||||
dpkg-deb -Zxz -b /tmp/pve-manager/ /tmp
|
||||
|
||||
#intall proxmox-ve without recommends. ifupdown2 will install failed but ok
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND=noninteractiv apt-get -y --no-install-recommends install proxmox-ve || echo ok
|
||||
RUN apt-get update &&
|
||||
DEBIAN_FRONTEND=noninteractiv apt-get -y --no-install-recommends install proxmox-ve || echo ok
|
||||
|
||||
##install again
|
||||
RUN dpkg -i /tmp/*.deb || echo ok
|
||||
|
||||
#set passwd for root
|
||||
RUN echo "root:root"|chpasswd
|
||||
RUN echo "root:root" | chpasswd
|
||||
|
||||
#clean
|
||||
RUN rm -rf /var/lib/apt/lists/* /*.deb
|
||||
RUN rm -rf /var/lib/apt/lists/* /*.deb
|
||||
|
||||
#use setup.sh to start proxmox service
|
||||
STOPSIGNAL SIGINT
|
||||
CMD [ "/lib/systemd/systemd", "log-level=info", "unit=sysinit.target"]
|
||||
CMD [ "/lib/systemd/systemd", "log-level=info", "unit=sysinit.target"]
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.15
|
||||
|
||||
|
||||
########## 预设部分输出和部分中间变量
|
||||
|
||||
cd /root >/dev/null 2>&1
|
||||
|
@ -11,16 +10,16 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
reading() { read -rp "$(_green "$1")" "$2"; }
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
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
|
||||
temp_file_apt_fix="/tmp/apt_fix.txt"
|
||||
|
||||
|
@ -28,7 +27,7 @@ temp_file_apt_fix="/tmp/apt_fix.txt"
|
|||
|
||||
install_package() {
|
||||
package_name=$1
|
||||
if command -v $package_name > /dev/null 2>&1 ; then
|
||||
if command -v $package_name >/dev/null 2>&1; then
|
||||
_green "$package_name already installed"
|
||||
_green "$package_name 已经安装"
|
||||
else
|
||||
|
@ -37,10 +36,9 @@ install_package() {
|
|||
apt_output=$(apt-get install -y $package_name --fix-missing 2>&1)
|
||||
fi
|
||||
if [ $? -ne 0 ]; then
|
||||
if echo "$apt_output" | grep -qE 'DEBIAN_FRONTEND=dialog dpkg --configure grub-pc' &&
|
||||
if echo "$apt_output" | grep -qE 'DEBIAN_FRONTEND=dialog dpkg --configure grub-pc' &&
|
||||
echo "$apt_output" | grep -qE 'dpkg --configure -a' &&
|
||||
echo "$apt_output" | grep -qE 'dpkg: error processing package grub-pc \(--configure\):'
|
||||
then
|
||||
echo "$apt_output" | grep -qE 'dpkg: error processing package grub-pc \(--configure\):'; then
|
||||
# 手动选择
|
||||
# DEBIAN_FRONTEND=dialog dpkg --configure grub-pc
|
||||
# 设置debconf的选择
|
||||
|
@ -66,9 +64,9 @@ install_package() {
|
|||
fi
|
||||
}
|
||||
|
||||
check_haveged(){
|
||||
check_haveged() {
|
||||
_yellow "checking haveged"
|
||||
if ! command -v haveged > /dev/null 2>&1; then
|
||||
if ! command -v haveged >/dev/null 2>&1; then
|
||||
apt-get install -o Dpkg::Options::="--force-confnew" -y haveged
|
||||
fi
|
||||
if which systemctl >/dev/null 2>&1; then
|
||||
|
@ -80,11 +78,11 @@ check_haveged(){
|
|||
fi
|
||||
}
|
||||
|
||||
check_time_zone(){
|
||||
check_time_zone() {
|
||||
_yellow "adjusting the time"
|
||||
systemctl stop ntpd
|
||||
service ntpd stop
|
||||
if ! command -v chronyd > /dev/null 2>&1; then
|
||||
if ! command -v chronyd >/dev/null 2>&1; then
|
||||
apt-get install -o Dpkg::Options::="--force-confnew" -y chrony
|
||||
fi
|
||||
if which systemctl >/dev/null 2>&1; then
|
||||
|
@ -100,15 +98,15 @@ check_time_zone(){
|
|||
}
|
||||
|
||||
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() {
|
||||
|
@ -126,23 +124,22 @@ is_private_ipv4() {
|
|||
if [[ -z $ip_address ]]; then
|
||||
return 0 # 输入为空
|
||||
fi
|
||||
IFS='.' read -r -a ip_parts <<< "$ip_address"
|
||||
IFS='.' read -r -a ip_parts <<<"$ip_address"
|
||||
# 检查IP地址是否符合内网IP地址的范围
|
||||
# 去除 回环,REC 1918,多播 地址
|
||||
if [[ ${ip_parts[0]} -eq 10 ]] ||
|
||||
[[ ${ip_parts[0]} -eq 172 && ${ip_parts[1]} -ge 16 && ${ip_parts[1]} -le 31 ]] ||
|
||||
[[ ${ip_parts[0]} -eq 192 && ${ip_parts[1]} -eq 168 ]] ||
|
||||
[[ ${ip_parts[0]} -eq 127 ]] ||
|
||||
[[ ${ip_parts[0]} -eq 0 ]] ||
|
||||
[[ ${ip_parts[0]} -ge 224 ]]
|
||||
then
|
||||
return 0 # 是内网IP地址
|
||||
[[ ${ip_parts[0]} -eq 172 && ${ip_parts[1]} -ge 16 && ${ip_parts[1]} -le 31 ]] ||
|
||||
[[ ${ip_parts[0]} -eq 192 && ${ip_parts[1]} -eq 168 ]] ||
|
||||
[[ ${ip_parts[0]} -eq 127 ]] ||
|
||||
[[ ${ip_parts[0]} -eq 0 ]] ||
|
||||
[[ ${ip_parts[0]} -ge 224 ]]; then
|
||||
return 0 # 是内网IP地址
|
||||
else
|
||||
return 1 # 不是内网IP地址
|
||||
return 1 # 不是内网IP地址
|
||||
fi
|
||||
}
|
||||
|
||||
check_ipv4(){
|
||||
check_ipv4() {
|
||||
IPV4=$(ip -4 addr show | grep global | awk '{print $2}' | cut -d '/' -f1 | head -n 1)
|
||||
if is_private_ipv4 "$IPV4"; then # 由于是内网IPV4地址,需要通过API获取外网地址
|
||||
IPV4=""
|
||||
|
@ -161,10 +158,11 @@ check_ipv4(){
|
|||
}
|
||||
|
||||
statistics_of_run-times() {
|
||||
COUNT=$(
|
||||
curl -4 -ksm1 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FspiritLHLS%2Fpve&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=&edge_flat=true" 2>&1 ||
|
||||
curl -6 -ksm1 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FspiritLHLS%2Fpve&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=&edge_flat=true" 2>&1) &&
|
||||
TODAY=$(expr "$COUNT" : '.*\s\([0-9]\{1,\}\)\s/.*') && TOTAL=$(expr "$COUNT" : '.*/\s\([0-9]\{1,\}\)\s.*')
|
||||
COUNT=$(
|
||||
curl -4 -ksm1 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FspiritLHLS%2Fpve&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=&edge_flat=true" 2>&1 ||
|
||||
curl -6 -ksm1 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FspiritLHLS%2Fpve&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=&edge_flat=true" 2>&1
|
||||
) &&
|
||||
TODAY=$(expr "$COUNT" : '.*\s\([0-9]\{1,\}\)\s/.*') && TOTAL=$(expr "$COUNT" : '.*/\s\([0-9]\{1,\}\)\s.*')
|
||||
}
|
||||
|
||||
get_system_arch() {
|
||||
|
@ -174,36 +172,36 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
check_china(){
|
||||
check_china() {
|
||||
_yellow "IP area being detected ......"
|
||||
if [[ -z "${CN}" ]]; then
|
||||
if [[ $(curl -m 6 -s https://ipapi.co/json | grep 'China') != "" ]]; then
|
||||
_yellow "根据ipapi.co提供的信息,当前IP可能在中国"
|
||||
read -e -r -p "是否选用中国镜像完成相关组件安装? ([y]/n) " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "不使用中国镜像"
|
||||
;;
|
||||
*)
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "不使用中国镜像"
|
||||
;;
|
||||
*)
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
esac
|
||||
else
|
||||
if [[ $? -ne 0 ]]; then
|
||||
|
@ -211,16 +209,16 @@ check_china(){
|
|||
_yellow "根据cip.cc提供的信息,当前IP可能在中国"
|
||||
read -e -r -p "是否选用中国镜像完成相关组件安装? [Y/n] " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "不使用中国镜像"
|
||||
;;
|
||||
*)
|
||||
echo "不使用中国镜像"
|
||||
;;
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "不使用中国镜像"
|
||||
;;
|
||||
*)
|
||||
echo "不使用中国镜像"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
@ -240,11 +238,11 @@ install_package sudo
|
|||
cdn_urls=("https://cdn.spiritlhl.workers.dev/" "https://cdn3.spiritlhl.net/" "https://cdn1.spiritlhl.net/" "https://ghproxy.com/" "https://cdn2.spiritlhl.net/")
|
||||
check_cdn_file
|
||||
|
||||
if ! command -v docker > /dev/null 2>&1; then
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
_yellow "Installing docker"
|
||||
curl -sSL https://get.docker.com/ | sh
|
||||
fi
|
||||
if ! command -v docker-compose > /dev/null 2>&1; then
|
||||
if ! command -v docker-compose >/dev/null 2>&1; then
|
||||
_yellow "Installing docker-compose"
|
||||
curl -Lk "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
|
||||
DNS_SERVER="8.8.8.8"
|
||||
|
@ -13,8 +13,8 @@ if [ $? -eq 0 ]; then
|
|||
else
|
||||
echo "Adding DNS server ${DNS_SERVER} to ${RESOLV_CONF}..."
|
||||
if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ]; then
|
||||
echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" >> ${RESOLV_CONF}
|
||||
echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" >>${RESOLV_CONF}
|
||||
else
|
||||
echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\nnameserver 2606:4700:4700::1111\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844" >> ${RESOLV_CONF}
|
||||
echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\nnameserver 2606:4700:4700::1111\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844" >>${RESOLV_CONF}
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.06.25
|
||||
|
||||
|
||||
# 检查是否存在 "iface eth0 inet6 auto" 行
|
||||
if ! grep -q "iface eth0 inet6 auto" /etc/network/interfaces; then
|
||||
# 追加 "iface eth0 inet6 auto" 行到文件末尾
|
||||
chattr -i /etc/network/interfaces
|
||||
echo "iface eth0 inet6 auto" >> /etc/network/interfaces
|
||||
echo "iface eth0 inet6 auto" >>/etc/network/interfaces
|
||||
chattr +i /etc/network/interfaces
|
||||
fi
|
||||
|
||||
if ! grep -q "pre-up echo 2 > /proc/sys/net/ipv6/conf/all/accept_ra" /etc/network/interfaces; then
|
||||
# 追加 "pre-up echo 2 > /proc/sys/net/ipv6/conf/all/accept_ra" 行到文件末尾
|
||||
chattr -i /etc/network/interfaces
|
||||
echo "pre-up echo 2 > /proc/sys/net/ipv6/conf/all/accept_ra" >> /etc/network/interfaces
|
||||
echo "pre-up echo 2 > /proc/sys/net/ipv6/conf/all/accept_ra" >>/etc/network/interfaces
|
||||
chattr +i /etc/network/interfaces
|
||||
fi
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.07.31
|
||||
|
||||
# 安装ifupdown2
|
||||
apt-get install -y ifupdown2
|
||||
echo "1" > "/usr/local/bin/ifupdown2_installed.txt"
|
||||
echo "1" >"/usr/local/bin/ifupdown2_installed.txt"
|
||||
|
||||
# 删除Systemd服务
|
||||
systemctl disable ifupdown2-install.service
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.03
|
||||
|
||||
|
||||
# 打印信息
|
||||
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
||||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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
|
||||
|
||||
if [ -f "/usr/local/bin/build_backend_pve.txt" ]; then
|
||||
|
@ -30,7 +29,7 @@ fi
|
|||
|
||||
# 创建资源池
|
||||
POOL_ID="mypool"
|
||||
if pvesh get /pools/$POOL_ID > /dev/null 2>&1 ; then
|
||||
if pvesh get /pools/$POOL_ID >/dev/null 2>&1; then
|
||||
_green "Resource pool $POOL_ID already exists!"
|
||||
_green "资源池 $POOL_ID 已经存在!"
|
||||
else
|
||||
|
@ -62,23 +61,23 @@ else
|
|||
fi
|
||||
|
||||
# 开启硬件直通
|
||||
if [ `dmesg | grep -e DMAR -e IOMMU|wc -l` = 0 ];then
|
||||
if [ $(dmesg | grep -e DMAR -e IOMMU | wc -l) = 0 ]; then
|
||||
_yellow "Hardware does not support passthrough"
|
||||
_yellow "硬件不支持直通"
|
||||
else
|
||||
if [ `cat /proc/cpuinfo|grep Intel|wc -l` = 0 ];then
|
||||
iommu="amd_iommu=on"
|
||||
if [ $(cat /proc/cpuinfo | grep Intel | wc -l) = 0 ]; then
|
||||
iommu="amd_iommu=on"
|
||||
else
|
||||
iommu="intel_iommu=on"
|
||||
iommu="intel_iommu=on"
|
||||
fi
|
||||
if [ `grep $iommu /etc/default/grub|wc -l` = 0 ];then
|
||||
if [ $(grep $iommu /etc/default/grub | wc -l) = 0 ]; then
|
||||
sed -i 's|quiet|quiet '$iommu'|' /etc/default/grub
|
||||
update-grub
|
||||
if [ `grep "vfio" /etc/modules|wc -l` = 0 ];then
|
||||
if [ $(grep "vfio" /etc/modules | wc -l) = 0 ]; then
|
||||
echo 'vfio
|
||||
vfio_iommu_type1
|
||||
vfio_pci
|
||||
vfio_virqfd' >> /etc/modules
|
||||
vfio_virqfd' >>/etc/modules
|
||||
fi
|
||||
else
|
||||
_green "Hardware passthrough is set"
|
||||
|
@ -87,7 +86,7 @@ else
|
|||
fi
|
||||
|
||||
# 检测AppArmor模块
|
||||
if ! dpkg -s apparmor > /dev/null 2>&1; then
|
||||
if ! dpkg -s apparmor >/dev/null 2>&1; then
|
||||
_green "AppArmor is being installed..."
|
||||
_green "正在安装 AppArmor..."
|
||||
apt-get update
|
||||
|
@ -118,4 +117,4 @@ else
|
|||
_yellow "The current kernel is already a PVE kernel, no need to reboot the system to update the kernel"
|
||||
_yellow "当前内核已是PVE内核,无需重启系统更新内核"
|
||||
fi
|
||||
echo "1" > "/usr/local/bin/build_backend_pve.txt"
|
||||
echo "1" >"/usr/local/bin/build_backend_pve.txt"
|
||||
|
|
|
@ -1,38 +1,37 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.22
|
||||
|
||||
|
||||
########## 预设部分输出和部分中间变量
|
||||
|
||||
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
||||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
reading() { read -rp "$(_green "$1")" "$2"; }
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
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
|
||||
rm -rf /usr/local/bin/build_backend_pve.txt
|
||||
|
||||
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() {
|
||||
|
@ -46,10 +45,10 @@ check_cdn_file() {
|
|||
|
||||
########## 查询信息
|
||||
|
||||
if ! command -v lshw > /dev/null 2>&1; then
|
||||
if ! command -v lshw >/dev/null 2>&1; then
|
||||
apt-get install -y lshw
|
||||
fi
|
||||
if ! command -v ipcalc > /dev/null 2>&1; then
|
||||
if ! command -v ipcalc >/dev/null 2>&1; then
|
||||
apt-get install -y ipcalc
|
||||
fi
|
||||
|
||||
|
@ -103,7 +102,7 @@ if [[ -f "/etc/network/interfaces.d/50-cloud-init" && -f "/etc/network/interface
|
|||
chattr +i /etc/network/interfaces.d/50-cloud-init
|
||||
fi
|
||||
fi
|
||||
if [ -f "/etc/network/interfaces.new" ];then
|
||||
if [ -f "/etc/network/interfaces.new" ]; then
|
||||
chattr -i /etc/network/interfaces.new
|
||||
rm -rf /etc/network/interfaces.new
|
||||
fi
|
||||
|
@ -124,7 +123,7 @@ if grep -q "vmbr0" "/etc/network/interfaces"; then
|
|||
_blue "vmbr0 已存在在 /etc/network/interfaces"
|
||||
else
|
||||
if [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ]; then
|
||||
cat << EOF | sudo tee -a /etc/network/interfaces
|
||||
cat <<EOF | sudo tee -a /etc/network/interfaces
|
||||
auto vmbr0
|
||||
iface vmbr0 inet static
|
||||
address $ipv4_address
|
||||
|
@ -134,7 +133,7 @@ iface vmbr0 inet static
|
|||
bridge_fd 0
|
||||
EOF
|
||||
elif [ -f "/usr/local/bin/iface_auto.txt" ]; then
|
||||
cat << EOF | sudo tee -a /etc/network/interfaces
|
||||
cat <<EOF | sudo tee -a /etc/network/interfaces
|
||||
auto vmbr0
|
||||
iface vmbr0 inet static
|
||||
address $ipv4_address
|
||||
|
@ -147,7 +146,7 @@ iface vmbr0 inet6 auto
|
|||
bridge_ports $interface
|
||||
EOF
|
||||
else
|
||||
cat << EOF | sudo tee -a /etc/network/interfaces
|
||||
cat <<EOF | sudo tee -a /etc/network/interfaces
|
||||
auto vmbr0
|
||||
iface vmbr0 inet static
|
||||
address $ipv4_address
|
||||
|
@ -166,7 +165,7 @@ if grep -q "vmbr1" "$interfaces_file"; then
|
|||
_blue "vmbr1 already exists in ${interfaces_file}"
|
||||
_blue "vmbr1 已存在在 ${interfaces_file}"
|
||||
elif [ -f "/usr/local/bin/iface_auto.txt" ]; then
|
||||
cat << EOF | sudo tee -a "$interfaces_file"
|
||||
cat <<EOF | sudo tee -a "$interfaces_file"
|
||||
auto vmbr1
|
||||
iface vmbr1 inet static
|
||||
address 172.16.1.1
|
||||
|
@ -182,7 +181,7 @@ iface vmbr1 inet static
|
|||
pre-up echo 2 > /proc/sys/net/ipv6/conf/vmbr0/accept_ra
|
||||
EOF
|
||||
elif [ -z "$ipv6_address" ] || [ -z "$ipv6_prefixlen" ] || [ -z "$ipv6_gateway" ]; then
|
||||
cat << EOF | sudo tee -a "$interfaces_file"
|
||||
cat <<EOF | sudo tee -a "$interfaces_file"
|
||||
auto vmbr1
|
||||
iface vmbr1 inet static
|
||||
address 172.16.1.1
|
||||
|
@ -196,7 +195,7 @@ iface vmbr1 inet static
|
|||
post-down iptables -t nat -D POSTROUTING -s '172.16.1.0/24' -o vmbr0 -j MASQUERADE
|
||||
EOF
|
||||
else
|
||||
cat << EOF | sudo tee -a "$interfaces_file"
|
||||
cat <<EOF | sudo tee -a "$interfaces_file"
|
||||
auto vmbr1
|
||||
iface vmbr1 inet static
|
||||
address 172.16.1.1
|
||||
|
@ -222,7 +221,7 @@ if [ "$ipv6_prefixlen" -le 64 ]; then
|
|||
_blue "vmbr2 already exists in ${interfaces_file}"
|
||||
_blue "vmbr2 已存在在 ${interfaces_file}"
|
||||
elif [ ! -z "$ipv6_address" ] && [ ! -z "$ipv6_prefixlen" ] && [ ! -z "$ipv6_gateway" ] && [ ! -z "$ipv6_address_without_last_segment" ]; then
|
||||
cat << EOF | sudo tee -a "$interfaces_file"
|
||||
cat <<EOF | sudo tee -a "$interfaces_file"
|
||||
auto vmbr2
|
||||
iface vmbr2 inet6 static
|
||||
address ${ipv6_address_without_last_segment}1/${ipv6_prefixlen}
|
||||
|
@ -230,12 +229,12 @@ iface vmbr2 inet6 static
|
|||
bridge_stp off
|
||||
bridge_fd 0
|
||||
EOF
|
||||
if [ -f "/usr/local/bin/ndpresponder" ]; then
|
||||
new_exec_start="ExecStart=/usr/local/bin/ndpresponder -i vmbr0 -n ${ipv6_address_without_last_segment}/${ipv6_prefixlen}"
|
||||
file_path="/etc/systemd/system/ndpresponder.service"
|
||||
line_number=6
|
||||
sed -i "${line_number}s|.*|${new_exec_start}|" "$file_path"
|
||||
fi
|
||||
if [ -f "/usr/local/bin/ndpresponder" ]; then
|
||||
new_exec_start="ExecStart=/usr/local/bin/ndpresponder -i vmbr0 -n ${ipv6_address_without_last_segment}/${ipv6_prefixlen}"
|
||||
file_path="/etc/systemd/system/ndpresponder.service"
|
||||
line_number=6
|
||||
sed -i "${line_number}s|.*|${new_exec_start}|" "$file_path"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
chattr +i /etc/network/interfaces
|
||||
|
@ -247,11 +246,11 @@ iptables -t nat -A POSTROUTING -j MASQUERADE
|
|||
sysctl net.ipv4.ip_forward=1
|
||||
sysctl_path=$(which sysctl)
|
||||
if grep -q "^net.ipv4.ip_forward=1" /etc/sysctl.conf; then
|
||||
if grep -q "^#net.ipv4.ip_forward=1" /etc/sysctl.conf; then
|
||||
sed -i 's/^#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
|
||||
fi
|
||||
if grep -q "^#net.ipv4.ip_forward=1" /etc/sysctl.conf; then
|
||||
sed -i 's/^#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
|
||||
fi
|
||||
else
|
||||
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
|
||||
echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf
|
||||
fi
|
||||
${sysctl_path} -p
|
||||
|
||||
|
@ -281,17 +280,17 @@ while IFS= read -r line; do
|
|||
delete_lines=1
|
||||
fi
|
||||
if [ $delete_lines -eq 0 ] || [[ $line == *"$start_pattern"* ]] || [[ $line == *"$end_pattern"* ]]; then
|
||||
echo "$line" >> "$output_file"
|
||||
echo "$line" >>"$output_file"
|
||||
fi
|
||||
if [[ $line == *"$end_pattern"* ]]; then
|
||||
delete_lines=0
|
||||
fi
|
||||
done < "$input_file"
|
||||
done <"$input_file"
|
||||
mv "$output_file" "$input_file"
|
||||
chattr +i /etc/network/interfaces
|
||||
|
||||
# 已加载网络,删除对应缓存文件
|
||||
if [ -f "/etc/network/interfaces.new" ];then
|
||||
if [ -f "/etc/network/interfaces.new" ]; then
|
||||
chattr -i /etc/network/interfaces.new
|
||||
rm -rf /etc/network/interfaces.new
|
||||
fi
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.21
|
||||
|
||||
|
||||
# ./buildct.sh CTID 密码 CPU核数 内存 硬盘 SSH端口 80端口 443端口 外网端口起 外网端口止 系统 存储盘 独立IPV6
|
||||
# ./buildct.sh 102 1234567 1 512 5 20001 20002 20003 30000 30025 debian11 local N
|
||||
|
||||
|
@ -12,7 +11,7 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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"
|
||||
|
@ -30,19 +29,19 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
check_china(){
|
||||
check_china() {
|
||||
_yellow "IP area being detected ......"
|
||||
if [[ -z "${CN}" ]]; then
|
||||
if [[ $(curl -m 6 -s https://ipapi.co/json | grep 'China') != "" ]]; then
|
||||
|
@ -61,8 +60,8 @@ check_china(){
|
|||
|
||||
get_system_arch
|
||||
if [ -z "${system_arch}" ] || [ ! -v system_arch ]; then
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
fi
|
||||
cd /root >/dev/null 2>&1
|
||||
CTID="${1:-102}"
|
||||
|
@ -86,53 +85,53 @@ system="$en_system-$num_system"
|
|||
if [ "$system_arch" = "arch" ]; then
|
||||
if [ "$en_system" = "ubuntu" ]; then
|
||||
case "$system_ori" in
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
elif [ "$en_system" = "debian" ]; then
|
||||
case "$system_ori" in
|
||||
debian6)
|
||||
version="squeeze"
|
||||
;;
|
||||
debian7)
|
||||
version="wheezy"
|
||||
;;
|
||||
debian8)
|
||||
version="jessie"
|
||||
;;
|
||||
debian9)
|
||||
version="stretch"
|
||||
;;
|
||||
debian10)
|
||||
version="buster"
|
||||
;;
|
||||
debian11)
|
||||
version="bullseye"
|
||||
;;
|
||||
debian12)
|
||||
version="bookworm"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Debian version."
|
||||
exit 1
|
||||
;;
|
||||
debian6)
|
||||
version="squeeze"
|
||||
;;
|
||||
debian7)
|
||||
version="wheezy"
|
||||
;;
|
||||
debian8)
|
||||
version="jessie"
|
||||
;;
|
||||
debian9)
|
||||
version="stretch"
|
||||
;;
|
||||
debian10)
|
||||
version="buster"
|
||||
;;
|
||||
debian11)
|
||||
version="bullseye"
|
||||
;;
|
||||
debian12)
|
||||
version="bookworm"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Debian version."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
version=${num_system}
|
||||
|
@ -152,7 +151,7 @@ if [ "$system_arch" = "arch" ]; then
|
|||
fi
|
||||
else
|
||||
system_name=$(pveam available --section system | grep "$system" | awk '{print $2}' | head -n1)
|
||||
if ! pveam available --section system | grep "$system" > /dev/null; then
|
||||
if ! pveam available --section system | grep "$system" >/dev/null; then
|
||||
_red "No such system"
|
||||
exit
|
||||
else
|
||||
|
@ -164,7 +163,7 @@ 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
|
||||
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
|
||||
|
@ -212,12 +211,12 @@ if [ "$independent_ipv6" == "y" ]; then
|
|||
else
|
||||
if [ -f /usr/local/bin/pve_check_ipv6 ]; then
|
||||
ipv6_address="2001:db8:1::2"
|
||||
IFS="/" read -ra parts <<< "$ipv6_address"
|
||||
IFS="/" read -ra parts <<<"$ipv6_address"
|
||||
part_1="${parts[0]}"
|
||||
part_2="${parts[1]}"
|
||||
IFS=":" read -ra part_1_parts <<< "$part_1"
|
||||
IFS=":" read -ra part_1_parts <<<"$part_1"
|
||||
if [ ! -z "${part_1_parts[*]}" ]; then
|
||||
part_1_last="${part_1_parts[-1]}"
|
||||
part_1_last="${part_1_parts[-1]}"
|
||||
if [ "$part_1_last" = "$CTID" ]; then
|
||||
ipv6_address=""
|
||||
else
|
||||
|
@ -308,28 +307,27 @@ if [ ! -f "/etc/iptables/rules.v4" ]; then
|
|||
touch /etc/iptables/rules.v4
|
||||
fi
|
||||
iptables-save | awk '{if($1=="COMMIT"){delete x}}$1=="-A"?!x[$0]++:1' | iptables-restore
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
iptables-save >/etc/iptables/rules.v4
|
||||
service netfilter-persistent restart
|
||||
|
||||
# 容器的相关信息将会存储到对应的容器的NOTE中,可在WEB端查看
|
||||
if [ "$independent_ipv6_status" == "Y" ]; then
|
||||
echo "$CTID $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system_ori $storage ${ipv6_address_without_last_segment}${CTID}" >> "ct${CTID}"
|
||||
echo "$CTID $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system_ori $storage ${ipv6_address_without_last_segment}${CTID}" >>"ct${CTID}"
|
||||
data=$(echo " CTID root密码-password CPU核数-CPU 内存-memory 硬盘-disk SSH端口 80端口 443端口 外网端口起-port-start 外网端口止-port-end 系统-system 存储盘-storage 独立IPV6地址-ipv6_address")
|
||||
else
|
||||
echo "$CTID $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system_ori $storage" >> "ct${CTID}"
|
||||
echo "$CTID $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system_ori $storage" >>"ct${CTID}"
|
||||
data=$(echo " CTID root密码-password CPU核数-CPU 内存-memory 硬盘-disk SSH端口 80端口 443端口 外网端口起-port-start 外网端口止-port-end 系统-system 存储盘-storage")
|
||||
fi
|
||||
values=$(cat "ct${CTID}")
|
||||
IFS=' ' read -ra data_array <<< "$data"
|
||||
IFS=' ' read -ra values_array <<< "$values"
|
||||
IFS=' ' read -ra data_array <<<"$data"
|
||||
IFS=' ' read -ra values_array <<<"$values"
|
||||
length=${#data_array[@]}
|
||||
for ((i=0; i<$length; i++))
|
||||
do
|
||||
for ((i = 0; i < $length; i++)); do
|
||||
echo "${data_array[$i]} ${values_array[$i]}"
|
||||
echo ""
|
||||
done > "/tmp/temp${CTID}.txt"
|
||||
done >"/tmp/temp${CTID}.txt"
|
||||
sed -i 's/^/# /' "/tmp/temp${CTID}.txt"
|
||||
cat "/etc/pve/lxc/${CTID}.conf" >> "/tmp/temp${CTID}.txt"
|
||||
cat "/etc/pve/lxc/${CTID}.conf" >>"/tmp/temp${CTID}.txt"
|
||||
cp "/tmp/temp${CTID}.txt" "/etc/pve/lxc/${CTID}.conf"
|
||||
rm -rf "/tmp/temp${CTID}.txt"
|
||||
cat "ct${CTID}"
|
||||
|
|
|
@ -10,7 +10,7 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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"
|
||||
|
@ -34,19 +34,19 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
check_china(){
|
||||
check_china() {
|
||||
_yellow "IP area being detected ......"
|
||||
if [[ -z "${CN}" ]]; then
|
||||
if [[ $(curl -m 6 -s https://ipapi.co/json | grep 'China') != "" ]]; then
|
||||
|
@ -65,8 +65,8 @@ check_china(){
|
|||
|
||||
get_system_arch
|
||||
if [ -z "${system_arch}" ] || [ ! -v system_arch ]; then
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
fi
|
||||
cd /root >/dev/null 2>&1
|
||||
CTID="${1:-102}"
|
||||
|
@ -82,53 +82,53 @@ num_system=$(echo "$system_ori" | sed 's/[a-zA-Z]*//g')
|
|||
if [ "$system_arch" = "arch" ]; then
|
||||
if [ "$en_system" = "ubuntu" ]; then
|
||||
case "$system_ori" in
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
elif [ "$en_system" = "debian" ]; then
|
||||
case "$system_ori" in
|
||||
debian6)
|
||||
version="squeeze"
|
||||
;;
|
||||
debian7)
|
||||
version="wheezy"
|
||||
;;
|
||||
debian8)
|
||||
version="jessie"
|
||||
;;
|
||||
debian9)
|
||||
version="stretch"
|
||||
;;
|
||||
debian10)
|
||||
version="buster"
|
||||
;;
|
||||
debian11)
|
||||
version="bullseye"
|
||||
;;
|
||||
debian12)
|
||||
version="bookworm"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Debian version."
|
||||
exit 1
|
||||
;;
|
||||
debian6)
|
||||
version="squeeze"
|
||||
;;
|
||||
debian7)
|
||||
version="wheezy"
|
||||
;;
|
||||
debian8)
|
||||
version="jessie"
|
||||
;;
|
||||
debian9)
|
||||
version="stretch"
|
||||
;;
|
||||
debian10)
|
||||
version="buster"
|
||||
;;
|
||||
debian11)
|
||||
version="bullseye"
|
||||
;;
|
||||
debian12)
|
||||
version="bookworm"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Debian version."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
version=${num_system}
|
||||
|
@ -149,7 +149,7 @@ if [ "$system_arch" = "arch" ]; then
|
|||
else
|
||||
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
|
||||
if ! pveam available --section system | grep "$system" >/dev/null; then
|
||||
_red "No such system"
|
||||
exit 1
|
||||
else
|
||||
|
@ -161,7 +161,7 @@ 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
|
||||
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
|
||||
|
@ -243,20 +243,19 @@ pct exec $CTID -- bash ssh.sh
|
|||
# pct reboot $CTID
|
||||
# fi
|
||||
|
||||
echo "$CTID $password $core $memory $disk $system_ori $storage ${ipv6_address_without_last_segment}${CTID}" >> "ct${CTID}"
|
||||
echo "$CTID $password $core $memory $disk $system_ori $storage ${ipv6_address_without_last_segment}${CTID}" >>"ct${CTID}"
|
||||
# 容器的相关信息将会存储到对应的容器的NOTE中,可在WEB端查看
|
||||
data=$(echo " CTID root密码-password CPU核数-CPU 内存-memory 硬盘-disk 系统-system 存储盘-storage 外网IPV6-ipv6")
|
||||
values=$(cat "ct${CTID}")
|
||||
IFS=' ' read -ra data_array <<< "$data"
|
||||
IFS=' ' read -ra values_array <<< "$values"
|
||||
IFS=' ' read -ra data_array <<<"$data"
|
||||
IFS=' ' read -ra values_array <<<"$values"
|
||||
length=${#data_array[@]}
|
||||
for ((i=0; i<$length; i++))
|
||||
do
|
||||
for ((i = 0; i < $length; i++)); do
|
||||
echo "${data_array[$i]} ${values_array[$i]}"
|
||||
echo ""
|
||||
done > "/tmp/temp${CTID}.txt"
|
||||
done >"/tmp/temp${CTID}.txt"
|
||||
sed -i 's/^/# /' "/tmp/temp${CTID}.txt"
|
||||
cat "/etc/pve/lxc/${CTID}.conf" >> "/tmp/temp${CTID}.txt"
|
||||
cat "/etc/pve/lxc/${CTID}.conf" >>"/tmp/temp${CTID}.txt"
|
||||
cp "/tmp/temp${CTID}.txt" "/etc/pve/lxc/${CTID}.conf"
|
||||
rm -rf "/tmp/temp${CTID}.txt"
|
||||
cat "ct${CTID}"
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.21
|
||||
|
||||
|
||||
# ./buildvm.sh VMID 用户名 密码 CPU核数 内存 硬盘 SSH端口 80端口 443端口 外网端口起 外网端口止 系统 存储盘 独立IPV6
|
||||
# ./buildvm.sh 102 test1 1234567 1 512 5 40001 40002 40003 50000 50025 debian11 local N
|
||||
|
||||
|
@ -32,7 +31,7 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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"
|
||||
|
@ -50,22 +49,22 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
|
@ -89,13 +88,13 @@ if [ ! -d "qcow" ]; then
|
|||
fi
|
||||
get_system_arch
|
||||
if [ -z "${system_arch}" ] || [ ! -v system_arch ]; then
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
fi
|
||||
if [ "$system_arch" = "x86" ]; then
|
||||
file_path=""
|
||||
systems=(
|
||||
"debian10"
|
||||
"debian10"
|
||||
"debian11"
|
||||
"debian12"
|
||||
"ubuntu18"
|
||||
|
@ -111,7 +110,7 @@ if [ "$system_arch" = "x86" ]; then
|
|||
"alpinelinux_stable"
|
||||
"rockylinux8"
|
||||
"centos8-stream"
|
||||
)
|
||||
)
|
||||
for sys in ${systems[@]}; do
|
||||
if [[ "$system" == "$sys" ]]; then
|
||||
file_path="/root/qcow/${system}.qcow2"
|
||||
|
@ -136,7 +135,7 @@ if [ "$system_arch" = "x86" ]; then
|
|||
array=("${!array_name}")
|
||||
if [[ " ${array[*]} " == *" $system "* ]]; then
|
||||
index=$(echo ${ver_list[*]} | tr -s ' ' '\n' | grep -n "$ver" | cut -d':' -f1)
|
||||
ver="${ver_name_list[$((index-1))]}"
|
||||
ver="${ver_name_list[$((index - 1))]}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -170,25 +169,25 @@ elif [ "$system_arch" = "arch" ]; then
|
|||
fi
|
||||
if [ -n "$file_path" ] && [ -f "$file_path" ]; then
|
||||
case "$system" in
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
url="http://cloud-images.ubuntu.com/${version}/current/${version}-server-cloudimg-arm64.img"
|
||||
curl -L -o "$file_path" "$url"
|
||||
|
@ -209,10 +208,10 @@ if [ "$independent_ipv6" == "y" ]; then
|
|||
else
|
||||
if [ -f /usr/local/bin/pve_check_ipv6 ]; then
|
||||
ipv6_address=$(cat /usr/local/bin/pve_check_ipv6)
|
||||
IFS="/" read -ra parts <<< "$ipv6_address"
|
||||
IFS="/" read -ra parts <<<"$ipv6_address"
|
||||
part_1="${parts[0]}"
|
||||
part_2="${parts[1]}"
|
||||
IFS=":" read -ra part_1_parts <<< "$part_1"
|
||||
IFS=":" read -ra part_1_parts <<<"$part_1"
|
||||
if [ ! -z "${part_1_parts[*]}" ]; then
|
||||
part_1_last="${part_1_parts[-1]}"
|
||||
if [ "$part_1_last" = "$vm_num" ]; then
|
||||
|
@ -320,28 +319,27 @@ if [ ! -f "/etc/iptables/rules.v4" ]; then
|
|||
touch /etc/iptables/rules.v4
|
||||
fi
|
||||
iptables-save | awk '{if($1=="COMMIT"){delete x}}$1=="-A"?!x[$0]++:1' | iptables-restore
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
iptables-save >/etc/iptables/rules.v4
|
||||
service netfilter-persistent restart
|
||||
|
||||
# 虚拟机的相关信息将会存储到对应的虚拟机的NOTE中,可在WEB端查看
|
||||
if [ "$independent_ipv6_status" == "Y" ]; then
|
||||
echo "$vm_num $user $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system $storage ${ipv6_address_without_last_segment}${vm_num}" >> "vm${vm_num}"
|
||||
echo "$vm_num $user $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system $storage ${ipv6_address_without_last_segment}${vm_num}" >>"vm${vm_num}"
|
||||
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk SSH端口 80端口 443端口 外网端口起-port-start 外网端口止-port-end 系统-system 存储盘-storage 独立IPV6地址-ipv6_address")
|
||||
else
|
||||
echo "$vm_num $user $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system $storage" >> "vm${vm_num}"
|
||||
echo "$vm_num $user $password $core $memory $disk $sshn $web1_port $web2_port $port_first $port_last $system $storage" >>"vm${vm_num}"
|
||||
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk SSH端口 80端口 443端口 外网端口起-port-start 外网端口止-port-end 系统-system 存储盘-storage")
|
||||
fi
|
||||
values=$(cat "vm${vm_num}")
|
||||
IFS=' ' read -ra data_array <<< "$data"
|
||||
IFS=' ' read -ra values_array <<< "$values"
|
||||
IFS=' ' read -ra data_array <<<"$data"
|
||||
IFS=' ' read -ra values_array <<<"$values"
|
||||
length=${#data_array[@]}
|
||||
for ((i=0; i<$length; i++))
|
||||
do
|
||||
for ((i = 0; i < $length; i++)); do
|
||||
echo "${data_array[$i]} ${values_array[$i]}"
|
||||
echo ""
|
||||
done > "/tmp/temp${vm_num}.txt"
|
||||
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"
|
||||
cat "/etc/pve/qemu-server/${vm_num}.conf" >>"/tmp/temp${vm_num}.txt"
|
||||
cp "/tmp/temp${vm_num}.txt" "/etc/pve/qemu-server/${vm_num}.conf"
|
||||
rm -rf "/tmp/temp${vm_num}.txt"
|
||||
cat "vm${vm_num}"
|
||||
|
|
|
@ -27,7 +27,7 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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"
|
||||
|
@ -45,26 +45,26 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
sleep 0.5
|
||||
done
|
||||
export cdn_success_url=""
|
||||
}
|
||||
|
@ -84,13 +84,13 @@ if [ ! -d "qcow" ]; then
|
|||
fi
|
||||
get_system_arch
|
||||
if [ -z "${system_arch}" ] || [ ! -v system_arch ]; then
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
fi
|
||||
if [ "$system_arch" = "x86" ]; then
|
||||
file_path=""
|
||||
systems=(
|
||||
"debian10"
|
||||
"debian10"
|
||||
"debian11"
|
||||
"debian12"
|
||||
"ubuntu18"
|
||||
|
@ -99,14 +99,14 @@ if [ "$system_arch" = "x86" ]; then
|
|||
"centos7"
|
||||
"archlinux"
|
||||
"almalinux8"
|
||||
"fedora33"
|
||||
"fedora34"
|
||||
"fedora33"
|
||||
"fedora34"
|
||||
"opensuse-leap-15"
|
||||
"alpinelinux_edge"
|
||||
"alpinelinux_stable"
|
||||
"rockylinux8"
|
||||
"centos8-stream"
|
||||
)
|
||||
)
|
||||
for sys in ${systems[@]}; do
|
||||
if [[ "$system" == "$sys" ]]; then
|
||||
file_path="/root/qcow/${system}.qcow2"
|
||||
|
@ -131,7 +131,7 @@ if [ "$system_arch" = "x86" ]; then
|
|||
array=("${!array_name}")
|
||||
if [[ " ${array[*]} " == *" $system "* ]]; then
|
||||
index=$(echo ${ver_list[*]} | tr -s ' ' '\n' | grep -n "$ver" | cut -d':' -f1)
|
||||
ver="${ver_name_list[$((index-1))]}"
|
||||
ver="${ver_name_list[$((index - 1))]}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -165,25 +165,25 @@ elif [ "$system_arch" = "arch" ]; then
|
|||
fi
|
||||
if [ -n "$file_path" ] && [ -f "$file_path" ]; then
|
||||
case "$system" in
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
url="http://cloud-images.ubuntu.com/${version}/current/${version}-server-cloudimg-arm64.img"
|
||||
curl -L -o "$file_path" "$url"
|
||||
|
@ -204,10 +204,10 @@ if [ "$independent_ipv6" == "y" ]; then
|
|||
else
|
||||
if [ -f /usr/local/bin/pve_check_ipv6 ]; then
|
||||
ipv6_address=$(cat /usr/local/bin/pve_check_ipv6)
|
||||
IFS="/" read -ra parts <<< "$ipv6_address"
|
||||
IFS="/" read -ra parts <<<"$ipv6_address"
|
||||
part_1="${parts[0]}"
|
||||
part_2="${parts[1]}"
|
||||
IFS=":" read -ra part_1_parts <<< "$part_1"
|
||||
IFS=":" read -ra part_1_parts <<<"$part_1"
|
||||
if [ ! -z "${part_1_parts[*]}" ]; then
|
||||
part_1_last="${part_1_parts[-1]}"
|
||||
if [ "$part_1_last" = "$vm_num" ]; then
|
||||
|
@ -226,10 +226,10 @@ else
|
|||
fi
|
||||
fi
|
||||
# 查询信息
|
||||
if ! command -v lshw > /dev/null 2>&1; then
|
||||
if ! command -v lshw >/dev/null 2>&1; then
|
||||
apt-get install -y lshw
|
||||
fi
|
||||
if ! command -v ping > /dev/null 2>&1; then
|
||||
if ! command -v ping >/dev/null 2>&1; then
|
||||
apt-get install -y iputils-ping
|
||||
apt-get install -y ping
|
||||
fi
|
||||
|
@ -246,24 +246,24 @@ user_ip_range=$(echo "$user_main_ip_range" | cut -d'/' -f2)
|
|||
ip_range=$((32 - user_ip_range))
|
||||
# 子网长度-1
|
||||
range=$((2 ** ip_range - 3))
|
||||
IFS='.' read -r -a octets <<< "$user_main_ip"
|
||||
IFS='.' read -r -a octets <<<"$user_main_ip"
|
||||
ip_list=()
|
||||
for ((i=0; i<$range; i++)); do
|
||||
octet=$((i % 256))
|
||||
if [ $octet -gt 254 ]; then
|
||||
break
|
||||
fi
|
||||
ip="${octets[0]}.${octets[1]}.${octets[2]}.$((octets[3] + octet))"
|
||||
ip_list+=("$ip")
|
||||
for ((i = 0; i < $range; i++)); do
|
||||
octet=$((i % 256))
|
||||
if [ $octet -gt 254 ]; then
|
||||
break
|
||||
fi
|
||||
ip="${octets[0]}.${octets[1]}.${octets[2]}.$((octets[3] + octet))"
|
||||
ip_list+=("$ip")
|
||||
done
|
||||
# 宿主机的IP列表
|
||||
_green "当前宿主机可用的外网IP列表长度为${range}"
|
||||
for ip in "${ip_list[@]}"; do
|
||||
if ! ping -c 1 "$ip" >/dev/null; then
|
||||
# 未使用的IP之一
|
||||
user_ip="$ip"
|
||||
break
|
||||
fi
|
||||
if ! ping -c 1 "$ip" >/dev/null; then
|
||||
# 未使用的IP之一
|
||||
user_ip="$ip"
|
||||
break
|
||||
fi
|
||||
done
|
||||
# 宿主机的网关
|
||||
gateway=$(grep -E "iface $interface" -A 3 "/etc/network/interfaces" | grep "gateway" | awk '{print $2}' | head -n 1)
|
||||
|
@ -352,23 +352,22 @@ qm start $vm_num
|
|||
|
||||
# 虚拟机的相关信息将会存储到对应的虚拟机的NOTE中,可在WEB端查看
|
||||
if [ "$independent_ipv6_status" == "Y" ]; then
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip" >> "vm${vm_num}"
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip" >>"vm${vm_num}"
|
||||
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk 系统-system 存储盘-storage 外网IP地址-ipv4")
|
||||
else
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip ${ipv6_address_without_last_segment}${vm_num}" >> "vm${vm_num}"
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip ${ipv6_address_without_last_segment}${vm_num}" >>"vm${vm_num}"
|
||||
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk 系统-system 存储盘-storage 外网IPV4-ipv4 外网IPV6-ipv6")
|
||||
fi
|
||||
values=$(cat "vm${vm_num}")
|
||||
IFS=' ' read -ra data_array <<< "$data"
|
||||
IFS=' ' read -ra values_array <<< "$values"
|
||||
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 ""
|
||||
done > "/tmp/temp${vm_num}.txt"
|
||||
for ((i = 0; i < $length; i++)); do
|
||||
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"
|
||||
cat "/etc/pve/qemu-server/${vm_num}.conf" >>"/tmp/temp${vm_num}.txt"
|
||||
cp "/tmp/temp${vm_num}.txt" "/etc/pve/qemu-server/${vm_num}.conf"
|
||||
rm -rf "/tmp/temp${vm_num}.txt"
|
||||
cat "vm${vm_num}"
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
# 2023.08.04
|
||||
# 手动指定要绑定的IPV4地址
|
||||
|
||||
|
||||
# ./buildvm_manual_ip.sh VMID 用户名 密码 CPU核数 内存 硬盘 系统 存储盘 IPV4地址 是否附加IPV6(默认为N)
|
||||
# ./buildvm_manual_ip.sh 152 test1 1234567 1 512 5 debian11 local a.b.c.d/24 N
|
||||
|
||||
|
@ -30,7 +29,7 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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"
|
||||
|
@ -48,15 +47,15 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
@ -64,9 +63,9 @@ is_ipv4() {
|
|||
local ip=$1
|
||||
local regex="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
|
||||
if [[ $ip =~ $regex ]]; then
|
||||
return 0 # 符合IPv4格式
|
||||
return 0 # 符合IPv4格式
|
||||
else
|
||||
return 1 # 不符合IPv4格式
|
||||
return 1 # 不符合IPv4格式
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -88,15 +87,15 @@ else
|
|||
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() {
|
||||
|
@ -110,17 +109,17 @@ 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
|
||||
get_system_arch
|
||||
if [ -z "${system_arch}" ] || [ ! -v system_arch ]; then
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
fi
|
||||
if [ "$system_arch" = "x86" ]; then
|
||||
file_path=""
|
||||
systems=(
|
||||
"debian10"
|
||||
"debian10"
|
||||
"debian11"
|
||||
"debian12"
|
||||
"ubuntu18"
|
||||
|
@ -136,7 +135,7 @@ if [ "$system_arch" = "x86" ]; then
|
|||
"alpinelinux_stable"
|
||||
"rockylinux8"
|
||||
"centos8-stream"
|
||||
)
|
||||
)
|
||||
for sys in ${systems[@]}; do
|
||||
if [[ "$system" == "$sys" ]]; then
|
||||
file_path="/root/qcow/${system}.qcow2"
|
||||
|
@ -161,7 +160,7 @@ if [ "$system_arch" = "x86" ]; then
|
|||
array=("${!array_name}")
|
||||
if [[ " ${array[*]} " == *" $system "* ]]; then
|
||||
index=$(echo ${ver_list[*]} | tr -s ' ' '\n' | grep -n "$ver" | cut -d':' -f1)
|
||||
ver="${ver_name_list[$((index-1))]}"
|
||||
ver="${ver_name_list[$((index - 1))]}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -195,35 +194,35 @@ elif [ "$system_arch" = "arch" ]; then
|
|||
fi
|
||||
if [ -n "$file_path" ] && [ -f "$file_path" ]; then
|
||||
case "$system" in
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
url="http://cloud-images.ubuntu.com/${version}/current/${version}-server-cloudimg-arm64.img"
|
||||
curl -L -o "$file_path" "$url"
|
||||
fi
|
||||
fi
|
||||
# 查询信息
|
||||
if ! command -v lshw > /dev/null 2>&1; then
|
||||
if ! command -v lshw >/dev/null 2>&1; then
|
||||
apt-get install -y lshw
|
||||
fi
|
||||
if ! command -v ping > /dev/null 2>&1; then
|
||||
if ! command -v ping >/dev/null 2>&1; then
|
||||
apt-get install -y iputils-ping
|
||||
apt-get install -y ping
|
||||
fi
|
||||
|
@ -270,10 +269,10 @@ if [ "$independent_ipv6" == "y" ]; then
|
|||
else
|
||||
if [ -f /usr/local/bin/pve_check_ipv6 ]; then
|
||||
ipv6_address=$(cat /usr/local/bin/pve_check_ipv6)
|
||||
IFS="/" read -ra parts <<< "$ipv6_address"
|
||||
IFS="/" read -ra parts <<<"$ipv6_address"
|
||||
part_1="${parts[0]}"
|
||||
part_2="${parts[1]}"
|
||||
IFS=":" read -ra part_1_parts <<< "$part_1"
|
||||
IFS=":" read -ra part_1_parts <<<"$part_1"
|
||||
if [ ! -z "${part_1_parts[*]}" ]; then
|
||||
part_1_last="${part_1_parts[-1]}"
|
||||
if [ "$part_1_last" = "$vm_num" ]; then
|
||||
|
@ -360,23 +359,22 @@ qm start $vm_num
|
|||
|
||||
# 虚拟机的相关信息将会存储到对应的虚拟机的NOTE中,可在WEB端查看
|
||||
if [ "$independent_ipv6_status" == "N" ]; then
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip" >> "vm${vm_num}"
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip" >>"vm${vm_num}"
|
||||
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk 系统-system 存储盘-storage 外网IP地址-ipv4")
|
||||
else
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip ${ipv6_address_without_last_segment}${vm_num}" >> "vm${vm_num}"
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage $user_ip ${ipv6_address_without_last_segment}${vm_num}" >>"vm${vm_num}"
|
||||
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk 系统-system 存储盘-storage 外网IPV4-ipv4 外网IPV6-ipv6")
|
||||
fi
|
||||
values=$(cat "vm${vm_num}")
|
||||
IFS=' ' read -ra data_array <<< "$data"
|
||||
IFS=' ' read -ra values_array <<< "$values"
|
||||
IFS=' ' read -ra data_array <<<"$data"
|
||||
IFS=' ' read -ra values_array <<<"$values"
|
||||
length=${#data_array[@]}
|
||||
for ((i=0; i<$length; i++))
|
||||
do
|
||||
for ((i = 0; i < $length; i++)); do
|
||||
echo "${data_array[$i]} ${values_array[$i]}"
|
||||
echo ""
|
||||
done > "/tmp/temp${vm_num}.txt"
|
||||
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"
|
||||
cat "/etc/pve/qemu-server/${vm_num}.conf" >>"/tmp/temp${vm_num}.txt"
|
||||
cp "/tmp/temp${vm_num}.txt" "/etc/pve/qemu-server/${vm_num}.conf"
|
||||
rm -rf "/tmp/temp${vm_num}.txt"
|
||||
cat "vm${vm_num}"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.22
|
||||
# 自动选择要绑定的IPV6地址
|
||||
|
@ -22,7 +22,7 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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"
|
||||
|
@ -46,22 +46,22 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
|
@ -85,13 +85,13 @@ if [ ! -d "qcow" ]; then
|
|||
fi
|
||||
get_system_arch
|
||||
if [ -z "${system_arch}" ] || [ ! -v system_arch ]; then
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
fi
|
||||
if [ "$system_arch" = "x86" ]; then
|
||||
file_path=""
|
||||
systems=(
|
||||
"debian10"
|
||||
"debian10"
|
||||
"debian11"
|
||||
"debian12"
|
||||
"ubuntu18"
|
||||
|
@ -107,7 +107,7 @@ if [ "$system_arch" = "x86" ]; then
|
|||
"alpinelinux_stable"
|
||||
"rockylinux8"
|
||||
"centos8-stream"
|
||||
)
|
||||
)
|
||||
for sys in ${systems[@]}; do
|
||||
if [[ "$system" == "$sys" ]]; then
|
||||
file_path="/root/qcow/${system}.qcow2"
|
||||
|
@ -132,7 +132,7 @@ if [ "$system_arch" = "x86" ]; then
|
|||
array=("${!array_name}")
|
||||
if [[ " ${array[*]} " == *" $system "* ]]; then
|
||||
index=$(echo ${ver_list[*]} | tr -s ' ' '\n' | grep -n "$ver" | cut -d':' -f1)
|
||||
ver="${ver_name_list[$((index-1))]}"
|
||||
ver="${ver_name_list[$((index - 1))]}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -166,25 +166,25 @@ elif [ "$system_arch" = "arch" ]; then
|
|||
fi
|
||||
if [ -n "$file_path" ] && [ -f "$file_path" ]; then
|
||||
case "$system" in
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
ubuntu14)
|
||||
version="trusty"
|
||||
;;
|
||||
ubuntu16)
|
||||
version="xenial"
|
||||
;;
|
||||
ubuntu18)
|
||||
version="bionic"
|
||||
;;
|
||||
ubuntu20)
|
||||
version="focal"
|
||||
;;
|
||||
ubuntu22)
|
||||
version="jammy"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Ubuntu version."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
url="http://cloud-images.ubuntu.com/${version}/current/${version}-server-cloudimg-arm64.img"
|
||||
curl -L -o "$file_path" "$url"
|
||||
|
@ -248,20 +248,19 @@ if [ $? -ne 0 ]; then
|
|||
fi
|
||||
fi
|
||||
qm start $vm_num
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage ${ipv6_address_without_last_segment}${vm_num}" >> "vm${vm_num}"
|
||||
echo "$vm_num $user $password $core $memory $disk $system $storage ${ipv6_address_without_last_segment}${vm_num}" >>"vm${vm_num}"
|
||||
# 虚拟机的相关信息将会存储到对应的虚拟机的NOTE中,可在WEB端查看
|
||||
data=$(echo " VMID 用户名-username 密码-password CPU核数-CPU 内存-memory 硬盘-disk 系统-system 存储盘-storage 外网IPV6-ipv6")
|
||||
values=$(cat "vm${vm_num}")
|
||||
IFS=' ' read -ra data_array <<< "$data"
|
||||
IFS=' ' read -ra values_array <<< "$values"
|
||||
IFS=' ' read -ra data_array <<<"$data"
|
||||
IFS=' ' read -ra values_array <<<"$values"
|
||||
length=${#data_array[@]}
|
||||
for ((i=0; i<$length; i++))
|
||||
do
|
||||
for ((i = 0; i < $length; i++)); do
|
||||
echo "${data_array[$i]} ${values_array[$i]}"
|
||||
echo ""
|
||||
done > "/tmp/temp${vm_num}.txt"
|
||||
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"
|
||||
cat "/etc/pve/qemu-server/${vm_num}.conf" >>"/tmp/temp${vm_num}.txt"
|
||||
cp "/tmp/temp${vm_num}.txt" "/etc/pve/qemu-server/${vm_num}.conf"
|
||||
rm -rf "/tmp/temp${vm_num}.txt"
|
||||
cat "vm${vm_num}"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.18
|
||||
|
||||
|
@ -8,35 +8,35 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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
|
||||
if [ ! -d /usr/local/bin ]; then
|
||||
mkdir -p /usr/local/bin
|
||||
fi
|
||||
|
||||
check_config(){
|
||||
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硬盘的最低要求"
|
||||
|
||||
|
||||
# 检查硬盘大小
|
||||
total_disk=$(df -h / | awk '/\//{print $2}')
|
||||
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")
|
||||
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
|
||||
|
||||
|
||||
# 检查CPU核心数
|
||||
cpu_cores=$(grep -c ^processor /proc/cpuinfo)
|
||||
if [ "$cpu_cores" -lt 2 ]; then
|
||||
|
@ -45,7 +45,7 @@ check_config(){
|
|||
_red "本机配置不满足最低要求:至少2核CPU"
|
||||
_red "本机CPU数量配置无法安装PVE"
|
||||
fi
|
||||
|
||||
|
||||
# 检查内存大小
|
||||
total_mem=$(free -m | awk '/^Mem:/{print $2}')
|
||||
if [ "$total_mem" -lt 2048 ]; then
|
||||
|
@ -98,7 +98,7 @@ is_private_ipv6() {
|
|||
return 1
|
||||
}
|
||||
|
||||
check_ipv6(){
|
||||
check_ipv6() {
|
||||
IPV6=$(ip -6 addr show | grep global | awk '{print $2}' | cut -d '/' -f1 | head -n 1)
|
||||
local response
|
||||
if is_private_ipv6 "$IPV6"; then # 由于是内网IPV4地址,需要通过API获取外网地址
|
||||
|
@ -113,17 +113,17 @@ check_ipv6(){
|
|||
sleep 1
|
||||
done
|
||||
fi
|
||||
echo $IPV6 > /usr/local/bin/pve_check_ipv6
|
||||
echo $IPV6 >/usr/local/bin/pve_check_ipv6
|
||||
}
|
||||
|
||||
# 检测IPV6网络配置
|
||||
if ! command -v lshw > /dev/null 2>&1 ; then
|
||||
if ! command -v lshw >/dev/null 2>&1; then
|
||||
apt-get install lshw -y
|
||||
fi
|
||||
if ! command -v ifconfig > /dev/null 2>&1 ; then
|
||||
apt-get install net-tools -y
|
||||
if ! command -v ifconfig >/dev/null 2>&1; then
|
||||
apt-get install net-tools -y
|
||||
fi
|
||||
if command -v lshw > /dev/null 2>&1 ; then
|
||||
if command -v lshw >/dev/null 2>&1; then
|
||||
# 检测物理接口
|
||||
interface_1=$(lshw -C network | awk '/logical name:/{print $3}' | sed -n '1p')
|
||||
interface_2=$(lshw -C network | awk '/logical name:/{print $3}' | sed -n '2p')
|
||||
|
@ -145,11 +145,11 @@ if command -v lshw > /dev/null 2>&1 ; then
|
|||
if [ -z "$ipv6_prefixlen" ]; then
|
||||
ipv6_prefixlen=$(ifconfig vmbr1 | grep -oP 'prefixlen \K\d+' | head -n 1)
|
||||
fi
|
||||
echo "$ipv6_prefixlen" > /usr/local/bin/pve_ipv6_prefixlen
|
||||
echo "$ipv6_prefixlen" >/usr/local/bin/pve_ipv6_prefixlen
|
||||
fi
|
||||
if [ ! -f /usr/local/bin/pve_ipv6_gateway ]; then
|
||||
ipv6_gateway=$(ip -6 route show | awk '/default via/{print $3}' | head -n1)
|
||||
echo "$ipv6_gateway" > /usr/local/bin/pve_ipv6_gateway
|
||||
echo "$ipv6_gateway" >/usr/local/bin/pve_ipv6_gateway
|
||||
fi
|
||||
ipv6_address=$(cat /usr/local/bin/pve_check_ipv6)
|
||||
ipv6_prefixlen=$(cat /usr/local/bin/pve_ipv6_prefixlen)
|
||||
|
@ -217,7 +217,7 @@ if ! lsmod | grep -q kvm; then
|
|||
_yellow "Trying to load KVM module ......"
|
||||
_yellow "尝试加载KVM模块……"
|
||||
modprobe kvm
|
||||
echo "kvm" >> /etc/modules
|
||||
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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
|
||||
divert_install_script() {
|
||||
|
@ -11,8 +11,8 @@ divert_install_script() {
|
|||
install_script="/var/lib/rpm/centos/${package_name}.postinst"
|
||||
fi
|
||||
ln -sf "${divert_script}" "${install_script}"
|
||||
echo '#!/bin/bash' > "${divert_script}"
|
||||
echo 'exit 1' >> "${divert_script}"
|
||||
echo '#!/bin/bash' >"${divert_script}"
|
||||
echo 'exit 1' >>"${divert_script}"
|
||||
chmod +x "${divert_script}"
|
||||
}
|
||||
|
||||
|
|
|
@ -9,15 +9,15 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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
|
||||
|
||||
get_system_arch() {
|
||||
|
@ -27,28 +27,28 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
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,19 +63,19 @@ 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/")
|
||||
check_cdn_file
|
||||
|
||||
pre_check(){
|
||||
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
|
||||
if ! command -v dos2unix > /dev/null 2>&1; then
|
||||
if ! command -v dos2unix >/dev/null 2>&1; then
|
||||
apt-get install dos2unix -y
|
||||
fi
|
||||
if [ ! -f "buildct.sh" ]; then
|
||||
curl -L ${cdn_success_url}https://raw.githubusercontent.com/spiritLHLS/pve/main/scripts/buildct.sh -o buildct.sh && chmod +x buildct.sh
|
||||
dos2unix buildct.sh
|
||||
curl -L ${cdn_success_url}https://raw.githubusercontent.com/spiritLHLS/pve/main/scripts/buildct.sh -o buildct.sh && chmod +x buildct.sh
|
||||
dos2unix buildct.sh
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ pre_check(){
|
|||
# done
|
||||
# fi
|
||||
|
||||
check_info(){
|
||||
check_info() {
|
||||
log_file="ctlog"
|
||||
if [ ! -f "ctlog" ]; then
|
||||
_yellow "ctrlog file does not exist in the current directory"
|
||||
|
@ -98,7 +98,7 @@ check_info(){
|
|||
else
|
||||
while read line; do
|
||||
last_line="$line"
|
||||
done < "$log_file"
|
||||
done <"$log_file"
|
||||
last_line_array=($last_line)
|
||||
ct_num="${last_line_array[0]}"
|
||||
password="${last_line_array[1]}"
|
||||
|
@ -123,7 +123,7 @@ check_info(){
|
|||
fi
|
||||
}
|
||||
|
||||
build_new_cts(){
|
||||
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
|
||||
|
@ -158,7 +158,7 @@ build_new_cts(){
|
|||
_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"
|
||||
storage="local"
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
@ -192,17 +192,17 @@ build_new_cts(){
|
|||
_yellow "输入无效,请输入Y或者N。"
|
||||
fi
|
||||
done
|
||||
for ((i=1; i<=$new_nums; i++)); do
|
||||
for ((i = 1; i <= $new_nums; i++)); do
|
||||
ct_num=$(($ct_num + 1))
|
||||
ori=$(date | md5sum)
|
||||
password=${ori: 2: 9}
|
||||
password=${ori:2:9}
|
||||
ssh_port=$(($web2_port + 1))
|
||||
web1_port=$(($web2_port + 2))
|
||||
web1_port=$(($web2_port + 2))
|
||||
web2_port=$(($web1_port + 1))
|
||||
port_start=$(($port_end + 1))
|
||||
port_end=$(($port_start + 25))
|
||||
./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
|
||||
cat "ct$ct_num" >>ctlog
|
||||
rm -rf "ct$ct_num"
|
||||
sleep 60
|
||||
done
|
||||
|
|
|
@ -9,15 +9,15 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|||
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
||||
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
||||
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
||||
reading(){ read -rp "$(_green "$1")" "$2"; }
|
||||
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
|
||||
|
||||
get_system_arch() {
|
||||
|
@ -27,28 +27,28 @@ get_system_arch() {
|
|||
fi
|
||||
# 根据架构信息设置系统位数并下载文件,其余 * 包括了 x86_64
|
||||
case "${sysarch}" in
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
"i386" | "i686" | "x86_64")
|
||||
system_arch="x86"
|
||||
;;
|
||||
"armv7l" | "armv8" | "armv8l" | "aarch64")
|
||||
system_arch="arch"
|
||||
;;
|
||||
*)
|
||||
system_arch=""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
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,19 +63,19 @@ 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/")
|
||||
check_cdn_file
|
||||
|
||||
pre_check(){
|
||||
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
|
||||
if ! command -v dos2unix > /dev/null 2>&1; then
|
||||
if ! command -v dos2unix >/dev/null 2>&1; then
|
||||
apt-get install dos2unix -y
|
||||
fi
|
||||
if [ ! -f "buildvm.sh" ]; then
|
||||
curl -L ${cdn_success_url}https://raw.githubusercontent.com/spiritLHLS/pve/main/scripts/buildvm.sh -o buildvm.sh && chmod +x buildvm.sh
|
||||
dos2unix buildvm.sh
|
||||
curl -L ${cdn_success_url}https://raw.githubusercontent.com/spiritLHLS/pve/main/scripts/buildvm.sh -o buildvm.sh && chmod +x buildvm.sh
|
||||
dos2unix buildvm.sh
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -87,44 +87,44 @@ pre_check(){
|
|||
# done
|
||||
# fi
|
||||
|
||||
check_info(){
|
||||
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
|
||||
port_end=50025
|
||||
_yellow "vmlog file does not exist in the current directory"
|
||||
_yellow "当前目录下不存在vmlog文件"
|
||||
vm_num=202
|
||||
web2_port=40003
|
||||
port_end=50025
|
||||
else
|
||||
while read line; do
|
||||
last_line="$line"
|
||||
done < "$log_file"
|
||||
last_line_array=($last_line)
|
||||
vm_num="${last_line_array[0]}"
|
||||
user="${last_line_array[1]}"
|
||||
password="${last_line_array[2]}"
|
||||
ssh_port="${last_line_array[6]}"
|
||||
web1_port="${last_line_array[7]}"
|
||||
web2_port="${last_line_array[8]}"
|
||||
port_start="${last_line_array[9]}"
|
||||
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服务器(NAT Server): $vm_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"
|
||||
while read line; do
|
||||
last_line="$line"
|
||||
done <"$log_file"
|
||||
last_line_array=($last_line)
|
||||
vm_num="${last_line_array[0]}"
|
||||
user="${last_line_array[1]}"
|
||||
password="${last_line_array[2]}"
|
||||
ssh_port="${last_line_array[6]}"
|
||||
web1_port="${last_line_array[7]}"
|
||||
web2_port="${last_line_array[8]}"
|
||||
port_start="${last_line_array[9]}"
|
||||
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服务器(NAT Server): $vm_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_vms(){
|
||||
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
|
||||
|
@ -159,7 +159,7 @@ build_new_vms(){
|
|||
_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"
|
||||
storage="local"
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
@ -174,49 +174,49 @@ build_new_vms(){
|
|||
fi
|
||||
done
|
||||
if [ "$system_arch" = "x86" ]; then
|
||||
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"
|
||||
fi
|
||||
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
|
||||
sys_status="true"
|
||||
break
|
||||
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"
|
||||
fi
|
||||
done
|
||||
if [ "$sys_status" = "true" ]; then
|
||||
break
|
||||
else
|
||||
_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
|
||||
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
|
||||
sys_status="true"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "$sys_status" = "true" ]; then
|
||||
break
|
||||
else
|
||||
_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
|
||||
else
|
||||
while true; do
|
||||
sys_status="false"
|
||||
_green "What system does each virtual machine use? (Leave blank or enter debian11 if all use debian11):"
|
||||
reading "每个虚拟机都使用什么系统?(若都使用ubuntu22,则留空或输入ubuntu22):" system
|
||||
if [ -z "$system" ]; then
|
||||
system="ubuntu22"
|
||||
fi
|
||||
systems=("ubuntu14" "ubuntu16" "ubuntu18" "ubuntu20" "ubuntu22")
|
||||
for sys in ${systems[@]}; do
|
||||
if [[ "$system" == "$sys" ]]; then
|
||||
sys_status="true"
|
||||
break
|
||||
while true; do
|
||||
sys_status="false"
|
||||
_green "What system does each virtual machine use? (Leave blank or enter debian11 if all use debian11):"
|
||||
reading "每个虚拟机都使用什么系统?(若都使用ubuntu22,则留空或输入ubuntu22):" system
|
||||
if [ -z "$system" ]; then
|
||||
system="ubuntu22"
|
||||
fi
|
||||
done
|
||||
if [ "$sys_status" = "true" ]; then
|
||||
break
|
||||
else
|
||||
_yellow "Unable to install corresponding system, please check http://cloud-images.ubuntu.com for supported system images "
|
||||
_yellow "无法安装对应系统,请查看 http://cloud-images.ubuntu.com 支持的系统镜像 "
|
||||
fi
|
||||
done
|
||||
systems=("ubuntu14" "ubuntu16" "ubuntu18" "ubuntu20" "ubuntu22")
|
||||
for sys in ${systems[@]}; do
|
||||
if [[ "$system" == "$sys" ]]; then
|
||||
sys_status="true"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "$sys_status" = "true" ]; then
|
||||
break
|
||||
else
|
||||
_yellow "Unable to install corresponding system, please check http://cloud-images.ubuntu.com for supported system images "
|
||||
_yellow "无法安装对应系统,请查看 http://cloud-images.ubuntu.com 支持的系统镜像 "
|
||||
fi
|
||||
done
|
||||
fi
|
||||
while true; do
|
||||
_green "Need to attach a separate IPV6 address to each virtual machine?([N]/y)"
|
||||
|
@ -229,18 +229,18 @@ build_new_vms(){
|
|||
_yellow "输入无效,请输入Y或者N。"
|
||||
fi
|
||||
done
|
||||
for ((i=1; i<=$new_nums; i++)); do
|
||||
for ((i = 1; i <= $new_nums; i++)); do
|
||||
vm_num=$(($vm_num + 1))
|
||||
user=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 4 | head -n 1)
|
||||
ori=$(date | md5sum)
|
||||
password=${ori: 2: 9}
|
||||
password=${ori:2:9}
|
||||
ssh_port=$(($web2_port + 1))
|
||||
web1_port=$(($web2_port + 2))
|
||||
web1_port=$(($web2_port + 2))
|
||||
web2_port=$(($web1_port + 1))
|
||||
port_start=$(($port_end + 1))
|
||||
port_end=$(($port_start + 25))
|
||||
./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
|
||||
cat "vm$vm_num" >>vmlog
|
||||
rm -rf "vm$vm_num"
|
||||
sleep 60
|
||||
done
|
||||
|
@ -249,8 +249,8 @@ build_new_vms(){
|
|||
pre_check
|
||||
get_system_arch
|
||||
if [ -z "${system_arch}" ] || [ ! -v system_arch ]; then
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
_red "This script can only run on machines under x86_64 or arm architecture."
|
||||
exit 1
|
||||
fi
|
||||
check_info
|
||||
build_new_vms
|
||||
|
|
File diff suppressed because it is too large
Load diff
137
scripts/ssh.sh
137
scripts/ssh.sh
|
@ -1,14 +1,13 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.09
|
||||
|
||||
if [ -f "/etc/resolv.conf" ]
|
||||
then
|
||||
if [ -f "/etc/resolv.conf" ]; then
|
||||
cp /etc/resolv.conf /etc/resolv.conf.bak
|
||||
chattr -i /etc/resolv.conf
|
||||
echo "nameserver 8.8.8.8" | tee -a /etc/resolv.conf > /dev/null
|
||||
echo "nameserver 8.8.4.4" | tee -a /etc/resolv.conf > /dev/null
|
||||
echo "nameserver 8.8.8.8" | tee -a /etc/resolv.conf >/dev/null
|
||||
echo "nameserver 8.8.4.4" | tee -a /etc/resolv.conf >/dev/null
|
||||
chattr +i /etc/resolv.conf
|
||||
fi
|
||||
|
||||
|
@ -19,7 +18,7 @@ PACKAGE_UPDATE=("! apt-get update && apt-get --fix-broken install -y && apt-get
|
|||
PACKAGE_INSTALL=("apt-get -y install" "apt-get -y install" "yum -y install" "yum -y install" "yum -y install" "pacman -Sy --noconfirm --needed" "pkg install -y")
|
||||
PACKAGE_REMOVE=("apt-get -y remove" "apt-get -y remove" "yum -y remove" "yum -y remove" "yum -y remove" "pacman -Rsc --noconfirm" "pkg delete")
|
||||
PACKAGE_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "" "pkg autoremove")
|
||||
CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)" "$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)" "$(grep . /etc/redhat-release 2>/dev/null)" "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')" "$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(uname -s)")
|
||||
CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)" "$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)" "$(grep . /etc/redhat-release 2>/dev/null)" "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')" "$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(uname -s)")
|
||||
SYS="${CMD[0]}"
|
||||
[[ -n $SYS ]] || exit 1
|
||||
for ((int = 0; int < ${#REGEX[@]}; int++)); do
|
||||
|
@ -32,15 +31,15 @@ done
|
|||
[[ $EUID -ne 0 ]] && exit 1
|
||||
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
|
||||
|
||||
check_china(){
|
||||
check_china() {
|
||||
echo "IP area being detected ......"
|
||||
if [[ -z "${CN}" ]]; then
|
||||
if [[ $(curl -m 6 -s https://ipapi.co/json | grep 'China') != "" ]]; then
|
||||
|
@ -58,28 +57,28 @@ check_china(){
|
|||
}
|
||||
|
||||
change_debian_apt_sources() {
|
||||
cp /etc/apt/sources.list /etc/apt/sources.list.bak
|
||||
echo "backup the current /etc/apt/sources.list to /etc/apt/sources.list.bak"
|
||||
DEBIAN_VERSION=$(lsb_release -sr)
|
||||
if [[ -z "${CN}" || "${CN}" != true ]]; then
|
||||
URL="http://deb.debian.org/debian"
|
||||
else
|
||||
# Use mirrors.aliyun.com sources list if IP is in China
|
||||
URL="http://mirrors.aliyun.com/debian"
|
||||
fi
|
||||
cp /etc/apt/sources.list /etc/apt/sources.list.bak
|
||||
echo "backup the current /etc/apt/sources.list to /etc/apt/sources.list.bak"
|
||||
DEBIAN_VERSION=$(lsb_release -sr)
|
||||
if [[ -z "${CN}" || "${CN}" != true ]]; then
|
||||
URL="http://deb.debian.org/debian"
|
||||
else
|
||||
# Use mirrors.aliyun.com sources list if IP is in China
|
||||
URL="http://mirrors.aliyun.com/debian"
|
||||
fi
|
||||
|
||||
case $DEBIAN_VERSION in
|
||||
6*) DEBIAN_RELEASE="squeeze";;
|
||||
7*) DEBIAN_RELEASE="wheezy";;
|
||||
8*) DEBIAN_RELEASE="jessie";;
|
||||
9*) DEBIAN_RELEASE="stretch";;
|
||||
10*) DEBIAN_RELEASE="buster";;
|
||||
11*) DEBIAN_RELEASE="bullseye";;
|
||||
12*) DEBIAN_RELEASE="bookworm";;
|
||||
*) echo "The system is not Debian 6/7/8/9/10/11/12 . No changes were made to the apt-get sources." && return 1;;
|
||||
esac
|
||||
case $DEBIAN_VERSION in
|
||||
6*) DEBIAN_RELEASE="squeeze" ;;
|
||||
7*) DEBIAN_RELEASE="wheezy" ;;
|
||||
8*) DEBIAN_RELEASE="jessie" ;;
|
||||
9*) DEBIAN_RELEASE="stretch" ;;
|
||||
10*) DEBIAN_RELEASE="buster" ;;
|
||||
11*) DEBIAN_RELEASE="bullseye" ;;
|
||||
12*) DEBIAN_RELEASE="bookworm" ;;
|
||||
*) echo "The system is not Debian 6/7/8/9/10/11/12 . No changes were made to the apt-get sources." && return 1 ;;
|
||||
esac
|
||||
|
||||
cat > /etc/apt/sources.list <<EOF
|
||||
cat >/etc/apt/sources.list <<EOF
|
||||
deb ${URL} ${DEBIAN_RELEASE} main contrib non-free
|
||||
deb ${URL} ${DEBIAN_RELEASE}-updates main contrib non-free
|
||||
deb ${URL} ${DEBIAN_RELEASE}-backports main contrib non-free
|
||||
|
@ -89,48 +88,47 @@ deb-src ${URL} ${DEBIAN_RELEASE}-backports main contrib non-free
|
|||
EOF
|
||||
}
|
||||
|
||||
checkupdate(){
|
||||
if command -v apt-get > /dev/null 2>&1; then
|
||||
apt_update_output=$(apt-get update 2>&1)
|
||||
echo "$apt_update_output" > "$temp_file_apt_fix"
|
||||
if grep -q 'NO_PUBKEY' "$temp_file_apt_fix"; then
|
||||
public_keys=$(grep -oE 'NO_PUBKEY [0-9A-F]+' "$temp_file_apt_fix" | awk '{ print $2 }')
|
||||
joined_keys=$(echo "$public_keys" | paste -sd " ")
|
||||
echo "No Public Keys: ${joined_keys}"
|
||||
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ${joined_keys}
|
||||
apt-get update
|
||||
if [ $? -eq 0 ]; then
|
||||
_green "Fixed"
|
||||
fi
|
||||
checkupdate() {
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
apt_update_output=$(apt-get update 2>&1)
|
||||
echo "$apt_update_output" >"$temp_file_apt_fix"
|
||||
if grep -q 'NO_PUBKEY' "$temp_file_apt_fix"; then
|
||||
public_keys=$(grep -oE 'NO_PUBKEY [0-9A-F]+' "$temp_file_apt_fix" | awk '{ print $2 }')
|
||||
joined_keys=$(echo "$public_keys" | paste -sd " ")
|
||||
echo "No Public Keys: ${joined_keys}"
|
||||
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ${joined_keys}
|
||||
apt-get update
|
||||
if [ $? -eq 0 ]; then
|
||||
_green "Fixed"
|
||||
fi
|
||||
fi
|
||||
rm "$temp_file_apt_fix"
|
||||
else
|
||||
${PACKAGE_UPDATE[int]}
|
||||
fi
|
||||
rm "$temp_file_apt_fix"
|
||||
else
|
||||
${PACKAGE_UPDATE[int]}
|
||||
fi
|
||||
}
|
||||
|
||||
install_required_modules() {
|
||||
modules=("sshpass" "openssh-server")
|
||||
for module in "${modules[@]}"
|
||||
do
|
||||
if command -v apt-get > /dev/null 2>&1; then
|
||||
if dpkg -s $module > /dev/null 2>&1 ; then
|
||||
echo "$module has benn installed."
|
||||
else
|
||||
apt-get install -y $module
|
||||
if [ $? -ne 0 ]; then
|
||||
apt-get install -y $module --fix-missing
|
||||
fi
|
||||
echo "$module has been tried and installed!"
|
||||
fi
|
||||
else
|
||||
${PACKAGE_INSTALL[int]} $module
|
||||
fi
|
||||
for module in "${modules[@]}"; do
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
if dpkg -s $module >/dev/null 2>&1; then
|
||||
echo "$module has benn installed."
|
||||
else
|
||||
apt-get install -y $module
|
||||
if [ $? -ne 0 ]; then
|
||||
apt-get install -y $module --fix-missing
|
||||
fi
|
||||
echo "$module has been tried and installed!"
|
||||
fi
|
||||
else
|
||||
${PACKAGE_INSTALL[int]} $module
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
remove_duplicate_lines() {
|
||||
awk '!NF || !x[$0]++' "$1" > "$1.tmp" && mv -f "$1.tmp" "$1"
|
||||
awk '!NF || !x[$0]++' "$1" >"$1.tmp" && mv -f "$1.tmp" "$1"
|
||||
}
|
||||
|
||||
check_china
|
||||
|
@ -142,17 +140,18 @@ fi
|
|||
checkupdate
|
||||
install_required_modules
|
||||
if [ -f "/etc/motd" ]; then
|
||||
echo 'Related repo https://github.com/spiritLHLS/pve' >> /etc/motd
|
||||
echo '--by https://t.me/spiritlhl' >> /etc/motd
|
||||
echo 'Related repo https://github.com/spiritLHLS/pve' >>/etc/motd
|
||||
echo '--by https://t.me/spiritlhl' >>/etc/motd
|
||||
fi
|
||||
service iptables stop 2> /dev/null ; chkconfig iptables off 2> /dev/null ;
|
||||
service iptables stop 2>/dev/null
|
||||
chkconfig iptables off 2>/dev/null
|
||||
if [ -f "/etc/sysconfig/selinux" ]; then
|
||||
sed -i.bak '/^SELINUX=/cSELINUX=disabled' /etc/sysconfig/selinux
|
||||
fi
|
||||
if [ -f "/etc/selinux/config" ]; then
|
||||
sed -i.bak '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
|
||||
fi
|
||||
setenforce 0;
|
||||
setenforce 0
|
||||
if [ -f /etc/ssh/sshd_config ]; then
|
||||
sed -i 's/^#\?Port.*/Port 22/g' /etc/ssh/sshd_config
|
||||
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
||||
|
|
Loading…
Reference in a new issue