#!/bin/bash

# Copyright (C) 2022 Pablo Iranzo Gómez <Pablo.Iranzo@gmail.com>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# long_name: reports NIC firmware versions
# description: reports NIC firmware versions
# priority: 100

# Load common functions
[[ -f "${RISU_BASE}/common-functions.sh" ]] && . "${RISU_BASE}/common-functions.sh"

if [[ "x$RISU_LIVE" == "x0" ]]; then
    for interface in $(ls ${RISU_ROOT}/sos_commands/networking/ethtool_-i*); do
        NIC=$(echo ${interface} | cut -d "_" -f 4-)
        echo "${NIC}: $(cat ${interface} | grep -E '^(firmware-version)' | cut -d ':' -f 2- | xargs echo)" >&2
    done
else
    for interface in $(ls -d /sys/class/net/*/device | cut -d/ -f5); do
        echo "${interface}: $(ethtool -i ${interface} | grep -E '^(firmware-version)' | cut -d ':' -f 2- | xargs echo)" >&2
    done
fi
exit ${RC_INFO}
