diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2022-07-11 16:53:10 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2022-07-11 16:58:26 +0200 |
commit | 89fe6b992f3eca01b4234b1ce1d8fd9e37c46535 (patch) | |
tree | 173cab87a3e01836fe42db7543341412e256a90e /src | |
download | usr_local_bin-main.tar.gz usr_local_bin-main.tar.bz2 usr_local_bin-main.zip |
Example usage:
$ ssh git.replicant.us
# su -l git
$ check-repos.py
[ !! ] repositories/contrib/GNUtoo/tools/test1.git
- missing repositories/contrib/GNUtoo/tools/test1.git/hooks/post-receive
[ !! ] repositories/contrib/GNUtoo/tools/test3.git
- missing repositories/contrib/GNUtoo/tools/test3.git/hooks/post-receive
[ !! ] repositories/contrib/GNUtoo/tools/foo.git
- missing repositories/contrib/GNUtoo/tools/foo.git/git-daemon-export-ok
- missing repositories/contrib/GNUtoo/tools/foo.git/hooks/post-receive
- missing repositories/contrib/GNUtoo/tools/foo.git/hooks/update
- "gitolite access -q contrib/GNUtoo/tools/foo gnutoo" failed
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'src')
-rwxr-xr-x | src/check-repos.py | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/check-repos.py b/src/check-repos.py new file mode 100755 index 0000000..0ccfc6b --- /dev/null +++ b/src/check-repos.py @@ -0,0 +1,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) |