Fix local server for multiple applications
[anna.git] / source / diameter / stack / setups / dependence.sh
1 #!/bin/bash
2
3 quit() {
4    echo
5    echo $1
6    echo
7    exit
8 }
9
10 dependence () {
11    FILE=$1
12    BN_FILE=`basename $FILE`
13    TMP_FILE=/var/tmp/.${BN_FILE}.tmp
14    TMP2_FILE=/var/tmp/.${BN_FILE}.tmp2
15
16    grep "<avprule id=" $FILE > $TMP_FILE
17    > $TMP2_FILE
18
19    while read -r line
20    do
21       AVP=$(echo $line | cut -d'"' -f2)
22       if test "$AVP" != "AVP"
23       then
24          grep -l " name=\"$AVP\"" ${DN_DEPENDENCE}/avps_* >> $TMP2_FILE
25       fi
26
27    done < $TMP_FILE
28
29    RESULT=`cat $TMP2_FILE | sort | uniq | grep -v "^${BN_FILE}$"`
30    if test "$RESULT" != ""
31    then
32       for i in $RESULT
33       do
34          # To avoid infinite loop:
35          processed=`echo $ACCUMULATED | grep -w $i`
36          if test "$processed" = ""
37          then
38             ACCUMULATED="$ACCUMULATED $i"
39             echo $i >> $RESULT_FILE
40             dependence $i
41          fi
42       done
43    fi
44 }
45
46
47
48 #############
49 # EJECUCION #
50 #############
51 [[ "$1" = "" ]] && quit "Use: $0 <dictionary>, i.e.: $0 commands_qosControl.xml, $0 avps_tme.xml, etc."
52 [[ ! -f "$1" ]] && quit "ERROR: file '$1' not found"
53 BN_FILE=`basename $1`
54 DN_DEPENDENCE=`dirname $0`
55 RESULT_FILE=/var/tmp/.${BN_FILE}.tmp3
56 > $RESULT_FILE
57 ACCUMULATED=
58
59 echo
60 echo "Finding dependences ..."
61 dependence $1
62
63 echo
64 echo "Generated '${1}.dep' with needed dictionaries:"
65 echo
66 cat $RESULT_FILE | sort | uniq > ${1}.dep
67 cat ${1}.dep
68 # Used for stackManagement: rm ${1}.dep
69 echo
70 HAVE_COMMANDS=`grep "<command name=" $1`
71 if test "$HAVE_COMMANDS" != ""
72 then
73    echo "Your application must accumulate those resources to read '$1' and get it fully operative."
74    echo "Note that probably you will need to add some more commands dictionary as 'Base Protocol' one (don't forget it)."
75 fi
76
77 cd /var/tmp
78 rm .*.tmp .*.tmp2 .*.tmp3
79 echo
80