aboutsummaryrefslogtreecommitdiffstats
path: root/service/do.sh
blob: 2dfd82ca97a77458bcbb892fd6795d16740fe5aa (plain) (blame)
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
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