mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-27 12:50:41 +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
+10
-10
@@ -173,10 +173,10 @@ get_current_ip() {
|
||||
# Check for Debian/Ubuntu (uses hostname -I)
|
||||
if grep -qE 'ID=debian|ID=ubuntu' /etc/os-release; then
|
||||
# Try IPv4 first
|
||||
CURRENT_IP=$(hostname -I 2>/dev/null | tr ' ' '\n' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' | head -n1)
|
||||
CURRENT_IP=$(hostname -I 2>/dev/null | tr ' ' '\n' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true)
|
||||
# Fallback to IPv6 if no IPv4
|
||||
if [[ -z "$CURRENT_IP" ]]; then
|
||||
CURRENT_IP=$(hostname -I 2>/dev/null | tr ' ' '\n' | grep -E ':' | head -n1)
|
||||
CURRENT_IP=$(hostname -I 2>/dev/null | tr ' ' '\n' | grep -E ':' | head -n1 || true)
|
||||
fi
|
||||
# Check for Alpine (uses ip command)
|
||||
elif grep -q 'ID=alpine' /etc/os-release; then
|
||||
@@ -1704,8 +1704,8 @@ ensure_storage_selection_for_vars_file() {
|
||||
|
||||
# Read stored values (if any)
|
||||
local tpl ct
|
||||
tpl=$(grep -E '^var_template_storage=' "$vf" | cut -d= -f2-)
|
||||
ct=$(grep -E '^var_container_storage=' "$vf" | cut -d= -f2-)
|
||||
tpl=$(grep -E '^var_template_storage=' "$vf" | cut -d= -f2- || true)
|
||||
ct=$(grep -E '^var_container_storage=' "$vf" | cut -d= -f2- || true)
|
||||
|
||||
if [[ -n "$tpl" && -n "$ct" ]]; then
|
||||
TEMPLATE_STORAGE="$tpl"
|
||||
@@ -1840,7 +1840,7 @@ advanced_settings() {
|
||||
if [[ -n "$BRIDGES" ]]; then
|
||||
while IFS= read -r bridge; do
|
||||
if [[ -n "$bridge" ]]; then
|
||||
local description=$(grep -A 10 "iface $bridge" /etc/network/interfaces 2>/dev/null | grep '^#' | head -n1 | sed 's/^#\s*//;s/^[- ]*//')
|
||||
local description=$(grep -A 10 "iface $bridge" /etc/network/interfaces 2>/dev/null | grep '^#' | head -n1 | sed 's/^#\s*//;s/^[- ]*//' || true)
|
||||
BRIDGE_MENU_OPTIONS+=("$bridge" "${description:- }")
|
||||
fi
|
||||
done <<<"$BRIDGES"
|
||||
@@ -3322,7 +3322,7 @@ configure_ssh_settings() {
|
||||
tag="${tag%\"}"
|
||||
tag="${tag#\"}"
|
||||
local line
|
||||
line=$(grep -E "^${tag}\|" "$MAPFILE" | head -n1 | cut -d'|' -f2-)
|
||||
line=$(grep -E "^${tag}\|" "$MAPFILE" | head -n1 | cut -d'|' -f2- || true)
|
||||
[[ -n "$line" ]] && printf '%s\n' "$line" >>"$SSH_KEYS_FILE"
|
||||
done
|
||||
;;
|
||||
@@ -3349,7 +3349,7 @@ configure_ssh_settings() {
|
||||
tag="${tag%\"}"
|
||||
tag="${tag#\"}"
|
||||
local line
|
||||
line=$(grep -E "^${tag}\|" "$MAPFILE" | head -n1 | cut -d'|' -f2-)
|
||||
line=$(grep -E "^${tag}\|" "$MAPFILE" | head -n1 | cut -d'|' -f2- || true)
|
||||
[[ -n "$line" ]] && printf '%s\n' "$line" >>"$SSH_KEYS_FILE"
|
||||
done
|
||||
else
|
||||
@@ -4050,7 +4050,7 @@ EOF
|
||||
# Fix Debian 13 LXC template bug where / is owned by nobody:nogroup
|
||||
# This must be done from the host as unprivileged containers cannot chown /
|
||||
local rootfs
|
||||
rootfs=$(pct config "$CTID" | grep -E '^rootfs:' | sed 's/rootfs: //' | cut -d',' -f1)
|
||||
rootfs=$(pct config "$CTID" | grep -E '^rootfs:' | sed 's/rootfs: //' | cut -d',' -f1 || true)
|
||||
if [[ -n "$rootfs" ]]; then
|
||||
local mount_point="/var/lib/lxc/${CTID}/rootfs"
|
||||
if [[ -d "$mount_point" ]] && [[ "$(stat -c '%U' "$mount_point")" != "root" ]]; then
|
||||
@@ -5142,7 +5142,7 @@ create_lxc_container() {
|
||||
fi
|
||||
|
||||
msg_info "Validating storage '$CONTAINER_STORAGE'"
|
||||
STORAGE_TYPE=$(grep -E "^[^:]+: $CONTAINER_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1 | head -1)
|
||||
STORAGE_TYPE=$(grep -E "^[^:]+: $CONTAINER_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1 | head -1 || true)
|
||||
|
||||
if [[ -z "$STORAGE_TYPE" ]]; then
|
||||
msg_error "Storage '$CONTAINER_STORAGE' not found in /etc/pve/storage.cfg"
|
||||
@@ -5181,7 +5181,7 @@ create_lxc_container() {
|
||||
msg_ok "Storage '$CONTAINER_STORAGE' ($STORAGE_TYPE) validated"
|
||||
|
||||
msg_info "Validating template storage '$TEMPLATE_STORAGE'"
|
||||
TEMPLATE_TYPE=$(grep -E "^[^:]+: $TEMPLATE_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1)
|
||||
TEMPLATE_TYPE=$(grep -E "^[^:]+: $TEMPLATE_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1 || true)
|
||||
|
||||
if ! pvesm status -content vztmpl 2>/dev/null | awk 'NR>1{print $1}' | grep -qx "$TEMPLATE_STORAGE"; then
|
||||
msg_warn "Template storage '$TEMPLATE_STORAGE' may not support 'vztmpl'"
|
||||
|
||||
Reference in New Issue
Block a user