Skip to content

Instantly share code, notes, and snippets.

@zuloo
Last active Jan 25, 2016
Embed
What would you like to do?
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