Repository navigation
Expand file tree
/
Copy pathsetup-devcontainer.sh
More file actions
executable file
·53 lines (47 loc) · 1.96 KB
/
Copy pathsetup-devcontainer.sh
File metadata and controls
executable file
·53 lines (47 loc) · 1.96 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
#!/bin/bash
#
# Runs after the Dev Container is created. Installs gcloud, asks for the gcloud logins, then makes
# the local config files with render-configs.sh --all true. This follows the duos-ui script. Each
# step can run again safely, so run this script again after a failure or when the certs rotate.
#
# Developers who do not use the Dev Container run render-configs.sh directly.
set -eu
set -o pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
# On failure, name the step that failed, and tell the developer how to recover.
STEP="the tool install"
on_exit() {
local status=$?
if ((status != 0)); then
echo >&2
echo "Dev Container setup failed at $STEP." >&2
if [[ "$STEP" == "render-configs.sh" ]]; then
echo "Are you connected to the non-split Broad VPN?" >&2
fi
echo "Fix the issue, then rebuild the container or run: ./scripts/setup-devcontainer.sh" >&2
fi
}
trap on_exit EXIT
# gcloud and the GKE auth plugin come from Google's own apt repository, as in duos-ui. jq,
# openssl and gzip are for the local config scripts.
install_tools() {
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg \
| sudo gpg --batch --yes --dearmor -o /usr/share/keyrings/cloud.google.gpg
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" \
| sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list > /dev/null
sudo apt-get update
sudo apt-get install -y google-cloud-cli google-cloud-cli-gke-gcloud-auth-plugin jq openssl gzip
}
# Log in on each run, as duos-ui does, so each build, rebuild or manual run has fresh credentials.
# The compose template mounts the Application Default Credentials into the app.
install_consent_config() {
printf "\n"
STEP="gcloud auth login"
gcloud auth login
STEP="gcloud auth application-default login"
gcloud auth application-default login
STEP="render-configs.sh"
./scripts/render-configs.sh --all true
}
install_tools
install_consent_config