Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mender-inventory-provides to read the device_type from mender.conf #1701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion support/mender-inventory-provides
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@ set -e
# Also submit device_type, which is in a separate file, not in the database. We don't know if the
# file contains a newline, so it's important that this is done last, to avoid corrupting other
# entries.
grep '^device_type=' /var/lib/mender/device_type

# 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="$mender_datastore_dir/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 "$mender_conf_dir/mender.conf" ]; then
device_type_file=$(sed -ne '/"'"$match"'" *: *"[^"]*"/ { s/.*"'"$match"'" *: *"\([^"]*\)".*/\1/; p }' "$mender_conf_dir/mender.conf" || true)
fi

if [ -f "$mender_datastore_dir/mender.conf" ]; then
if [ -z "$device_type_file" ] || [ ! -f "$device_type_file" ]; then
device_type_file=$(sed -ne '/"'"$match"'" *: *"[^"]*"/ { s/.*"'"$match"'" *: *"\([^"]*\)".*/\1/; p }' "$mender_datastore_dir/mender.conf" || true)
fi
fi

# Use default if DeviceTypeFile is not set, empty, or the file does not exist
if [ -z "$device_type_file" ] || [ ! -f "$device_type_file" ]; then
device_type_file="$default_device_type_file"
fi

# Extract the device_type value from the file specified by DeviceTypeFile
grep '^device_type=' "$device_type_file"

exit 0