From fefc6c24ddf29bb29cb7d4c2713a4fde9dab0e25 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Tue, 26 Oct 2021 22:24:57 -0400 Subject: Add 'age' backend. Init functions. --- dpw-gpg | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'dpw-gpg') diff --git a/dpw-gpg b/dpw-gpg index d26b665..b0669dc 100755 --- a/dpw-gpg +++ b/dpw-gpg @@ -59,7 +59,7 @@ while true ; do if [ -e "$id_file" ] ; then keys="" while read -r key ; do - keys=" -r $key" + keys="$keys -r $key" done < "$id_file" export PASSWORD_STORE_KEY="$keys" @@ -88,7 +88,7 @@ exec gpg $__gpg_opts -d < "${PASSWORD_STORE_DIR}/${pth}.gpg" insert() { pth="$1"; shift _set_gpg_id "$pth" -mkdir -p "$(dirname "$pth")" +mkdir -p "$PASSWORD_STORE_DIR/$(dirname "$pth")" #shellcheck disable=SC2086 gpg $__gpg_opts -e ${PASSWORD_STORE_KEY} \ > "${PASSWORD_STORE_DIR}/${pth}.gpg" @@ -133,11 +133,59 @@ rm $recursive $force $files _git_commit "Remove: $*" } +_init_help() { +cat <... +EOF +exit 1 +} + +_init() { +USE_GIT=1 +if [ -d "${PASSWORD_STORE_DIR}" ] ; then + echo "Cannot init new password store, one exists" + exit 1 +fi +while [ $# -gt 0 ] ; do case $1 in + --no-git) USE_GIT=0 ; shift ;; + -h|--help) _init_help ;; + *) break ;; +esac ; done + +if [ $# -eq 0 ] ; then + echo "No GPG id supplied, bailing" + exit 1 +fi + +mkdir -p "${PASSWORD_STORE_DIR}" +cd "${PASSWORD_STORE_DIR}" + +if [ $USE_GIT -eq 1 ] ; then + git init + cat >> .git/config <> .gitattributes +fi + +for id in "$@" ; do + echo "$id" >> .gpg-id +done + +_git_commit + +echo "Password store initialized" +} + act="$1"; shift case $act in show) show "$@" ;; list) list "$@" ;; insert) insert "$@" ;; rm) remove "$@" ;; + init) _init "$@" ;; *) echo "Bad command $act"; exit 1; ;; esac -- cgit v1.2.3