forked from ictsc/ictsc-github-member
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite_authorized_keys.sh
executable file
·34 lines (29 loc) · 1.03 KB
/
rewrite_authorized_keys.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash -x
# rewrite_authorized_keys.sh - Rewrite a authorized_keys file with imported public keys by a Github Team defined on github.com/ictsc/ictsc-github-member
#
# Usage:
# bash rewrite_authorized_keys.sh [Github Team] [Output File]
#
# Example:
# curl -sS https://raw.githubusercontent.com/ictsc/ictsc-github-member/master/rewrite_authorized_keys.sh | bash -s -- ictsc2019 ~/.ssh/authorized_keys
team=$1
output=$2
if [ -z $output ]
then
output="/dev/null"
fi
members=`curl -sS https://raw.githubusercontent.com/ictsc/ictsc-github-member/production/terraform.tfstate | grep github_team_membership.$team | sed -e 's/^.*ictsc[0-9]*-\(.*\)\".*$/\1/'`
if [ -z "$members" ]
then
echo "members are not found, maybe $team does not exists"
exit 1
fi
echo "# These public keys are imported from GitHub team $team at github.com/ictsc/ictsc-github-member" > $output
for m in $members
do
curl -sS https://github.com/$m.keys | xargs -n1 -I{} echo {} $m@gh | tee --append $output
done
if [ $output != "/dev/null" ]
then
chmod 600 $output
fi