Added gpotp.
authorFredrik Tolf <fredrik@dolda2000.com>
Tue, 12 Oct 2021 13:33:43 +0000 (15:33 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Tue, 12 Oct 2021 13:33:43 +0000 (15:33 +0200)
gpotp [new file with mode: 0755]

diff --git a/gpotp b/gpotp
new file mode 100755 (executable)
index 0000000..ced1910
--- /dev/null
+++ b/gpotp
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+usage() {
+    echo "usage: gpotp KEY-NAME"
+}
+
+set -e
+while getopts h opt; do
+    case "$opt" in
+       h)
+           usage
+           exit 0
+           ;;
+       *)
+           usage >&2
+           exit 1
+           ;;
+    esac
+done
+shift $((OPTIND - 1))
+if [ $# -lt 1 ]; then
+    usage >&2
+    exit 1
+fi
+
+if ! echo "$1" | grep -q /; then
+    key="$HOME/passwd/otp/$1.gpg"
+else
+    key="$1"
+fi
+if [ ! -e "$key" ]; then
+    echo "gpotp: $key: does not exist" >&2
+    exit 1
+fi
+
+gpg --quiet --decrypt --armor <"$key" | (
+    read type secret dig
+    oathtool "--$type" -d "$dig" "$secret"
+)