#!/bin/bash

usage="
        Usage: $(basename "$0") <phyId> [-h]
      Example: $(basename "$0") 1
Functionality: It resolves the PhyPath for the given phyId. For example, it may return \"1\" for \"phy0\".
			   It is the inverse function of PATH2PHY.

      Options:
	-h		Show usage information
"

while getopts 'h' OPT; do
    case $OPT in
        h)
            echo "$usage"
			exit 1
    esac
done

if [[ $# == 0 ]]; then
	(>&2 echo "Argument phyId is mandatory.")
	echo "$usage"
	exit 1
fi

scriptDir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"

PhyPathMapping="$(${scriptDir}/GetPhyPathMapping)"
echo "$PhyPathMapping" | grep -E "PHY:$1 " | grep -Eo "PHYPATH:\S+" | sed -e "s:PHYPATH\:::g" | sed -e "s: ::g"