-
-
Save fjallstrom/006de119849ccf778e9ca8ed889d9911 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
# import github keys | |
$ch = curl_init('https://api.github.com/orgs/EarthPeople/members'); | |
curl_setopt($ch, CURLOPT_USERPWD, "XXX:XXX"); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 30); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_USERAGENT,'EpBot'); | |
$users = @json_decode(curl_exec($ch)); | |
curl_close($ch); | |
echo "found ".count($users)." users in organisation\n"; | |
if($users){ | |
foreach($users as $user => $params){ | |
echo "user: ".$params->login."\n"; | |
$keys[] = file_get_contents('https://github.com/'.$params->login.'.keys'); | |
} | |
} | |
echo "found ".count($keys)." keys\n"; | |
if(count($users) === count($keys)){ | |
file_put_contents('/root/.ssh/authorized_keys', implode($keys, "\n")); | |
echo "imported to keys to ~/.ssh/authorized_keys\n"; | |
}else{ | |
echo "error, could not fetch keys for all users\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment