summaryrefslogtreecommitdiff
path: root/vault.sh
blob: 4fa1a03be0635b47ed72e8f2b13af74a53e9a888 (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"