config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 10616a9cd652018219547e83ecfac29613ef07e5
parent 38b46e6f0d3ebd07999b102ce487651ab927f3ec
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Thu, 13 May 2021 20:37:56 -0700

Simplify tspm

- Use aescbc(1) from plan9port instead of gpg2(1). If you don't
  have aescbc(1) then there is a function which emulates it using
  openssl(1). Note that the data produced by these tools is
  incompadable.

- Replace the find command with simple list command

Diffstat:
Mlocal/bin/.local/bin/tspm | 65+++++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/local/bin/.local/bin/tspm b/local/bin/.local/bin/tspm @@ -3,44 +3,57 @@ # License: GPLv3 # # tspm -- truly simple password manager -# -# While I say "truly simple password manager" it uses gpg(1) which -# is a bit of an abomination. -IFS=' -' +dir="${XDG_DATA_HOME:-$HOME/.local/share}/tspm" die() { - printf '%s: %s.\n' "$(basename $0)" "$1" 1>&2 + printf "$@" 1>&2 exit 1 } -gpg() gpg2 --yes --batch -qr "${TSPM_KEY:?No key specified.}" "$@" - -add() { - for e in "$@"; do - test -e "$e" && die "$e: File exists" - mkdir -p $(dirname "$e") - gpg -eo "$e" +# uncomment if aescbc(1) from plan9 is not installed +#aescbc() openssl enc -aes-256-cbc "$@" + +add() ( + for f in "$@" + do + test -z "$tr" -a -e "$dir/$f" && + die "%s: File exists.\n" "$dir/$f" + mkdir -p "$(dirname "$dir/$f")" + + printf '%s:\n' "$f" 1>&2 + aescbc -e >"$dir/$f" || { + rm "$dir/$f" + exit 1 + } done -} - -del() rm -ri "$@" - -find() { - command find . -type f | cut -d/ -f2- | egrep "${@:-.}" -} - -show() gpg -d $(find "$@") - -cd "${XDG_DATA_HOME:-$HOME/.local/share}/tspm" +) + +del() ( + rm -ri "$@" +) + +list() ( + cd "$dir" + find "./$1" -type f | cut -d/ -f2- +) + +show() ( + for f in "$@" + do + ! test -f "$dir/$f" && + die '%s: No such file or directory.\n' "$dir/$f" + aescbc -d <"$dir/$f" + done +) case "$1" in (a|add) shift; add "$@";; (d|del) shift; del "$@";; -(f|find) shift; find "$@";; +(l|list) shift; list "$@";; (s|show) shift; show "$@";; +(t|tr) shift; tr=1 add "$@";; (*) - printf 'usage: %s add|del|find|show [entry...]\n' "$(basename $0)" 1>&2 + printf 'usage: %s a|d|l|s|t [argument...]\n' "$(basename $0)" 1>&2 exit 1 esac