Thomas Vachuska
Committed by Gerrit Code Review

Fixed onos-setup-karaf to work on Linux as well as on Darwin (OSX).

Change-Id: I9225dde1bed84380d785559a9b8ae65969cc7f42
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
14 export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION} 14 export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION}
15 export STAGE=$(dirname $KARAF_ROOT) 15 export STAGE=$(dirname $KARAF_ROOT)
16 16
17 +# Validates the specified IP regular expression against existing adapters.
18 +# Excludes local-loopback.
19 +function validateIp {
20 + [ $(uname) = "Darwin" ] && \
21 + ifconfig | grep 'inet ' | cut -d\ -f2 | grep -v "127\.0\.0\.1" | grep $1 || \
22 + ifconfig | grep 'inet addr:' | cut -d: -f2 | cut -d\ -f1 | grep -v "127\.0\.0\.1" | grep $1
23 +}
24 +
17 # Clean the previous Karaf directory if requested and if it exists. 25 # Clean the previous Karaf directory if requested and if it exists.
18 if [ "$1" = "clean" ]; then 26 if [ "$1" = "clean" ]; then
19 shift 27 shift
...@@ -24,12 +32,12 @@ IP="${1:-$ONOS_IP}" ...@@ -24,12 +32,12 @@ IP="${1:-$ONOS_IP}"
24 32
25 # If IP was not given, nor configured attempt to use ONOS_NIC env. variable 33 # If IP was not given, nor configured attempt to use ONOS_NIC env. variable
26 if [ -z "$IP" -a -n "$ONOS_NIC" ]; then 34 if [ -z "$IP" -a -n "$ONOS_NIC" ]; then
27 - IP=$(ifconfig | grep 'inet ' | cut -d\ -f2 | grep $ONOS_NIC) 35 + IP=$(validateIp $ONOS_NIC)
28 [ -z "$IP" ] && echo "No adapter with IP matching $ONOS_NIC found!" 36 [ -z "$IP" ] && echo "No adapter with IP matching $ONOS_NIC found!"
29 else 37 else
30 # Otherwise, verify that the IP address given exists among the adapters. 38 # Otherwise, verify that the IP address given exists among the adapters.
31 saveIp=$IP 39 saveIp=$IP
32 - IP=$(ifconfig | grep 'inet ' | cut -d\ -f2 | grep $IP) 40 + IP=$(validateIp $IP)
33 [ -z "$IP" ] && echo "No adapter with IP $saveIp found!" 41 [ -z "$IP" ] && echo "No adapter with IP $saveIp found!"
34 fi 42 fi
35 43
...@@ -37,7 +45,7 @@ fi ...@@ -37,7 +45,7 @@ fi
37 if [ -z "$IP" -o "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then 45 if [ -z "$IP" -o "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then
38 echo "usage: $(basename $0) [clean] <ip-address>" 46 echo "usage: $(basename $0) [clean] <ip-address>"
39 echo "Available IP addresses are:" 47 echo "Available IP addresses are:"
40 - ifconfig | grep 'inet ' | cut -d\ -f2 | grep -v "127.0.0.1" 48 + validateIp .
41 exit 1 49 exit 1
42 fi 50 fi
43 51
......