enowars5-service-stldoctor

STL-Analyzing A/D Service for ENOWARS5 in 2021
git clone https://git.sinitax.com/sinitax/enowars5-service-stldoctor
Log | Files | Refs | README | LICENSE | sfeed.txt

do.sh (4130B)


      1#!/bin/sh
      2
      3REPOROOT="$(git rev-parse --show-toplevel)"
      4SCRIPTPATH="$(dirname $(readlink -f "$0"))"
      5cd "$SCRIPTPATH"
      6
      7makefile="
      8all: service/.copyts
      9
     10service/.copyts: src/*
     11	bash do.sh cleansrc src service/src
     12	touch service/.copyts
     13"
     14
     15shopt -s expand_aliases
     16alias pushd="pushd &>/dev/null"
     17alias popd="popd &>/dev/null"
     18
     19if [ "$1" == "compose" ]; then
     20	# ensure built service files are up to date
     21	make --file <(echo "$makefile")
     22
     23	# forward commands to compose
     24	pushd service
     25	docker-compose ${@:2}
     26	popd
     27elif [ "$1" == "cleansrc" ]; then
     28	if [ $# -lt 3 ]; then
     29		echo "USAGE: do.sh cleansrc <SRC> <DST>"
     30		exit 0
     31	fi
     32
     33	# copy files
     34	src="$2"
     35	dst="$3"
     36	[ -e "$dst" ] && rm -rf "$dst"
     37	mkdir -p "$dst"
     38	cp -r "$src"/{*.c,*.h,Makefile,msgs,.gitignore} "$dst"
     39
     40	# strip comments
     41	find "$dst" | while read path; do
     42		if [ -f "$path" ]; then
     43			if [ ! -z $(echo "$path" | grep '.[hc]$') ]; then
     44				sed -i -e 's/^\s*\/\*.*\*\/\s*$//g' "$path"     # remove /* */ style comments
     45				sed -i -e 's/\s*\/\*.*\*\/\s*/ /g' "$path"      # remove /* */ style comments
     46				sed -i -e 's/\s*\/\/.*//g' "$path"              # remove // style comments
     47				sed -i -e ':a;N;$!ba;s/\n\{3,\}/\n\n/g' "$path" # collapse multiple newlines
     48				sed -i -e 's/fprintf(\s*stderr\s*,\s*/printf(/g' "$path" # replace fprintf stderr
     49			elif [ "$(basename "$path")" == "Makefile" ]; then
     50				sed -i -e 's/\s*#.*//g' "$path"                 # remove # style comments
     51				sed -i -e ':a;N;$!ba;s/\n\{3,\}/\n\n/g' "$path" # collapse multiple newlines
     52			fi
     53		fi
     54	done
     55
     56	# apply patches if requested
     57	if [ ! -z "$PATCHED" ]; then
     58		pushd "$dst"
     59		git apply "$REPOROOT/src/patches/"*.diff
     60		popd
     61	fi
     62elif [ "$1" == "test" ]; then
     63	SRCDIR="$PWD/service/src" DATADIR="$PWD/service/data" bash "tests/test.sh" ${@:2}
     64elif [ "$1" == "make" ]; then
     65	make -C service/src
     66elif [ "$1" == "ci-test" ]; then
     67	cd "$REPOROOT"
     68
     69	docker-compose -f service/docker-compose.yml up --build -d -V
     70	docker-compose -f checker/docker-compose.yml up --build -d -V
     71
     72	if [ -z "$ADDRESS" ]; then
     73		echo "Specify your local network address via the ADDRESS var"
     74		exit 1
     75	fi
     76	export ENOCHECKER_TEST_CHECKER_ADDRESS=$ADDRESS
     77	export ENOCHECKER_TEST_CHECKER_PORT=9091
     78	export ENOCHECKER_TEST_SERVICE_ADDRESS=$ADDRESS
     79	export ENOCHECKER_TEST_SERVICE_PORT=9090
     80	enochecker_test
     81
     82	docker-compose -f service/docker-compose.yml logs --no-color --tail=1000 > /tmp/ci-test-service.log
     83	docker-compose -f checker/docker-compose.yml logs --no-color --tail=1000 > /tmp/ci-test-checker.log
     84
     85	docker-compose -f service/docker-compose.yml down
     86	docker-compose -f checker/docker-compose.yml down
     87elif [ "$1" == "host-socat" ]; then
     88	RESULTDIR=service/data/uploads socat -x -v -T180 -s TCP-LISTEN:9090,nodelay,reuseaddr,fork \
     89		EXEC:./run-proxy.sh,raw,pty,echo=0,stderr
     90elif [ "$1" == "checker-local" ]; then
     91	cd checker
     92	if [ -z "$(docker ps | grep stldoctor-mongo)" ]; then
     93		docker-compose down -v
     94		docker-compose up -d stldoctor-mongo
     95	fi
     96
     97	export MONGO_ENABLED=1
     98	export MONGO_HOST=localhost
     99	export MONGO_PORT=27017
    100	export MONGO_USER=stldoctor_checker
    101	export MONGO_PASSWORD=stldoctor_checker
    102
    103	python3 -u src/checker.py $@
    104elif [ "$1" == "host-ncat" ]; then
    105	RESULTDIR=service/data/uploads ncat -v -k -l -p 9090 \
    106		-m 200 --no-shutdown -w10s -i180s -c "./run-proxy.sh"
    107elif [ "$1" == "parse-log" ]; then
    108	python3 -c '
    109#!/usr/bin/env python3
    110
    111import jsons, sys
    112
    113for l in open(sys.argv[1]).read().split("\n"):
    114	if "##ENOLOGMESSAGE" not in l: continue
    115	l = l.split("##ENOLOGMESSAGE ", 1)[1]
    116	jmsg = jsons.loads(l)
    117	print("[[ %s #%s ]] " % (jmsg["method"], jmsg["variantId"]), end="")
    118	print(jmsg["message"] + "\n--------")
    119	' "$2"
    120else
    121	echo "USAGE: do.sh (compose|test|cleansrc) [args..]"
    122	echo "EXAMPLES:"
    123	echo "    do.sh compose up --build       # setup src and start the container"
    124	echo "    do.sh test stl-upload test.stl # test the upload of STL files"
    125	echo "    do.sh make                     # build local binary in src"
    126	echo "    do.sh cleansrc <src> <dst>     # post-process source files for release"
    127	echo "                                   # if \$PATCHED is set, patches are applied"
    128fi