-
Notifications
You must be signed in to change notification settings - Fork 1
/
updates.py
211 lines (179 loc) · 6.42 KB
/
updates.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/python
import errno
from glob import glob
import os
import re
import shutil
import subprocess
from bodhi.client.bindings import BodhiClient
# Discover the latest kernel versions in Bodhi and rebuild some kmod SRPMs
# against those versions.
def get_fedora_releases(client):
"""
Return a set of active Fedora releases.
For example: set(["25", "26"])
:param client: BodhiClient
"""
# return set(['28']) # XXX debugging!
allreleases = client.get_releases().releases
releases = set()
for release in allreleases:
# Even though we're operating on "dist-tags" here, note it's really a
# Bodhi representation: "f"- something, not the more commonly-known RPM
# disttag macro ("fc"-something).
if release.state == 'current' and release.dist_tag.startswith('f'):
releases.add(release.version)
return releases
def get_latest_kernel(client, release):
"""
Get the NVR of the latest testing or stable kernel for a Fedora release.
"""
kwargs = {
'packages': ['kernel'],
'releases': ['f' + release],
'content_type': 'rpm',
'rows_per_page': 1,
}
result = client.query(status='testing', **kwargs)
if not result.updates:
result = client.query(status='stable', **kwargs)
nvr = result.updates[0].builds[0].nvr
return nvr
def kernel_filenames(nvr):
"""
Return a set of .rpm filenames we will need in order to build a kmod pkg.
"""
vr = nvr[7:]
filenames = set([
'kernel-%s.x86_64.rpm',
'kernel-core-%s.x86_64.rpm',
'kernel-devel-%s.x86_64.rpm',
'kernel-modules-%s.x86_64.rpm',
])
return set([f % vr for f in filenames])
def download_kernel(nvr):
"""
Download the relevant kernel RPMs for this name-version-release
Place the files into a version-release subdirectory.
Skip downloading if a file already exists.
"""
vr = nvr[7:]
try:
os.makedirs(vr)
except OSError as e:
if e.errno != errno.EEXIST:
raise
for filename in kernel_filenames(nvr):
cmd = ('koji', 'download-build', '-a', 'x86_64', '--key', '9db62fb1',
'--rpm', filename)
if not os.path.exists(os.path.join(vr, filename)):
print(' '.join(cmd))
subprocess.check_call(cmd, cwd=vr)
# Verify that the package matches its checksums.
# todo: verify gpg signature as well
subprocess.check_call(('rpm', '-K', '--nosignature', filename), cwd=vr)
def rpm_name(srpm, vr):
"""
Return the .rpm file name,
:param srpm: an SRPM file name
:param vr: a kernel version-release.
"""
pkg = os.path.basename(srpm)
(name, kmod, rest) = pkg.split('-', 2)
m = re.search('fc\d\d$', vr)
distarch = m.group(0)
rest = re.sub('fc\d\d\.src\.rpm', distarch, rest)
return 'kmod-{name}-{vr}.x86_64-{rest}.x86_64.rpm'.format(name=name,
vr=vr,
rest=rest)
def mock_build(release, nvr):
"""
mockbuild all our packages for this Fedora release and kernel nvr.
Skips SRPMs that are already built for this kernel nvr.
:returns: list of all built packages (SRPMs). If we skipped all SRPMs,
this list will be empty.
"""
vr = nvr[7:]
packages = ['facetimehd-kmod-0-1.20161214git0712f39.fc28.src.rpm']
packages += ['../wl-kmod/wl-kmod-6.30.223.271-16.fc28.src.rpm']
# Only rebuild packages that we have not yet built.
to_build = []
for srpm in packages:
rpm = rpm_name(srpm, vr)
filename = os.path.join(vr, rpm)
if os.path.exists(filename):
# print(' RPM %s already exists' % filename)
continue
to_build.append(srpm)
if not to_build:
return []
# Initialize a clean mock chroot
mockcfg = 'fedora-%s-x86_64-rpmfusion_free' % release
# Before I ran "clean" here, I would get stale old --define kernels values.
# Not sure why running "clean" here fixes it. It may have been an older
# stray syntax error when I invoked mock a while back?
# Commenting this out to see if the problem ever resurfaces.
# cmd = ('mock', '-r', mockcfg, 'clean')
# print(' '.join(cmd))
# subprocess.check_call(cmd)
cmd = ('mock', '-r', mockcfg, 'init')
print(' '.join(cmd))
subprocess.check_call(cmd)
# Install our exact kernel pkgs
cmd = ['mock', '-r', mockcfg, 'install'] + list(kernel_filenames(nvr))
print(' '.join(cmd))
subprocess.check_call(cmd, cwd=vr)
# Rebuild our packages
built = []
for srpm in to_build:
cmd = ('mock', '-r', mockcfg,
'--no-clean',
'rebuild', srpm,
'--define=kernels %s.x86_64' % vr)
print(' '.join(cmd))
subprocess.check_call(cmd)
rpm = rpm_name(srpm, vr)
output = os.path.join('/var/lib/mock',
'fedora-%s-x86_64' % release,
'result', rpm)
built.append(rpm)
print('saving %s' % output)
shutil.copy(output, vr)
return built
def generate_repo(release, nvr):
"""
Generate a Yum repo with the kmod RPMs from this kernel NVR directory.
"""
vr = nvr[7:]
repo = 'f' + release
try:
os.makedirs(repo)
except OSError as e:
if e.errno != errno.EEXIST:
raise
for filename in glob(vr + '/kmod-*.rpm'):
basename = os.path.basename(filename)
if not os.path.exists(os.path.join(repo, basename)):
print('copying %s to %s repo' % (os.path.basename(filename), repo))
shutil.copy(filename, repo)
subprocess.check_call(['createrepo', '.'], cwd=repo)
def publish_repo(release):
"""
Publish a repository to fedorapeople.org.
"""
DESTINATION = 'fedorapeople.org:public_html/macbook/'
repo = 'f' + release
subprocess.check_call(['rsync', '-aP', repo, DESTINATION])
client = BodhiClient(debug=True)
releases = get_fedora_releases(client)
for release in releases:
print('querying kernel pkg in Fedora %s...' % release)
kernel = get_latest_kernel(client, release)
print('f%s: %s' % (release, kernel))
download_kernel(kernel)
builds = mock_build(release, kernel)
if not builds:
print('skipped all builds for %s' % kernel)
continue
generate_repo(release, kernel)
publish_repo(release)