Skip to content

Instantly share code, notes, and snippets.

@packetpilot
Created August 8, 2019 19:57
Show Gist options
  • Save packetpilot/2fcdb46c56225a0a88d7f4c1f09ee8ad to your computer and use it in GitHub Desktop.
Save packetpilot/2fcdb46c56225a0a88d7f4c1f09ee8ad to your computer and use it in GitHub Desktop.
pubkey external sync script
#!/bin/bash
#######################################
# pubess: PUBkey External Sync Script #
#######################################
## ships "with the safety on" [L{40,42}]
# !! be sure to set your username here !!
# if you don't, the author considers it an invitation to visit.
ghsource=github.com
ghusername=packetpilot
glsource=git.allocor.tech
glusername=dc
# what is the name of your golden retriever?
getmethod="curl --silent"
# this may be safe to leave alone.
ussher=$HOME/.ssh
authfile=$ussher/authorized_keys
# do not put shit where shit does not yet exist
if [[ ! -d "${ussher}" || ! -f "${authfile}" ]]; then
echo "Either ${authfile} or the dir containing it is missing. kthxbai."
exit 1
fi
# note that `grep` is in place to be sure not to
# lock you out if the server's in a weird state.
glkeys="$(
${getmethod} https://${glsource}/${glusername}.keys | grep ^ssh
)"
ghkeys="$(
${getmethod} https://${ghsource}/${ghusername}.keys | grep ^ssh
)"
# append; DO NOT overwrite (note: ships "with the safety on")
echo "${glkeys}" \
#safety >> "${authfile}"
echo "${ghkeys}" \
#safety >> "${authfile}"
# sort and flatten dupes
sort -u "${authfile}" -o "${authfile}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment