Skip to content

Commit

Permalink
fix: handles Env Variables for mender-inventory-provides
Browse files Browse the repository at this point in the history
Title: None
Changelog: None

Signed-off-by: Luis Ramirez <[email protected]>
  • Loading branch information
MuchoLucho committed Dec 5, 2024
1 parent 7154e05 commit bff1a4f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions support/mender-inventory-provides
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bff1a4f

Please sign in to comment.