Skip to content

Instantly share code, notes, and snippets.

@jwir3
Created June 23, 2023 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwir3/b92d5f71d3ea541da8bfc81f6a492447 to your computer and use it in GitHub Desktop.
Save jwir3/b92d5f71d3ea541da8bfc81f6a492447 to your computer and use it in GitHub Desktop.
Script for checking whether a yubikey is present
#!/bin/bash
#
# A script to determine if a yubikey is present on the current host
#
RESULT=`2>&1 gpg --card-status`
CARD_ABSENT=`echo $RESULT | grep "OpenPGP card not available"`
if [ -z "${CARD_ABSENT}" ]
then
SAVEIFS=$IFS # Save current IFS (Internal Field Separator)
IFS=$'\n' # Change IFS to newline char
lines=($RESULT)
IFS=$SAVEIFS # Restore original IFS
SIGNATURE=`echo ${lines[17]} | awk -F":" '{print $2}'`
if [ -z "${SIGNATURE}" ]
then
echo "false"
else
echo "true"
fi
else
echo "false"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment