#!/bin/bash

# Set interface name
INTERFACE="eth0"
CONFIG_FILE="/usr/local/etc/lldpd.conf"

# Get current IPv4 address
IP_ADDR=$(ip -4 addr show "$INTERFACE" | awk '/inet / {print $2}' | cut -d/ -f1)

# Fallback if IP not found
if [[ -z "$IP_ADDR" ]]; then
  echo "Could not find IPv4 address for $INTERFACE"
  exit 1
fi

# Get hostname
SYSNAME=$(hostname)

# Get firmware version or set a default description
if [[ -f /opt/bogen/appliance/VERSION.config ]]; then
  SYSDESCR=$(cat /opt/bogen/appliance/VERSION.config | tr -d '\n')
else
  SYSDESCR="Nyquist Device"
fi

# Platform string (optional customization)
PLATFORM="Nyquist"

# Overwrite the LLDP config file
cat > "$CONFIG_FILE" <<EOF
configure system chassisid $IP_ADDR
configure system hostname $SYSNAME
configure system description $SYSDESCR
configure system platform $PLATFORM
configure system management-address $IP_ADDR
EOF

exit 0

