From 1151d1cc4a804bbc627f342e15faa94a647d88a9 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 10 Jul 2020 01:15:29 +0000 Subject: [PATCH] Add script for generating otpauth:// URIs --- utils/scripts/create-otp-uri.sh | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 utils/scripts/create-otp-uri.sh diff --git a/utils/scripts/create-otp-uri.sh b/utils/scripts/create-otp-uri.sh new file mode 100644 index 0000000..5738a0c --- /dev/null +++ b/utils/scripts/create-otp-uri.sh @@ -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 +# . + +usage() +{ + cat - <&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"