summaryrefslogtreecommitdiff
path: root/environment.sh
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2018-12-08 21:11:19 +0100
committerChristian Pointner <equinox@spreadspace.org>2018-12-08 21:11:19 +0100
commit57cc6098cf6315b0c2fee544c94d43d2a47bbfa4 (patch)
tree3f8031db65b81c69a2c619c66d1fdcf546542c8d /environment.sh
parentvault readme is outdated (diff)
further improve script helpers
Diffstat (limited to 'environment.sh')
-rw-r--r--environment.sh68
1 files changed, 3 insertions, 65 deletions
diff --git a/environment.sh b/environment.sh
index 38a38340..7d99979a 100644
--- a/environment.sh
+++ b/environment.sh
@@ -1,71 +1,9 @@
##
-## must be sourced in your interactive shell or by scripts before using vault files
+## must be sourced in your interactive shell session before using vault files
+## scripts should source common/utils and call the functions directly
##
-print_error() {
- echo "\033[1;31mERROR:\033[1;0m $1"
-}
-
-vault_environment__get() {
- echo "${ANSIBLE_VAULT_IDENTITY_LIST}" | tr ',' '\n' | awk -F '@' '{ print($1) }' | sed '/^$/d'
-}
-
-vault_environment__set() {
- unset ANSIBLE_VAULT_IDENTITY_LIST
- for e in "$@"; do
- vault_environment__activate $e
- done
-}
-
-vault_environment__activate() {
- if [ -z "$1" ]; then
- print_error "please specify an environment"
- return
- fi
-
- if [ ! -f "gpg/get-vault-pass-$1" ]; then
- print_error "failed to activate environment: '$1' .. could not find password file 'gpg/get-vault-pass-$1'"
- return
- fi
-
- for e in $(vault_environment__get); do
- if [ "$1" = "$e" ]; then
- return
- fi
- done
-
- if [ -z "${ANSIBLE_VAULT_IDENTITY_LIST}" ]; then
- export ANSIBLE_VAULT_IDENTITY_LIST="$1@gpg/get-vault-pass-$1"
- else
- export ANSIBLE_VAULT_IDENTITY_LIST="${ANSIBLE_VAULT_IDENTITY_LIST},$1@gpg/get-vault-pass-$1"
- fi
-}
-
-vault_environment__deactivate() {
- local new_list
-
- if [ -z "$1" ]; then
- print_error "please specify an environment"
- return
- fi
-
- new_list=""
- for e in $(vault_environment__get); do
- if [ "$1" != "$e" ]; then
- if [ -z "$new_list" ]; then
- new_list="$e@gpg/get-vault-pass-$e"
- else
- new_list="$new_list,$e@gpg/get-vault-pass-$e"
- fi
- fi
- done
-
- if [ -z "$new_list" ]; then
- unset ANSIBLE_VAULT_IDENTITY_LIST
- else
- export ANSIBLE_VAULT_IDENTITY_LIST="$new_list"
- fi
-}
+source common/utils.sh
op="$1"
if [ -n "$op" ]; then