优化镜像标签获取逻辑,调整 VMID 生成方式,确保版本信息处理更为灵活

This commit is contained in:
Ing 2025-12-16 13:31:55 +08:00
parent d5dcb28318
commit 57eac55d54

View File

@ -95,16 +95,15 @@ if ! command -v qm >/dev/null 2>&1; then
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}' | sed 's/^[v|V]//g')"
fi
if [ -n "${IMG}" ] && [ -f "${IMG}" ]; then
IMG_PATH="${IMG}"
else
if ! command -v curl >/dev/null 2>&1; then
apt-get update >/dev/null 2>&1 && apt-get install -y curl >/dev/null 2>&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}' | sed 's/^[v|V]//g')"
fi
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")
@ -137,14 +136,9 @@ fi
echo "Creating VM with RR ... "
# 获取可用的 VMID
last_vmid=$(qm list | awk 'NR>1{print$1}' | sort -n | tail -1 2>/dev/null)
if [ -z "$last_vmid" ]; then
# 如果 last_vmid 是空字符串说明没有VM设置一个起始ID
VMID=100
else
# 否则在最后一个ID的基础上加1
VMID=$((last_vmid + 1))
fi
LAST_VMID=$(qm list | awk 'NR>1{print$1}' | sort -n | tail -1 2>/dev/null)
VMID=$((${LAST_VMID:-99} + 1))
ARGS=""
SATAIDX=0
@ -232,7 +226,7 @@ qm set ${VMID} --net0 virtio,bridge=${BRIDGE}
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} --smbios1 "uuid=$(cat /proc/sys/kernel/random/uuid),manufacturer=$(echo -n "RROrg" | base64),product=$(echo -n "RR" | base64),version=$(echo -n "${TAG:-local}" | base64),base64=1"
qm set ${VMID} --onboot "${ONBOOT}"
echo "Created success, VMID=${VMID}"