-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
84 lines (74 loc) · 1.72 KB
/
utils.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
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
is_true() {
test "$1" = "true" && return 0
return 1
}
is_empty() {
test -z "$1" && return 0
return 1
}
error_exit() {
is_empty "$1" && echo "$1"
exit 1
}
read_user() {
echo -n "Username: "
read USERNAME
}
read_pass() {
echo -n "Password: "
read -s PASSWORD
echo -ne "\033[2K\r"
}
cert_info() {
step certificate inspect $1 --short
}
cert_details() {
step certificate inspect $1
}
is_container_running() {
if is_empty "$1"; then
echo -n "Container name: "
read CONTAINER_NAME
else
CONTAINER_NAME=$1
fi
is_empty $(docker ps -q -f name="$CONTAINER_NAME") && \
return 1
return 0
}
check_ca_health() {
# Usage: check_ca_health [conatiner_name] [-v]
CONTAINER_NAME=""
if test "$1" = "-v"; then
if is_empty "$2"; then
CONTAINER_NAME="${2:-stepca}";
fi
else
if is_empty "$1"; then
CONTAINER_NAME="${1:-stepca}";
fi
fi
STATUS=$(docker exec $CONTAINER_NAME curl -sk https://ca:9000/health 2>/dev/null)
!(test "$STATUS" = "{\"status\":\"ok\"}") && \
return 1
test "$2" = "-v" -o "$1" = "-v" && echo "$STATUS"
return 0
}
prune() {
# Usage: prune [-i]
docker volume prune --force
docker network prune --force
test "$1" = "-i" && docker image prune -a --force
}
compose_down() {
# Usage: compose_down [compose_project_name]
if !(test -d "./$1"); then
echo "$1 is not a directory in the current folder"
return 1
fi
compose_file="$(pwd)/$1/docker-compose.yml"
if test -f $compose_file; then
docker compose -f "$compose_file" down && echo "$1 is down" || \
echo "Failed to take down $1"
fi
}