#!/bin/bash

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

      Options:
	-h		Show usage information
"

#if [[ $UID == 0 ]]; then
#	(>&2 echo "DO NOT run with sudo.")
#	echo "$usage"
#	exit 1
#fi

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

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

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

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