2021-11-23 11:05:34 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-03-29 12:43:29 +00:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
NOTIF_PERSIST=30000
|
|
|
|
NOTIF_INFORM=5000
|
|
|
|
|
|
|
|
stdout=
|
|
|
|
caller=
|
|
|
|
notif=
|
2021-11-23 11:05:34 +00:00
|
|
|
|
|
|
|
while getopts "on:" o; do
|
2023-03-29 12:43:29 +00:00
|
|
|
case "${o}" in
|
|
|
|
o)
|
|
|
|
stdout=1;;
|
|
|
|
n)
|
|
|
|
caller="${OPTARG}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exec ykman oath accounts list
|
|
|
|
;;
|
|
|
|
esac
|
2021-11-23 11:05:34 +00:00
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
2023-03-29 12:43:29 +00:00
|
|
|
exec ykman oath accounts list
|
2021-11-23 11:05:34 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$caller" ]; then
|
2023-03-29 12:43:29 +00:00
|
|
|
notif="$(notify-send -p -t $NOTIF_PERSIST "Touch your Yubikey" "$caller is requesting otp for $1")"
|
|
|
|
trap 'notify-send -r $notif -t 1 "Touch your Yubikey" "$caller is requesting otp for $1"' EXIT
|
2021-11-23 11:05:34 +00:00
|
|
|
fi
|
|
|
|
|
2023-03-29 12:43:29 +00:00
|
|
|
code=$(ykman oath accounts code -s "$1")
|
|
|
|
if [ -z "$stdout" ]; then
|
|
|
|
echo "$code" | tee >(xclip -i)
|
|
|
|
xdotool type "$code"
|
|
|
|
else
|
|
|
|
echo "$code"
|
|
|
|
fi
|
2021-11-23 11:05:34 +00:00
|
|
|
|
2023-03-29 12:43:29 +00:00
|
|
|
if [ -n "$code" ] && [ -n "$notif" ]; then
|
|
|
|
trap : EXIT
|
|
|
|
notify-send -r "$notif" -t $NOTIF_INFORM "Yubikey Touched" "otp generated for $caller"
|
2021-11-23 11:05:34 +00:00
|
|
|
fi
|