source: ProjectBuilder/devel/rpmbootstrap/bin/rpmbootstrap@ 1802

Last change on this file since 1802 was 1802, checked in by Bruno Cornec, 10 years ago
  • Adds mageia 3 VE support
  • Adds rbsmirrorupd feature
  • No -s option for oppatchcmd by default now
  • Start to improve rpmbootstrap for new Fedora mirror
File size: 22.9 KB
Line 
1#!/usr/bin/perl -w
2#
3# rpmbootstrap application, a debootstrap like for RPM distros
4#
5# $Id$
6#
7# Copyright B. Cornec 2010-2012
8# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
9# Provided under the GPL v2
10
11# Syntax: see at end
12
13use strict 'vars';
14use Getopt::Long qw(:config auto_abbrev no_ignore_case);
15use Data::Dumper;
16use English;
17use LWP::UserAgent;
18use File::Basename;
19use File::Copy;
20use File::Find;
21use ProjectBuilder::Version;
22use ProjectBuilder::Base;
23use ProjectBuilder::Env;
24use ProjectBuilder::Conf;
25use ProjectBuilder::Distribution;
26
27# Global variables
28my %opts; # CLI Options
29
30=pod
31
32=head1 NAME
33
34rpmbootstrap - creates a chrooted RPM based distribution a la debootstrap, aka Virtual Environment (VE)
35
36=head1 DESCRIPTION
37
38rpmbootstrap creates a chroot environment (Virtual Environment or VE)
39with a minimal distribution in it, suited for building packages for example.
40It's very much like debootstrap but for RPM based distribution.
41It aims at supporting all distributions supported by project-builder.org
42(RHEL, RH, Fedora, OpeSUSE, SLES, Mandriva, ...)
43
44It is inspired by work done by Steve Kemp for rinse (http://www.steve.org.uk/),
45and similar to mock or febootstrap, but fully integrated with project-builder.org
46(which also supports rinse and mock). Contrary to these, rpmbootstrap creates
47an environment where the packages commands are usable after build, as described
48hereafter.
49
50rpmbootstrap works in 2 phases. The first one is used to download all
51the required packages to have a working package management system in the
52chroot working. This list of packages is stored in /etc/pb/pb.conf under
53the rbsmindep parameter (aka rpmbootstrap minimal dependencies). Once the
54packages have been downloaded from the mirror, they are extracted with
55rpm2cpio. At that point you should be able to use yum on Fedora, urpmi
56on Mandriva/Mageia and zypper on OpenSuSE.
57The second phase uses exactly the previous mentioned tools to install
58exactly the same package list to have a coherent RPM db at the end.
59
60rpmbootstrap has additional options to execute a post-install script
61(-s) or to add packages (-a). Then pb can use the chroot to perform even
62more actions in it.
63
64=head1 SYNOPSIS
65
66rpmbootstrap [-vhmqpdk][-s script][-i iso][-a pkg1[,pkg2,...]] distribution-version-arch [target-dir] [mirror [script]]
67
68rpmbootstrap [--verbose][--help][--man][--quiet][--print-rpms][--download-only]
69[--keep][--script script][--iso iso][--add pkg1,[pkg2,...]] distribution-version-arch [target-dir] [mirror [script]]
70
71=head1 OPTIONS
72
73=over 4
74
75=item B<-v|--verbose>
76
77Print a brief help message and exits.
78
79=item B<-h|--help>
80
81Print a brief help message and exits.
82
83=item B<--man>
84
85Prints the manual page and exits.
86
87=item B<-q|--quiet>
88
89Do not print any output.
90
91=item B<-p|--print-rpms>
92
93Print the packages to be installed, and exit.
94Note that a target directory must be specified so rpmbootstrap can determine
95which packages should be installed, and to resolve dependencies.
96The target directory will be deleted.
97
98=item B<-d|--download-only>
99
100Download packages, but don't perform installation.
101
102=item B<-k|--keep>
103
104Keep packages in the cache dir for later reuse. By default remove them.
105
106=item B<-s|--script script>
107
108Name of the script you want to execute on the related VEs after the installation.
109It is executed in host environment.
110You can use the chroot command to execute actions in the VE.
111
112=item B<-i|--iso iso_image>
113
114Name of the ISO image of the distribution you want to install on the related VE.
115
116=item B<-a|--add pkg1[,pkg2,...]>
117
118Additional packages to add from the distribution you want to install on the related VE
119at the end of the chroot build.
120
121=item B<--no-stop-on-error>
122
123Continue through errors with best effort.
124
125=back
126
127=head1 ARGUMENTS
128
129=over 4
130
131=item B<distribution-version-arch>
132
133Full name of the distribution that needs to be installed in the VE. E.g. fedora-11-x86_64.
134
135=item B<target-dir>
136
137This is the target directory under which the VE will be created.
138Created on the fly if needed.
139If none is given use the default directory hosting VE for project-builder.org
140(Cf: vepath parameter in $HOME/.pbrc)
141
142=back
143
144=head1 EXAMPLE
145
146To setup a Fedora 12 distribution with an i386 architecture issue:
147
148rpmbootstrap fedora-12-i386 /tmp/fedora/12/i386
149
150=head1 WEB SITES
151
152The main Web site of the project is available at L<http://www.project-builder.org/>.
153Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
154
155=head1 USER MAILING LIST
156
157Cf: L<http://www.mondorescue.org/sympa/info/pb-announce> for announces and
158L<http://www.mondorescue.org/sympa/info/pb-devel> for the development of the pb project.
159
160=head1 CONFIGURATION FILE
161
162Uses Project-Builder.org configuration file (/etc/pb/pb.conf or /usr/local/etc/pb/pb.conf)
163
164=head1 AUTHORS
165
166The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
167
168=head1 COPYRIGHT
169
170Project-Builder.org is distributed under the GPL v2.0 license
171described in the file C<COPYING> included with the distribution.
172
173=cut
174
175# ---------------------------------------------------------------------------
176
177$Global::pb_stop_on_error = 1;
178my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
179my $appname = "rpmbootstrap";
180$ENV{'PBPROJ'} = $appname;
181
182# Initialize the syntax string
183
184pb_syntax_init("$appname Version $projectbuilderver-$projectbuilderrev\n");
185pb_temp_init();
186
187GetOptions("help|?|h" => \$opts{'h'},
188 "man|m" => \$opts{'man'},
189 "verbose|v+" => \$opts{'v'},
190 "quiet|q" => \$opts{'q'},
191 "log-files|l=s" => \$opts{'l'},
192 "script|s=s" => \$opts{'s'},
193 "print-rpms|p" => \$opts{'p'},
194 "download-only|d" => \$opts{'d'},
195 "keep|k" => \$opts{'k'},
196 "iso|i=s" => \$opts{'i'},
197 "add|a=s" => \$opts{'a'},
198 "version|V=s" => \$opts{'V'},
199 "stop-on-error!" => \$Global::pb_stop_on_error,
200) || pb_syntax(-1,0);
201
202if (defined $opts{'h'}) {
203 pb_syntax(0,1);
204}
205if (defined $opts{'man'}) {
206 pb_syntax(0,2);
207}
208if (defined $opts{'v'}) {
209 $pbdebug = $opts{'v'};
210}
211if (defined $opts{'q'}) {
212 $pbdebug=-1;
213}
214if (defined $opts{'l'}) {
215 open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
216 $pbLOG = \*pbLOG;
217 $pbdebug = 0 if ($pbdebug == -1);
218}
219pb_log_init($pbdebug, $pbLOG);
220#pb_display_init("text","");
221
222#if (defined $opts{'s'}) {
223#$pbscript = $opts{'s'};
224#}
225#if (defined $opts{'i'}) {
226#$iso = $opts{'i'};
227#}
228
229# Get VE name
230$ENV{'PBV'} = shift @ARGV;
231die pb_syntax(-1,1) if (not defined $ENV{'PBV'});
232
233die "Needs to be run as root" if ($EFFECTIVE_USER_ID != 0);
234
235#
236# Initialize distribution info from pb conf file
237#
238pb_log(0,"Starting VE build for $ENV{'PBV'}\n");
239my $pbos = pb_distro_get_context($ENV{'PBV'});
240
241#
242# Check target dir
243# Create if not existent and use default if none given
244#
245pb_env_init_pbrc(); # to get content of HOME/.pbrc
246my $vepath = shift @ARGV;
247
248#
249# Check for command requirements
250#
251my ($req,$opt) = pb_conf_get_if("oscmd","oscmdopt");
252pb_check_requirements($req,$opt,$appname);
253
254if (not defined $vepath) {
255 my ($vestdpath) = pb_conf_get("vepath");
256 $vepath = pb_path_expand("$vestdpath->{'default'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}") if (defined $vestdpath->{'default'});
257}
258
259die pb_log(0,"No target-dir specified and no default vepath found in $ENV{'PBETC'}\n") if (not defined $vepath);
260
261pb_mkdir_p($vepath) if (! -d $vepath);
262
263#
264# Get the package list to download, store them in a cache directory
265#
266my ($rbscachedir) = pb_conf_get_if("cachedir");
267my ($pkgs,$mirror) = pb_distro_get_param($pbos,pb_conf_get("rbsmindep","rbsmirrorsrv"));
268my ($updater) = pb_distro_get_param($pbos,pb_conf_get_if("rbsmirrorupd"));
269die "No packages defined for $pbos->{name}-$pbos->{version}-$pbos->{arch}" unless $pkgs =~ /\w/;
270
271my $cachedir = "/var/cache/rpmbootstrap";
272$cachedir = $rbscachedir->{'default'} if (defined $rbscachedir->{'default'});
273$cachedir = $rbscachedir->{$appname} if (defined $rbscachedir->{$appname});
274
275# Point to the right subdir and create it if needed
276$cachedir .= "/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
277pb_mkdir_p($cachedir) if (! -d $cachedir);
278
279# Get the complete package name from the mirror
280#
281my $ua = LWP::UserAgent->new;
282$ua->timeout(10);
283$ua->env_proxy;
284
285die "No mirror defined for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}" if ((not defined $mirror) || ($mirror =~ /^\t*$/));
286my $resp;
287my @list_pkg;
288
289$resp = rbs_mirror_response($mirror);
290@list_pkg = split(/\n/,$resp->as_string());
291
292# If an update source is availble add it after so that these pkgs update the main ones
293if (defined $updater) {
294 $resp = rbs_mirror_response($mirror.$updater);
295 push(@list_pkg,split(/\n/,$resp->as_string()));
296}
297
298# Manages architectures specificities
299my $parch = $pbos->{'arch'};
300$parch = "i[3456]86" if ($pbos->{'arch'} eq "i386");
301my $repowithletter = 0;
302
303# Get the list of packages and their URL in this hash
304my %url;
305foreach my $l (@list_pkg) {
306 my ($url,$desc) = rbs_find_pkg($l,$parch,"pkg");
307 if (defined $url) {
308 $url{$url} = "$mirror/$desc";
309 } else {
310 pb_log(3,"not a package, maybe a dir containing packages\n");
311 my $response1 = $ua->get("$mirror/Packages");
312 # Check if we have a fedora 17/18 type of repo
313 if ($response1->is_success) {
314 foreach my $d (split(/\n/,$response1->as_string())) {
315 ($url,$desc) = rbs_find_pkg($d,$parch,"dir");
316 if (defined $url) {
317 # Here we have the dir in which are packages
318 my $response2 = $ua->get("$mirror/Packages/$desc");
319 foreach my $p (split(/\n/,$response2->as_string())) {
320 ($url,$desc) = rbs_find_pkg($d,$parch,"dir");
321 if (defined $url) {
322 $url{$p} = "$mirror/$desc";
323 } else {
324 pb_log(3,"not a package, and not a dir containing packages\n");
325 }
326 }
327 } else {
328 }
329 }
330 } else {
331 }
332 }
333}
334
335#
336# Prepare early the yum cache env for the VE in order to copy in it packages on the fly
337#
338my $oscachedir = "/tmp";
339my $osupdcachedir;
340my $osupdname = "";
341
342if ($pbos->{'install'} =~ /yum/) {
343 $oscachedir = "$vepath/var/cache/yum/core/packages/";
344 $osupdcachedir = "$vepath/var/cache/yum/updates-released/packages/";
345 $osupdname = "YUM";
346 # Recent Fedora release use a new yum cache dir
347 if (($pbos->{'name'} eq "fedora") && ($pbos->{'version'} > 8)) {
348 $oscachedir = "$vepath/var/cache/yum/$pbos->{'arch'}/$pbos->{'version'}/fedora/packages";
349 $osupdcachedir = "$vepath/var/cache/yum/$pbos->{'arch'}/$pbos->{'version'}/updates/packages";
350 $osupdcachedir = "$vepath/var/cache/yum/updates-released/packages/";
351 }
352} elsif ($pbos->{'install'} =~ /zypper/) {
353 $oscachedir = "$vepath/var/cache/zypp/packages/opensuse/suse/$pbos->{'arch'}";
354 $osupdname = "Zypper";
355} elsif ($pbos->{'install'} =~ /urpmi/) {
356 $oscachedir = "$vepath/var/cache/urpmi/rpms";
357 $osupdname = "URPMI";
358}
359pb_log(1,"Setting up $osupdname cache in VE\n");
360pb_mkdir_p($oscachedir);
361pb_mkdir_p($osupdcachedir) if (defined $osupdcachedir);
362
363# For each package to process, get it, put it in the cache dir
364# and extract it in the target dir. If not asked to keep, remove it
365# Just download if asked so.
366
367my $warning = 0;
368my $lwpkg ="";
369my @installed_packages;
370
371foreach my $p (split(/,/,$pkgs)) {
372 $p =~ s/\s+//go;
373 pb_log(1,"Processing package $p ...\n");
374 # Just print packages names if asked so.
375 if (defined $url{$p}) {
376 if ($opts{'p'}) {
377 pb_log(0,"$url{$p}\n");
378 next;
379 } else {
380 # Now download if not already in cache
381 my $p1 = basename($url{$p});
382 if (! -f "$cachedir/$p1") {
383 pb_system("wget --quiet -O $cachedir/$p1-new $url{$p}","Downloading package $p1 ...");
384 rename("$cachedir/$p1-new", "$cachedir/$p1") || die "mv $cachedir/$p1-new $cachedir/$p1 failed: $!";
385 } else {
386 pb_log(1,"Package $p1 already in cache\n");
387 }
388
389 # End if download only
390 if ($opts{'d'}) {
391 next;
392 }
393
394 #
395 # Copy the cached .RPM files into the oscachedir directory, so that os doesn't need to download them again.
396 #
397 pb_log(1,"Link package into $oscachedir\n");
398 copy("$cachedir/$p1",$oscachedir) if (defined $oscachedir);
399 symlink("$oscachedir/$p1","$osupdcachedir/p1") if (defined $osupdcachedir);
400
401 # And extract it to the finale dir
402 pb_system("cd $vepath ; rpm2cpio $cachedir/$p1 | cpio -ivdum","Extracting package $p1 into $vepath");
403
404 # Remove cached package if not asked to keep
405 if (! $opts{'k'}) {
406 unlink("$cachedir/$p1");
407 }
408 push(@installed_packages, $p);
409 }
410 } else {
411 pb_log(0,"WARNING: unable to find URL for $p\n");
412 $warning++;
413 $lwpkg .= " $p";
414 }
415}
416
417if ($warning ge 1) {
418pb_log(0,"$warning WARNINGS found.\nMaybe you should review your package list for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}\nand remove$lwpkg\n");
419}
420
421# Stop here if we just print
422if ($opts{'p'}) {
423 pb_exit(0);
424}
425
426# Now executes the VE finalization steps required for it to work correctly
427pb_log(0,"VE post configuration\n");
428
429# yum needs that distro-release package be installed, so force it
430if ($pbos->{'install'} =~ /yum/) {
431 my $ddir = $pbos->{'name'};
432 foreach my $p1 (<$cachedir/($ddir|redhat)-release-*.rpm>) {
433 copy("$cachedir/$p1","$vepath/tmp");
434 pb_system("chroot $vepath rpm -ivh --force --nodeps /tmp/$p1","Forcing RPM installation of $p1");
435 unlink("$vepath/tmp/$p1");
436 }
437# RedHat 6.2 has a buggy termcap setup and doesn't support usage of setarch, so still returns x86_64 in a chroot
438} elsif (($pbos->{'name'} =~ /redhat/) && ( $pbos->{'version'} =~ /^6/)) {
439 pb_system("chroot $vepath ldconfig","Forcing ldconfig on $pbos->{'name'} $pbos->{'version'}");
440 pb_system("chroot $vepath echo 'arch_canon: x86_64: x86_64 1' >> /etc/rpmrc","Forcing ldconfig on $pbos->{'name'} $pbos->{'version'}");
441 pb_system("chroot $vepath echo 'arch_compat: x86_64: i386' >> /etc/rpmrc","Forcing ldconfig on $pbos->{'name'} $pbos->{'version'}");
442 pb_system("chroot $vepath echo 'buildarch_compat: x86_64: i386' >> /etc/rpmrc","Forcing ldconfig on $pbos->{'name'} $pbos->{'version'}");
443 pb_system("chroot $vepath echo 'buildarchtranslate: x86_64: i386' >> /etc/rpmrc","Forcing ldconfig on $pbos->{'name'} $pbos->{'version'}");
444}
445#
446# Make sure there is a resolv.conf file present, such that DNS lookups succeed.
447#
448pb_log(1,"Creating resolv.conf\n");
449pb_mkdir_p("$vepath/etc");
450copy("/etc/resolv.conf","$vepath/etc/");
451
452#
453# BUGFIX:
454#
455if ((($pbos->{'name'} eq "centos") || ($pbos->{'name'} eq "rhel")) && ($pbos->{'version'} eq "5")) {
456 pb_log(1,"BUGFIX for centos-5\n");
457 pb_mkdir_p("$vepath/usr/lib/python2.4/site-packages/urlgrabber.skx");
458 foreach my $i (<$vepath/usr/lib/python2.4/site-packages/urlgrabber/keepalive.*>) {
459 move($i,"$vepath/usr/lib/python2.4/site-packages/urlgrabber.skx/");
460 }
461}
462
463#
464# /proc needed
465#
466pb_mkdir_p("$vepath/proc");
467pb_system("mount -o bind /proc $vepath/proc","Mounting /proc") unless (-d "$vepath/proc/$$");
468
469#
470# Some devices may be needed
471#
472pb_mkdir_p("$vepath/dev");
473chmod 0755,"$vepath/dev";
474pb_system("mknod -m 644 $vepath/dev/random c 1 8","Creating $vepath/dev/random") if (! -c "$vepath/dev/random");
475pb_system("mknod -m 644 $vepath/dev/urandom c 1 9","Creating $vepath/dev/urandom") if (! -c "$vepath/dev/urandom");
476pb_system("mknod -m 666 $vepath/dev/zero c 1 5","Creating $vepath/dev/zero") if (! -c "$vepath/dev/zero");
477pb_system("mknod -m 666 $vepath/dev/null c 1 3","Creating $vepath/dev/null") if (! -c "$vepath/dev/null");
478
479my $minipkglist;
480
481pb_log(1,"Adapting $osupdname repository entries\n");
482if ($pbos->{'install'} =~ /yum/) {
483 #
484 # Force the architecture for yum
485 # The goal is to allow i386 chroot on x86_64
486 #
487 # FIX: Not sufficient to have yum working
488 # mirrorlist is not usable
489 # $releasever also needs to be filtered
490 # yum.conf as well
491 foreach my $i (<$vepath/etc/yum.repos.d/*.repo>,"$vepath/etc/yum.conf") {
492 pb_system("sed -i -e 's/\$basearch/$pbos->{'arch'}/g' $i","","quiet");
493 pb_system("sed -i -e 's/\$releasever/$pbos->{'version'}/g' $i","","quiet");
494 pb_system("sed -i -e 's/^mirrorlist/#mirrorlist/' $i","","quiet");
495 # rather use neutral separators here
496 pb_system("sed -i -e 's|^#baseurl.*\$|baseurl=$mirror|' $i","","quiet");
497 }
498 $minipkglist = "ldconfig yum passwd vim-minimal dhclient authconfig";
499} elsif ($pbos->{'install'} =~ /zypper/) {
500 pb_mkdir_p("$vepath/etc/zypp/repos.d");
501 open(REPO,"> $vepath/etc/zypp/repos.d/$pbos->{'name'}-$pbos->{'version'}") || die "Unable to create repo file";
502 my $baseurl = dirname(dirname($mirror));
503 # Setup the repo
504 if ($pbos->{'version'} eq "10.2") {
505 pb_system("chroot $vepath /bin/bash -c \"yes | /usr/bin/zypper sa $baseurl $pbos->{'name'}-$pbos->{'version'}\"","Bootstrapping Zypper");
506 } else {
507 # don't care if remove fails if add succeeds.
508 pb_system("chroot $vepath /bin/bash -c \"/usr/bin/zypper rr $pbos->{'name'}-$pbos->{'version'}\"","Bootstrapping Zypper","mayfail");
509 pb_system("chroot $vepath /bin/bash -c \"/usr/bin/zypper ar $baseurl $pbos->{'name'}-$pbos->{'version'}\"","Bootstrapping Zypper");
510 }
511 #print REPO << "EOF";
512#[opensuse]
513#name=$pbos->{'name'}-$pbos->{'version'}
514#baseurl=$baseurl
515#enabled=1
516#gpgcheck=1
517#
518#EOF
519 close(REPO);
520 $minipkglist = "zypper aaa_base";
521 # TODO: Re-installing packages missing and necessary on opensuse 11.4 to get /etc/passwd created.
522} elsif ($pbos->{'install'} =~ /urpmi/) {
523 # Setup the repo
524 my $baseurl = dirname(dirname(dirname($mirror)));
525 pb_system("chroot $vepath /bin/bash -c \"urpmi.addmedia --distrib $baseurl\"","Bootstrapping URPMI");
526 # TODO here too ?
527 $minipkglist = "ldconfig urpmi passwd vim-minimal dhcp-client";
528} elsif ($pbos->{'install'} =~ /\/rpm/) {
529 opendir(CDIR,$cachedir) || die "Unable to open directory $cachedir: $!";
530 foreach my $p (@installed_packages) {
531 foreach my $f (readdir(CDIR)) {
532 # find an rpm package ref name-ver-tag.arch.rpm
533 next if ($f =~ /^\./);
534 if ($f =~ /^$p-([^-]+)-([^-]+)\.(noarch|$parch)\.rpm$/) {
535 # Copy it to the chroot and reference it
536 copy("$cachedir/$f","$vepath/var/cache");
537 $minipkglist .= " /var/cache/$f";
538 last;
539 }
540 }
541 rewinddir(CDIR);
542 }
543 closedir(CDIR);
544}
545
546#
547# Run "install the necessary modules".
548# No need for sudo here
549#
550$pbos->{'install'} =~ s/sudo//g;
551if (((defined $ENV{http_proxy}) && ($ENV{http_proxy} ne '')) || ((defined $ENV{ftp_proxy}) && ($ENV{ftp_proxy} ne ''))) {
552 if ($pbos->{'name'} eq "opensuse") {
553 # For opensuse 11.4 or 12.1 -- one of them didn't work with http_proxy or HTTP_PROXY set.
554 open(PROXY, "> $vepath/etc/sysconfig/proxy") || die "can't open $vepath/etc/sysconfig/proxy: $!";
555 print PROXY "HTTP_PROXY=$ENV{http_proxy}\n" if ((defined $ENV{http_proxy}) && ($ENV{http_proxy} ne ''));
556 print PROXY "FTP_PROXY=$ENV{ftp_proxy}\n" if ((defined $ENV{ftp_proxy}) && ($ENV{ftp_proxy} ne ''));
557 close(PROXY);
558 }
559}
560
561# Keep redhat variants from destroying nis domain on install
562#pb_system("chroot $vepath /bin/bash -e -c \"ln -snf /bin/true /bin/domainname\"");
563
564#if ($pbos->{'name'} =~ /fedora/i) { # hack to prevent fedora from destroying NIS settings on host
565# open (AUTH, ">$vepath/etc/pam.d/system-auth-ac") || die "unable to open $vepath/etc/pam.d/system-auth-ac for write: $!";
566# print AUTH "#pam_systemd -- will fix later in bootstrap\n";
567# close(AUTH);
568#}
569pb_system("chroot $vepath /bin/bash -c \"$pbos->{'install'} $minipkglist \"","Bootstrapping OS by running $pbos->{'install'} $minipkglist");
570
571# CentOS6 will replace the yum.repos.d files; oddly it will leave the yum.conf file alone and make the new one ".rpmnew"
572if (($pbos->{'name'} eq "centos") && ($pbos->{'version'} =~ /^6.*/)) {
573 pb_log(0,"Fixing $pbos->{'name'} $pbos->{'version'} bug for yum conf files");
574 foreach my $from (<$vepath/etc/yum.repos.d/*.rpmorig>) {
575 my $to = $from;
576 $to =~ s/.rpmorig$//;
577 pb_system("mv $from $to", "Recover $from");
578 }
579}
580
581#
582# make 'passwd' work.
583#
584pb_log(1,"Authfix\n");
585# TODO: Not generic enough to be done like that IMHO
586# In case it was changed during the install
587#pb_system("chroot $vepath /bin/bash -e -c \"ln -snf /bin/true /bin/domainname\"");
588pb_system("chroot $vepath /bin/bash -c \"if [ -x /usr/bin/authconfig ]; then /usr/bin/authconfig --enableshadow --update --nostart; fi\"","Calling authconfig");
589
590# Installed additional packages we were asked to
591if (defined $opts{'a'}) {
592 $opts{'a'} =~ s/,/ /g;
593 pb_system("chroot $vepath /bin/bash -c \"$pbos->{'install'} $opts{'a'} \"","Adding packages to OS by running $pbos->{'install'} $opts{'a'}");
594}
595
596#
597# Clean up
598#
599pb_log(1,"Cleaning up\n");
600if ($pbos->{'install'} =~ /yum/) {
601 pb_system("chroot $vepath /usr/bin/yum clean all","Cleaning yum");
602}
603pb_system("umount $vepath/proc","Unmounting /proc");
604find(\&unlink_old_conf, $vepath);
605
606# Executes post-install step if asked for
607if ($opts{'s'}) {
608 pb_system("$opts{'s'} $vepath","Executing the post-install script: $opts{'s'} $vepath");
609}
610
611if ($warning > 0) {
612 pb_log(0,"\n\n\n\n$warning WARNINGS found.\nMaybe you should review your package list for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}\nand remove$lwpkg\n");
613 pb_log(0,"waiting 60 seconds to give you a chance to notice.\n");
614 sleep(60);
615}
616
617pb_exit();
618
619# Function for File::Find
620sub unlink_old_conf {
621
622 unlink($_) if ($_ =~ /\.rpmorig$/);
623 unlink($_) if ($_ =~ /\.rpmnew$/);
624}
625
626# Function to store packages found on Web pages
627
628sub rbs_find_pkg {
629
630my $l = shift;
631my $parch = shift;
632my $type = shift;
633
634pb_log(2,"Entering rbs_find_pkg with l=$l and parch=$parch\n");
635# Find a href ref in first pos
636if ($l =~ /<a href="([^<>]*)">([^<>]*)<\/a>/i) {
637 my $pkg = $1;
638 my $desc = $2;
639 pb_log(3,"Found desc URL $desc: ");
640 # find an rpm package ref name-ver-tag.arch.rpm
641 if (($type eq "pkg") && ($pkg =~ /(.+)-([^-]+)-([^-]+)\.(noarch|$parch)\.rpm$/)) {
642 pb_log(3,"package ($1 + $2 + $3 + $4)\n");
643 my $url = $1;
644 pb_log(2,"Exiting rbs_find_pkg with url=$url and desc=$desc\n");
645 return($url,$desc);
646 } elsif (($type eq "dir") && ($pkg =~ /([0-z])\//)) {
647 my $url = $1;
648 pb_log(3,"dir ($1)\n");
649 return($url,$1);
650 } else {
651 pb_log(3,"not a package\n");
652 }
653}
654pb_log(2,"Exiting rbs_find_pkg with undef\n");
655return(undef,undef);
656}
657
658sub rbs_mirror_response {
659
660my $mirror = shift;
661
662pb_log(0,"Downloading package list from $mirror ...\n");
663my $response = $ua->get($mirror);
664if (! $response->is_success) {
665 if ($mirror =~ /i386/) {
666 # Some distro have an i586 or i686 mirror dir instead for i386
667 warn "Unable to download package from $mirror for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.".$response->status_line;
668 $mirror =~ s|/i386/|/i586/|;
669 pb_log(0,"Downloading now package list from $mirror ...\n");
670 $response = $ua->get($mirror);
671 if (! $response->is_success) {
672 die "Unable to download package from $mirror for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}".$response->status_line;
673 }
674 }
675}
676pb_log(3,"Mirror $mirror gave answer: ".Dumper($response->dump(maxlength => 0))."\n");
677
678# Try to find where the repodata structure is for later usage
679my $repo = $mirror;
680my $found = 0;
681if ($pbos->{'install'} =~ /yum/) {
682 my $response1;
683 while ($found == 0) {
684 $response1 = $ua->get("$repo/repodata");
685 pb_log(2,"REPO analyzed: $repo\n");
686 if (! $response1->is_success) {
687 $repo = dirname($repo);
688
689 # There is a limit to the loop, when / is reached and nothing found
690 my ($scheme, $account, $host, $port, $path) = pb_get_uri($repo);
691 die "Unable to find the repodata structure of the mirror $mirror\nPlease check the URL or warn the dev team.\n" if (($path =~ /^[\/]+$/) || ($path =~ /^$/));
692
693 # / not reached, so looping
694 next;
695 } else {
696 # repodata found $repo is correct
697 $found = 1;
698 pb_log(2,"REPO found: $repo\n");
699 last;
700 }
701 }
702}
703return($response);
704}
705
Note: See TracBrowser for help on using the repository browser.