testing: The expect-connection helper may use swanctl to check for connections
[strongswan.git] / testing / hosts / default / usr / local / bin / expect-connection
1 #!/bin/bash
2 #
3 # Wait until a given IPsec connection becomes available
4 #
5 # Params:
6 # $1 - connection name
7 # $2 - maximum time to wait in seconds, default is 5 seconds
8
9 if [[ $# -lt 1 || $# -gt 2 ]]
10 then
11         echo "invalid arguments"
12         exit 1
13 fi
14
15 secs=$2
16 [ ! $secs ] && secs=5
17
18 cmd="swanctl --list-conns"
19 grep 'load.*stroke' /etc/strongswan.conf >/dev/null
20 if [ $? -eq 0 ]; then
21         cmd="ipsec statusall"
22 fi
23
24 let steps=$secs*10
25 for i in `seq 1 $steps`
26 do
27         $cmd 2>&1 | grep ^[[:space:]]*$1: >/dev/null
28         [ $? -eq 0 ] && exit 0
29         sleep 0.1
30 done
31
32 echo "Connection '$1' not available after $secs second(s)"
33 exit 1