Created
December 6, 2017 06:02
-
-
Save ayumi/bb77240c1f0cd6559fccccd80b223bb5 to your computer and use it in GitHub Desktop.
Qubes script to make Yubikey OpenPGP smart cards easier to use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Based on https://micahflee.com/2016/12/qubes-tip-making-yubikey-openpgp-smart-cards-slightly-more-usable/ | |
# Detach only: | |
# ./toggle-yubikey.sh | |
# (Detach &&) Attach: | |
# ./toggle-yubikey.sh {vm-attachment-target} | |
YUBIKEY=`qvm-usb | grep Yubikey` | |
if [ -z "$YUBIKEY" ]; then | |
echo "No Yubikey present." | |
exit 1 | |
fi | |
echo "Found Yubikey:" | |
echo " $YUBIKEY" | |
# If it's attached, detach it. | |
USB_DEVICE=`qvm-usb | grep Yubikey | cut -f1` | |
USB_ATTACHED=`echo $YUBIKEY | grep "(attached"` | |
if [ $? -eq 0 ]; then | |
echo "Detaching." | |
qvm-usb -d "$USB_DEVICE" | |
if [ -z "$1" ]; then | |
exit 0 | |
fi | |
sleep 1 | |
else | |
if [ -z "$1" ]; then | |
echo "Exiting. (Provide VM attachment target as script argument to attach it there.)" | |
exit 1 | |
fi | |
fi | |
echo "Attaching to: $1" | |
qvm-usb -a $1 "$USB_DEVICE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment