Child: [ddf08c] (diff)

Download this file

prep-scm-sandbox.py    76 lines (64 with data), 2.1 kB

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import string
HOME=os.environ['HOME']
USERS=['user%.2d' % i for i in range(1, 21) ]
USERS += [
'admin1', 'admin2',
'dovethunder', 'dovetail', 'dovestream', 'dovetree', 'dovespangle',
'dovemeade', 'dovestar', 'dovebuyer', 'dovesomething', 'dovesweet', 'dovewood' ]
SSH_CONFIG = '%s/.ssh/config' % HOME
LDIF_FILE = '%s/users.ldif' % HOME
KEYFILE='%s/.ssh/allura_rsa' % HOME
def main():
# Generate ssh key for SCM login
os.system('cp %s %s.bak' % (SSH_CONFIG, SSH_CONFIG))
with open(SSH_CONFIG) as fp:
lines = fp.readlines()
new_lines = [
SSH_TMPL.substitute(
sb_host=sb_host,
sb=sb,
veid='%d0%.2d' % (sb_host, sb))
for sb_host in 5,6,7,9
for sb in range(99) ]
new_lines = '\n'.join(new_lines)
found_star = False
with open(SSH_CONFIG, 'w') as fp:
for line in lines:
if not found_star and line.startswith('Host *'):
print >> fp, new_lines
found_star = True
print >> fp, line.rstrip()
if not found_star:
print >> fp, new_lines
os.system("ssh-keygen -t rsa -b 2048 -N '' -f %s" % KEYFILE)
# Generate ldif
pubkey = open(KEYFILE + '.pub').read()
with open(LDIF_FILE, 'w') as fp:
for user in USERS:
print >> fp, LDIF_TMPL.substitute(
user=user, pubkey=pubkey)
# Update LDAP
assert 0 == os.system('/usr/local/sbin/ldaptool modify -v -f %s' % LDIF_FILE)
SSH_TMPL=string.Template('''
Host hg*-$veid hg*-${veid}.sb.sf.net
Hostname 10.58.${sb_host}.${sb}
Port 17
IdentityFile ~/.ssh/allura_rsa
Host svn*-$veid svn*-${veid}.sb.sf.net
Hostname 10.58.${sb_host}.${sb}
Port 16
IdentityFile ~/.ssh/allura_rsa
Host git*-$veid git*-${veid}.sb.sf.net
Hostname 10.58.${sb_host}.${sb}
Port 23
IdentityFile ~/.ssh/allura_rsa
''')
LDIF_TMPL=string.Template('''
dn: cn=$user,ou=users,dc=sf,dc=net
changetype: modify
add: sshPublicKey
sshPublicKey: $pubkey
''')
if __name__ == '__main__':
main()