#!/bin/bash

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

      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 deviceId is mandatory.")
	echo "$usage"
	exit 1
fi

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

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