mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-18 00:12:17 +00:00
Make shell command substitutions safe with || true (#13279)
Add defensive fallbacks (|| true) to multiple command substitutions to prevent non-zero exits when commands produce no output or are unavailable. Changes touch misc/api.func, misc/build.func and misc/tools.func and cover places like lspci, /proc/cpuinfo parsing, /etc/os-release reads, hostname -I usage, grep reads from vars files and maps, pct config parsing, storage/template lookups, tool version detection, NVIDIA driver version extraction, and MeiliSearch config parsing. These edits do not change functional behavior aside from ensuring the scripts continue running (variables will be empty) instead of failing in stricter shells or when commands return non-zero status.
This commit is contained in:
committed by
GitHub
parent
de356fa8b6
commit
53bc492fdb
@@ -524,12 +524,12 @@ is_tool_installed() {
|
||||
case "$tool_name" in
|
||||
mariadb)
|
||||
if command -v mariadb >/dev/null 2>&1; then
|
||||
installed_version=$(mariadb --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
|
||||
installed_version=$(mariadb --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)
|
||||
fi
|
||||
;;
|
||||
mysql)
|
||||
if command -v mysql >/dev/null 2>&1; then
|
||||
installed_version=$(mysql --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
|
||||
installed_version=$(mysql --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)
|
||||
fi
|
||||
;;
|
||||
mongodb | mongod)
|
||||
@@ -539,7 +539,7 @@ is_tool_installed() {
|
||||
;;
|
||||
node | nodejs)
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
installed_version=$(node -v 2>/dev/null | grep -oP '^v\K[0-9]+')
|
||||
installed_version=$(node -v 2>/dev/null | grep -oP '^v\K[0-9]+' || true)
|
||||
fi
|
||||
;;
|
||||
php)
|
||||
@@ -4837,7 +4837,7 @@ _setup_nvidia_gpu() {
|
||||
# Use regex to extract version number (###.##.## or ###.## pattern)
|
||||
local nvidia_host_version=""
|
||||
if [[ -f /proc/driver/nvidia/version ]]; then
|
||||
nvidia_host_version=$(grep -oP '\d{3,}\.\d+(\.\d+)?' /proc/driver/nvidia/version 2>/dev/null | head -1)
|
||||
nvidia_host_version=$(grep -oP '\d{3,}\.\d+(\.\d+)?' /proc/driver/nvidia/version 2>/dev/null | head -1 || true)
|
||||
fi
|
||||
|
||||
if [[ -z "$nvidia_host_version" ]]; then
|
||||
@@ -7321,7 +7321,7 @@ function setup_meilisearch() {
|
||||
MEILI_HOST="${MEILISEARCH_HOST:-127.0.0.1}"
|
||||
MEILI_PORT="${MEILISEARCH_PORT:-7700}"
|
||||
MEILI_DUMP_DIR="${MEILISEARCH_DUMP_DIR:-/var/lib/meilisearch/dumps}"
|
||||
MEILI_MASTER_KEY=$(grep -E "^master_key\s*=" /etc/meilisearch.toml 2>/dev/null | sed 's/.*=\s*"\(.*\)"/\1/' | tr -d ' ')
|
||||
MEILI_MASTER_KEY=$(grep -E "^master_key\s*=" /etc/meilisearch.toml 2>/dev/null | sed 's/.*=\s*"\(.*\)"/\1/' | tr -d ' ' || true)
|
||||
|
||||
# Create dump before update if migration is needed
|
||||
local DUMP_UID=""
|
||||
@@ -7387,7 +7387,7 @@ function setup_meilisearch() {
|
||||
# We choose option 2: backup and proceed with warning
|
||||
if [[ "$NEEDS_MIGRATION" == "true" ]] && [[ -z "$DUMP_UID" ]]; then
|
||||
local MEILI_DB_PATH
|
||||
MEILI_DB_PATH=$(grep -E "^db_path\s*=" /etc/meilisearch.toml 2>/dev/null | sed 's/.*=\s*"\(.*\)"/\1/' | tr -d ' ')
|
||||
MEILI_DB_PATH=$(grep -E "^db_path\s*=" /etc/meilisearch.toml 2>/dev/null | sed 's/.*=\s*"\(.*\)"/\1/' | tr -d ' ' || true)
|
||||
MEILI_DB_PATH="${MEILI_DB_PATH:-/var/lib/meilisearch/data}"
|
||||
|
||||
if [[ -d "$MEILI_DB_PATH" ]] && [[ -n "$(ls -A "$MEILI_DB_PATH" 2>/dev/null)" ]]; then
|
||||
@@ -7407,7 +7407,7 @@ function setup_meilisearch() {
|
||||
# If migration needed and dump was created, remove old data and import dump
|
||||
if [[ "$NEEDS_MIGRATION" == "true" ]] && [[ -n "$DUMP_UID" ]]; then
|
||||
local MEILI_DB_PATH
|
||||
MEILI_DB_PATH=$(grep -E "^db_path\s*=" /etc/meilisearch.toml 2>/dev/null | sed 's/.*=\s*"\(.*\)"/\1/' | tr -d ' ')
|
||||
MEILI_DB_PATH=$(grep -E "^db_path\s*=" /etc/meilisearch.toml 2>/dev/null | sed 's/.*=\s*"\(.*\)"/\1/' | tr -d ' ' || true)
|
||||
MEILI_DB_PATH="${MEILI_DB_PATH:-/var/lib/meilisearch/data}"
|
||||
|
||||
msg_info "Removing old MeiliSearch database for migration"
|
||||
|
||||
Reference in New Issue
Block a user