From 3a5bd1ffaddeeea57cfc5e729acd5a4bc5e74b69 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Feb 2024 13:56:33 +0100 Subject: [is] Add is_debug: Check whether system is running in debug mode See $SLX_DEBUG in docs. --- modules/is.inc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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 +} -- cgit v1.2.3-55-g7522