forked from perfana/perfana-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
executable file
·54 lines (45 loc) · 1.47 KB
/
common.sh
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
#!/usr/bin/env bash
export MONGO_VERSION="4.4"
COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME:-$(basename $(pwd))}
# use current directory as basename for the network, this only works when common.sh is in same dir as
# the docker-compose.yml file and is executed from that directory
PERFANA_NETWORK=${COMPOSE_PROJECT_NAME}_perfana
if [[ "$(docker network ls)" =~ $PERFANA_NETWORK ]]; then
DOCKER_HOST_IP=$(docker network inspect $PERFANA_NETWORK -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
else
echo "WARN: network '$PERFANA_NETWORK' does not exist"
DOCKER_HOST_IP=""
fi
# https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux#answer-33828925
# use as: current_os="$(check-os)"
check-os () {
case "$OSTYPE" in
linux*) echo "linux" ;;
darwin*) echo "mac" ;;
win*) echo "windows" ;;
msys*) echo "git-bash" ;;
cygwin*) echo "cygwin" ;;
*) echo "unknown" ;;
esac
}
current_os="$(check-os)"
if [ $current_os != "mac" ] && [ $current_os == "cygwin" ]; then
CONFIG_FILE=`cygpath.exe -m $(pwd)/init-mongo.js`
DOCKER_CMD="winpty docker"
else
DOCKER_CMD="docker"
CONFIG_FILE=$(pwd)/init-mongo.js
fi
GRAFANA_CREDS=perfana:perfana
confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}