From db85e17b026d67f3de8c3494a2e664b398244614 Mon Sep 17 00:00:00 2001 From: Ing Date: Fri, 12 Sep 2025 13:23:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20pve.sh=20=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E6=94=AF=E6=8C=81=E5=88=9B=E5=BB=BA=E5=92=8C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20Proxmox=20VE=20=E8=99=9A=E6=8B=9F=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/pve.sh | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 scripts/pve.sh diff --git a/scripts/pve.sh b/scripts/pve.sh new file mode 100644 index 00000000..12ac4ccc --- /dev/null +++ b/scripts/pve.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2022 Ing +# +# This is free software, licensed under the MIT License. +# See /LICENSE for more information. +# + +REPO="https://github.com/RROrg/rr" + +# 参数 +ONBOOT=1 # 开机启动,默认1 +# BLTYPE="usb" # 引导盘类型, 支持 usb,sata,nvme 默认 usb +TAG="" # 镜像tag,默认自动获取 +IMG="" # 本地镜像路径,默认空 + +while [[ $# -gt 0 ]]; do + case "$1" in + --onboot) + ONBOOT="${2}" + shift 2 + ;; + #--bltype) + # BLTYPE="${2}" + # shift 2 + # ;; + --tag) + TAG="${2}" + shift 2 + ;; + --img) + IMG="${2}" + shift 2 + ;; + *) + # echo "Usage: $0 [--onboot <0|1>] [--bltype ] [--tag ] [--img ]" + echo "Usage: $0 [--onboot <0|1>] [--tag ] [--img ]" + exit 1 + ;; + esac +done + +if ! command -v qm >/dev/null 2>&1; then + echo "Not a Proxmox VE environment" + exit 1 +fi + +if [ -z "$TAG" ]; then + TAG="$(curl -skL --connect-timeout 10 -w "%{url_effective}" -o /dev/null "${REPO}/releases/latest" | awk -F'/' '{print $NF}')" + [ "${TAG:0:1}" = "v" ] && TAG="${TAG:1}" +fi + +if [ -n "${IMG}" ] && [ -f "${IMG}" ]; then + IMG_PATH="${IMG}" +else + rm -f "/tmp/rr-${TAG}.img.zip" + echo "Downloading rr-${TAG}.img.zip ... " + STATUS=$(curl -skL --connect-timeout 10 -w "%{http_code}" "${REPO}/releases/download/${TAG}/rr-${TAG}.img.zip" -o "/tmp/rr-${TAG}.img.zip") + if [ $? -ne 0 ] || [ "${STATUS:-0}" -ne 200 ]; then + rm -f "/tmp/rr-${TAG}.img.zip" + echo "Download failed" + exit 1 + fi + if ! command -v unzip >/dev/null 2>&1; then + apt-get update >/dev/null 2>&1 && apt-get install -y unzip >/dev/null 2>&1 + fi + rm -f "/tmp/rr.img" + echo "Unzipping rr-${TAG}.img.zip ... " + unzip -o "/tmp/rr-${TAG}.img.zip" -d /tmp/ >/dev/null 2>&1 + STATUS=$? + rm -f "/tmp/rr-${TAG}.img.zip" + if [ "${STATUS:-0}" -ne 0 ]; then + echo "Unzip failed" + exit 1 + fi + IMG_PATH="/tmp/rr.img" +fi + +echo "Creating VM with RR ... " + +# 获取可用的 VMID +VMID="$(($(qm list | awk 'NR>1{print $1}' | sort -n | tail -1 2>/dev/null || echo 99) + 1))" + +# 创建 VM +qm create ${VMID} --name RR-DSM --machine q35 --ostype l26 --vga virtio --sockets 1 --cores 2 --cpu host --numa 0 --memory 4096 --scsihw virtio-scsi-single +if [ $? -ne 0 ]; then + echo "Create VM failed" + exit 1 +fi + +# 导入磁盘 +qm importdisk ${VMID} "${IMG_PATH}" local-lvm >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Import disk failed" + exit 1 +fi +[ -n "${IMG}" ] || rm -f "${IMG_PATH}" + +# 设置 VM 配置 +qm set ${VMID} --bios ovmf --efidisk0 local-lvm:4,efitype=4m,pre-enrolled-keys=0 +qm set ${VMID} --sata0 local-lvm:vm-${VMID}-disk-0 +qm set ${VMID} --sata1 local-lvm:32 +qm set ${VMID} --net0 virtio,bridge=vmbr0 +qm set ${VMID} --serial0 socket +qm set ${VMID} --agent enabled=1 +qm set ${VMID} --smbios1 "uuid=$(cat /proc/sys/kernel/random/uuid),manufacturer=$(echo -n "RROrg" | base64),product=$(echo -n "RR" | base64),version=$(echo -n "$TAG" | base64),base64=1" +qm set ${VMID} --onboot "${ONBOOT}" + +echo "Created success, VMID=${VMID}"