diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2025-12-17 18:43:57 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2025-12-17 18:43:57 -0500 |
| commit | 2ebc6e0e9e27f75fccfdb3b7baede6dc166859c2 (patch) | |
| tree | d77fcbdb77a78d87fc37613aa8277a6549a4a518 | |
| parent | 014c2ee5eb6b4ba8b16b2e81ac71b13ecf401081 (diff) | |
| download | dpw-2ebc6e0e9e27f75fccfdb3b7baede6dc166859c2.tar.gz dpw-2ebc6e0e9e27f75fccfdb3b7baede6dc166859c2.tar.xz | |
Add a sync function and ability to expose the configured backend through the dpw frontend
| -rwxr-xr-x | dpw | 39 | ||||
| -rwxr-xr-x | dpw-age | 13 |
2 files changed, 46 insertions, 6 deletions
@@ -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 [<key>]" "Same as above" _printH "mv <a> <b>" "Moves key a to b, conflict handling depends on backend" _printH "cp <a> <b>" "Copies key a to b, conflict handling depends on backend" _printH "rm <key>" "Removes an entry, additional flags are passed to the backend" +_printH "_backend <args>..." "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 <key>" "Re-inserts the key, useful for backends that don't rotate keys until you remove/reinsert" _printH "edit <key>" "Edits with your \$EDITOR($EDITOR). Saves to a tmpfile removes when complete" _printH "otp <key>" "Generate otp from otpauth:// URL in a secret ( requires: oathtool ) " _printH "otp show <key>" "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 ;; @@ -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 |
