1 | #!/usr/bin/env bash |
---|
2 | BITLBEE=$1 |
---|
3 | typeset -ix PORT=`echo $2 | egrep '^[0-9]{1,5}$'` |
---|
4 | SCRIPT=$3 |
---|
5 | shift 3 |
---|
6 | |
---|
7 | [ -n "$SCRIPT" -a -n "$BITLBEE" -a -e "$SCRIPT" -a "$PORT" -ne 0 ] || { echo Syntax: `basename "$0"` bitlbee-executable listening-port test-script test-script-args; exit 1; } |
---|
8 | |
---|
9 | # Create or empty test dir |
---|
10 | mkdir livetest 2>/dev/null || rm livetest/bitlbeetest*.xml bitlbeetest.pid 2>/dev/null |
---|
11 | |
---|
12 | # Run the bee |
---|
13 | echo Running bitlbee... |
---|
14 | $VALGRIND $BITLBEE -n -c bitlbee.conf -d livetest/ -D -P bitlbeetest.pid -p $PORT 2>bitlbee.log & |
---|
15 | sleep 2 |
---|
16 | |
---|
17 | # Check if it's really running |
---|
18 | kill -0 `cat bitlbeetest.pid 2>/dev/null ` 2>/dev/null || { echo Failed to run bitlbee daemon on port $PORT; exit 1; } |
---|
19 | |
---|
20 | if [ -z "$TUNNELED_MODE" ]; then |
---|
21 | # Set up skyped |
---|
22 | |
---|
23 | rm -rf etc |
---|
24 | mkdir etc |
---|
25 | cd etc |
---|
26 | cp ../../skyped.cnf . |
---|
27 | cp ~/.skyped/skyped.cert.pem . |
---|
28 | cp ~/.skyped/skyped.key.pem . |
---|
29 | cd .. |
---|
30 | echo "[skyped]" > skyped.conf |
---|
31 | echo "username = $TEST_SKYPE_ID" >> skyped.conf |
---|
32 | SHA1=`which sha1sum` |
---|
33 | if [ -z "$SHA1" ]; then |
---|
34 | SHA1=`which sha1` |
---|
35 | fi |
---|
36 | if [ -z "$SHA1" ]; then |
---|
37 | echo Test failed |
---|
38 | echo "(Can't compute password for skyped.conf)" |
---|
39 | exit 77 |
---|
40 | fi |
---|
41 | echo "password = $(echo -n $TEST_SKYPE_PASSWORD|$SHA1|sed 's/ *-$//')" >> skyped.conf |
---|
42 | # we use ~ here to test that resolve that syntax works |
---|
43 | echo "cert = $(pwd|sed "s|$HOME|~|")/etc/skyped.cert.pem" >> skyped.conf |
---|
44 | echo "key = $(pwd|sed "s|$HOME|~|")/etc/skyped.key.pem" >> skyped.conf |
---|
45 | echo "port = 2727" >> skyped.conf |
---|
46 | |
---|
47 | # Run skyped |
---|
48 | python ../skyped.py -c skyped.conf -l skypedtest.log > skypedtest.pid |
---|
49 | sleep 2 |
---|
50 | fi |
---|
51 | |
---|
52 | if [ "$TUNNELED_MODE" = "yes" ]; then |
---|
53 | rm -f tunnel.pid |
---|
54 | if [ -n "$TUNNEL_SCRIPT" ]; then |
---|
55 | $TUNNEL_SCRIPT & |
---|
56 | echo $! > tunnel.pid |
---|
57 | sleep 5 |
---|
58 | fi |
---|
59 | fi |
---|
60 | |
---|
61 | # Run the test |
---|
62 | echo Running test script... |
---|
63 | "$SCRIPT" $* |
---|
64 | RET=$? |
---|
65 | |
---|
66 | if [ -z "$TUNNELED_MODE" ]; then |
---|
67 | # skyped runs on another host: no means to kill it |
---|
68 | # Kill skyped |
---|
69 | killall -TERM skype |
---|
70 | kill -TERM $(sed 's/.*: //' skypedtest.pid) |
---|
71 | fi |
---|
72 | |
---|
73 | if [ "$TUNNELED_MODE" = "yes" ]; then |
---|
74 | if [ -n "$TUNNEL_SCRIPT" ]; then |
---|
75 | cat tunnel.pid >> /tmp/tunnel.pid |
---|
76 | kill `cat tunnel.pid` |
---|
77 | rm -f tunnel.pid |
---|
78 | fi |
---|
79 | fi |
---|
80 | |
---|
81 | # Kill bee |
---|
82 | echo Killing bitlbee... |
---|
83 | kill `cat bitlbeetest.pid` |
---|
84 | |
---|
85 | if [ "$TUNNELED_MODE" = "yes" ]; then |
---|
86 | # give the skyped a chance to timeout |
---|
87 | sleep 30 |
---|
88 | fi |
---|
89 | |
---|
90 | # Return test result |
---|
91 | [ $RET -eq 0 ] && echo Test passed |
---|
92 | [ $RET -ne 0 ] && echo Test failed |
---|
93 | [ $RET -eq 22 ] && echo '(timed out)' |
---|
94 | [ $RET -eq 66 ] && echo '(environment variables missing)' |
---|
95 | exit $RET |
---|