Changeset 1177 for devel/rpmbootstrap


Ignore:
Timestamp:
Feb 7, 2011, 2:24:17 PM (7 years ago)
Author:
bruno
Message:

r4161@eelzbach2: bruno | 2011-02-06 21:07:30 +0100

  • Introduction of a new hash $pbos to manage all os related info through a single data structure. All functions reviewed accordingly. Externally transparent, hopefully, but much cleaner code as a consequence. VM/VE/RM remains to be tested.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/rpmbootstrap/bin/rpmbootstrap

    r1128 r1177  
    164164
    165165GetOptions("help|?|h" => \$opts{'h'},
    166         "man|m" => \$opts{'man'},
    167         "verbose|v+" => \$opts{'v'},
    168         "quiet|q" => \$opts{'q'},
    169         "log-files|l=s" => \$opts{'l'},
    170         "script|s=s" => \$opts{'s'},
    171         "print-rpms|p" => \$opts{'p'},
    172         "download-only|d" => \$opts{'d'},
    173         "keep|k" => \$opts{'k'},
    174         "iso|i=s" => \$opts{'i'},
    175         "add|a=s" => \$opts{'a'},
    176         "version|V=s" => \$opts{'V'},
     166    "man|m" => \$opts{'man'},
     167    "verbose|v+" => \$opts{'v'},
     168    "quiet|q" => \$opts{'q'},
     169    "log-files|l=s" => \$opts{'l'},
     170    "script|s=s" => \$opts{'s'},
     171    "print-rpms|p" => \$opts{'p'},
     172    "download-only|d" => \$opts{'d'},
     173    "keep|k" => \$opts{'k'},
     174    "iso|i=s" => \$opts{'i'},
     175    "add|a=s" => \$opts{'a'},
     176    "version|V=s" => \$opts{'V'},
    177177) || pb_syntax(-1,0);
    178178
     
    193193    $pbLOG = \*pbLOG;
    194194    $pbdebug = 0  if ($pbdebug == -1);
    195     }
     195}
    196196pb_log_init($pbdebug, $pbLOG);
    197197#pb_display_init("text","");
     
    214214#
    215215pb_log(0,"Starting VE build for $ENV{'PBV'}\n");
    216 my ($name,$ver,$darch) = split(/-/,$ENV{'PBV'});
    217 chomp($darch);
    218 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins) = pb_distro_init($name,$ver,$darch);
     216my $pbos = pb_distro_get_context($ENV{'PBV'});
    219217
    220218#
     
    233231if (not defined $vepath) {
    234232    my ($vestdpath) = pb_conf_get_if("vepath");
    235     $vepath = "$vestdpath->{'default'}/$ddir/$dver/$darch";
     233    $vepath = "$vestdpath->{'default'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}";
    236234}
    237235
     
    243241# Get the package list to download, store them in a cache directory
    244242#
    245 my ($rbsmindep,$rbsmirrorsrv) = pb_conf_get("rbsmindep","rbsmirrorsrv");
    246243my ($rbscachedir) = pb_conf_get_if("rbscachedir");
    247 my $pkgs = pb_distro_get_param($ddir,$dver,$darch,$rbsmindep);
    248 my $mirror = pb_distro_get_param($ddir,$dver,$darch,$rbsmirrorsrv);
     244my ($pkgs,$mirror) = pb_distro_get_param($pbos->{'name'},$pbos->{'version'},$pbos->{'arch'},pb_conf_get("rbsmindep","rbsmirrorsrv"));
    249245
    250246my $cachedir = "/var/cache/rpmbootstrap";
     
    252248
    253249# Point to the right subdir and create it if needed
    254 $cachedir .= "/$ddir-$dver-$darch";
     250$cachedir .= "/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
    255251pb_mkdir_p($cachedir) if (! -d $cachedir);
    256252
     
    266262    if ($mirror =~ /i386/) {
    267263        # Some distro have an i586 or i686 mirror dir instead for i386
    268         warn "Unable to download packages from $mirror for $ddir-$dver-$darch.";
     264        warn "Unable to download packages from $mirror for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.";
    269265        $mirror =~ s|/i386/|/i586/|;
    270266        $response = $ua->get($mirror);
    271267        if (! $response->is_success) {
    272             die "Unable to download packages from $mirror for $ddir-$dver-$darch";
     268            die "Unable to download packages from $mirror for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
    273269        }
    274270    }
     
    279275my $repo = $mirror;
    280276my $found = 0;
    281 if ($pbins =~ /yum/) {
     277if ($pbos->{'install'} =~ /yum/) {
    282278    my $response1;
    283279    while ($found == 0) {
     
    290286            my ($scheme, $account, $host, $port, $path) = pb_get_uri($repo);
    291287            die "Unable to find the repodata structure of the mirror $mirror\nPlease check the URL or warn the dev team.\n" if ($path =~ /^[\/]+$/);
    292            
     288       
    293289            # / not reached, so looping
    294290            next;
     
    302298
    303299# Manages architectures specificities
    304 my $parch = $darch;
    305 $parch = "i[3456]86" if ($darch eq "i386");
     300my $parch = $pbos->{'arch'};
     301$parch = "i[3456]86" if ($pbos->{'arch'} eq "i386");
    306302
    307303# Get the list of packages and their URL in this hash
     
    331327my $osupdname = "";
    332328
    333 if ($pbins =~ /yum/) {
     329if ($pbos->{'install'} =~ /yum/) {
    334330    $oscachedir = "$vepath/var/cache/yum/core/packages/";
    335331    $osupdcachedir = "$vepath/var/cache/yum/updates-released/packages/";
    336332    $osupdname = "YUM";
    337333    # Recent Fedora release use a new yum cache dir
    338     if (($ddir eq "fedora") && ($dver > 8)) {
    339         $oscachedir = "$vepath/var/cache/yum/$darch/$dver/fedora/packages";
    340         $osupdcachedir = "$vepath/var/cache/yum/$darch/$dver/updates/packages";
     334    if (($pbos->{'name'} eq "fedora") && ($pbos->{'version'} > 8)) {
     335        $oscachedir = "$vepath/var/cache/yum/$pbos->{'arch'}/$pbos->{'version'}/fedora/packages";
     336        $osupdcachedir = "$vepath/var/cache/yum/$pbos->{'arch'}/$pbos->{'version'}/updates/packages";
    341337        $osupdcachedir = "$vepath/var/cache/yum/updates-released/packages/";
    342338    }
    343 } elsif ($pbins =~ /zypper/) {
    344     $oscachedir = "$vepath/var/cache/zypp/packages/opensuse/suse/$darch";
     339} elsif ($pbos->{'install'} =~ /zypper/) {
     340    $oscachedir = "$vepath/var/cache/zypp/packages/opensuse/suse/$pbos->{'arch'}";
    345341    $osupdname = "Zypper";
    346 } elsif ($pbins =~ /urpmi/) {
     342} elsif ($pbos->{'install'} =~ /urpmi/) {
    347343    $oscachedir = "$vepath/var/cache/urpmi/rpms";
    348344    $osupdname = "URPMI";
     
    373369                pb_log(1,"Package $p1 already in cache\n");
    374370            }
    375            
     371       
    376372            # End if download only
    377373            if ($opts{'d'}) {
    378374                next;
    379375            }
    380 
     376   
    381377            #
    382378            # Copy the cached .RPM files into the oscachedir directory, so that os doesn't need to download them again.
    383379            #
    384380            pb_log(1,"Link package into $oscachedir\n");
    385             copy("$cachedir/$p1",$oscachedir) if (defined $oscachedir);
    386             symlink("$oscachedir/$p1","$osupdcachedir/p1") if (defined $osupdcachedir);
     381            copy("$cachedir/$p1",$oscachedir) if (defined $oscachedir);
     382            symlink("$oscachedir/$p1","$osupdcachedir/p1") if (defined $osupdcachedir);
    387383
    388384            # And extract it to the finale dir
    389385            pb_system("cd $vepath ; rpm2cpio $cachedir/$p1 | cpio -ivdum","Extracting package $p1 into $vepath");
    390 
     386       
    391387            # Remove cached package if not asked to keep
    392388            if (! $opts{'k'}) {
    393389                unlink("$cachedir/$p1");
    394390            }
    395 
     391   
    396392        }
    397393    } else {
     
    403399
    404400if ($warning ge 1) {
    405     pb_log(0,"$warning WARNINGS found.\nMaybe you should review your package list for $ddir-$dver-$darch\nand remove$lwpkg\n");
     401pb_log(0,"$warning WARNINGS found.\nMaybe you should review your package list for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}\nand remove$lwpkg\n");
    406402}
    407403
     
    415411
    416412# yum needs that distro-release package be installed, so force it
    417 if ($pbins =~ /yum/) {
     413if ($pbos->{'install'} =~ /yum/) {
     414    my $ddir = $pbos->{'name'};
    418415    foreach my $p1 (<$cachedir/($ddir|redhat)-release-*.rpm>) {
    419416        copy("$cachedir/$p1","$vepath/tmp");
     
    432429# BUGFIX:
    433430#
    434 if ((($ddir eq "centos") || ($ddir eq "rhel")) && ($dver eq "5")) {
     431if ((($pbos->{'name'} eq "centos") || ($pbos->{'name'} eq "rhel")) && ($pbos->{'version'} eq "5")) {
    435432    pb_log(1,"BUGFIX for centos-5\n");
    436433    pb_mkdir_p("$vepath/usr/lib/python2.4/site-packages/urlgrabber.skx");
     
    458455
    459456pb_log(1,"Adapting $osupdname repository entries\n");
    460 if ($pbins =~ /yum/) {
     457if ($pbos->{'install'} =~ /yum/) {
    461458    #
    462459    # Force the architecture for yum
     
    468465    # yum.conf as well
    469466    foreach my $i (<$vepath/etc/yum.repos.d/*>,"$vepath/etc/yum.conf") {
    470         pb_system("sed -i -e 's/\$basearch/$darch/g' $i","","quiet");
    471         pb_system("sed -i -e 's/\$releasever/$dver/g' $i","","quiet");
     467        pb_system("sed -i -e 's/\$basearch/$pbos->{'arch'}/g' $i","","quiet");
     468        pb_system("sed -i -e 's/\$releasever/$pbos->{'version'}/g' $i","","quiet");
    472469        pb_system("sed -i -e 's/^mirrorlist/#mirrorlist/' $i","","quiet");
    473470        # rather use neutral separators here
     
    475472    }
    476473    $minipkglist = "ldconfig yum passwd vim-minimal dhclient authconfig";
    477 } elsif ($pbins =~ /zypper/) {
     474} elsif ($pbos->{'install'} =~ /zypper/) {
    478475    pb_mkdir_p("$vepath/etc/zypp/repos.d");
    479     open(REPO,"> $vepath/etc/zypp/repos.d/$ddir-$dver") || die "Unable to create repo file";
     476    open(REPO,"> $vepath/etc/zypp/repos.d/$pbos->{'name'}-$pbos->{'version'}") || die "Unable to create repo file";
    480477    my $baseurl = dirname(dirname($mirror));
    481478    # Setup the repo
    482479    print REPO << 'EOF';
    483480[opensuse]
    484 name=$ddir-$dver
     481name=$pbos->{'name'}-$pbos->{'version'}
    485482baseurl=$baseurl
    486483enabled=1
     
    491488    $minipkglist = "zypper vim-minimal dhclient";
    492489    # Bootstraping zypper
    493     if ($dver eq "10.2") {
    494         pb_system("chroot $vepath /bin/bash -c \"yes | /usr/bin/zypper sa $baseurl $ddir-$dver\"","Bootstrapping Zypper");
    495     }
    496 } elsif ($pbins =~ /urpmi/) {
     490    if ($pbos->{'version'} eq "10.2") {
     491        pb_system("chroot $vepath /bin/bash -c \"yes | /usr/bin/zypper sa $baseurl $pbos->{'name'}-$pbos->{'version'}\"","Bootstrapping Zypper");
     492    }
     493} elsif ($pbos->{'install'} =~ /urpmi/) {
    497494    # Setup the repo
    498495    my $baseurl = dirname(dirname(dirname($mirror)));
     
    505502# No need for sudo here
    506503#
    507 $pbins =~ s/sudo//g;
    508 pb_system("chroot $vepath /bin/bash -c \"$pbins $minipkglist \"","Bootstrapping OS by running $pbins $minipkglist");
     504$pbos->{'install'} =~ s/sudo//g;
     505pb_system("chroot $vepath /bin/bash -c \"$pbos->{'install'} $minipkglist \"","Bootstrapping OS by running $pbos->{'install'} $minipkglist");
    509506
    510507#
     
    517514if (defined $opts{'a'}) {
    518515    $opts{'a'} =~ s/,/ /g;
    519     pb_system("chroot $vepath /bin/bash -c \"$pbins $opts{'a'} \"","Adding packages to OS by running $pbins $opts{'a'}");
     516    pb_system("chroot $vepath /bin/bash -c \"$pbos->{'install'} $opts{'a'} \"","Adding packages to OS by running $pbos->{'install'} $opts{'a'}");
    520517}
    521518
     
    524521#
    525522pb_log(1,"Cleaning up\n");
    526 if ($pbins =~ /yum/) {
     523if ($pbos->{'install'} =~ /yum/) {
    527524    pb_system("chroot $vepath /usr/bin/yum clean all","Cleaning yum");
    528525}
Note: See TracChangeset for help on using the changeset viewer.