add otp script
This commit is contained in:
parent
836e9d3a61
commit
dc4f3598fc
2 changed files with 41 additions and 0 deletions
40
.config/scripts/otp.sh
Executable file
40
.config/scripts/otp.sh
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
|
||||
YUBIKEY_5C_IDENTIFIER="28854922"
|
||||
YUBIKEY_NANO_IDENTIFIER="33923085"
|
||||
YUBIKEY_SERIAL=$(ykman list | sed -n 's/.*Serial: //p')
|
||||
|
||||
# Check for connected YubiKeys
|
||||
if echo "$YUBIKEY_SERIAL" | grep -q "$YUBIKEY_5C_IDENTIFIER"; then
|
||||
YUBIKEY_SERIAL=$YUBIKEY_5C_IDENTIFIER
|
||||
elif echo "$YUBIKEY_SERIAL" | grep -q "$YUBIKEY_NANO_IDENTIFIER"; then
|
||||
YUBIKEY_SERIAL=$YUBIKEY_NANO_IDENTIFIER
|
||||
else
|
||||
echo "No YubiKey detected!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prompt for the password using zenity
|
||||
password=$(zenity --password --title="Password Required" --text="Enter your password:")
|
||||
|
||||
# Check if the user pressed Cancel
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Password dialog was cancelled."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
accounts=$(ykman -d $YUBIKEY_SERIAL oath accounts list -p $password)
|
||||
|
||||
# Create an array to hold the keys
|
||||
declare -a keys
|
||||
|
||||
# Read the input line by line
|
||||
while IFS= read -r line; do
|
||||
# Extract the part before the colon and store it in the array
|
||||
key="${line%%:*}"
|
||||
keys+=("$key")
|
||||
done <<<"$accounts"
|
||||
|
||||
selection=$(printf "%s\n" "${keys[@]}" | wofi -dmenu -i -p "New Session" --columns 1)
|
||||
|
||||
ykman -d $YUBIKEY_SERIAL oath accounts code $selection -p $password | cut -d' ' -f3 | wl-copy
|
||||
|
|
@ -120,6 +120,7 @@ required_packages_pacman:
|
|||
- ccid
|
||||
- libfido2
|
||||
- yubikey-manager
|
||||
- zenity
|
||||
|
||||
flatpak_remote:
|
||||
- { name: "flathub", url: "https://dl.flathub.org/repo/flathub.flatpakrepo" }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue