commit 16b3dff93e5d1096174749e1b809728f585d95fb parent 64e9b2ad130c0cf28797c3530683fc1cc6b0e9d3 Author: Louis Burda <quent.burda@gmail.com> Date: Wed, 19 May 2021 13:48:31 +0200 refactored service structure and added do.sh for automation Diffstat:
16 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/service/.dockerignore b/service/.dockerignore @@ -0,0 +1 @@ +patches diff --git a/service/.gitignore b/service/.gitignore @@ -1,2 +1,3 @@ data/* !data/.keep +.cleansrc diff --git a/service/container/.gitignore b/service/container/.gitignore @@ -0,0 +1 @@ +src/ diff --git a/service/Dockerfile b/service/container/Dockerfile diff --git a/service/cleaner.sh b/service/container/cleaner.sh diff --git a/service/container/data/lastclean b/service/container/data/lastclean diff --git a/service/docker-compose.yml b/service/container/docker-compose.yml diff --git a/service/entrypoint.sh b/service/container/entrypoint.sh diff --git a/service/do.sh b/service/do.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +SCRIPTPATH="$(dirname $(readlink -f "$0"))" +cd "$SCRIPTPATH" + +makefile=" +all: .cleansrc + +.cleansrc: src/* + bash do.sh cleansrc src container/src + touch .cleansrc +" + +shopt -s expand_aliases +alias pushd="pushd &>/dev/null" +alias popd="popd &>/dev/null" + +if [ "$1" == "compose" ]; then + # ensure container files are up to date + make --file <(echo "$makefile") + + # forward commands to compose + pushd container + docker-compose ${@:2} + popd +elif [ "$1" == "cleansrc" ]; then + # copy files + src="$2" + dst="$3" + [ -e "$dst" ] && rm -rf "$dst" + cp -r "$src" "$dst" + + # strip comments + find "$dst" | while read path; do + if [ -f "$path" ]; then + sed -i -e 's/^\s*\/\*.*\*\/\s*$//g' "$path" # remove /* */ style comments + sed -i -e 's/\s*\/\*.*\*\/\s*/ /g' "$path" # remove /* */ style comments + sed -i -e 's/\/\/.*//g' "$path" # remove // style comments + sed -i -e ':a;N;$!ba;s/\n{2,}/\n/g' "$path" # collapse multiple newlines + fi + done +else + echo "USAGE: do.sh (compose) [args..]" + echo "EXAMPLES:" + echo " do.sh compose up --build # starts the docker container" +fi diff --git a/service/patches/flagstore1.diff b/service/patches/flagstore1.diff @@ -0,0 +1,15 @@ +diff --git a/service/src/util.c b/service/src/util.c +--- a/service/src/util.c ++++ b/service/src/util.c +@@ -75,10 +75,9 @@ void + freadstr(FILE *f, char **dst) + { + size_t start, len; +- char c; + + start = ftell(f); +- for (len = 0; (c = fgetc(f)) != EOF && c; len++); ++ for (len = 0; fgetc(f) > 0; len++); + fseek(f, start, SEEK_SET); + + *dst = checkp(calloc(1, len + 1)); diff --git a/service/src/util.c b/service/src/util.c @@ -75,10 +75,9 @@ void freadstr(FILE *f, char **dst) { size_t start, len; - char c; start = ftell(f); - for (len = 0; (c = fgetc(f)) != EOF && c; len++); + for (len = 0; fgetc(f) > 0; len++); fseek(f, start, SEEK_SET); *dst = checkp(calloc(1, len + 1)); diff --git a/service/src/tests/evil1.stl b/service/tests/data/evil1.stl diff --git a/service/src/tests/flag1.stl b/service/tests/data/flag1.stl diff --git a/service/src/tests/sample-ascii.stl b/service/tests/data/sample-ascii.stl diff --git a/service/src/tests/sample-binary.stl b/service/tests/data/sample-binary.stl Binary files differ. diff --git a/service/src/test.sh b/service/tests/test.sh