Switch to unified view

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