#!/bin/bash

#used for cli command "set management-ethernet-speed eth0"
#input:
#       $1: "eth0"
#       $2: the speed of eth0,"auto","10","100","1000"
#no ouput var

if [ $(expr "`sudo /sbin/ethtool $1`" : ".*Link detected: yes.*") -ne 0 ] ; then
    if [ $2 = "auto" ];then
        sudo /sbin/ethtool -s $1 autoneg on
    fi

    if [ $2 = "1000" ];then
        sudo /sbin/ethtool -s $1 speed 1000 duplex full autoneg on
    fi

    if [ $2 = "100" ];then
        sudo /sbin/ethtool -s $1 speed 100 autoneg off
    fi

    if [ $2 = "10" ];then
        sudo /sbin/ethtool -s $1 speed 10 autoneg off
    fi
else
    echo "The management port $1 is link-down!"
fi
                                                                                                                            
exit 0
