Created
August 1, 2023 23:16
-
-
Save norcalli/0df794eb05e2f615019fc0daf5e88887 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
p() { | |
echo "$@" >&2 | |
} | |
test -z "$USERNAME" && USERNAME=$1 | |
test -z "$USERNAME" && { | |
p "Usage: $0 <github_username>" | |
p "Alternatively, pass USERNAME (github username) in as an environment variable" | |
p "e.g. curl script.sh | env USERNAME=bigboi69 bash" | |
exit 1 | |
} | |
GITHUB_KEYS="$(curl https://github.com/$USERNAME.keys | cut -d' ' -f1,2)" | |
if test -e ~/.ssh/authorized_keys; then | |
EXISTING_KEYS="$(cat ~/.ssh/authorized_keys | cut -d' ' -f1,2)" | |
else | |
EXISTING_KEYS="" | |
fi | |
p "Adding github keys to authorized keys." | |
printf "%s\n" "$EXISTING_KEYS" "$GITHUB_KEYS" | sort -u > ~/.ssh/authorized_keys | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment