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