deploy_kgb.py 2.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright © 2015 Mattia Rizzolo <mattia@mapreri.org>
# Licensed under GPL-2
#
# Depends: python3 python3-yaml
#
# Generates the kgb client configuration, using the passwords listed in the
# file pointed by `secrets`.

import os
import yaml

secrets = '/srv/jenkins/kgb/secrets.yml'
16
outputs = '/srv/jenkins/kgb/'
17 18 19 20 21

with open(secrets) as fd:
    passwords = yaml.load(fd)

channels = [
22
    {'name': 'debconf-video', 'id': 'debconf-video'},
23 24 25 26
    {'name': 'debian-boot', 'id': 'jenkins-debian-boot'},
    {'name': 'debian-bootstrap', 'id': 'jenkins-debian-bootstrap'},
    {'name': 'debian-cinnamon', 'id': 'jenkins-debian-cinnamon'},
    {'name': 'debian-edu', 'id': 'jenkins-debian-edu'},
27
    {'name': 'debian-ftp', 'id': 'jenkins-debian-ftp'},
28 29 30
    {'name': 'debian-haskell', 'id': 'jenkins-debian-haskell'},
    {'name': 'debian-qa', 'id': 'jenkins-debian-qa'},
    {'name': 'debian-reproducible', 'id': 'jenkins-debian-reproducible'},
31
    {'name': 'debian-reproducible-changes', 'id': 'debian-reproducible-changes'},
32
    {'name': 'debian-ruby', 'id': 'pkg-ruby-extras'},
33
    {'name': 'reproducible-builds', 'id': 'reproducible-builds'},
34
    {'name': 'openwrt-devel', 'id': 'openwrt-devel'},
35
    {'name': 'archlinux-reproducible', 'id': 'archlinux-reproducible'},
36
    {'name': 'alpine-reproducible', 'id': 'alpine-reproducible'},
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
]

template = """repo-id: '{repo_id}'
password: {password}
use-irc-notices: 1
servers:
   # KGB-0, run by dmn@debian.org
 - uri: http://kgb.ktnx.org:9418/
   # KGB-1, run by tincho@debian.org
 - uri: http://kgb.tincho.org:9418/
   # KGB-2, run by gregoa@debian.org
 - uri: http://colleen.colgarra.priv.at:8080/
status-dir: /srv/jenkins/kgb/client-status/
"""

for chan in channels:
    print('Producing conf for #' + chan['name'] + '...')
    conf = template.format(repo_id=chan['id'],
                           password=passwords[chan['name']])
    if not os.access(outputs, os.R_OK):
        try:
            os.makedirs(outputs, exist_ok=True)
        except OSError as e:
            if e.errno == 17:  # that's "file exists" error
                print('ERROR: the output directory ' + outputs +
                      ' has bad permissions')
            raise
    if not os.access(outputs, os.W_OK):
            print('ERROR: the output directory ' + outputs +
                  ' has bad permissions')
            raise OSError
    filename = outputs + chan['name'] + '.conf'
    with open(filename, 'w') as fd:
        fd.write(conf)

print('All kgb configurations generated successfully')