Add sbin paths for hypervisor tool detection on non-root users
This commit is contained in:
@@ -196,6 +196,9 @@ gather_container_stats() {
|
|||||||
[ -n "$uptime_s" ] && echo "uptime_seconds=$uptime_s"
|
[ -n "$uptime_s" ] && echo "uptime_seconds=$uptime_s"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Ensure sbin paths are available (not always in PATH for non-root users)
|
||||||
|
export PATH="$PATH:/usr/sbin:/usr/local/sbin:/sbin"
|
||||||
|
|
||||||
# Use sudo if available and needed (infmap user won't have direct access)
|
# Use sudo if available and needed (infmap user won't have direct access)
|
||||||
_sudo() {
|
_sudo() {
|
||||||
if [ "$(id -u)" -eq 0 ]; then
|
if [ "$(id -u)" -eq 0 ]; then
|
||||||
|
|||||||
@@ -206,9 +206,18 @@ fi
|
|||||||
SUDOERS_FILE="/etc/sudoers.d/infmap"
|
SUDOERS_FILE="/etc/sudoers.d/infmap"
|
||||||
SUDO_CMDS=""
|
SUDO_CMDS=""
|
||||||
|
|
||||||
# Detect which hypervisor tools are present
|
# Detect which hypervisor tools are present (check common sbin paths too)
|
||||||
for cmd in pct qm lxc virsh; do
|
for cmd in pct qm lxc virsh; do
|
||||||
cmd_path=$(command -v "$cmd" 2>/dev/null)
|
cmd_path=$(command -v "$cmd" 2>/dev/null)
|
||||||
|
# Also check sbin paths not always in PATH
|
||||||
|
if [ -z "$cmd_path" ]; then
|
||||||
|
for p in /usr/sbin/$cmd /usr/local/sbin/$cmd /sbin/$cmd; do
|
||||||
|
if [ -x "$p" ]; then
|
||||||
|
cmd_path="$p"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
if [ -n "$cmd_path" ]; then
|
if [ -n "$cmd_path" ]; then
|
||||||
SUDO_CMDS="${SUDO_CMDS}${USERNAME} ALL=(root) NOPASSWD: ${cmd_path}\n"
|
SUDO_CMDS="${SUDO_CMDS}${USERNAME} ALL=(root) NOPASSWD: ${cmd_path}\n"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user