-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconsole.sh
More file actions
executable file
·76 lines (57 loc) · 1.81 KB
/
Copy pathconsole.sh
File metadata and controls
executable file
·76 lines (57 loc) · 1.81 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
#!/usr/bin/env bash
# --- directory setup ----------------------------------------------------------
ORIG_DIR="$(pwd)"
cd "$(dirname "$0")"
BIN_DIR="$(pwd)"
function onExit() {
cd "${ORIG_DIR}"
}
trap "onExit" EXIT
# --- environment setup --------------------------------------------------------
if [ -f .env ] ; then source .env; fi
if [ -z "$LOCALCODA_ROOT" ]; then
echo "ERROR: LOCALCODA_ROOT is not set"
exit 1
fi
# --- argument handling --------------------------------------------------------
TUTORIAL="${1:-${TUTORIAL}}"
# If no tutorial provided, infer from running list
if [ -z "$TUTORIAL" ]; then
mapfile -t lines < <(./list.sh)
case "${#lines[@]}" in
0)
echo "ERROR: No tutorials are currently running" >&2
exit 1
;;
1)
read -r id TUTORIAL <<< "${lines[0]}"
;;
*)
echo "ERROR: No tutorial specified and ${#lines[@]} tutorials are running; cannot infer" >&2
exit 1
;;
esac
fi
# --- verify that the specified tutorial is running ----------------------------
# Extract the ID for the selected tutorial
TUTORIAL_ID="$(
./list.sh | awk -v t="$TUTORIAL" '$2 == t { print $1 }'
)"
if [ -z "$TUTORIAL_ID" ]; then
echo "ERROR: Tutorial '$TUTORIAL' is not running" >&2
exit 1
fi
# --- extract container name using the ID -----------------------------------------
CONTAINER_NAME="$(
"${LOCALCODA_ROOT}"/backend/bin/backend_ls.sh \
| jq -r --arg id "$TUTORIAL_ID" '
.[] | select(.id == $id) | .instance_name
'
)"
if [ -z "$CONTAINER_NAME" ] || [ "$CONTAINER_NAME" = "null" ]; then
echo "ERROR: Could not determine container name for tutorial '$TUTORIAL'" >&2
exit 1
fi
# --- open console ------------------------------------------------------------
echo "Opening console for tutorial '$TUTORIAL'"
docker exec -it "$CONTAINER_NAME" bash