forked from ITISFoundation/cookiecutter-osparc-cli-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.sh
executable file
·45 lines (35 loc) · 1.18 KB
/
execute.sh
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
#!/bin/bash
# set sh strict mode
set -o errexit
set -o nounset
IFS=$(printf '\n\t')
mkdir /home/scu/run
cd /home/scu/run
echo "starting service as"
echo User : "$(id "$(whoami)")"
echo Workdir : "$(pwd)"
echo "..."
echo
# Sanity check: list the files available as inputs, if any
echo "Files in input folder..."
ls -al "${INPUT_FOLDER}"
# Copy input files to current working directory
cp "${INPUT_FOLDER}"/* .
echo "--------------------------------"
# Strip any surrounding quotes from INPUT_1 command if they exist
COMMAND=$(echo "${INPUT_1}" | sed -e 's/^"//' -e 's/"$//')
# This is the command that will be executed
echo "executing command: ${COMMAND}"
eval "${COMMAND}"
echo "---------------------------------"
echo "execution completed, processing outputs..."
# Check which files are created by the execution (i.e. all files in the current dir that are not in INPUT_FOLDER)
# Put all those files in a zip
# If no output file is generate, exit error
files=$(find . -maxdepth 1 -type f ! -exec test -e "${INPUT_FOLDER}"/{} \; -print)
if [ -n "$files" ]; then
echo "$files" | zip "${OUTPUT_FOLDER}"/output_data.zip -@
else
echo "Error: No output file were generated." >&2
exit 1
fi