-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge.sh
More file actions
38 lines (35 loc) · 1.33 KB
/
bridge.sh
File metadata and controls
38 lines (35 loc) · 1.33 KB
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
#!/usr/bin/env bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SESSION_TMP_DIR=${SESSION_TMP_DIR:-/tmp}
function log() {
if [[ "${LOG_LEVEL}" == 'debug' ]]; then
>&2 echo $@
fi
}
cat | while read message; do
args=${message#*;}
command=${message%;"$args"}
if [[ "${command}" == "define" ]]; then
FUNC_ID=$(echo "${args}" | awk '{print $1}')
FUNC_DEF=$(echo "${args}" | awk '{print $2}' | base64 --decode)
log "define FUNC_ID=${FUNC_ID} FUNC_DEF=${FUNC_DEF}"
eval "${FUNC_DEF}"
elif [[ "${command}" == "invoke" ]]; then
CALL_ID=$(echo "${args}" | awk '{print $1}')
FUNC_ID=$(echo "${args}" | awk '{print $2}')
FUNC_ARGS=$(echo "${args}" | awk '{$1=$2=""; print $0}' | base64 --decode)
log "invoke CALL_ID=${CALL_ID} FUNC_ID=${FUNC_ID} FUNC_ARGS=${FUNC_ARGS}"
${FUNC_ID} ${FUNC_ARGS} > ${SESSION_TMP_DIR}/responsefile${CALL_ID}
EXIT_STATUS=$?
log "EXIT_STATUS=${EXIT_STATUS}"
EXIT_STR="exit; ${EXIT_STATUS}";
LAST_LINE=$(tail -c 1 ${SESSION_TMP_DIR}/responsefile${CALL_ID})
if [[ "${LAST_LINE}" != "" ]]; then
EXIT_STR="\n${EXIT_STR}"
fi
echo -e "${EXIT_STR}" >> ${SESSION_TMP_DIR}/responsefile${CALL_ID}
if [[ "${LOG_LEVEL}" == 'debug' ]]; then
log "responsefile=$(cat ${SESSION_TMP_DIR}/responsefile${CALL_ID})"
fi
fi
done