Skip to content

Instantly share code, notes, and snippets.

@zuloo
Last active January 25, 2016 14:28
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 zuloo/81784afe2d633fc31323 to your computer and use it in GitHub Desktop.
Save zuloo/81784afe2d633fc31323 to your computer and use it in GitHub Desktop.
change the smart card reader used by gnupg2 (the dirty way)
#!/bin/bash
gpg2 --card-status > /dev/null 2>&1
READERS=($(echo scd getinfo reader_list | gpg-connect-agent –decode | awk '/^D/ {print $2}' | sed 's/%0A/ /g; /^$/d'))
BADCHOICE=true
while $BADCHOICE
do
INDEX=0
for READER in "${READERS[@]}"
do
INDEX=$(( INDEX + 1))
echo ${INDEX}: ${READER} $(lsusb | grep -i ${READER//:X:0} | cut -d" " -f7-)
done
echo
echo -n "Enter your choice [1-${INDEX}]:"
read CHOICE
[ $CHOICE -le $INDEX ] && [ $CHOICE -ge 1 ] && BADCHOICE=false || echo "Error: Bad option!"
echo
done
CHOICE=$((CHOICE-1))
echo "reader-port ${READERS[$CHOICE]}" > ~/.gnupg/scdaemon.conf
killall -9 scdaemon
sleep 2
gpg2 --card-status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment