Format misc/api.func: spacing and heredocs

Clean up formatting in misc/api.func for readability. Normalized spacing in the categorize_error case patterns, removed trailing blank-space lines, and standardized detect_gpu blank-line spacing. Converted heredoc assignments to use multiline $() style for JSON_PAYLOAD in post_tool_to_api, post_addon_to_api, and post_update_to_api_extended, and added a final newline at end of file. No functional changes intended; purely whitespace/formatting cleanup.
This commit is contained in:
CanbiZ (MickLesk) 2026-02-10 08:17:50 +01:00
parent ed3af96585
commit 53cf705799

View File

@ -422,29 +422,29 @@ EOF
categorize_error() { categorize_error() {
local code="$1" local code="$1"
case "$code" in case "$code" in
# Network errors # Network errors
6|7|22|28|35) echo "network" ;; 6 | 7 | 22 | 28 | 35) echo "network" ;;
# Storage errors # Storage errors
214|217|219) echo "storage" ;; 214 | 217 | 219) echo "storage" ;;
# Dependency/Package errors # Dependency/Package errors
100|101|102|127|160|161|162) echo "dependency" ;; 100 | 101 | 102 | 127 | 160 | 161 | 162) echo "dependency" ;;
# Permission errors # Permission errors
126|152) echo "permission" ;; 126 | 152) echo "permission" ;;
# Timeout errors # Timeout errors
124|28|211) echo "timeout" ;; 124 | 28 | 211) echo "timeout" ;;
# Configuration errors # Configuration errors
203|204|205|206|207|208) echo "config" ;; 203 | 204 | 205 | 206 | 207 | 208) echo "config" ;;
# Resource errors (OOM, etc) # Resource errors (OOM, etc)
137|134) echo "resource" ;; 137 | 134) echo "resource" ;;
# Default # Default
*) echo "unknown" ;; *) echo "unknown" ;;
esac esac
} }
@ -485,13 +485,13 @@ get_install_duration() {
detect_gpu() { detect_gpu() {
GPU_VENDOR="" GPU_VENDOR=""
GPU_PASSTHROUGH="none" GPU_PASSTHROUGH="none"
# Detect Intel GPU # Detect Intel GPU
if lspci 2>/dev/null | grep -qi "VGA.*Intel"; then if lspci 2>/dev/null | grep -qi "VGA.*Intel"; then
GPU_VENDOR="intel" GPU_VENDOR="intel"
GPU_PASSTHROUGH="igpu" GPU_PASSTHROUGH="igpu"
fi fi
# Detect AMD GPU # Detect AMD GPU
if lspci 2>/dev/null | grep -qi "VGA.*AMD\|VGA.*ATI"; then if lspci 2>/dev/null | grep -qi "VGA.*AMD\|VGA.*ATI"; then
GPU_VENDOR="amd" GPU_VENDOR="amd"
@ -502,13 +502,13 @@ detect_gpu() {
GPU_PASSTHROUGH="igpu" GPU_PASSTHROUGH="igpu"
fi fi
fi fi
# Detect NVIDIA GPU # Detect NVIDIA GPU
if lspci 2>/dev/null | grep -qi "VGA.*NVIDIA\|3D.*NVIDIA"; then if lspci 2>/dev/null | grep -qi "VGA.*NVIDIA\|3D.*NVIDIA"; then
GPU_VENDOR="nvidia" GPU_VENDOR="nvidia"
GPU_PASSTHROUGH="dgpu" GPU_PASSTHROUGH="dgpu"
fi fi
export GPU_VENDOR GPU_PASSTHROUGH export GPU_VENDOR GPU_PASSTHROUGH
} }
@ -535,10 +535,10 @@ post_tool_to_api() {
# Generate UUID for this tool execution # Generate UUID for this tool execution
uuid=$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen 2>/dev/null || echo "tool-$(date +%s)") uuid=$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen 2>/dev/null || echo "tool-$(date +%s)")
duration=$(get_install_duration) duration=$(get_install_duration)
# Map status # Map status
[[ "$status" == "done" ]] && status="success" [[ "$status" == "done" ]] && status="success"
if [[ "$status" == "failed" ]]; then if [[ "$status" == "failed" ]]; then
[[ ! "$exit_code" =~ ^[0-9]+$ ]] && exit_code=1 [[ ! "$exit_code" =~ ^[0-9]+$ ]] && exit_code=1
error=$(explain_exit_code "$exit_code") error=$(explain_exit_code "$exit_code")
@ -551,7 +551,8 @@ post_tool_to_api() {
fi fi
local JSON_PAYLOAD local JSON_PAYLOAD
JSON_PAYLOAD=$(cat <<EOF JSON_PAYLOAD=$(
cat <<EOF
{ {
"random_id": "${uuid}", "random_id": "${uuid}",
"type": "tool", "type": "tool",
@ -565,7 +566,7 @@ post_tool_to_api() {
"pve_version": "${pve_version}" "pve_version": "${pve_version}"
} }
EOF EOF
) )
curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
@ -597,10 +598,10 @@ post_addon_to_api() {
# Generate UUID for this addon installation # Generate UUID for this addon installation
uuid=$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen 2>/dev/null || echo "addon-$(date +%s)") uuid=$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen 2>/dev/null || echo "addon-$(date +%s)")
duration=$(get_install_duration) duration=$(get_install_duration)
# Map status # Map status
[[ "$status" == "done" ]] && status="success" [[ "$status" == "done" ]] && status="success"
if [[ "$status" == "failed" ]]; then if [[ "$status" == "failed" ]]; then
[[ ! "$exit_code" =~ ^[0-9]+$ ]] && exit_code=1 [[ ! "$exit_code" =~ ^[0-9]+$ ]] && exit_code=1
error=$(explain_exit_code "$exit_code") error=$(explain_exit_code "$exit_code")
@ -615,7 +616,8 @@ post_addon_to_api() {
fi fi
local JSON_PAYLOAD local JSON_PAYLOAD
JSON_PAYLOAD=$(cat <<EOF JSON_PAYLOAD=$(
cat <<EOF
{ {
"random_id": "${uuid}", "random_id": "${uuid}",
"type": "addon", "type": "addon",
@ -630,7 +632,7 @@ post_addon_to_api() {
"os_version": "${os_version}" "os_version": "${os_version}"
} }
EOF EOF
) )
curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
@ -667,7 +669,7 @@ post_update_to_api_extended() {
# Get duration # Get duration
duration=$(get_install_duration) duration=$(get_install_duration)
# Get GPU info (if detected) # Get GPU info (if detected)
gpu_vendor="${GPU_VENDOR:-}" gpu_vendor="${GPU_VENDOR:-}"
gpu_passthrough="${GPU_PASSTHROUGH:-}" gpu_passthrough="${GPU_PASSTHROUGH:-}"
@ -701,7 +703,8 @@ post_update_to_api_extended() {
fi fi
local JSON_PAYLOAD local JSON_PAYLOAD
JSON_PAYLOAD=$(cat <<EOF JSON_PAYLOAD=$(
cat <<EOF
{ {
"random_id": "${RANDOM_UUID}", "random_id": "${RANDOM_UUID}",
"type": "${TELEMETRY_TYPE:-lxc}", "type": "${TELEMETRY_TYPE:-lxc}",
@ -715,11 +718,11 @@ post_update_to_api_extended() {
"gpu_passthrough": "${gpu_passthrough}" "gpu_passthrough": "${gpu_passthrough}"
} }
EOF EOF
) )
curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$JSON_PAYLOAD" &>/dev/null || true -d "$JSON_PAYLOAD" &>/dev/null || true
POST_UPDATE_DONE=true POST_UPDATE_DONE=true
} }