Last active
April 10, 2017 17:58
-
-
Save Dunedan/14cfb8b5243f374fe340 to your computer and use it in GitHub Desktop.
OTP token generation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Reads OTP secrets belonging to an readable name from a file and generates OTP | |
# tokens. The secrets should be in a file, separated by a colon. | |
# E.g. test:secretkey | |
# | |
# Works really nicely together with an alias: | |
# alias otp='~/otp.sh' | |
# | |
# Licensed under CC0 <https://creativecommons.org/publicdomain/zero/1.0/> | |
SECRETS_FILE=~/.otp-secrets | |
if [ ! $(command -v oathtool) ]; then | |
echo >&2 "Can't find oathtool. Please install it." | |
exit 1 | |
fi | |
if [ ! -r "$SECRETS_FILE" ]; then | |
echo >&2 "Can't read your otp secrets from $SECRETS_FILE" | |
exit 1 | |
fi | |
if [ "$1" = "--avail" ]; then | |
cat "$SECRETS_FILE" | cut -d":" -f 1 | |
exit 0 | |
elif [ -z "$1" -o "$1" = "--help" ]; then | |
echo "Usage: $0 entry" | |
echo " $0 --avail" | |
exit 0 | |
fi | |
SECRET_KEY=$(grep "^$1 *:" "$SECRETS_FILE" | cut -d":" -f 2) | |
if [ "$SECRET_KEY" != "" ]; then | |
oathtool --totp -b $SECRET_KEY | |
else | |
echo >&2 "Unknown key \"$1\"" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the help of
xclip
it's also easy to get the token directly into the clipboard for pasting: