summaryrefslogtreecommitdiff
path: root/vault.sh
blob: b8b91c12e62be671c48cac32c15557b9132e2f51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

if [ -z "$1" ] || [ -z "$2" ]; then
  echo "$0 <command> <file>"
  exit 1
fi
command="$1"
file="$2"
shift 2

file=$(realpath --relative-to "${BASH_SOURCE%/*}" "$file")
env_group=${file%%/*}
if [ $env_group = "files" ]; then
  tmp=$(realpath --relative-to "${BASH_SOURCE%/*}/files" "$file")
  env_group=${tmp%%/*}
fi

cd "${BASH_SOURCE%/*}"
source common/utils.sh
vault_environment__set "$env_group" || exit 1

exec ansible-vault "$command" "$file" "$@"