commit f13612b92620586abb3047c47a30fb927a2357fe
parent 30250f05d3baeee7a478af87600b43068fbb64ab
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sat, 27 Mar 2021 00:07:19 -0700
Simplify tspm script
- Require gpg2(1) key to be specified in environ(7)
- Read password without disabling echo
- Remove long-form license header
- Remove other copyright notices (it's entirely rewritten now)
- Properly pass arguments (using `@' rather than `*')
Since it's now entirely rewritten I removed the long license header
and other copyright notices.
Diffstat:
1 file changed, 22 insertions(+), 70 deletions(-)
diff --git a/local/bin/.local/bin/tspm b/local/bin/.local/bin/tspm
@@ -1,94 +1,46 @@
#!/bin/sh -e
-# Copyright 2013-2016 Sören Tempel
-# Copyright 2016, 2017 Klemens Nanni <kl3@posteo.org>
# Copyright 2021 Jacob R. Edwards
+# License: GPLv3
#
-# tspm -- truely simple password manager
+# tspm -- truly simple password manager
#
-# A clean and easy to understand fork of spm(1) with only features
-# I want. Also, the name is a lie, this still uses gpg2(2) and is
-# overly complex.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# While I say "truly simple password manager" it uses gpg(1) which
+# is a bit of an abomination, especially on that front.
IFS='
'
-cd "${XDG_DATA_HOME:-$HOME/.local/share}/tspm"
-umask u=rwx,go=
-
-err() {
- printf '%s: %s\n' `basename $0` $1 1>&2
+die() {
+ printf '%s: %s.\n' "$(basename $0)" "$1" 1>&2
exit 1
}
-gpg() {
- if test -z "$PASSWORD_STORE_KEY"; then
- gpg2 -q --yes --batch --default-recipient-self $*
- else
- gpg2 -q --yes --batch -r "$PASSWORD_STORE_KEY" $*
- fi
-}
-
-getpass() {
- test -t 0 && {
- stty -echo
- printf '%s' $1
- }
- read -r $2
- test -t 0 && {
- stty echo
- printf '\n'
- }
- test -n $2
-}
+gpg() gpg2 --yes --batch -qr "${TSPM_KEY:?No key specified.}" "$@"
add() {
- for entry in $*
- do
- test -e $entry && err "$entry: File exists"
- getpass "$entry: " pw || err "$entry: Unable to get passphrase"
- mkdir -p "$(dirname $entry)" &&
- echo $pw | gpg -eo $entry
+ for e in "$@"; do
+ test -e "$e" && die "$e: File exists"
+ mkdir -p $(dirname "$e")
+ gpg -eo "$e"
done
}
-del() {
- rm -ri $*
-}
+del() rm -ri "$@"
find() {
- command find . -type f -or -type l | cut -d/ -f2- | egrep -i ${*:-.}
+ command find . -type f | cut -d/ -f2- | egrep "${@:-.}"
}
-show() {
- for entry in `find $*`
- do
- gpg -d $entry
- done
-}
+show() gpg -d $(find "$@")
+
+cd "${XDG_DATA_HOME:-$HOME/.local/share}/tspm"
-case $1 in
-(a|add)
- shift; add $*;;
-(d|del)
- shift; del $*;;
-(f|find)
- shift; find $*;;
-(s|show)
- shift; show $*;;
+case "$1" in
+(a|add) shift; add "$@";;
+(d|del) shift; del "$@";;
+(f|find) shift; find "$@";;
+(s|show) shift; show "$@";;
(*)
- printf 'usage: %s add|del|find|show [entry...]\n' `basename $0` 1>&2
+ printf 'usage: %s add|del|find|show [entry...]\n' "$(basename $0)" 1>&2
exit 1
esac