| 1 | #!/bin/sh |
| 2 | |
| 3 | usage() { |
| 4 | echo "usage: gpotp KEY-NAME" |
| 5 | } |
| 6 | |
| 7 | set -e |
| 8 | while 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 |
| 19 | done |
| 20 | shift $((OPTIND - 1)) |
| 21 | if [ $# -lt 1 ]; then |
| 22 | usage >&2 |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
| 26 | if ! echo "$1" | grep -q /; then |
| 27 | key="$HOME/passwd/otp/$1.gpg" |
| 28 | else |
| 29 | key="$1" |
| 30 | fi |
| 31 | if [ ! -e "$key" ]; then |
| 32 | echo "gpotp: $key: does not exist" >&2 |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | gpg --quiet --decrypt --armor <"$key" | ( |
| 37 | read type secret dig |
| 38 | oathtool "--$type" -d "$dig" "$secret" |
| 39 | ) |