#!/bin/bash
# Generate TOTP token

algo=SHA1    bytes=20
#algo=SHA256   bytes=32
#algo=SHA512  bytes=64

# URL Fluff
account=${1:-"chainsaw"}
issuer="OrangeMan"
digits="6"
period=30


key=$(openssl rand -hex $bytes)
secret=$(echo "${key}" | xxd -r -p | base32 | cut -d= -f1 | fold -w4)
URL="otpauth://totp/$issuer:$account?secret=${secret}&issuer=$issuer&algorithm=$algo&digits=6&period=30"
echo "For the data store: $key"
# QREncode the URL
echo $URL
qrencode "$URL" -o $account.png
