Last active
January 12, 2021 06:13
-
-
Save kookxiang/a202303bff3959cb3152cc35c3fc6566 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 sh | |
TARGET_DIR='/home/kookxiang/.ssh' | |
GITHUB_USERNAME='kookxiang' | |
if ! [ -d ${TARGET_DIR} ]; then | |
mkdir ${TARGET_DIR} | |
chmod 0700 ${TARGET_DIR} | |
fi | |
if ! [ -f ${TARGET_DIR}/authorized_keys ]; then | |
touch ${TARGET_DIR}/authorized_keys | |
chmod 0600 ${TARGET_DIR}/authorized_keys | |
fi | |
curl -sS https://api.github.com/users/${GITHUB_USERNAME}/keys | grep -Po '"key": ".+?"' | sed -e 's/\"key\": \"//' -e 's/"$//' >> ${TARGET_DIR}/authorized_keys.new | |
if [ $? != 0 ]; then exit 1; fi | |
cat ${TARGET_DIR}/authorized_keys.new > ${TARGET_DIR}/authorized_keys | |
rm -rf ${TARGET_DIR}/authorized_keys.new | |
echo >> ${TARGET_DIR}/authorized_keys | |
if [ -f ${TARGET_DIR}/alternate_keys ]; then | |
cat ${TARGET_DIR}/alternate_keys >> ${TARGET_DIR}/authorized_keys | |
echo >> ${TARGET_DIR}/authorized_keys | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment