From 2ebc6e0e9e27f75fccfdb3b7baede6dc166859c2 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Wed, 17 Dec 2025 18:43:57 -0500 Subject: Add a sync function and ability to expose the configured backend through the dpw frontend --- dpw | 39 ++++++++++++++++++++++++++++++++++++++- dpw-age | 13 ++++++++----- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/dpw b/dpw index d66fff1..f7119bc 100755 --- a/dpw +++ b/dpw @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright 2024 Mitchell Riedstra +# Copyright 2025 Mitchell Riedstra # # Permission to use, copy, modify, and/or distribute this software for any purpose # with or without fee is hereby granted, provided that the above copyright notice @@ -78,6 +78,9 @@ _printH "ls []" "Same as above" _printH "mv " "Moves key a to b, conflict handling depends on backend" _printH "cp " "Copies key a to b, conflict handling depends on backend" _printH "rm " "Removes an entry, additional flags are passed to the backend" +_printH "_backend ..." "Directly calls the configured backend, most of the time not needed but occasionally useful" +_printH "sync" "Calls sync command for the particular backend, may not be implemented" +_printH "reinsert " "Re-inserts the key, useful for backends that don't rotate keys until you remove/reinsert" _printH "edit " "Edits with your \$EDITOR($EDITOR). Saves to a tmpfile removes when complete" _printH "otp " "Generate otp from otpauth:// URL in a secret ( requires: oathtool ) " _printH "otp show " "Same as above" @@ -202,6 +205,37 @@ remove() { "${DPW_BACKEND}" rm "$@" } +_backend() { +"${DPW_BACKEND}" "$@" +} + +_sync() { +"${DPW_BACKEND}" sync "$@" +} + +reinsert() { +_pth="$1"; shift +tmpdir=/dev/shm +if ! [ -d "$tmpdir" ] ; then + printf "Your system does not have /dev/shm, continue? [Yy] " + read -r resp + ok=0 + case $resp in + Y*|y*) ok=1 + esac + echo "" + [ $ok -eq 0 ] && return + tmpdir=/tmp +fi +_f="$(mktemp "${tmpdir}/dpw.XXXXXXXXXX")" +#shellcheck disable=SC2064 +trap "rm -f \"$_f\"; exit 0" EXIT INT +show "$_pth" > "$_f" +remove "$_pth" +insert "$_pth" < "$_f" +rm -f "$_f" +} + edit() { _pth="$1"; shift tmpdir=/dev/shm @@ -301,6 +335,9 @@ case $1 in rm) action=remove; shift ;; mv) action=move; shift ;; cp) action=_cp; shift ;; + sync) action=_sync; shift ;; + _backend) action=_backend; shift ;; + reinsert) action=reinsert; shift ;; edit) action=edit; shift ;; find|fnd) action=_find; shift ;; otp) action=otp; shift ;; diff --git a/dpw-age b/dpw-age index 079e2ee..0c72b73 100755 --- a/dpw-age +++ b/dpw-age @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright 2021 Mitchell Riedstra +# Copyright 2025 Mitchell Riedstra # # Permission to use, copy, modify, and/or distribute this software for any purpose # with or without fee is hereby granted, provided that the above copyright notice @@ -24,6 +24,8 @@ DPW_AGE_DIR="${DPW_AGE_DIR:-$HOME/.dpw-age}" DPW_AGE_KEY="${DPW_AGE_KEY:-$HOME/.dpw-age-key}" DPW_AGE_RECIPIENT_SUFFIX="${DPW_AGE_RECIPIENT_SUFFIX:-.recipients}" DPW_AGE_AUTO_SYNC="${DPW_AGE_AUTO_SYNC:-NO}" +DPW_AGE_BIN="${DPW_AGE_BIN:-age}" +age="$DPW_AGE_BIN" # No user overrides DPW_AGE_RECIPIENTS_FILE="" @@ -32,6 +34,7 @@ USE_GIT=0 # Helper functions + _git_commit() { [ $USE_GIT -eq 0 ] && return cd "${DPW_AGE_DIR}" @@ -97,7 +100,7 @@ sync() { show() { pth="$1"; shift #shellcheck disable=SC2086 -exec age -i "${DPW_AGE_KEY}" -d < "${DPW_AGE_DIR}/${pth}.age" +exec "$age" -i "${DPW_AGE_KEY}" -d < "${DPW_AGE_DIR}/${pth}.age" } @@ -106,7 +109,7 @@ pth="$1"; shift _set_age_recipients "$pth" mkdir -p "$DPW_AGE_DIR/$(dirname "$pth")" #shellcheck disable=SC2086 -age -R "$DPW_AGE_RECIPIENTS_FILE" -e \ +"$age" -R "$DPW_AGE_RECIPIENTS_FILE" -e \ > "${DPW_AGE_DIR}/${pth}.age" _git_commit "Insert: $pth" } @@ -226,9 +229,9 @@ grep -q YUBIKEY "${DPW_AGE_KEY}" \ && echo "Detected yubikey, you may need to tap it..." # Test the key and recipients before we get too far along tmpf="$(mktemp)" -echo "testing our key... works!" | age -R "${DPW_AGE_RECIPIENTS_FILE}" -e \ +echo "testing our key... works!" | "$age" -R "${DPW_AGE_RECIPIENTS_FILE}" -e \ > "$tmpf" -age -i "${DPW_AGE_KEY}" -d < "$tmpf" +"$age" -i "${DPW_AGE_KEY}" -d < "$tmpf" if [ $USE_GIT -eq 1 ] ; then git init -- cgit v1.2.3