summaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/swm/package/nix/dist_files/opt/app/aai-traversal/execTool.sh
blob: ab634c0f0d859435f0d014525cea9d91d5754f15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash

export WORKING_DIR="$( cd "$(dirname "$0")" ; pwd -P )/"

DOCKER_COMPOSE_CMD="docker-compose -f ${WORKING_DIR}/docker-compose.yaml";

ARG=$1;

if [ -z "$ARG" ]; then
        echo "Error: You need to at least provide one argument which is the script to execute";
        exit 1;
fi;

if [ "${ARG}" = "--debug" ]; then

    SCRIPT_NAME=$2;

    if [ -z "$SCRIPT_NAME" ]; then
        echo "Error: You need to provide the tool name after specifying the --debug flag";
        exit 1;
    fi;

    shift 2;

else
    SCRIPT_NAME=$1;
    shift 1;
fi;

CONTAINER_NAME=$(${DOCKER_COMPOSE_CMD} ps -q aai-traversal);

if [ $? -ne 0 ]; then
    echo "Error: seems like the container is not running, please run the commands to start aai-traversal";
    exit 1;
fi;

if [ ${SCRIPT_NAME} = "putTool.sh" ]; then

    PAYLOAD_FILE=$2;

    if [ ! -z "${PAYLOAD_FILE}" ] && [ -f "${PAYLOAD_FILE}" ]; then
        docker cp ${PAYLOAD_FILE} ${CONTAINER_NAME}:/tmp/$(basename ${PAYLOAD_FILE})
    fi;
fi;

${DOCKER_COMPOSE_CMD} exec --user aaiadmin aai-traversal ls /opt/app/aai-traversal/scripts/${SCRIPT_NAME} && {

    if [ "${ARG}" = "--debug" ]; then
        ${DOCKER_COMPOSE_CMD} exec --user aaiadmin aai-traversal bash -x /opt/app/aai-traversal/scripts/${SCRIPT_NAME} "$@"
    else
        ${DOCKER_COMPOSE_CMD} exec --user aaiadmin aai-traversal /opt/app/aai-traversal/scripts/${SCRIPT_NAME} "$@"
    fi;

    exit 0;
} || {
    echo "Unable to find the tool in the /opt/app/aai-traversal/scripts";
    exit 1;
}