#!/bin/bash
# config-scripts/src/share/networktop.sh
# 
#  Copyright: ©2007–2011, Güralp Systems Ltd.
#  Author: Laurence Withers <lwithers@guralp.com>
#  Author: Bob Dunlop <rdunlop@guralp.com>
#  License: GPLv3
#

# Handle navbar without loading anything else
if [ "X$1" == "X--navbar" ]
then
    echo "networktop Networking"
    exit 0
fi

# Load support functions
script_dir=$(dirname $0)
. $script_dir/functions.sh

# List the current interfaces
declare -i i=0
for file in "${NETCONFDIR}/eth"* "${NETCONFDIR}/vlan"*
do
    if [ -f "${file}" ]
    then
        dev="$(gcs_get_varf device "${file}")"
        if [ -n "${dev}" ]
        then
        desc="$(gcs_get_varf desc "${file}")"

        echo "select_netif${i}=${dev} ${dev} - ${desc}"
        ((++i))
        fi
    fi
done

# Create new VLAN interface
echo "select_netif${i}=vcreate Create a new VLAN interface"
((++i))

# List the wireless interfaces
i=0
for dir in "${NETCONFDIR}/wlan"*
do
    file="${dir}/dev"
    if [ -f "${file}" ]
    then
        dev="$(gcs_get_varf device "${file}")"
        if [ -n "${dev}" ]
        then
            desc="$(gcs_get_varf desc "${file}")"

            echo "select_wlanif${i}=${dev} ${dev} - ${desc:-${dev}}"
            ((++i))
        fi
    fi
done

exit 0

# vim: ts=4:sw=4:expandtab
