From bff1a4ff09dd646023fe10b3dbf08df939aaff87 Mon Sep 17 00:00:00 2001 From: Luis Ramirez Date: Thu, 5 Dec 2024 13:25:52 -0600 Subject: [PATCH] fix: handles Env Variables for mender-inventory-provides Title: None Changelog: None Signed-off-by: Luis Ramirez --- support/mender-inventory-provides | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/support/mender-inventory-provides b/support/mender-inventory-provides index 4025b78dc..0339e9963 100755 --- a/support/mender-inventory-provides +++ b/support/mender-inventory-provides @@ -11,18 +11,22 @@ set -e # file contains a newline, so it's important that this is done last, to avoid corrupting other # entries. +# Set default values for configuration directories +MENDER_CONF_DIR=${MENDER_CONF_DIR:-/etc/mender} +MENDER_DATASTORE_DIR=${MENDER_DATASTORE_DIR:-/var/lib/mender} + # Set default value for DeviceTypeFile default_device_type_file="/var/lib/mender/device_type" # Poor man's case insensitive match. # Read mender.conf file to find the DeviceTypeFile key if it exists prioritizing /etc over /var/lib MATCH="[Dd][Ee][Vv][Ii][Cc][Ee][Tt][Yy][Pp][Ee][Ff][Ii][Ll][Ee]" -if [ -f /etc/mender/mender.conf ]; then - device_type_file=$(sed -ne '/"'"$MATCH"'" *: *"[^"]*"/ { s/.*"'"$MATCH"'" *: *"\([^"]*\)".*/\1/; p }' "/etc/mender/mender.conf" || true) +if [ -f "$MENDER_CONF_DIR/mender.conf" ]; then + device_type_file=$(sed -ne '/"'"$MATCH"'" *: *"[^"]*"/ { s/.*"'"$MATCH"'" *: *"\([^"]*\)".*/\1/; p }' "$MENDER_CONF_DIR/mender.conf" || true) fi -if [ -z "$device_type_file" ] && [ -f /var/lib/mender/mender.conf ]; then - device_type_file=$(sed -ne '/"'"$MATCH"'" *: *"[^"]*"/ { s/.*"'"$MATCH"'" *: *"\([^"]*\)".*/\1/; p }' "/var/lib/mender/mender.conf" || true) +if [ -z "$device_type_file" ] && [ -f "$MENDER_DATASTORE_DIR/mender.conf" ]; then + device_type_file=$(sed -ne '/"'"$MATCH"'" *: *"[^"]*"/ { s/.*"'"$MATCH"'" *: *"\([^"]*\)".*/\1/; p }' "$MENDER_DATASTORE_DIR/mender.conf" || true) fi # Use default if DeviceTypeFile is not set, empty, or the file does not exist