-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg-verify.py
executable file
·72 lines (45 loc) · 1.99 KB
/
pkg-verify.py
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
#!/usr/bin/env python3
import sys
import argparse
import subprocess
import logging
from Mtree import Mtree
def mtree_path(pkg, version):
return '/'.join(['/var/lib/pacman/local', pkg + '-' + version, 'mtree'])
def pkg_version(pkg):
logging.debug("Getting version for %s", pkg)
try:
cmd = ['/usr/bin/pacman', '-Q', pkg]
logging.debug("Running %s", cmd)
output = subprocess.run(cmd, stdout=subprocess.PIPE, check=False, encoding='utf-8').stdout.strip().split(' ')
except SubprocessError as exc:
logging.error("Failed to run %s: %s", ' '.join(cmd), exc)
sys.exit(1)
return output
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='''Verify pacman pacmages, including checksums.''')
parser.add_argument('-v', '--verbose', action='count', help='Be verbose (multiples okay)')
parser.add_argument('-R', '--altroot', action='store', help='set alternate root directory')
parser.add_argument('-T', '--check-dir-mtime', action='count', default=False, help='Check mtimes on directories (normally ignored)')
try:
parsed_options, remaining_args = parser.parse_known_args()
except SystemExit as exc:
print("Failed parsing arguments: %s" % exc)
sys.exit(2)
verbose_value = 0 if parsed_options.verbose is None else parsed_options.verbose
LOG_LEVEL = (30 - verbose_value * 10)
logging.basicConfig(format='%(asctime)-15s [%(levelname)s] %(message)s', level=LOG_LEVEL)
logging.debug("Starting")
RC = 0
for arg in remaining_args:
pkg, version = pkg_version(arg)
mpath = mtree_path(pkg, version)
logging.debug("%s %s %s", pkg, version, mpath)
mtree = Mtree(mpath)
for entry in iter(mtree.objects):
verified, failure_str = entry.verify()
if not verified:
RC = 1
if LOG_LEVEL < 30 or not failure_str.startswith('.........'):
print(failure_str)
sys.exit(RC)