2 # mockbuild - mass RPM build driver for use with mock and many kernel-devel
4 # from Simon Wilkinson for OpenAFS
5 # for "modern" yum, use "showdupesfromrepos=1" in all cfg files in /etc/mock
15 my $rootbase="/var/lib/mock/";
16 my $resultbase="/tmp/result/";
17 my $stashbase="/disk/scratch/repository/";
18 my $mockcommand = "/usr/bin/mock";
20 my $ignorerelease = 1;
23 # Words cannot describe how gross this is. Yum no longer provides usable
24 # output, so we need to call the python interface. At some point this
25 # probably means this script should be entirely rewritten in python,
26 # but this is not that point.
28 sub findKernelModules {
29 my ($root, $uname, @modules) = @_;
31 my $modlist = join(",",map { "'".$_."'" } @modules);
36 base.doConfigSetup('$root/etc/yum.conf', '$root');
44 for pkg, values in base.searchPackageProvides(['kernel-devel-uname-r']).items():
45 if values[0].find('kernel-devel-uname-r = ') != -1:
46 print '%s.%s %s' % (pkg.name, pkg.arch, values[0].replace('kernel-devel-uname-r = ',''));
52 print '\\n'.join(['%s.%s %s' % (x.name, x.arch, x.printVer()) for x in base.searchPackageProvides([$modlist]).keys()]);
57 # my $output = `$suser -c "python -c \\\"$python\\\"" `;
58 my $output = `python -c "$python"`;
60 die "Python script to figure out available kernels failed : $output"
67 my %platconf = ( "fedora-5-i386" => { osver => "fc5",
70 updaterepo => 'updates-released',
71 results => 'fc5/i386' },
72 "fedora-5-x86_64" => { osver => "fc5",
75 updaterepo => 'updates-released',
76 results => 'fc5/x86_64' },
77 "fedora-6-i386" => { osver => "fc6",
80 updaterepo => 'updates-released',
81 results => "fc6/i386" },
82 "fedora-6-x86_64" => { osver => "fc6",
85 updaterepo => 'updates-released',
86 results => "fc6/x86_64" },
87 "fedora-7-i386" => { osver => "fc7",
90 updaterepo => 'updates-released',
91 results => "fc7/i386" },
92 "fedora-7-x86_64" => { osver => "fc7",
95 updaterepo => 'updates-released',
96 results => "fc7/x86_64" },
97 "fedora-8-i386" => { osver => "fc8",
100 updaterepo => 'updates-released',
101 results => "fc8/i386" },
102 "fedora-8-x86_64" => { osver => "fc8",
104 basearch => 'x86_64',
105 updaterepo => 'updates-released',
106 results => "fc8/x86_64" },
107 "centos-4-i386" => { osver => "el4",
110 updaterepo => 'update',
111 results => 'el4/i386' },
112 "centos-4-x86_64" => { osver => "el4",
114 basearch => 'x86_64',
115 updaterepo => 'update',
116 results => "el4/x86_64" },
117 "centos-5-i386" => { osver => "el5",
120 updaterepo => 'update',
121 results => "el5/i386" },
122 "centos-5-x86_64" => { osver => "el5",
124 basearch => 'x86_64',
125 updaterepo => 'update',
126 results => "el5/x86_64" },
127 "fedora-development-i386" => { osver => "fcd",
130 results => 'fedora-devel/i386'},
131 "fedora-development-x86_64" => { osver => "fcd",
133 basearch => 'x86_64',
134 results => 'fedora-devel/x86_64'}
137 # The following are kernels that we can't successfully build modules against
138 # due to issues in the packaged kernel-devel RPM.
141 "2.6.21-2950.fc8" => { "xen" => 1}, # Missing build ID
145 my $ok = GetOptions("resultdir=s" => \$resultbase,
148 my @platforms = @ARGV;
149 my $srpm = pop @platforms;
151 if (!$ok || $help || !$srpm || $#platforms==-1) {
152 print "Usage: $0 [options] <platform> [<platform> [...]] <srpm>\n";
153 print " Options are : \n";
154 print " --resultdir <dir> Location to place output RPMS\n";
156 print " Platform may be:\n";
157 foreach ("all", sort(keys(%platconf))) { print " ".$_."\n"; };
161 my $oafsversion = `rpm -q --queryformat=%{VERSION} -p $srpm` or die $!;
163 my $oafsrelease = `rpm -q --queryformat=%{RELEASE} -p $srpm` or die $!;
165 $oafsrelease=~s/^[^\.]*\.(.*)$/$1/;
167 print "Release is $oafsrelease\n";
169 if ($platforms[0] eq "all" and $#platforms == 0) {
170 @platforms = keys(%platconf);
173 foreach my $platform (@platforms) {
174 print "*******************************************************************\n";
175 print "Building for $platform\n";
176 die "Unknown platform $platform" if !$platconf{$platform};
177 my $osver = $platconf{$platform}{'osver'};
178 my $root = $rootbase.$platform."/root";
179 my $mockresults = $rootbase.$platform."/result";
180 my $resultdir = $resultbase.$platconf{$platform}{'results'};
181 my $basearch = $platconf{$platform}{'basearch'};
182 my $rpmstashdir = $stashbase.$platconf{$platform}{'results'}."/";
185 if (exists($platconf{$platform}{'updaterepo'})) {
186 $yumcachedir = $rootbase."cache/".$platform."/yum_cache/".
187 $platconf{$platform}{'updaterepo'}."/packages/";
190 File::Path::mkpath($resultdir, 0, 0755);
192 if (system($mockcommand, "-r", $platform, "init") != 0) {
193 die "Initialising the root failed: $?\n";
198 print "-------------------------------------------------------------------\n";
199 print "Finding available kernel modules\n";
201 my $arbitraryversion = "";
204 if ($platform=~/fedora-development/) {
205 $modules = findKernelModules($root, 0, "kernel-devel");
206 } elsif ($platform=~/centos-4/) {
207 $modules = findKernelModules($root, 0, "kernel-devel", "kernel-smp-devel",
208 "kernel-hugemem-devel", "kernel-xenU-devel");
210 $modules = findKernelModules($root, 0, 'kernel-devel');
213 foreach my $module (split(/\n/, $modules)) {
215 my ($package, $version, $repo)=split(/\s+/, $module);
216 my ($arch) = ($package=~/\.(.*)$/);
217 my ($variant) = ($package=~/kernel-(.*)-devel/);
218 $variant = "" if !defined($variant);
219 next if ($package !~ /^kernel/);
220 next if ($arch eq "noarch");
222 if (exists($badkernels{$version}) && ($badkernels{$version}{$variant}));
223 if ($platform=~/fedora-5/) {
224 next if ($variant eq "xen0"); # Fedora 5 has some bad xen0 kernel-devels
225 next if ($variant eq "smp");
227 if ($platform=~/fedora-8/ || $platform=~/fedora-9/ || $platform=~/fedora-development/) {
228 next if ($variant =~/debug$/); # Fedora 8 debug kernels are bad
230 print "$arch : $variant : $version\n";
231 $modulelist{$arch} ={} if !$modulelist{$arch};
232 $modulelist{$arch}{$version} = {} if !$modulelist{$arch}{$version};
233 $modulelist{$arch}{$version}{$variant} = 1;
234 $arbitraryversion = $version;
237 if (!$arbitraryversion) {
238 die "Unable to find a valid kernel-devel package for $platform\n";
241 print "-------------------------------------------------------------------\n";
242 print "Building the userland RPMs\n";
243 my @rpms = ('', '-authlibs', '-authlibs-devel', '-client', '-compat',
244 '-debuginfo', '-devel', '-docs', '-kernel-source', '-kpasswd',
248 foreach my $rpm (@rpms) {
249 if (! -f $resultdir."/openafs".$rpm."-".$oafsversion."-".$osver.".".
250 $oafsrelease.".".$basearch.".rpm") {
252 print $resultdir."/openafs".$rpm."-".$oafsversion."-".$osver.".".
253 $oafsrelease.".".$basearch.".rpm is missing!\n"
257 system($mockcommand." -r ".$platform." rebuild ".
258 ' --define "fedorakmod 1" '.
259 ' --define "kernvers '.$arbitraryversion.'" '.
260 ' --define "osvers '.$osver.'" '.
261 ' --define "build_modules 0" '.
262 ' --define "build_userspace 1" '.
263 ' --define "build_authlibs 1" '.
265 or die "build failed with : $!\n";
266 foreach my $rpm (@rpms) {
267 system("cp ".$mockresults."/openafs".$rpm."-".$oafsversion."-".
268 $osver.".".$oafsrelease.".".$basearch.".rpm ".
270 or die "Copy failed with : $!\n";
271 push @newrpms, $mockresults."/openafs".$rpm."-".$oafsversion."-".
272 $osver.".".$oafsrelease.".".$basearch.".rpm";
275 print "All userland RPMs present for $platform. Skipping build\n";
278 print "-------------------------------------------------------------------\n";
279 print "Building kernel modules\n";
281 foreach my $arch (keys(%modulelist)) {
282 foreach my $version (keys(%{$modulelist{$arch}})) {
283 my $kversion = $version;
288 @tobuild = keys(%{$modulelist{$arch}{$version}});
290 foreach my $variant (keys(%{$modulelist{$arch}{$version}})) {
291 my $dvariant=$variant;
292 $dvariant.="-" if ($dvariant);
293 if (!-f $resultdir."/kmod-openafs-".$dvariant.
294 $oafsversion."-".$oafsrelease.".".$kversion.".".
296 my @done = glob ($resultdir."/kmod-openafs-".$dvariant.
297 $oafsversion."-*.".$kversion.".".$arch.".rpm");
299 if ($ignorerelease && $#done>=0) {
300 print "Kernel module for $kversion already exists for an".
301 "older release. Skipping building it this time.\n";
303 push @tobuild, $variant;
304 print $resultdir."/kmod-openafs-".$dvariant.
305 $oafsversion."-".$oafsrelease.".".$kversion.".".
306 $arch.".rpm is missing\n";
313 my $variants = join(" ", map {$_ or '\\\\\"\\\\\"'} @tobuild);
314 print "Building $arch module for kernel $version with variants $variants\n";
315 system ("setarch $arch $mockcommand -r $platform rebuild ".
317 ' --define "fedorakmod 1" '.
318 ' --define "osvers '.$osver.'" '.
319 ' --define "kernvers '.$version.'" '.
320 ' --define "kvariants '.$variants.'" '.
321 ' --define "build_modules 1" '.
322 ' --define "build_userspace 0" '.
324 or die "Build failed with : $!\n";
325 foreach my $variant (@tobuild) {
329 system("cp ".$mockresults."/kmod-openafs-".$variant.$oafsversion."-".$oafsrelease.".".$kversion.".".$arch.".rpm $resultdir") == 0
330 or die "Copy failed with : $!\n";
331 push @newrpms, $mockresults."/kmod-openafs-".$variant.$oafsversion."-".$oafsrelease.".".$kversion.".".$arch.".rpm";
334 print "All kernel modules already built for $version on $arch\n";
338 print "-------------------------------------------------------------------\n";
339 print "Creating repository data\n";
340 system ("cd $resultdir; createrepo .") == 0
341 or die "Unable to build repository data\n";
344 print "-------------------------------------------------------------------\n";
345 print "Stashing kernel-devel RPMs\n";
348 my $dirh = IO::Dir->new($yumcachedir);
349 if (defined($dirh)) {
351 while (defined($file = $dirh->read)) {
352 if ( $file=~/^kernel.*devel/ &&
353 -f $yumcachedir.$file && ! -f $rpmstashdir.$file) {
354 print "Stashing $file for later use\n";
355 system("cp ".$yumcachedir.$file." ".$rpmstashdir.$file) == 0
356 or die "Copy failed with : $!\n";
363 print "Updating stash repodata\n";
364 system ("cd $rpmstashdir; createrepo .") == 0
365 or die "Unable to update RPM stash repository data\n";
370 print "=====================================================================\n";
371 print "All builds complete\nBuilt:\n";
372 print join("\n",@newrpms);