blob: 06365486abb2b722cbe30b99fe8c3a7f064c93b6 [file] [log] [blame]
Jonathan Hart518e5e72014-10-31 15:28:35 -07001#!/bin/bash
2
3validate_number () {
4 local re="^[0-9]+$"
5 if [[ ! $1 =~ $re ]] ; then
Thomas Vachuska1c188d32018-04-16 14:02:18 -07006 return 1
Jonathan Hart518e5e72014-10-31 15:28:35 -07007 fi
Jonathan Hart518e5e72014-10-31 15:28:35 -07008 return 0
9}
10
11find_node () {
12 if validate_number $1 ; then
Thomas Vachuska1c188d32018-04-16 14:02:18 -070013 # input is a number, try to find if an OC node is defined
14 oc_try="OC$1"
15 node=${!oc_try}
Jonathan Hart518e5e72014-10-31 15:28:35 -070016
Thomas Vachuska1c188d32018-04-16 14:02:18 -070017 if [ -n "$node" ]; then
18 # node lookup succeeded, return node
19 echo $node
20 else
21 # node lookup failed, return original input
22 echo $1
23 fi
Jonathan Hart518e5e72014-10-31 15:28:35 -070024 else
Thomas Vachuska1c188d32018-04-16 14:02:18 -070025 echo $1
Jonathan Hart518e5e72014-10-31 15:28:35 -070026 fi
Jonathan Hart518e5e72014-10-31 15:28:35 -070027 return 0
28}