[976] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # rpmbootstrap application, a debootstrap like for RPM distros
|
---|
| 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
| 7 | # Copyright B. Cornec 2010
|
---|
| 8 | # Provided under the GPL v2
|
---|
| 9 |
|
---|
| 10 | # Syntax: see at end
|
---|
| 11 |
|
---|
| 12 | use strict 'vars';
|
---|
| 13 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
| 14 | use Data::Dumper;
|
---|
| 15 | use English;
|
---|
| 16 | use LWP::UserAgent;
|
---|
[984] | 17 | use File::Basename;
|
---|
| 18 | use File::Copy;
|
---|
| 19 | use File::Find;
|
---|
[976] | 20 | use ProjectBuilder::Version;
|
---|
| 21 | use ProjectBuilder::Base;
|
---|
| 22 | use ProjectBuilder::Env;
|
---|
| 23 | use ProjectBuilder::Conf;
|
---|
| 24 | use ProjectBuilder::Distribution;
|
---|
| 25 |
|
---|
| 26 | # Global variables
|
---|
| 27 | my %opts; # CLI Options
|
---|
| 28 |
|
---|
| 29 | =pod
|
---|
| 30 |
|
---|
| 31 | =head1 NAME
|
---|
| 32 |
|
---|
| 33 | rpmbootstrap - creates a chrooted RPM based distribution a la debootstrap, aka Virtual Environment (VE)
|
---|
| 34 |
|
---|
| 35 | =head1 DESCRIPTION
|
---|
| 36 |
|
---|
[1082] | 37 | rpmbootstrap creates a chroot environment (Virtual Environment or VE)
|
---|
| 38 | with a minimal distribution in it, suited for building packages for example.
|
---|
| 39 | It's very much like debootstrap but for RPM based distribution.
|
---|
| 40 | It aims at supporting all distributions supported by project-builder.org
|
---|
| 41 | (RHEL, RH, Fedora, OpeSUSE, SLES, Mandriva, ...)
|
---|
[976] | 42 |
|
---|
[1082] | 43 | It is inspired by work done by Steve Kemp for rinse (http://www.steve.org.uk/),
|
---|
| 44 | and similar to mock, but fully integrated with project-builder.org
|
---|
| 45 | (which also supports rinse and mock).
|
---|
[976] | 46 |
|
---|
[1315] | 47 | rpmbootstrap works in 2 phases. The first one is used to download all
|
---|
| 48 | the required packages to have a working package management system in the
|
---|
| 49 | chroot working. This list of packages is stored in /etc/pb/pb.conf under
|
---|
| 50 | the rbsmindep parameter (aka rpmbootstrap minimal dependencies). Once the
|
---|
| 51 | packages have been downloaded from the mirror, they are extracted with
|
---|
| 52 | rpm2cpio. At that point you should be able to use yum on Fedora, urpmi
|
---|
| 53 | on Mandriva/Mageia and zypper on OpenSuSE.
|
---|
| 54 | The second phase uses exactly the previous mentioned tools to install
|
---|
| 55 | exactly the same package list to have a coherent RPM db at the end.
|
---|
| 56 |
|
---|
| 57 | rpmbootstrap has additional options to execute a post-install script
|
---|
| 58 | (-s) or to add packages (-a). Then pb can use the chroot to perform even
|
---|
| 59 | more actions in it.
|
---|
| 60 |
|
---|
[976] | 61 | =head1 SYNOPSIS
|
---|
| 62 |
|
---|
[991] | 63 | rpmbootstrap [-vhmqpdk][-s script][-i iso][-a pkg1[,pkg2,...]] distribution-version-arch [target-dir] [mirror [script]]
|
---|
[976] | 64 |
|
---|
[1082] | 65 | rpmbootstrap [--verbose][--help][--man][--quiet][--print-rpms][--download-only]
|
---|
| 66 | [--keep][--script script][--iso iso][--add pkg1,[pkg2,...]] distribution-version-arch [target-dir] [mirror [script]]
|
---|
[976] | 67 |
|
---|
| 68 | =head1 OPTIONS
|
---|
| 69 |
|
---|
| 70 | =over 4
|
---|
| 71 |
|
---|
| 72 | =item B<-v|--verbose>
|
---|
| 73 |
|
---|
| 74 | Print a brief help message and exits.
|
---|
| 75 |
|
---|
| 76 | =item B<-h|--help>
|
---|
| 77 |
|
---|
| 78 | Print a brief help message and exits.
|
---|
| 79 |
|
---|
| 80 | =item B<--man>
|
---|
| 81 |
|
---|
| 82 | Prints the manual page and exits.
|
---|
| 83 |
|
---|
| 84 | =item B<-q|--quiet>
|
---|
| 85 |
|
---|
| 86 | Do not print any output.
|
---|
| 87 |
|
---|
| 88 | =item B<-p|--print-rpms>
|
---|
| 89 |
|
---|
[1082] | 90 | Print the packages to be installed, and exit.
|
---|
| 91 | Note that a target directory must be specified so rpmbootstrap can determine
|
---|
| 92 | which packages should be installed, and to resolve dependencies.
|
---|
| 93 | The target directory will be deleted.
|
---|
[976] | 94 |
|
---|
| 95 | =item B<-d|--download-only>
|
---|
| 96 |
|
---|
| 97 | Download packages, but don't perform installation.
|
---|
| 98 |
|
---|
| 99 | =item B<-k|--keep>
|
---|
| 100 |
|
---|
| 101 | Keep packages in the cache dir for later reuse. By default remove them.
|
---|
| 102 |
|
---|
| 103 | =item B<-s|--script script>
|
---|
| 104 |
|
---|
| 105 | Name of the script you want to execute on the related VEs after the installation.
|
---|
[1082] | 106 | It is executed in host environment.
|
---|
| 107 | You can use the chroot command to execute actions in the VE.
|
---|
[976] | 108 |
|
---|
| 109 | =item B<-i|--iso iso_image>
|
---|
| 110 |
|
---|
| 111 | Name of the ISO image of the distribution you want to install on the related VE.
|
---|
| 112 |
|
---|
[991] | 113 | =item B<-a|--add pkg1[,pkg2,...]>
|
---|
| 114 |
|
---|
[1082] | 115 | Additional packages to add from the distribution you want to install on the related VE
|
---|
| 116 | at the end of the chroot build.
|
---|
[991] | 117 |
|
---|
[976] | 118 | =back
|
---|
| 119 |
|
---|
| 120 | =head1 ARGUMENTS
|
---|
| 121 |
|
---|
[1044] | 122 | =over 4
|
---|
| 123 |
|
---|
[976] | 124 | =item B<distribution-version-arch>
|
---|
| 125 |
|
---|
| 126 | Full name of the distribution that needs to be installed in the VE. E.g. fedora-11-x86_64.
|
---|
| 127 |
|
---|
| 128 | =item B<target-dir>
|
---|
| 129 |
|
---|
[1082] | 130 | This is the target directory under which the VE will be created.
|
---|
| 131 | Created on the fly if needed.
|
---|
| 132 | If none is given use the default directory hosting VE for project-builder.org
|
---|
| 133 | (Cf: vepath parameter in $HOME/.pbrc)
|
---|
[976] | 134 |
|
---|
[1044] | 135 | =back
|
---|
| 136 |
|
---|
[976] | 137 | =head1 EXAMPLE
|
---|
| 138 |
|
---|
| 139 | To setup a Fedora 12 distribution with an i386 architecture issue:
|
---|
| 140 |
|
---|
| 141 | rpmbootstrap fedora-12-i386 /tmp/fedora/12/i386
|
---|
| 142 |
|
---|
| 143 | =head1 WEB SITES
|
---|
| 144 |
|
---|
[1082] | 145 | The main Web site of the project is available at L<http://www.project-builder.org/>.
|
---|
| 146 | Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
|
---|
[976] | 147 |
|
---|
| 148 | =head1 USER MAILING LIST
|
---|
| 149 |
|
---|
[1082] | 150 | Cf: L<http://www.mondorescue.org/sympa/info/pb-announce> for announces and
|
---|
| 151 | L<http://www.mondorescue.org/sympa/info/pb-devel> for the development of the pb project.
|
---|
[976] | 152 |
|
---|
| 153 | =head1 CONFIGURATION FILE
|
---|
| 154 |
|
---|
| 155 | Uses Project-Builder.org configuration file (/etc/pb/pb.conf or /usr/local/etc/pb/pb.conf)
|
---|
| 156 |
|
---|
| 157 | =head1 AUTHORS
|
---|
| 158 |
|
---|
| 159 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 160 |
|
---|
| 161 | =head1 COPYRIGHT
|
---|
| 162 |
|
---|
| 163 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 164 | described in the file C<COPYING> included with the distribution.
|
---|
| 165 |
|
---|
| 166 | =cut
|
---|
| 167 |
|
---|
| 168 | # ---------------------------------------------------------------------------
|
---|
| 169 |
|
---|
| 170 | my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
|
---|
| 171 | my $appname = "rpmbootstrap";
|
---|
[983] | 172 | $ENV{'PBPROJ'} = $appname;
|
---|
[976] | 173 |
|
---|
| 174 | # Initialize the syntax string
|
---|
| 175 |
|
---|
| 176 | pb_syntax_init("$appname Version $projectbuilderver-$projectbuilderrev\n");
|
---|
[984] | 177 | pb_temp_init();
|
---|
[976] | 178 |
|
---|
| 179 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
[1177] | 180 | "man|m" => \$opts{'man'},
|
---|
| 181 | "verbose|v+" => \$opts{'v'},
|
---|
| 182 | "quiet|q" => \$opts{'q'},
|
---|
| 183 | "log-files|l=s" => \$opts{'l'},
|
---|
| 184 | "script|s=s" => \$opts{'s'},
|
---|
| 185 | "print-rpms|p" => \$opts{'p'},
|
---|
| 186 | "download-only|d" => \$opts{'d'},
|
---|
| 187 | "keep|k" => \$opts{'k'},
|
---|
| 188 | "iso|i=s" => \$opts{'i'},
|
---|
| 189 | "add|a=s" => \$opts{'a'},
|
---|
| 190 | "version|V=s" => \$opts{'V'},
|
---|
[976] | 191 | ) || pb_syntax(-1,0);
|
---|
| 192 |
|
---|
| 193 | if (defined $opts{'h'}) {
|
---|
| 194 | pb_syntax(0,1);
|
---|
| 195 | }
|
---|
| 196 | if (defined $opts{'man'}) {
|
---|
| 197 | pb_syntax(0,2);
|
---|
| 198 | }
|
---|
| 199 | if (defined $opts{'v'}) {
|
---|
| 200 | $pbdebug = $opts{'v'};
|
---|
| 201 | }
|
---|
| 202 | if (defined $opts{'q'}) {
|
---|
| 203 | $pbdebug=-1;
|
---|
| 204 | }
|
---|
| 205 | if (defined $opts{'l'}) {
|
---|
| 206 | open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
|
---|
| 207 | $pbLOG = \*pbLOG;
|
---|
| 208 | $pbdebug = 0 if ($pbdebug == -1);
|
---|
[1177] | 209 | }
|
---|
[976] | 210 | pb_log_init($pbdebug, $pbLOG);
|
---|
[981] | 211 | #pb_display_init("text","");
|
---|
[976] | 212 |
|
---|
[981] | 213 | #if (defined $opts{'s'}) {
|
---|
| 214 | #$pbscript = $opts{'s'};
|
---|
| 215 | #}
|
---|
| 216 | #if (defined $opts{'i'}) {
|
---|
| 217 | #$iso = $opts{'i'};
|
---|
| 218 | #}
|
---|
[976] | 219 |
|
---|
| 220 | # Get VE name
|
---|
| 221 | $ENV{'PBV'} = shift @ARGV;
|
---|
| 222 | die pb_syntax(-1,1) if (not defined $ENV{'PBV'});
|
---|
| 223 |
|
---|
| 224 | die "Needs to be run as root" if ($EFFECTIVE_USER_ID != 0);
|
---|
| 225 |
|
---|
| 226 | #
|
---|
| 227 | # Initialize distribution info from pb conf file
|
---|
| 228 | #
|
---|
[984] | 229 | pb_log(0,"Starting VE build for $ENV{'PBV'}\n");
|
---|
[1177] | 230 | my $pbos = pb_distro_get_context($ENV{'PBV'});
|
---|
[976] | 231 |
|
---|
| 232 | #
|
---|
| 233 | # Check target dir
|
---|
| 234 | # Create if not existent and use default if none given
|
---|
| 235 | #
|
---|
| 236 | pb_env_init_pbrc(); # to get content of HOME/.pbrc
|
---|
| 237 | my $vepath = shift @ARGV;
|
---|
| 238 |
|
---|
[982] | 239 | #
|
---|
| 240 | # Check for command requirements
|
---|
| 241 | #
|
---|
| 242 | my ($req,$opt) = pb_conf_get_if("oscmd","oscmdopt");
|
---|
[1128] | 243 | pb_check_requirements($req,$opt,$appname);
|
---|
[982] | 244 |
|
---|
[976] | 245 | if (not defined $vepath) {
|
---|
[1181] | 246 | my ($vestdpath) = pb_conf_get("vepath");
|
---|
| 247 | $vepath = "$vestdpath->{'default'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}" if (defined $vestdpath->{'default'});
|
---|
[976] | 248 | }
|
---|
| 249 |
|
---|
[981] | 250 | die pb_log(0,"No target-dir specified and no default vepath found in $ENV{'PBETC'}\n") if (not defined $vepath);
|
---|
[976] | 251 |
|
---|
| 252 | pb_mkdir_p($vepath) if (! -d $vepath);
|
---|
| 253 |
|
---|
| 254 | #
|
---|
| 255 | # Get the package list to download, store them in a cache directory
|
---|
| 256 | #
|
---|
| 257 | my ($rbscachedir) = pb_conf_get_if("rbscachedir");
|
---|
[1181] | 258 | my ($pkgs,$mirror) = pb_distro_get_param($pbos,pb_conf_get("rbsmindep","rbsmirrorsrv"));
|
---|
[976] | 259 |
|
---|
| 260 | my $cachedir = "/var/cache/rpmbootstrap";
|
---|
| 261 | $cachedir = $rbscachedir->{'default'} if (defined $rbscachedir->{'default'});
|
---|
| 262 |
|
---|
| 263 | # Point to the right subdir and create it if needed
|
---|
[1177] | 264 | $cachedir .= "/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
[976] | 265 | pb_mkdir_p($cachedir) if (! -d $cachedir);
|
---|
| 266 |
|
---|
| 267 | # Get the complete package name from the mirror
|
---|
| 268 | #
|
---|
| 269 | my $ua = LWP::UserAgent->new;
|
---|
| 270 | $ua->timeout(10);
|
---|
| 271 | $ua->env_proxy;
|
---|
| 272 |
|
---|
[1314] | 273 | die "No mirror defined for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}" if ((not defined $mirror) || ($mirror =~ /^\t*$/));
|
---|
[984] | 274 | pb_log(0,"Downloading package list from $mirror ...\n");
|
---|
[976] | 275 | my $response = $ua->get($mirror);
|
---|
| 276 | if (! $response->is_success) {
|
---|
[992] | 277 | if ($mirror =~ /i386/) {
|
---|
| 278 | # Some distro have an i586 or i686 mirror dir instead for i386
|
---|
[1177] | 279 | warn "Unable to download packages from $mirror for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.";
|
---|
[992] | 280 | $mirror =~ s|/i386/|/i586/|;
|
---|
| 281 | $response = $ua->get($mirror);
|
---|
| 282 | if (! $response->is_success) {
|
---|
[1177] | 283 | die "Unable to download packages from $mirror for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
[992] | 284 | }
|
---|
| 285 | }
|
---|
[976] | 286 | }
|
---|
[983] | 287 | pb_log(3,"Mirror $mirror gave answer: ".Dumper($response->dump(maxlength => 0))."\n");
|
---|
[976] | 288 |
|
---|
[1031] | 289 | # Try to find where the repodata structure is for later usage
|
---|
| 290 | my $repo = $mirror;
|
---|
| 291 | my $found = 0;
|
---|
[1177] | 292 | if ($pbos->{'install'} =~ /yum/) {
|
---|
[1031] | 293 | my $response1;
|
---|
| 294 | while ($found == 0) {
|
---|
| 295 | $response1 = $ua->get("$repo/repodata");
|
---|
[1253] | 296 | pb_log(2,"REPO analyzed: $repo\n");
|
---|
[1031] | 297 | if (! $response1->is_success) {
|
---|
| 298 | $repo = dirname($repo);
|
---|
| 299 |
|
---|
| 300 | # There is a limit to the loop, when / is reached and nothing found
|
---|
| 301 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($repo);
|
---|
[1253] | 302 | die "Unable to find the repodata structure of the mirror $mirror\nPlease check the URL or warn the dev team.\n" if (($path =~ /^[\/]+$/) || ($path =~ /^$/));
|
---|
[1177] | 303 |
|
---|
[1031] | 304 | # / not reached, so looping
|
---|
| 305 | next;
|
---|
| 306 | } else {
|
---|
| 307 | # repodata found $repo is correct
|
---|
| 308 | $found = 1;
|
---|
[1253] | 309 | pb_log(2,"REPO found: $repo\n");
|
---|
[1031] | 310 | last;
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | }
|
---|
| 314 |
|
---|
[983] | 315 | # Manages architectures specificities
|
---|
[1177] | 316 | my $parch = $pbos->{'arch'};
|
---|
| 317 | $parch = "i[3456]86" if ($pbos->{'arch'} eq "i386");
|
---|
[983] | 318 |
|
---|
| 319 | # Get the list of packages and their URL in this hash
|
---|
| 320 | my %url;
|
---|
| 321 | foreach my $l (split(/\n/,$response->as_string())) {
|
---|
| 322 | # Find a href ref
|
---|
| 323 | if ($l =~ /<a href="(.*)">(.*)<\/a>/i) {
|
---|
| 324 | my $url = $1;
|
---|
| 325 | my $pkg = $1;
|
---|
| 326 | my $desc = $2;
|
---|
| 327 | pb_log(3,"Found desc URL $desc: ");
|
---|
| 328 | # find an rpm package ref name-ver-tag.arch.rpm
|
---|
| 329 | if ($pkg =~ /(.+)-([^-]+)-([^-]+)\.(noarch|$parch)\.rpm$/) {
|
---|
| 330 | pb_log(3,"package ($1 + $2 + $3 + $4)\n");
|
---|
| 331 | $url{$1} = "$mirror/$url";
|
---|
| 332 | } else {
|
---|
| 333 | pb_log(3,"not a package\n");
|
---|
| 334 | }
|
---|
| 335 | }
|
---|
[976] | 336 | }
|
---|
| 337 |
|
---|
[984] | 338 | #
|
---|
| 339 | # Prepare early the yum cache env for the VE in order to copy in it packages on the fly
|
---|
| 340 | #
|
---|
[990] | 341 | my $oscachedir = "/tmp";
|
---|
| 342 | my $osupdcachedir;
|
---|
| 343 | my $osupdname = "";
|
---|
| 344 |
|
---|
[1177] | 345 | if ($pbos->{'install'} =~ /yum/) {
|
---|
[990] | 346 | $oscachedir = "$vepath/var/cache/yum/core/packages/";
|
---|
| 347 | $osupdcachedir = "$vepath/var/cache/yum/updates-released/packages/";
|
---|
| 348 | $osupdname = "YUM";
|
---|
| 349 | # Recent Fedora release use a new yum cache dir
|
---|
[1177] | 350 | if (($pbos->{'name'} eq "fedora") && ($pbos->{'version'} > 8)) {
|
---|
| 351 | $oscachedir = "$vepath/var/cache/yum/$pbos->{'arch'}/$pbos->{'version'}/fedora/packages";
|
---|
| 352 | $osupdcachedir = "$vepath/var/cache/yum/$pbos->{'arch'}/$pbos->{'version'}/updates/packages";
|
---|
[990] | 353 | $osupdcachedir = "$vepath/var/cache/yum/updates-released/packages/";
|
---|
| 354 | }
|
---|
[1177] | 355 | } elsif ($pbos->{'install'} =~ /zypper/) {
|
---|
| 356 | $oscachedir = "$vepath/var/cache/zypp/packages/opensuse/suse/$pbos->{'arch'}";
|
---|
[990] | 357 | $osupdname = "Zypper";
|
---|
[1177] | 358 | } elsif ($pbos->{'install'} =~ /urpmi/) {
|
---|
[992] | 359 | $oscachedir = "$vepath/var/cache/urpmi/rpms";
|
---|
| 360 | $osupdname = "URPMI";
|
---|
[984] | 361 | }
|
---|
[991] | 362 | pb_log(1,"Setting up $osupdname cache in VE\n");
|
---|
[990] | 363 | pb_mkdir_p($oscachedir);
|
---|
| 364 | pb_mkdir_p($osupdcachedir) if (defined $osupdcachedir);
|
---|
[983] | 365 |
|
---|
[976] | 366 | # For each package to process, get it, put it in the cache dir
|
---|
| 367 | # and extract it in the target dir. If not asked to keep, remove it
|
---|
| 368 | # Just download if asked so.
|
---|
| 369 |
|
---|
[983] | 370 | my $warning = 0;
|
---|
| 371 | my $lwpkg ="";
|
---|
[981] | 372 | foreach my $p (split(/,/,$pkgs)) {
|
---|
[983] | 373 | pb_log(1,"Processing package $p ...\n");
|
---|
| 374 | # Just print packages names if asked so.
|
---|
[984] | 375 | if (defined $url{$p}) {
|
---|
| 376 | if ($opts{'p'}) {
|
---|
[983] | 377 | pb_log(0,"$url{$p}\n");
|
---|
[984] | 378 | next;
|
---|
[983] | 379 | } else {
|
---|
[984] | 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 $url{$p}","Downloading package $p1 ...");
|
---|
| 384 | } else {
|
---|
| 385 | pb_log(1,"Package $p1 already in cache\n");
|
---|
| 386 | }
|
---|
[1177] | 387 |
|
---|
[984] | 388 | # End if download only
|
---|
| 389 | if ($opts{'d'}) {
|
---|
| 390 | next;
|
---|
| 391 | }
|
---|
[1177] | 392 |
|
---|
[984] | 393 | #
|
---|
[990] | 394 | # Copy the cached .RPM files into the oscachedir directory, so that os doesn't need to download them again.
|
---|
[984] | 395 | #
|
---|
[990] | 396 | pb_log(1,"Link package into $oscachedir\n");
|
---|
[1177] | 397 | copy("$cachedir/$p1",$oscachedir) if (defined $oscachedir);
|
---|
| 398 | symlink("$oscachedir/$p1","$osupdcachedir/p1") if (defined $osupdcachedir);
|
---|
[984] | 399 |
|
---|
| 400 | # And extract it to the finale dir
|
---|
| 401 | pb_system("cd $vepath ; rpm2cpio $cachedir/$p1 | cpio -ivdum","Extracting package $p1 into $vepath");
|
---|
[1177] | 402 |
|
---|
[984] | 403 | # Remove cached package if not asked to keep
|
---|
| 404 | if (! $opts{'k'}) {
|
---|
| 405 | unlink("$cachedir/$p1");
|
---|
| 406 | }
|
---|
[1177] | 407 |
|
---|
[983] | 408 | }
|
---|
[984] | 409 | } else {
|
---|
| 410 | pb_log(0,"WARNING: unable to find URL for $p\n");
|
---|
| 411 | $warning++;
|
---|
| 412 | $lwpkg .= " $p";
|
---|
[976] | 413 | }
|
---|
[983] | 414 | }
|
---|
| 415 |
|
---|
| 416 | if ($warning ge 1) {
|
---|
[1177] | 417 | pb_log(0,"$warning WARNINGS found.\nMaybe you should review your package list for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}\nand remove$lwpkg\n");
|
---|
[983] | 418 | }
|
---|
| 419 |
|
---|
[984] | 420 | # Stop here if we just print
|
---|
[983] | 421 | if ($opts{'p'}) {
|
---|
| 422 | exit(0);
|
---|
| 423 | }
|
---|
[984] | 424 |
|
---|
| 425 | # Now executes the VE finalization steps required for it to work correctly
|
---|
| 426 | pb_log(0,"VE post configuration\n");
|
---|
| 427 |
|
---|
| 428 | # yum needs that distro-release package be installed, so force it
|
---|
[1177] | 429 | if ($pbos->{'install'} =~ /yum/) {
|
---|
| 430 | my $ddir = $pbos->{'name'};
|
---|
[990] | 431 | foreach my $p1 (<$cachedir/($ddir|redhat)-release-*.rpm>) {
|
---|
| 432 | copy("$cachedir/$p1","$vepath/tmp");
|
---|
| 433 | pb_system("chroot $vepath rpm -ivh --force --nodeps /tmp/$p1","Forcing RPM installation of $p1");
|
---|
| 434 | unlink("$vepath/tmp/$p1");
|
---|
| 435 | }
|
---|
[984] | 436 | }
|
---|
| 437 | #
|
---|
| 438 | # Make sure there is a resolv.conf file present, such that DNS lookups succeed.
|
---|
| 439 | #
|
---|
| 440 | pb_log(1,"Creating resolv.conf\n");
|
---|
| 441 | pb_mkdir_p("$vepath/etc");
|
---|
| 442 | copy("/etc/resolv.conf","$vepath/etc/");
|
---|
| 443 |
|
---|
| 444 | #
|
---|
| 445 | # BUGFIX:
|
---|
| 446 | #
|
---|
[1177] | 447 | if ((($pbos->{'name'} eq "centos") || ($pbos->{'name'} eq "rhel")) && ($pbos->{'version'} eq "5")) {
|
---|
[984] | 448 | pb_log(1,"BUGFIX for centos-5\n");
|
---|
| 449 | pb_mkdir_p("$vepath/usr/lib/python2.4/site-packages/urlgrabber.skx");
|
---|
| 450 | foreach my $i (<$vepath/usr/lib/python2.4/site-packages/urlgrabber/keepalive.*>) {
|
---|
| 451 | move($i,"$vepath/usr/lib/python2.4/site-packages/urlgrabber.skx/");
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | #
|
---|
| 456 | # /proc needed
|
---|
| 457 | #
|
---|
| 458 | pb_mkdir_p("$vepath/proc");
|
---|
| 459 | pb_system("mount -o bind /proc $vepath/proc","Mounting /proc");
|
---|
| 460 |
|
---|
| 461 | #
|
---|
| 462 | # Some devices may be needed
|
---|
| 463 | #
|
---|
[992] | 464 | pb_mkdir_p("$vepath/dev");
|
---|
[1029] | 465 | chmod 0755,"$vepath/dev";
|
---|
[984] | 466 | pb_system("mknod -m 644 $vepath/dev/random c 1 8","Creating $vepath/dev/random") if (! -c "$vepath/dev/random");
|
---|
| 467 | pb_system("mknod -m 644 $vepath/dev/urandom c 1 9","Creating $vepath/dev/urandom") if (! -c "$vepath/dev/urandom");
|
---|
| 468 | pb_system("mknod -m 666 $vepath/dev/zero c 1 5","Creating $vepath/dev/zero") if (! -c "$vepath/dev/zero");
|
---|
[1309] | 469 | pb_system("mknod -m 666 $vepath/dev/null c 1 3","Creating $vepath/dev/null") if (! -c "$vepath/dev/null");
|
---|
[984] | 470 |
|
---|
[990] | 471 | my $minipkglist;
|
---|
| 472 |
|
---|
[1027] | 473 | pb_log(1,"Adapting $osupdname repository entries\n");
|
---|
[1177] | 474 | if ($pbos->{'install'} =~ /yum/) {
|
---|
[984] | 475 | #
|
---|
| 476 | # Force the architecture for yum
|
---|
| 477 | # The goal is to allow i386 chroot on x86_64
|
---|
| 478 | #
|
---|
| 479 | # FIX: Not sufficient to have yum working
|
---|
| 480 | # mirrorlist is not usable
|
---|
| 481 | # $releasever also needs to be filtered
|
---|
| 482 | # yum.conf as well
|
---|
| 483 | foreach my $i (<$vepath/etc/yum.repos.d/*>,"$vepath/etc/yum.conf") {
|
---|
[1177] | 484 | pb_system("sed -i -e 's/\$basearch/$pbos->{'arch'}/g' $i","","quiet");
|
---|
| 485 | pb_system("sed -i -e 's/\$releasever/$pbos->{'version'}/g' $i","","quiet");
|
---|
[984] | 486 | pb_system("sed -i -e 's/^mirrorlist/#mirrorlist/' $i","","quiet");
|
---|
[1015] | 487 | # rather use neutral separators here
|
---|
[1031] | 488 | pb_system("sed -i -e 's|^#baseurl.*\$|baseurl=$repo|' $i","","quiet");
|
---|
[984] | 489 | }
|
---|
[990] | 490 | $minipkglist = "ldconfig yum passwd vim-minimal dhclient authconfig";
|
---|
[1177] | 491 | } elsif ($pbos->{'install'} =~ /zypper/) {
|
---|
[990] | 492 | pb_mkdir_p("$vepath/etc/zypp/repos.d");
|
---|
[1177] | 493 | open(REPO,"> $vepath/etc/zypp/repos.d/$pbos->{'name'}-$pbos->{'version'}") || die "Unable to create repo file";
|
---|
[990] | 494 | my $baseurl = dirname(dirname($mirror));
|
---|
[992] | 495 | # Setup the repo
|
---|
[1177] | 496 | if ($pbos->{'version'} eq "10.2") {
|
---|
| 497 | pb_system("chroot $vepath /bin/bash -c \"yes | /usr/bin/zypper sa $baseurl $pbos->{'name'}-$pbos->{'version'}\"","Bootstrapping Zypper");
|
---|
[1299] | 498 | } else {
|
---|
| 499 | pb_system("chroot $vepath /bin/bash -c \"/usr/bin/zypper ar $baseurl $pbos->{'name'}-$pbos->{'version'}\"","Bootstrapping Zypper");
|
---|
[990] | 500 | }
|
---|
[1299] | 501 | #print REPO << "EOF";
|
---|
| 502 | #[opensuse]
|
---|
| 503 | #name=$pbos->{'name'}-$pbos->{'version'}
|
---|
| 504 | #baseurl=$baseurl
|
---|
| 505 | #enabled=1
|
---|
| 506 | #gpgcheck=1
|
---|
| 507 | #
|
---|
| 508 | #EOF
|
---|
| 509 | close(REPO);
|
---|
| 510 | $minipkglist = "zypper";
|
---|
[1177] | 511 | } elsif ($pbos->{'install'} =~ /urpmi/) {
|
---|
[992] | 512 | # Setup the repo
|
---|
[993] | 513 | my $baseurl = dirname(dirname(dirname($mirror)));
|
---|
| 514 | pb_system("chroot $vepath /bin/bash -c \"urpmi.addmedia --distrib $baseurl\"","Bootstrapping URPMI");
|
---|
| 515 | $minipkglist = "ldconfig urpmi passwd vim-minimal dhcp-client";
|
---|
[984] | 516 | }
|
---|
| 517 |
|
---|
| 518 | #
|
---|
[990] | 519 | # Run "install the necessary modules".
|
---|
| 520 | # No need for sudo here
|
---|
| 521 | #
|
---|
[1177] | 522 | $pbos->{'install'} =~ s/sudo//g;
|
---|
| 523 | pb_system("chroot $vepath /bin/bash -c \"$pbos->{'install'} $minipkglist \"","Bootstrapping OS by running $pbos->{'install'} $minipkglist");
|
---|
[990] | 524 |
|
---|
| 525 | #
|
---|
[984] | 526 | # make 'passwd' work.
|
---|
| 527 | #
|
---|
| 528 | pb_log(1,"Authfix\n");
|
---|
| 529 | pb_system("chroot $vepath /bin/bash -c \"if [ -x /usr/bin/authconfig ]; then /usr/bin/authconfig --enableshadow --update; fi\"","Calling authconfig");
|
---|
| 530 |
|
---|
[991] | 531 | # Installed additional packages we were asked to
|
---|
| 532 | if (defined $opts{'a'}) {
|
---|
| 533 | $opts{'a'} =~ s/,/ /g;
|
---|
[1177] | 534 | pb_system("chroot $vepath /bin/bash -c \"$pbos->{'install'} $opts{'a'} \"","Adding packages to OS by running $pbos->{'install'} $opts{'a'}");
|
---|
[991] | 535 | }
|
---|
| 536 |
|
---|
[984] | 537 | #
|
---|
| 538 | # Clean up
|
---|
| 539 | #
|
---|
| 540 | pb_log(1,"Cleaning up\n");
|
---|
[1177] | 541 | if ($pbos->{'install'} =~ /yum/) {
|
---|
[984] | 542 | pb_system("chroot $vepath /usr/bin/yum clean all","Cleaning yum");
|
---|
| 543 | }
|
---|
| 544 | pb_system("umount $vepath/proc","Unmounting /proc");
|
---|
| 545 | find(\&unlink_old_conf, $vepath);
|
---|
| 546 |
|
---|
| 547 | # Executes post-install step if asked for
|
---|
| 548 | if ($opts{'s'}) {
|
---|
| 549 | pb_system("$opts{'s'} $vepath","Executing the post-install script: $opts{'s'} $vepath");
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | # Function for File::Find
|
---|
| 553 | sub unlink_old_conf {
|
---|
| 554 |
|
---|
| 555 | unlink($_) if ($_ =~ /\.rpmorig$/);
|
---|
| 556 | unlink($_) if ($_ =~ /\.rpmnew$/);
|
---|
| 557 | }
|
---|