aboutsummaryrefslogtreecommitdiffstats
path: root/src/check-repos.py
blob: 0ccfc6b30653a80508fc416c2ae504a0bc9829bc (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
#
# Copyright (C) 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import glob
import os
import re
import sh

class Repository(object):
    def __init__(self, path):
        self.path = path
        self.git_daemon_export_ok = os.path.exists(
            self.path + os.sep + 'git-daemon-export-ok')
        self.post_receive =  os.path.exists(
            self.path + os.sep + 'hooks' + os.sep + 'post-receive')
        self.update =  os.path.exists(
            self.path + os.sep + 'hooks' + os.sep + 'update')

    def __str__(self):
        return self.path

rules = []
basedir = 'repositories'

if sh.hostname('-s').replace(os.linesep, '') == 'replicantserver0':
    rules = sh.gitolite('list-repos').split(os.linesep)
    rules.remove('')
else:
    rules = [
        'contrib/Fil/..*',
        'contrib/GNUtoo/.+/..*',
        'contrib/JeremyRand/..*',
        'contrib/PaulK/..*',
        'contrib/Putti/..*',
        'contrib/belgin/..*',
        'contrib/hominoid/..*',
        'contrib/irelativism/..*',
        'contrib/scintill/..*',
        'contrib/tehnoetic/..*',
        'contrib/wiewo/..*',
        'gitolite-admin',
        'infrastructure/..*',
        'mirrors/..*/..*',
        'mirrors/git.paulk.fr/..*',
        'private/..*',
        'replicant-next/..*',
        'replicant/..*',
        'replicant/vendor_replicant-data']

rules.remove('gitolite-admin')
rules.remove('private/..*')

repos = []

for rule in rules:
    rule = re.sub(re.escape('..*') + '$', '*.git', rule)
    rule = rule.replace('.+', '*')
    rule = rule.replace('..*', '*')
    if not re.search('.git$', rule):
        rule = rule + '.git'
    rule = basedir + os.sep + rule
    for path in glob.glob(rule):
        errors = []
        repo = Repository(path)
        if not repo.git_daemon_export_ok:
            errors.append('missing {}/{}'.format(repo.path, 'git-daemon-export-ok'))

        if not repo.post_receive:
            errors.append('missing {}/{}'.format(repo.path, 'hooks/post-receive'))

        if not repo.update:
            errors.append('missing {}/{}'.format(repo.path, 'hooks/update'))

        if path.startswith(basedir + os.sep + 'contrib' + os.sep + 'GNUtoo'):
            relative_path = path 
            relative_path = re.sub('^' + re.escape(basedir) + re.escape(os.sep), '', relative_path)
            relative_path = re.sub(re.escape('.git') + '$', '', relative_path)
            try:
                output = sh.gitolite(
                    'access', '-q', relative_path, 'gnutoo').replace(os.linesep, '')
            except:
                errors.append('"gitolite access -q {} gnutoo" failed'.format(relative_path))

        if (len(errors) > 0):
            print('[ !! ] {}'.format(repo.path))
        # else:
        #     print('[ OK ] {}'.format(repo.path))
        for error in errors:
            print('       - {}'.format(error))

for repo in repos:
    print(repo)