acmecert: Initial commit.
[utils.git] / gpotp
... / ...
CommitLineData
1#!/bin/sh
2
3usage() {
4 echo "usage: gpotp KEY-NAME"
5}
6
7set -e
8while getopts h opt; do
9 case "$opt" in
10 h)
11 usage
12 exit 0
13 ;;
14 *)
15 usage >&2
16 exit 1
17 ;;
18 esac
19done
20shift $((OPTIND - 1))
21if [ $# -lt 1 ]; then
22 usage >&2
23 exit 1
24fi
25
26if ! echo "$1" | grep -q /; then
27 key="$HOME/passwd/otp/$1.gpg"
28else
29 key="$1"
30fi
31if [ ! -e "$key" ]; then
32 echo "gpotp: $key: does not exist" >&2
33 exit 1
34fi
35
36gpg --quiet --decrypt --armor <"$key" | (
37 read type secret dig
38 oathtool "--$type" -d "$dig" "$secret"
39)