-
-
Save satouriko/02525de6715e5e3622143ec651ef83a4 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