#!/usr/bin/env python3 # # Copyright (C) 2022 Denis 'GNUtoo' Carikli # # 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 . 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)