#!/bin/sh

# Load ipmodule variables
. /opt/gira/share/devicestack/ipmodule-vars
me="[$(printf $0 | xargs basename)]"
INTERFACE=eth0

printf "\\n=== Begin of system information block ===\\n"

BRIDGE_PRESENT=$(ifconfig | grep br0 | wc -l)

if [ 0 -lt ${BRIDGE_PRESENT} ]
then
  INTERFACE=br0
fi

set -- $(ifconfig ${INTERFACE} | grep "HWaddr")
ETH0_HWADDR=$(printf "%s\\n" "$5")
set -- $(ifconfig ${INTERFACE} | grep "inet addr")
ETH0_IPADDR=$(printf "%s\\n" "$2" | cut -d':' -f2)
ETH0_NETMASK=$(printf "%s\\n" "$4" | cut -d':' -f2)
printf "%s_hwaddr      : %s\\n" "${INTERFACE}" "${ETH0_HWADDR}"
printf "%s_ipaddr      : %s\\n" "${INTERFACE}" "${ETH0_IPADDR}"
printf "%s_netmask     : %s\\n" "${INTERFACE}" "${ETH0_NETMASK}"
[ -r ${DS_MODULEID_FILE} ] && printf "module_id        : %s\\n" "$(cat ${DS_MODULEID_FILE})"
[ -r ${DS_FWVERSION_FILE} ] && printf "firmware_version : %s\\n" "$(cat ${DS_FWVERSION_FILE})"
[ -r ${DS_DEVNAME_FILE} ] && printf "device_name      : %s\\n" "$(cat ${DS_DEVNAME_FILE})"
[ -r ${DS_MANUFACTURER_FILE} ] && printf "manufacturer     : %s\\n" "$(cat ${DS_MANUFACTURER_FILE})"
[ -r ${DS_MODEL_FILE} ] && printf "model            : %s\\n" "$(cat ${DS_MODEL_FILE})"
printf "=== End of system information block   ===\\n"

exit 0
