From 2f63f8051b726baafc78547060d6a4199fde1be1 Mon Sep 17 00:00:00 2001 From: Yukin Chan Date: Tue, 7 Apr 2026 17:30:25 +0800 Subject: [PATCH] Detect and run commands directly when already in a container --- scripts/pattern-util.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/pattern-util.sh b/scripts/pattern-util.sh index 30f8b219..610b3824 100755 --- a/scripts/pattern-util.sh +++ b/scripts/pattern-util.sh @@ -22,6 +22,27 @@ if [ -n "${PATTERN_DISCONNECTED_HOME}" ]; then echo " PATTERN_INSTALL_CHART: ${PATTERN_INSTALL_CHART}" fi +function is_running_in_container { + # Check if we're running inside a podman container + # Podman creates /run/.containerenv in all containers (rootful and rootless) + if [ -f /run/.containerenv ]; then + return 0 + fi + # Use systemd-detect-virt if available to detect container environment + if command -v systemd-detect-virt >/dev/null 2>&1; then + if systemd-detect-virt --container >/dev/null 2>&1; then + return 0 + fi + fi + return 1 +} + +# If already running in a container, execute the command directly +if is_running_in_container; then + echo "Detected running inside a container, executing command directly..." + exec "$@" +fi + readonly commands=(podman) for cmd in ${commands[@]}; do is_available "$cmd"; done