aboutsummaryrefslogtreecommitdiffstats
path: root/service/do.sh
diff options
context:
space:
mode:
Diffstat (limited to 'service/do.sh')
-rw-r--r--service/do.sh49
1 files changed, 43 insertions, 6 deletions
diff --git a/service/do.sh b/service/do.sh
index 2dfd82c..9a4823d 100644
--- a/service/do.sh
+++ b/service/do.sh
@@ -24,23 +24,60 @@ if [ "$1" == "compose" ]; then
docker-compose ${@:2}
popd
elif [ "$1" == "cleansrc" ]; then
+ if [ $# -lt 3 ]; then
+ echo "USAGE: do.sh cleansrc <SRC> <DST>"
+ exit 0
+ fi
+
# copy files
src="$2"
dst="$3"
[ -e "$dst" ] && rm -rf "$dst"
- cp -r "$src" "$dst"
+ mkdir -p "$dst"
+ cp -r "$src"/{*.c,*.h,Makefile,msgs} "$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
+ if [ ! -z $(echo "$path" | grep '.[hc]$') ]; 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\{3,\}/\n\n/g' "$path" # collapse multiple newlines
+ sed -i -e 's/fprintf(\s*stderr\s*,\s*/printf(/g' "$path" # replace fprintf stderr
+ elif [ "$(basename "$path")" == "Makefile" ]; then
+ sed -i -e 's/\s*#.*//g' "$path" # remove # style comments
+ sed -i -e ':a;N;$!ba;s/\n\{3,\}/\n\n/g' "$path" # collapse multiple newlines
+ fi
fi
done
+elif [ "$1" == "test" ]; then
+ SRCDIR="$PWD/src" DATADIR="$PWD/data" bash "tests/test.sh" ${@:2}
+elif [ "$1" == "make" ]; then
+ cd src
+
+ make clean
+ make
+elif [ "$1" == "make-safe" ]; then
+ cd "src"
+
+ make clean
+
+ for f in $(ls | grep '\.[ch]$'); do
+ cp "$f" "safe_$f"
+ done
+
+ git apply patches/flagstore1.diff
+ git apply patches/flagstore2.diff
+
+ PREFIX="safe_" make
+
+ rm safe_*
else
echo "USAGE: do.sh (compose) [args..]"
echo "EXAMPLES:"
- echo " do.sh compose up --build # starts the docker container"
+ echo " do.sh compose up --build # starts the docker container"
+ echo " do.sh cleansrc <src> <dst> # post-process source files for release"
+ echo " do.sh make-safe # create patched version of binary"
+ echo " do.sh test <cmd> # run a test on the binary"
fi