summaryrefslogtreecommitdiff
path: root/gpg/create-environment.sh
blob: 5334a85b4f64960d7307d8ae40bdc59e6cb6b10f (plain) (blame)
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
#!/bin/bash

if [ -z "$1" ]; then
  echo "Usage: $0 <environment> [ <keyfile> ]"
  exit 1
fi
NAME="$1"
shift

if [ -e "${BASH_SOURCE%/*}/get-vault-pass-$NAME" ]; then
  echo "environment '$NAME' already exists."
  exit 0
fi


if [ -z "$1" ]; then
  echo "no keyfile specified, reading from stdin ..."
fi

"${BASH_SOURCE%/*}/gpg2.sh" "$NAME" --import "$@"
if [ $? -ne 0 ]; then
  echo -e "\nERROR: importing key(s) failed."
  exit 1
fi


### enable this as soon https://github.com/ansible/ansible/issues/18319 has landed
#ln -s get-vault-pass- "${BASH_SOURCE%/*}/get-vault-pass-$NAME"
cp "${BASH_SOURCE%/*}/get-vault-pass-" "${BASH_SOURCE%/*}/get-vault-pass-$NAME"

echo ""
echo "Please type in passphrase:"
"${BASH_SOURCE%/*}/set-vault-pass.sh" "$NAME"
if [ $? -ne 0 ]; then
  echo -e "\nERROR: creating vault password file failed!"
  exit 1
fi
echo ""
echo "Successfully created vault password file!"
echo "  Don't forget to commit ${0%/*}/get-vault-pass-$NAME, ${0%/*}/vault-pass-$NAME.gpg and ${0%/*}/vault-keyring-$NAME.gpg."