Created
March 24, 2014 13:01
-
-
Save chorn/9739604 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
if [[ $# != 2 ]] ; then | |
echo "Usage: $0 <domain name> <hostname not including domain name>" | |
exit 1 | |
fi | |
if ! command -v dnsimple >/dev/null 2>/dev/null ; then | |
echo 'You must have the dnsimple command line tool installed and in your $PATH.' | |
echo "Try 'gem install dnsimple-ruby' and then make a $HOME/.dnsimple config file." | |
exit 1 | |
fi | |
DOMAIN="${1}" | |
NAME="${2}" | |
HOSTNAME="${NAME}.${DOMAIN}" | |
declare -i int_type=0 | |
for type in rsa dsa ecdsa ; do | |
let int_type++ | |
PUBKEY="${NAME}.${type}" | |
ssh-keyscan -t $type "${HOSTNAME}" > "${PUBKEY}" | |
if [ -s "${PUBKEY}" ] ; then | |
FINGERPRINT=$(ssh-keygen -l -f "${PUBKEY}" | cut -f 2 -d ' ') | |
RECORD="${int_type} 1 ${FINGERPRINT}" | |
dnsimple record:create "${DOMAIN}" "${NAME}" SSHFP "'${RECORD}'" | |
fi | |
rm "${PUBKEY}" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment