#!/bin/bash

usage="
        Usage: $(basename "$0") <phyId> [-h]
      Example: $(basename "$0") phy0
Functionality: It resolves the deviceId for the given phyId, for example, returning \"wlan0\" for \"phy0\".
			   It is the inverse function of DEV2PHY.

      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 deviceId 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 "DEV:\S+" | sed -e "s:DEV\:::g"