Add script for generating otpauth:// URIs

This commit is contained in:
Lucas 2020-07-10 01:15:29 +00:00
parent 5ea77d06dc
commit 1151d1cc4a
1 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,57 @@
#!/bin/sh
# env
# Written in 2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any
# warranty. You should have received a copy of the CC0 Public Domain
# Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
usage()
{
cat - <<EOF >&2
Usage:
${0##*/} [-d digits] [-p period] [-a algorithm]
${0##*/} [-H counter] [-d digits] [-a algorithm]
EOF
exit 1
}
err()
{
printf "%s: %s\n" "${0##*/}" "$*" >&2
exit 1
}
algorithm=
counter=
digits=
period=
type=totp
while getopts a:d:H:p: flag; do
case $flag in
a) algorithm=$OPTARG
;;
d) digits=$OPTARG
;;
H) counter=$OPTARG
type=hotp
;;
p) period=$OPTARG
;;
*) usage
;;
esac
done
printf "otpauth://%s/" "$type"
printf "?secret="
cat - | tr -d "\n"
[ -n "$algorithm" ] && printf "&algorithm=%s" "$algorithm"
[ -n "$counter" ] && printf "&counter=%s" "$counter"
[ -n "$digits" ] && printf "&digits=%s" "$digits"
[ -n "$period" ] && printf "&period=%s" "$period"
printf "\n"