Skip to content

Instantly share code, notes, and snippets.

@njdancer
Created April 24, 2018 12:08
Show Gist options
  • Save njdancer/ef8187d40600f571855c35ebb547721a to your computer and use it in GitHub Desktop.
Save njdancer/ef8187d40600f571855c35ebb547721a to your computer and use it in GitHub Desktop.
#!/bin/bash
SSH_DIR=$(getent passwd $1 | cut -d: -f6)/.ssh
KEY_LOC=$SSH_DIR/keyLocation
CACHE=$KEY_LOC.cache
AUTH_KEYS=""
if [ -e "$KEY_LOC" ]
then
while read URL
do
if [ ! -z "$URL" ]
then
KEY=$(curl -sf "$URL")
CURL_EXIT_STATUS=$?
if [ $CURL_EXIT_STATUS != 0 ]
then
cat $CACHE
exit $?
fi
AUTH_KEYS+=$(curl -sf "$URL")$'\n'
fi
done <$KEY_LOC
fi
if [ ! -z "$AUTH_KEYS" ]
then
printf "$AUTH_KEYS" > "$CACHE"
printf "$AUTH_KEYS"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment