diff --git a/build_backend.sh b/build_backend.sh index 7c4f1f1..316467b 100644 --- a/build_backend.sh +++ b/build_backend.sh @@ -8,26 +8,31 @@ _yellow() { echo -e "\033[33m\033[01m$@\033[0m"; } _blue() { echo -e "\033[36m\033[01m$@\033[0m"; } # 创建资源池 -_green "正在创建资源池 mypool..." -pvesh create /pools --poolid mypool -_green "资源池 mypool 已创建!" - -# 安装必备模块 -apt-get update -apt-get install -y sudo -apt-get install -y ifupdown2 -apt-get install -y lshw -apt-get install -y iproute2 -apt-get install -y net-tools -apt-get install -y cloud-init -if ! dpkg -s novnc > /dev/null 2>&1 ; then - apt-get update - apt-get install -y novnc - echo "noVNC已成功安装" +POOL_ID="mypool" +if pvesh get /pools/$POOL_ID > /dev/null 2>&1 ; then + echo "资源池 $POOL_ID 已经存在!" else - echo "noVNC已安装" + # 如果不存在则创建 + _green "正在创建资源池 $POOL_ID..." + pvesh create /pools --poolid $POOL_ID + _green "资源池 $POOL_ID 已创建!" fi +# 安装必备模块 +install_required_modules() { + modules=("sudo" "ifupdown2" "lshw" "iproute2" "net-tools" "cloud-init" "novnc") + for module in "${modules[@]}" + do + if dpkg -s $module > /dev/null 2>&1 ; then + echo "$module 已经安装!" + else + apt-get update + apt-get install -y $module + echo "$module 已成功安装!" + fi + done +} +install_required_modules # 检测AppArmor模块 if ! dpkg -s apparmor > /dev/null 2>&1; then