+#!/bin/bash
+
+#############
+# VARIABLES #
+#############
+SCR_DIR=`readlink -f $(dirname $0)`
+PROJECT_ROOT=$(readlink -f $SCR_DIR/../../..)
+SETUPS_DIR=$PROJECT_ROOT/source/diameter/stack/setups
+MSGDTD=$PROJECT_ROOT/include/anna/diameter/codec/message.dtd
+DCTDTD=$PROJECT_ROOT/include/anna/diameter/stack/dictionary.dtd
+SERVICES=$SCR_DIR/resources/services_examples
+SCRIPTS=$SCR_DIR/resources/scripts
+STACK_EXAMPLES=$SCR_DIR/resources/stack_examples
+SRVDTD=$SERVICES/services.dtd
+VARIANT=
+
+#############
+# FUNCTIONS #
+#############
+_exit () {
+ echo -e "\n$1\n"
+ exit 1
+}
+
+usage () {
+ echo "Usage: $0 [deployment_type: a|b|f|s] [deployment_path]"
+ echo
+ echo " deployment_type:"
+ echo " a=advanced"
+ echo " b=basic"
+ echo " f=function test client"
+ echo " s=system test client"
+ echo " deployment_path:"
+ echo " non-existent path directory."
+ echo
+ echo " For example:"
+ echo " $0 b $HOME/ADML-basicServer"
+ echo " $0 b $HOME/ADML-MMSbalancer"
+ echo " $0 f $HOME/ADML-tester"
+ echo " $0 s $HOME/ADML-stress-client"
+ echo
+ exit 0
+}
+
+# $1: deployment type
+createRunScript () {
+ # Basic launcher 'run.sh' will be created at deployment configuration:
+ [ "$1" = "b" ] && return
+
+ local other=
+ [ "$1" = "a" ] && other="--httpServer \`grep -v ^# .httpServer\`"
+ [ "$1" = "f" ] && ln -s ADML $EXE
+ [ "$1" = "s" ] && { other="--disableLogs"; ln -s ADML $EXE ; }
+
+ echo "Creating 'run.sh' script ..."
+
+ cat << EOF > run.sh
+#!/bin/bash
+cd \`dirname \$0\`
+EXE=$EXE
+STARTED=\`pgrep \$EXE$ 2>/dev/null\`
+[ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
+./pre-start.sh
+0> launcher.trace
+rm -f counters/* test-reports/*
+# Execution line:
+export LD_LIBRARY_PATH=\$PWD/dynlibs
+./\$EXE --services services.xml --cntDir counters --tmDir test-reports $other &
+echo \$! > .pid
+EOF
+
+ chmod a+x run.sh
+}
+
+#############
+# EXECUTION #
+#############
+cd $SCR_DIR
+echo
+echo "---------------------------------------"
+echo "Anna Diameter Launcher (ADML) deployment"
+echo "---------------------------------------"
+[ "$1" = "--help" -o "$1" = "-h" ] && usage
+echo " (--help or -h for more info)"
+echo
+echo "Basic checkings ..."
+
+# Get variant and main executables:
+[ -f $SCR_DIR/release/example_diameter_launcher ] && VARIANT=release
+[ -f $SCR_DIR/debug/example_diameter_launcher ] && VARIANT=debug
+[ -z "$VARIANT" ] && _exit "Cannot locate neither 'release' nor 'debug' variant !"
+echo "Variant: $VARIANT"
+ADML_EXEC=$SCR_DIR/$VARIANT/example_diameter_launcher
+STACKMGMT_EXEC=$(readlink -f $SCR_DIR/../stackManagement/$VARIANT/example_diameter_stackManagement)
+
+[ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
+
+echo
+if [ "$1" = "" ]
+then
+ echo
+ echo "Deploy one of these versions:"
+ echo
+ echo " (a)dvanced version: includes burst management script and templates for different scenarios. Automatic configuration during start."
+ echo " (b)asic version: 4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
+ echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests."
+ echo " (s)ystem test client: special client for stress testing. Requires a server/s to perform the tests."
+ echo
+ echo "Input option [b]:"
+ read option
+ [ "$option" = "" ] && option=b
+else
+ option=$1
+fi
+
+case $option in
+ a)
+ echo "Advanced deployment"
+ DEPLOYMENTS_DIR=deployments/advanced
+ DPATH_dflt=$HOME/ADML-advanced
+ ;;
+
+ b)
+ echo "Basic deployment"
+ DEPLOYMENTS_DIR=deployments/basic
+ DPATH_dflt=$HOME/ADML-basic
+ ;;
+
+ f)
+ echo "FT deployment"
+ DEPLOYMENTS_DIR=deployments/ft-client
+ DPATH_dflt=$HOME/ADML-ft-client
+ ;;
+
+ s)
+ echo "ST deployment"
+ DEPLOYMENTS_DIR=deployments/st-client
+ DPATH_dflt=$HOME/ADML-st-client
+ ;;
+
+ *)
+ _exit "Invalid deployment type '$option' !!"
+ ;;
+esac
+
+echo
+if [ "$2" = "" ]
+then
+ echo "Input deployment path [$DPATH_dflt]:"
+ read DPATH
+ [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
+else
+ DPATH=$2
+fi
+
+[ -d $DPATH ] && _exit "The installation path '$DPATH' must not exists."
+EXE=`basename $DPATH`
+
+echo "Copying to '$DPATH' ..."
+mkdir -p $DPATH
+mkdir -p $DPATH/DTDs
+mkdir -p $DPATH/counters
+mkdir -p $DPATH/test-reports
+
+# Dynamic libs:
+mkdir -p $DPATH/dynlibs
+DYNLIBS=( $(find $PROJECT_ROOT -name "*.so" | grep -w $VARIANT) )
+
+for dynlib in ${DYNLIBS[@]}
+do
+ dynlib_bn=$(basename $dynlib)
+ if [ "$dynlib_bn" != "libanna_dynamicLauncherProcedure.so" ]
+ then
+ cp $dynlib $DPATH/dynlibs
+ else
+ ########## ADML Dynamic libs system ##########
+ # Create structure from $PROJECT_ROOT/dynamic/launcher
+ suffix_path=$(echo $dynlib | awk -F"$PROJECT_ROOT/dynamic/launcher/" '{ print $2 }')
+ target=$(dirname $DPATH/dynlibs/$(dirname $suffix_path))
+ mkdir -p $target
+ cp $dynlib $target
+
+ # Additional resources
+ dynlib_dn=$(dirname $dynlib)
+ dynlib_dn_dn=$(dirname $dynlib_dn)
+ cp $dynlib_dn_dn/*.xml $target 2>/dev/null
+ cp $dynlib_dn_dn/dynamic.suffix $target 2>/dev/null
+ cp -r $dynlib_dn_dn/services $target 2>/dev/null
+ fi
+done
+
+# ADML dynamic libs selection script:
+cp $SCR_DIR/resources/scripts/select_dynlib.sh $DPATH/dynlibs/select.sh
+
+# Default dynamic library:
+cd $DPATH/dynlibs
+ln -s default/libanna_dynamicLauncherProcedure.so
+cd - >/dev/null
+
+# Basic setup:
+[ "$option" = "b" ] && mkdir -p $DPATH/services
+
+# Copy resources:
+cp -rL $DEPLOYMENTS_DIR/* $DPATH
+mkdir -p $DPATH/stack_examples/other
+cp $STACK_EXAMPLES/* $DPATH/stack_examples/other
+cp $SETUPS_DIR/*xml $DPATH/stack_examples
+cp $SETUPS_DIR/*sh $DPATH/stack_examples
+cp $SETUPS_DIR/readme.txt $DPATH/stack_examples
+cp $MSGDTD $DPATH/DTDs
+cp $DCTDTD $DPATH/DTDs
+cp $SRVDTD $DPATH/DTDs
+[ "$option" = "b" ] && cp $SERVICES/* $DPATH/services
+cp $SCRIPTS/clone.sh $DPATH
+cp $SCRIPTS/tinyTestcase.sh $DPATH
+
+# Copy executables:
+cp $ADML_EXEC $DPATH/ADML
+[ ! -f $DPATH/stack_examples/stack-mgmt ] && cp $STACKMGMT_EXEC $DPATH/stack_examples/stack-mgmt
+
+echo "Default stack dynamic generation ..."
+cd $DPATH
+createRunScript $option
+stack_examples/makeAutonomous.sh commands_qosControl.xml stack_examples/stack-mgmt >/dev/null
+ln -s stack_examples/autonomous.commands_qosControl.xml dictionary.xml
+cd - >/dev/null
+
+if [ "$option" = "s" ]
+then
+ cd $DPATH
+ ln -s services_example services
+ mv run.sh .run-one.sh
+ mv run_all.sh run.sh
+ mv operation.sh .operation-one.sh
+ mv operation_all.sh operation.sh
+ rm dictionary.xml
+ cd - >/dev/null
+fi
+
+# Help:
+echo "Done !"
+echo "(see README at '$DPATH')"
+echo
+