Usage of stdint.h types
[anna.git] / example / diameter / launcher / DEPLOY.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6 SETUPS_DIR=../../../source/diameter/stack/setups
7 MSGDTD=../../../include/anna/diameter/codec/message.dtd
8 DCTDTD=../../../include/anna/diameter/stack/dictionary.dtd
9 BASE_PROT=commands_baseProtocol.xml
10
11 # Executables in priority order:
12 EXEC_installed=/opt/bin/anna/example_diameter_launcher
13 EXECS=( $EXEC_installed ./release/example_diameter_launcher ./debug/example_diameter_launcher )
14
15 #############
16 # FUNCTIONS #
17 #############
18 _exit () {
19    echo
20    echo $1
21    echo
22    exit 1
23 }
24
25 usage () {
26   echo "Usage: $0 [deployment_type: a|b|f] [deployment_path]"
27   echo
28   echo "       deployment_type:"
29   echo "          a=advanced"
30   echo "          b=basic"
31   echo "          f=function test client"
32   echo "       deployment_path:"
33   echo "          non-existent path directory."
34   echo
35   echo "       For example:"
36   echo "          $0 b $HOME/ADL/basicServer"
37   echo "          $0 b $HOME/ADL/MMSbalancer"
38   echo "          $0 f $HOME/ADL/tester"
39   echo
40   exit 0
41 }
42  
43 # $1: deployment type
44 createRunScript () {
45
46   # Basic launcher 'run.sh' will be created at deployment configuration: 
47   [ "$1" = "b" ] && return
48   [ "$1" = "a" ] && exe=ADL-launcher
49   [ "$1" = "f" ] && { exe=ADL-ftclient ; ln -s ADL-launcher $exe ; }
50
51   cat << EOF > run.sh
52 #!/bin/bash
53 cd \`dirname \$0\`
54 EXE=$exe
55 STARTED=\`pgrep \$EXE 2>/dev/null\`
56 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
57 ./pre-start.sh
58 0> launcher.trace
59 rm -f counters/*
60 # Execution line:
61 ./\$EXE --cntDir counters $(for i in `cat args.txt | grep -v "^#"`; do echo -n "$i "; done)&
62 echo \$! > .pid
63 EOF
64
65   chmod a+x run.sh
66   rm args.txt
67 }
68
69 createDictionaryPaths () {
70   for i in stacks/*commands*xml
71   do
72     stacks/dependence.sh $i >/dev/null
73     stack=`basename $i`
74     if test "$stack" != "$BASE_PROT"
75     then
76       > .dictionary__${stack}
77       for j in `cat ${i}.dep`
78       do
79         echo -n "${j}," >> .dictionary__${stack}
80       done
81       echo "stacks/$BASE_PROT,stacks/${stack}" >> .dictionary__${stack}
82     fi
83   done
84
85   # Default:
86   ln -s .dictionary__commands_qosControl.xml .dictionary
87
88   # Remove deps:
89   rm -f stacks/*.dep
90 }
91
92 #############
93 # EXECUTION #
94 #############
95 cd `dirname $0`
96 echo
97 echo "---------------------------------------"
98 echo "Anna Diameter Launcher (ADL) deployment"
99 echo "---------------------------------------"
100 [ "$1" = "--help" -o "$1" = "-h" ] && usage
101 echo " (--help or -h for more info)"
102 echo
103 echo "Basic checkings ..."
104 available=
105 for EXEC in ${EXECS[@]}; do
106   echo -n "Looking executable at '$EXEC' ... "
107   [ -x $EXEC ] && { available=yes ; echo "available !" ; break ; }
108   echo "not found"
109 done
110 [ -z "$available" ] && _exit "Anna Diameter Launcher (ADL) is not installed neither linked. See README.md (Install section)."
111 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
112
113 echo
114 if [ "$1" = "" ]
115 then
116   echo
117   echo "Deploy one of these versions:"
118   echo
119   echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
120   echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
121   echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests."
122   echo
123   echo "Input option [b]:"
124   read option
125   [ "$option" = "" ] && option=b
126 else
127   option=$1
128 fi
129
130 case $option in
131   a)
132     echo "Advanced deployment"
133     DEPLOYMENTS_DIR=deployments/advanced
134     DPATH_dflt=$HOME/ADL/advanced
135   ;;
136
137   b)
138     echo "Basic deployment"
139     DEPLOYMENTS_DIR=deployments/basic
140     DPATH_dflt=$HOME/ADL/basic
141   ;;
142
143   f)
144     echo "FT deployment"
145     DEPLOYMENTS_DIR=deployments/ft-client
146     DPATH_dflt=$HOME/ADL/ft-client
147   ;;
148
149   *)
150     _exit "Invalid deployment type '$option' !!"
151   ;;
152 esac
153
154 echo
155 if [ "$2" = "" ]
156 then
157   echo "Input deployment path [$DPATH_dflt]:"
158   read DPATH
159   [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
160 else
161   DPATH=$2
162 fi
163
164 [ -d $DPATH ] && _exit "The installation path '$DPATH' must not exists."
165
166 echo "Copying to '$DPATH' ..."
167 mkdir -p $DPATH
168 mkdir -p $DPATH/stacks
169 mkdir -p $DPATH/DTDs
170 mkdir -p $DPATH/counters
171 mkdir -p $DPATH/resources
172 if [ "$EXEC" = "$EXEC_installed" ]
173 then
174   ln -s $EXEC_installed $DPATH/ADL-launcher
175 else
176   cp $EXEC $DPATH/ADL-launcher
177 fi
178 cp -rL $DEPLOYMENTS_DIR/* $DPATH
179 cp resources/* $DPATH/resources
180 cp $SETUPS_DIR/*xml $DPATH/stacks
181 cp $SETUPS_DIR/*sh $DPATH/stacks
182 cp $SETUPS_DIR/readme.txt $DPATH/stacks
183 cp $MSGDTD $DPATH/DTDs
184 cp $DCTDTD $DPATH/DTDs
185
186 echo "Preparing ..."
187 cd $DPATH
188 createRunScript $option
189 createDictionaryPaths
190 cd - >/dev/null
191
192 # Help:
193 echo
194 echo "Go to '$DPATH' and see README file"
195 echo
196 echo "Done!"
197 echo
198 echo
199
200