-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path+
executable file
·144 lines (133 loc) · 3.54 KB
/
+
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
# Copyright 2020-2022 Thomann Bits & Beats GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ "$0" = "$SHELL" ]
then
if [ -z "$(which '+' 2>/dev/null)" ]
then
if [ -z "$(find "$PWD" -name '+')" ]
then
echo "source this script from within its parent directory to add it to PATH" >&2
else
PATH="$PWD:$PATH"
echo "added $PWD to path" >&2
fi
fi
return
fi
set -e
if [ $# -eq 0 ]
then
cat >&2 <<EOF
usage: $0 [COMMAND...]
supported commands:
edit
enter-db
run-runner
run-scanalyzer
start
start-db
start-monitoring
start-placebo
start-scanalyzer
start-services
start-webserver
stop
stop-services
EOF
exit 0
fi
SELF_DIR="$(dirname "$0")"
TEST_DIR="$SELF_DIR/test"
SCAN_DIR="$TEST_DIR/scan"
TEST_COMPOSE_NAME=portmantool_test
COMPOSE_FILE="$SELF_DIR/${COMPOSE_FILE:-docker-compose.test.yml}"
SCAN_INTERVAL="${SCAN_INTERVAL:-10s}"
export DB_NAME="${DB_NAME:-postgres}"
export DB_USER="${DB_USER:-postgres}"
export DB_PASSWORD="${DB_PASSWORD:-23BassSword42}"
export NMAP_PATH="${NMAP_PATH:-$(which nmap)}"
export RUNNER_ID="${RUNNER_ID:-$HOSTNAME}"
export SCANALYZER_ADDRESS="${SCANALYZER_ADDRESS:-localhost:8000}"
err() {
echo "$1" >&2
exit 1
}
while [ $# -ne 0 ]
do
case "$1" in
edit)
"${EDITOR:-ed}" "$SELF_DIR/+"
shift 1
[ $# -ne 0 ] && echo "ignoring remaining commands after edit: $*" >&2
exit 0
;;
enter-db)
sudo docker-compose -f "$COMPOSE_FILE" exec database psql "$DB_NAME" "$DB_USER"
;;
run-runner)
pushd "$SCAN_DIR" || err "could not enter $SCAN_DIR"
export PATH="$SELF_DIR/runner:$PATH"
while true
do
run.sh -p 80,4369,5432,5671-5672,6379,9000,15691-15692,25672 '10.23.42.0/24' &
sleep "$SCAN_INTERVAL"
wait "$!"
done
popd || err "could not leave $SCAN_DIR"
;;
run-scanalyzer)
pushd "$SCAN_DIR" || err "could not enter $SCAN_DIR"
"$SELF_DIR/scanalyzer/scanalyzer"
popd || err "could not leave $SCAN_DIR"
;;
start)
sudo docker-compose -f "$COMPOSE_FILE" up -d database scanalyzer web
;;
start-db)
sudo docker-compose -f "$COMPOSE_FILE" up -d database
;;
start-monitoring)
sudo docker-compose -f "$COMPOSE_FILE" up -d prometheus grafana
;;
start-placebo)
pushd "$TEST_DIR" || err "could not enter $TEST_DIR"
sudo docker-compose -f docker-compose.placebo.yml -p "$TEST_COMPOSE_NAME" up -d
popd || err "could not leave $TEST_DIR"
;;
start-scanalyzer)
sudo docker-compose -f "$COMPOSE_FILE" up --build -d --force-recreate scanalyzer
;;
start-services)
pushd "$TEST_DIR" || err "could not enter $TEST_DIR"
sudo docker-compose -p "$TEST_COMPOSE_NAME" up -d
popd || err "could not leave $TEST_DIR"
;;
start-webserver)
sudo docker-compose -f "$COMPOSE_FILE" up --build -d --force-recreate web
;;
stop)
sudo docker-compose -f "$COMPOSE_FILE" down
;;
stop-services)
pushd "$TEST_DIR" || err "could not enter $TEST_DIR"
sudo docker-compose -p "$TEST_COMPOSE_NAME" down
popd || err "could not leave $TEST_DIR"
;;
*)
echo "ignoring unrecognized command \"$1\"" >&2
;;
esac
shift 1
done