[Fuego] [PATCH v2] need_check: add linux distro automatic detection
Daniel Sangorrin
daniel.sangorrin at toshiba.co.jp
Fri Jan 12 01:52:42 UTC 2018
This function can be used by tests that need to know the
distribution in the target board. The automatic detection
can be disabled/overriden by manually setting the variables
BOARD_DISTRO_ID and BOARD_DISTRO_VERSION_ID in the board
file.
IMPORTANT: this is not a substitute for individual command
checks. For example, even if the BOARD_DISTRO_ID is "debian"
test writers should still check for the existance of "apt-get"
in case they want to use it.
Signed-off-by: Daniel Sangorrin <daniel.sangorrin at toshiba.co.jp>
---
engine/scripts/need_check.sh | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/engine/scripts/need_check.sh b/engine/scripts/need_check.sh
index 1fd6d6d..2b00d46 100755
--- a/engine/scripts/need_check.sh
+++ b/engine/scripts/need_check.sh
@@ -123,6 +123,33 @@ function get_free_storage {
echo $result
}
+# This function detects the Linux distribution used on the target board and
+# exports the following variables:
+# BOARD_DISTRO_ID (e.g. ubuntu, debian, centos)
+# BOARD_DISTRO_VERSION_ID (e.g. "16.04", "8", "7")
+#
+# If the distribution cannot be automatically detected it will return 1.
+# Defining BOARD_DISTRO_ID and BOARD_DISTRO_VERSION_ID on the board file
+# disables automatic detection.
+function check_distro {
+ if [ -z "$BOARD_DISTRO_ID" ] || [ -z "$BOARD_DISTRO_VERSION_ID" ]; then
+ os_release_tmpfile=$(mktemp)
+ if get "/etc/os-release" $os_release_tmpfile ; then
+ export BOARD_DISTRO_ID="$(grep ^ID= $os_release_tmpfile | cut -c 4-)"
+ export BOARD_DISTRO_VERSION_ID="$(grep ^VERSION_ID= $os_release_tmpfile | cut -c 12-)"
+ fi
+ rm $os_release_tmpfile
+ fi
+
+ if [ -z "$BOARD_DISTRO_ID" ] || [ -z "$BOARD_DISTRO_VERSION_ID" ]; then
+ echo "ERROR: could not detect the distribution running on the board."
+ echo "Define BOARD_DISTRO_ID and BOARD_DISTRO_VERSION_ID in your board file."
+ return 1
+ else
+ echo "Board distribution is $BOARD_DISTRO_ID $BOARD_DISTRO_VERSION_ID"
+ fi
+}
+
# $1 has a single string holding a space-separated args:
# arg1 = size
# arg2 = directory to check
--
2.7.4
More information about the Fuego
mailing list