main
1#!/usr/bin/env bash
2set -e
3
4if [ -f ~/.oath/key ]; then
5 # File-based HOTP
6 oathtool --hotp "$(cat ~/.oath/key)" -c "$([ ! -f ~/.oath/counter ] && echo -n 0 > ~/.oath/counter || echo -n $(($(cat ~/.oath/counter)+1)) > ~/.oath/counter; cat ~/.oath/counter)"
7else
8 # Fallback: YubiKey OATH
9 if ! ykman info &>/dev/null; then
10 notify-send --urgency=critical "authkey" "YubiKey not connected. Please plug in your YubiKey."
11 echo "Error: YubiKey not connected" >&2
12 exit 1
13 fi
14 ykman oath accounts code --single "Red Hat:redhat" 2>/dev/null | grep -oE '[0-9]{6,8}'
15fi