Add first work package for REST API implementation
[anna.git] / example / diameter / launcher / deployments / advanced / clientSocketManager.sh
1 #!/bin/bash
2 ENTITY=`cat .entity 2>/dev/null`
3 # If missing following, 1 is assigned (ENTITY_SS_1 is ENTITY_SS - 1)
4 ENTITY_SS=`cat .entityServerSessions 2>/dev/null`
5 [[ "$ENTITY_SS" = "" ]] && ENTITY_SS=1
6 TARGET=$2
7
8 use () {
9    echo
10    echo
11    echo "Use: $0 <hide|show|hidden|shown> \"[<address>:<port>]|[socket id]\""
12    echo
13    echo "Hides/shows/query hidden state/query shown state, the socket/s provided."
14    echo "If missing server (first parameter) all applications sockets will be affected by action."
15    echo "If missing socket (second parameter) for specific server, all its sockets will be affected by action."
16    echo
17    exit
18 }
19
20 states () {
21    echo
22    echo "Select option to switch (0 = quit):"
23    echo
24    option=1
25    for i in `echo $ENTITY | sed 's/,/ /g'`
26    do
27       for j in `seq 0 $ENTITY_SS_1`
28       do
29          TARGET="${i}|${j}"
30          RES=$(./operation.sh "shown|$TARGET" | tail -1 | grep "true$")
31          res=hidden
32          [[ "$RES" != "" ]] && res=shown
33          echo "${option}. $TARGET     ($res)"
34          action=show
35          [[ "$RES" != "" ]] && action=hide
36          echo "./operation \"$action|$TARGET\"" > .switch_${option}
37          chmod a+x .switch_${option}
38          option=$((option+1))
39       done
40    done
41    echo
42 }
43
44 if test "$ENTITY" != ""
45 then
46    ENTITY_SS_1=$((ENTITY_SS-1))
47    while true
48    do
49       states
50       read option
51       [[ "$option" = "0" ]] && break
52       .switch_${option}
53    done
54    echo
55    echo "Exiting"
56    rm .switch_*
57    exit
58 else
59    [[ "$1" = "" ]] && use
60 fi
61
62 echo
63 echo
64 operation="$1|$TARGET"
65 [[ "$TARGET" = "" ]] && operation="$1"
66 ./operation.sh "$operation"
67