summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-02-08 13:56:33 +0100
committerSimon Rettberg2024-02-08 13:56:33 +0100
commit3a5bd1ffaddeeea57cfc5e729acd5a4bc5e74b69 (patch)
tree5e56b6dc17bc669ac4bb838257c95dc5245cb6a7
parent[dev] Make some of the debug messages depend on $SLX_DEBUG (diff)
downloadslx-tools-3a5bd1ffaddeeea57cfc5e729acd5a4bc5e74b69.tar.gz
slx-tools-3a5bd1ffaddeeea57cfc5e729acd5a4bc5e74b69.tar.xz
slx-tools-3a5bd1ffaddeeea57cfc5e729acd5a4bc5e74b69.zip
[is] Add is_debug: Check whether system is running in debug mode
See $SLX_DEBUG in docs.
-rw-r--r--modules/is.inc26
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/is.inc b/modules/is.inc
index 17e8a0d..3d623b8 100644
--- a/modules/is.inc
+++ b/modules/is.inc
@@ -1,6 +1,32 @@
#!/bin/ash
+# Check whether a value should be considered true/on. Checks for
+# 'on', 'yes', 'true', or 1, in either upper- or lowercase, but not
+# mixed case.
is_on() {
[ "$1" = "ON" ] || [ "$1" = "on" ] || [ "$1" = "YES" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] || [ "$1" = "TRUE" ] || [ "$1" -ne 0 ] 2>/dev/null || return 1
return 0
}
+
+# Checks whether we're running bwLehrpool/OpenSLX in debug mode.
+# Either $SLX_DEBUG is_on, or 'debug' is passed on KCL.
+is_debug() {
+ if [ -z "$SLX_PXE_SERVER_IP" ]; then
+ if [ -s /opt/openslx/config ]; then
+ . /opt/openslx/config
+ elif [ -s /etc/openslx ]; then
+ . /etc/openslx
+ fi
+ fi
+ # Replace function for future calls as this is const
+ if is_on "$SLX_DEBUG" || grep -qE '\bdebug\b' "/proc/cmdline"; then
+ is_debug() {
+ return 0
+ }
+ else
+ is_debug() {
+ return 1
+ }
+ fi
+ is_debug
+}