Improve deployments and installation procedures
[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
23 }
24
25 # $1: deployment type
26 createRunScript () {
27
28   # Basic launcher 'run.sh' will be created at deployment configuration: 
29   [ "$1" = "b" ] && return
30   [ "$1" = "a" ] && exe=ADL-launcher
31   [ "$1" = "f" ] && { exe=ADL-ftclient ; ln -s ADL-launcher $exe ; }
32
33   cat << EOF > run.sh
34 #!/bin/bash
35 cd \`dirname \$0\`
36 EXE=$exe
37 STARTED=\`pgrep \$EXE 2>/dev/null\`
38 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
39 ./pre-start.sh
40 0> launcher.traces
41 rm -f counters/*
42 # Execution line:
43 ./\$EXE -cntDir counters $(for i in `cat args.txt | grep -v "^#"`; do echo -n "$i "; done)&
44 echo \$! > .pid
45 EOF
46
47   chmod a+x run.sh
48   rm args.txt
49 }
50
51 createDictionaryPaths () {
52   for i in stacks/*commands*xml
53   do
54     stacks/dependence.sh $i >/dev/null
55     stack=`basename $i`
56     if test "$stack" != "$BASE_PROT"
57     then
58       > .dictionary__${stack}
59       for j in `cat ${i}.dep`
60       do
61         echo -n "${j}," >> .dictionary__${stack}
62       done
63       echo "stacks/$BASE_PROT,stacks/${stack}" >> .dictionary__${stack}
64     fi
65   done
66
67   # Default:
68   ln -s .dictionary__commands_qosControl.xml .dictionary
69
70   # Remove deps:
71   rm -f stacks/*.dep
72 }
73
74 #############
75 # EXECUTION #
76 #############
77 cd `dirname $0`
78 echo
79 echo "---------------------------------------"
80 echo "Anna Diameter Launcher (ADL) deployment"
81 echo "---------------------------------------"
82 echo
83 echo "Basic checkings ..."
84 available=
85 for EXEC in ${EXECS[@]}; do
86   echo -n "Looking executable at '$EXEC' ... "
87   [ -x $EXEC ] && { available=yes ; echo "available !" ; break ; }
88   echo "not found"
89 done
90 [ -z "$available" ] && _exit "Anna Diameter Launcher (ADL) is not installed neither linked. See README.md (Install section)."
91 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
92
93 echo
94 echo "Deploy one of these versions:"
95 echo
96 echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
97 echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
98 echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs."
99 echo
100 echo "Input option [b]:"
101 read option
102 [ "$option" = "" ] && option=b
103 case $option in
104   a)
105     DEPLOYMENTS_DIR=deployments/advanced
106     DPATH_dflt=$HOME/ADL-advanced
107   ;;
108
109   b)
110     DEPLOYMENTS_DIR=deployments/basic
111     DPATH_dflt=$HOME/ADL-basic
112   ;;
113
114   f)
115     DEPLOYMENTS_DIR=deployments/ft-client
116     DPATH_dflt=$HOME/ADL-ft-client
117   ;;
118
119   *)
120     _exit "Unknown option !!"
121   ;;
122 esac
123
124 echo
125 echo "Input deployment path [$DPATH_dflt]:"
126 read DPATH
127 [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
128 [ -d $DPATH ] && _exit "The path '$DPATH' already exists. Remove it before continue..."
129
130 echo "Copying ..."
131 mkdir -p $DPATH
132 mkdir -p $DPATH/stacks
133 mkdir -p $DPATH/DTDs
134 mkdir -p $DPATH/counters
135 mkdir -p $DPATH/resources
136 if [ "$EXEC" = "$EXEC_installed" ]
137 then
138   ln -s $EXEC_installed $DPATH/ADL-launcher
139 else
140   cp $EXEC $DPATH/ADL-launcher
141 fi
142 cp -rL $DEPLOYMENTS_DIR/* $DPATH
143 cp resources/* $DPATH/resources
144 cp $SETUPS_DIR/*xml $DPATH/stacks
145 cp $SETUPS_DIR/*sh $DPATH/stacks
146 cp $SETUPS_DIR/readme.txt $DPATH/stacks
147 cp $MSGDTD $DPATH/DTDs
148 cp $DCTDTD $DPATH/DTDs
149
150 echo "Preparing ..."
151 cd $DPATH
152 createRunScript $option
153 createDictionaryPaths
154 cd - >/dev/null
155
156 # Help:
157 echo
158 echo "Go to '$DPATH' and see README file"
159 echo
160 echo "Done!"
161 echo
162 echo
163
164