#!/bin/sh

# MEDIACASTER_DIR is set in environment

# Where to store host-persisted values
GUEST_PERSIST_FILE="/etc/oe-release"
HOST_PERSIST_FILE="${MEDIACASTER_DIR}${GUEST_PERSIST_FILE}"

# Get the system name from the 'system' command
FRIENDLY_NAME=$(system get dev_name 2>/dev/null)
FNRESULT=$?

if [ "$FNRESULT" == "127" ] || [ "$FNRESULT" == "1" ]; then
    # Get the system name from the 'config' command
    CONFIG_KEY_FRIENDLY_NAME="upnp_serverName"
    FRIENDLY_NAME=$(config get "${CONFIG_KEY_FRIENDLY_NAME}" 2>/dev/null)
fi

# If no friendly name is set, use the default model name.
if [ "${FRIENDLY_NAME}" == "" ]; then
    FRIENDLY_NAME="R7800"
fi

# Save the friendly name to oe-release for kwiltReady binding API.
echo "FriendlyName ${FRIENDLY_NAME}" >> "${HOST_PERSIST_FILE}"
