|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +# Configure Atmos XDG paths to use container's home directory |
| 4 | +# This is required for Atmos auth to work correctly with mounted volumes |
| 5 | +export ATMOS_XDG_CONFIG_HOME="${ATMOS_XDG_CONFIG_HOME:-${HOME}/.config}" |
| 6 | +export ATMOS_XDG_DATA_HOME="${ATMOS_XDG_DATA_HOME:-${HOME}/.local/share}" |
| 7 | +export ATMOS_XDG_CACHE_HOME="${ATMOS_XDG_CACHE_HOME:-${HOME}/.cache}" |
| 8 | + |
| 9 | +# Helper function for Atmos auth integration |
| 10 | +# Usage: use-identity [identity-name] [other atmos auth env flags] |
| 11 | +# This uses Atmos auth to authenticate and set credentials in the environment |
| 12 | +# If called with no arguments, it brings up the identity selector |
| 13 | +function use-identity() { |
| 14 | + if ! command -v atmos >/dev/null 2>&1; then |
| 15 | + echo "Error: atmos command not found. Please install atmos first." >&2 |
| 16 | + return 1 |
| 17 | + fi |
| 18 | + |
| 19 | + # Run atmos auth env and evaluate the output to set credentials |
| 20 | + local auth_output |
| 21 | + if [ $# -eq 0 ]; then |
| 22 | + # No arguments: bring up the selector by passing --identity with no value |
| 23 | + if ! auth_output=$(atmos auth env --identity 2>&1); then |
| 24 | + echo "Error running atmos auth: $auth_output" >&2 |
| 25 | + return 1 |
| 26 | + fi |
| 27 | + else |
| 28 | + # Arguments provided: pass --identity=<value> with the first argument, then any additional flags |
| 29 | + if ! auth_output=$(atmos auth env --identity="$1" "${@:2}" 2>&1); then |
| 30 | + echo "Error running atmos auth: $auth_output" >&2 |
| 31 | + return 1 |
| 32 | + fi |
| 33 | + fi |
| 34 | + |
| 35 | + # Evaluate the output to set environment variables |
| 36 | + eval "$auth_output" |
| 37 | + |
| 38 | + # If export_current_aws_role function exists (from aws.sh), refresh the AWS role display |
| 39 | + if declare -f export_current_aws_role >/dev/null 2>&1; then |
| 40 | + export_current_aws_role |
| 41 | + fi |
| 42 | +} |
| 43 | + |
3 | 44 | function atmos_configure_base_path() { |
4 | 45 | # Leave $ATMOS_BASE_PATH alone if it is already set |
5 | 46 | if [[ -n $ATMOS_BASE_PATH ]]; then |
|
0 commit comments