#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
ansible_vault_pass_cmd() {
#shellcheck disable=SC2034
declare desc="insert new vault password for encrypt/decrypt of passwords"
if [[ -f "$DOKKU_LIB/data/ansible/.vault-pass" ]]; then
dokku_col_log_info1_quiet "Vault password already in place"
exit 0
fi
read -srp "Vault password", vault_password
if [[ -d "$DOKKU_LIB/data/ansible" ]]; then
dokku_col_log_info1_quiet "Creating $DOKKU_LIB/data/ansible"
mkdir -p "$DOKKU_LIB/data/ansible"
dokku_col_log_info1_quiet "Generating $DOKKU_LIB/data/ansible/.vault-pass"
echo "$vault_password" > "$DOKKU_LIB/data/ansible/.vault-pass"
}
ansible_vault_pass_cmd "$@"