Skip to content

Commit e4df346

Browse files
authored
Merge pull request #654 from yukinchan/detect-container
Detect and run commands directly when already in a container
2 parents 85fad00 + 2f63f80 commit e4df346

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

scripts/pattern-util.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ if [ -n "${PATTERN_DISCONNECTED_HOME}" ]; then
2222
echo " PATTERN_INSTALL_CHART: ${PATTERN_INSTALL_CHART}"
2323
fi
2424

25+
function is_running_in_container {
26+
# Check if we're running inside a podman container
27+
# Podman creates /run/.containerenv in all containers (rootful and rootless)
28+
if [ -f /run/.containerenv ]; then
29+
return 0
30+
fi
31+
# Use systemd-detect-virt if available to detect container environment
32+
if command -v systemd-detect-virt >/dev/null 2>&1; then
33+
if systemd-detect-virt --container >/dev/null 2>&1; then
34+
return 0
35+
fi
36+
fi
37+
return 1
38+
}
39+
40+
# If already running in a container, execute the command directly
41+
if is_running_in_container; then
42+
echo "Detected running inside a container, executing command directly..."
43+
exec "$@"
44+
fi
45+
2546
readonly commands=(podman)
2647
for cmd in ${commands[@]}; do is_available "$cmd"; done
2748

0 commit comments

Comments
 (0)