[Fuego] [PATCH] need_check: add linux distro automatic detection

Daniel Sangorrin daniel.sangorrin at toshiba.co.jp
Thu Jan 11 04:29:36 UTC 2018


Hi Tim,

If the patch is OK, could you please add these variables to the documentation as well?

Thanks,
Daniel

> -----Original Message-----
> From: fuego-bounces at lists.linuxfoundation.org [mailto:fuego-bounces at lists.linuxfoundation.org] On Behalf Of Daniel Sangorrin
> Sent: Thursday, January 11, 2018 1:13 PM
> To: fuego at lists.linuxfoundation.org
> Subject: [Fuego] [PATCH] need_check: add linux distro automatic detection
> 
> This function can be used by tests that require different
> commands depending on the target board distribution.
> The automatic detection can be disabled by manually
> defining the value for BOARD_DISTRO_ID and
> BOARD_DISTRO_VERSION_ID.
> 
> 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..a6e5182 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
> +        if cmd "test -f /etc/os-release" ; then
> +            os_release_tmpfile=$(mktemp)
> +            get "/etc/os-release" $os_release_tmpfile
> +            export BOARD_DISTRO_ID="$(awk -F  "=" '/^ID=/ {print $2}' $os_release_tmpfile)"
> +            export BOARD_DISTRO_VERSION_ID="$(awk -F  "=" '/^VERSION_ID=/ {print $2}' $os_release_tmpfile)"
> +        fi
> +    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|VERSION_ID) on 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
> 
> 
> _______________________________________________
> Fuego mailing list
> Fuego at lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/fuego





More information about the Fuego mailing list