-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-shell.sh
More file actions
executable file
·53 lines (45 loc) · 1.32 KB
/
dev-shell.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.32 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
print_fancy(){
echo -e "\033[1;92m${1}\033[0m"
}
if ! command -v aws &> /dev/null; then
echo "Error: aws CLI is not available on PATH." >&2
exit 1
fi
if ! command -v json-env-helper &> /dev/null; then
echo "Error: json-env-helper is not available on PATH." >&2
exit 1
fi
if [ -z "$SVT_SECRET_ENV_NAME" ]; then
echo "Error: SVT_SECRET_ENV_NAME is not set." >&2
exit 1
fi
if [ -z "$SVT_SECRET_PROJECT" ]; then
echo "Error: SVT_SECRET_PROJECT is not set." >&2
exit 1
fi
echo "Fetching secrets..."
secret_json=$(aws secretsmanager get-secret-value \
--secret-id "$SVT_SECRET_ENV_NAME/$SVT_SECRET_PROJECT/env" \
--query SecretString \
--output text \
--profile svt-dev)
if [ $? -ne 0 ]; then
echo "Error: Failed to retrieve secret from AWS Secrets Manager." >&2
exit 1
fi
export SVT_DEV_SHELL=1
echo -ne "\033]0;dev-shell: $SVT_SECRET_PROJECT\007" # Set window title
print_fancy "*** Dev shell ready ***"
print_fancy "Project: $SVT_SECRET_PROJECT"
print_fancy "Secret: $SVT_SECRET_ENV_NAME"
echo
if [ $# -eq 0 ]; then
echo "$secret_json" | json-env-helper -- bash
else
echo "$secret_json" | json-env-helper -- "$@"
fi
cmd_exit=$?
echo -ne "\033]0;\007" # Clear window title, letting the terminal revert to default
print_fancy "*** Dev shell exited ***"
exit $cmd_exit