aboutsummaryrefslogtreecommitdiff
path: root/dpw-gpg
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-10-26 22:24:57 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2021-10-26 22:24:57 -0400
commitfefc6c24ddf29bb29cb7d4c2713a4fde9dab0e25 (patch)
tree92936b7c1e56272a75905f2fb7fc8c7f89099ae0 /dpw-gpg
parent34d76d7d76f7554f846e59b62e4d21d76a85d970 (diff)
downloaddpw-fefc6c24ddf29bb29cb7d4c2713a4fde9dab0e25.tar.gz
dpw-fefc6c24ddf29bb29cb7d4c2713a4fde9dab0e25.tar.xz
Add 'age' backend. Init functions.
Diffstat (limited to 'dpw-gpg')
-rwxr-xr-xdpw-gpg52
1 files changed, 50 insertions, 2 deletions
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
+usage: $0 [--no-git] <GPG IDs>...
+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 <<EOF
+[diff "gpg"]
+ binary = true
+ textconv = gpg --no-tty --decrypt
+EOF
+
+ echo "*.gpg diff=gpg" >> .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