reimplemented list

This commit is contained in:
alterNERDtive 2022-07-19 12:34:29 +02:00
parent 1ac43f83b7
commit ef14d2f0a9
Signed by: alterNERDtive
GPG key ID: 547787A4FE6533F1

53
gpgtool
View file

@ -80,6 +80,8 @@ EOF
echo -n "${tempdir}" > /tmp/gpgtool.tempdir echo -n "${tempdir}" > /tmp/gpgtool.tempdir
echo "GPGtool initialized. Temporary working directory: ${tempdir}, key path ${keypath}." echo "GPGtool initialized. Temporary working directory: ${tempdir}, key path ${keypath}."
echo ""
echo "Try \`${0} list\` next."
} }
# Cleans up GPGtool. Clears the temp directory and closes the mounted volume. # Cleans up GPGtool. Clears the temp directory and closes the mounted volume.
@ -88,9 +90,9 @@ clear () {
[[ ! -f "${_tempdir}" ]] && echo "GPGtool not currently initialized, aborting …" && exit 1 [[ ! -f "${_tempdir}" ]] && echo "GPGtool not currently initialized, aborting …" && exit 1
local tempdir="$(cat /tmp/gpgtool.tempdir)" local tempdir="$(cat /tmp/gpgtool.tempdir)"
source "${tempdir}/env"
# Unmount device: # Unmount device:
source "${tempdir}/env"
if [[ ! -z "${mountdev}" ]]; then if [[ ! -z "${mountdev}" ]]; then
echo "Unmounting ${mountdev} …" echo "Unmounting ${mountdev} …"
udisksctl unmount -b "${mountdev}" udisksctl unmount -b "${mountdev}"
@ -107,6 +109,35 @@ clear () {
rm -f "${_tempdir}" rm -f "${_tempdir}"
} }
# Lists all keys stored in the key path.
list () {
# Abort if not currently initialized:
[[ ! -f "${_tempdir}" ]] && echo "GPGtool not currently initialized, aborting …" && exit 1
local tempdir="$(cat /tmp/gpgtool.tempdir)"
source "${tempdir}/env"
# Abort if no keys found:
[[ -z "$(ls ${keypath})" ]] &&
echo "No keys found in key path. Try \`gpgtool create\`" && exit 0
echo -e "Key Fingerprint\t\t\t\t\tDescription"
perl -E 'say "-" x 82'
for key in $(ls ${keypath} | sort -k 1.9 | grep -v old)
do
echo -e "${key}\t$(cat ${keypath}/${key}/info)"
done
echo
if [[ -z "$(ls -l ${_pkdir} | grep ^l)" ]]
then
echo "No open keys. Try \`gpgtool open FINGERPRINT\`."
else
echo "Currently Opened Keys:"
ls -l ${_pkdir} | grep ^l | awk {'print $NF'}
fi
}
# Prints usage information. # Prints usage information.
usage () { usage () {
echo FIXXME echo FIXXME
@ -132,7 +163,7 @@ for dir in "$(dirname $0)" "${HOME}/.config/gpgtool" "${XDG_CONFIG_HOME}"; do
done done
# Handle Subcommands: # Handle Subcommands:
[[ "$(type -w $1)" =~ "(.+\s+)?function" ]] \ [[ "$(type -w $1)" =~ "(.+\s+)?function" && ! "$1" =~ "_.*" ]] \
&& $@ \ && $@ \
|| echo "Invalid command: $1. See \`$0 --help\`." >&2 && exit 64 || echo "Invalid command: $1. See \`$0 --help\`." >&2 && exit 64
@ -227,21 +258,3 @@ send () {
gpg --send-keys --keyserver hkps://keyserver.ubuntu.com ${id} gpg --send-keys --keyserver hkps://keyserver.ubuntu.com ${id}
done done
} }
# gpgtools list
list () {
echo -e "Key ID\t\tDescription"
perl -E 'say "-" x 40'
for key in $(ls ${_dir} | sort -k 1.9 | grep -v old)
do
echo -e "${key:0:8}\t${key:9}"
done
echo
if [ -z "$(ls -l ${_pkdir} | grep ^l)" ]
then
echo "No open keys."
else
echo "Currently Opened Keys:"
ls -l ${_pkdir} | grep ^l | awk {'print $NF'}
fi
}