Changeset 11


Ignore:
Timestamp:
Jul 30, 2007, 2:21:01 AM (11 years ago)
Author:
bruno
Message:

Addition of distro management

Location:
devel/pb
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb.pl

    r9 r11  
    2020use common qw (env_init);
    2121use pb qw (defpkgdir extpkgdir version pb_init);
     22use distro qw (distro_init);
    2223use cms;
    2324
     
    126127            print " OK\n";
    127128        }
     129        open(D,"$ENV{'PBCONF'}/DISTROS") || die "Unable to find $ENV{'PBCONF'}/DISTROS\n";
     130        while (<D>) {
     131            my $d = $_;
     132            my ($dir,$ver) = split(/_/,$d);
     133            chomp($ver);
     134            print "Generating build files for $dir ($ver)\n";
     135            my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver);
     136            #print Dumper($ddir, $dver, $dfam, $dtype, $dsuf);
     137        }
     138        close(D);
    128139    }
    129140} else {
  • devel/pb/lib/common.pm

    r9 r11  
    5757# Check pb conf compliance
    5858#
    59 die "Project $ENV{'PBPROJ'} not ProjectBuild compliant. Please populate $ENV{'PBROOT'}/pbconf" if ( not -d "$ENV{'PBROOT'}/pbconf");
     59$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
     60die "Project $ENV{'PBPROJ'} not ProjectBuild compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
    6061
    6162#
    6263# Get global VERSION
    6364#
    64 open(VER, "$ENV{'PBROOT'}/pbconf/VERSION") || die "Unable to open $ENV{'PBROOT'}/pbconf/VERSION: $?";
     65open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
    6566$ver = <VER>;
    6667chomp($ver);
     
    7374#Get global TAG
    7475#
    75 open(TAG, "$ENV{'PBROOT'}/pbconf/TAG") || die "Unable to open $ENV{'PBROOT'}/pbconf/TAG: $?";
     76open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
    7677$tag = <TAG>;
    7778chomp($tag);
  • devel/pb/lib/distro.pm

    r2 r11  
    1 #!/bin/bash
     1#!/usr/bin/perl -w
    22#
    3 # Create env depending on the distro on which we are
     3# Creates common environment for distributions
    44#
    55# $Id$
    66#
    7 # Input parameters : $ddir (distro name) and $dver (distro version)
    8 # If they do not exist then deduce from current distro
    9 # Exports : $dfam (distro family) $suf (pkg suffix) $dtype (distro type) TOPBUILDDIR (dir to build packages)
    107
    11 #
    12 # Guess ddir and dver from the underlying distro
    13 #
    14 if [ _"$ddir" = _"" ]; then
    15     if [ -e /etc/mandriva-release ]; then
    16         export ddir="mandriva"
    17         export dver=`awk '{print $4}' /etc/mandriva-release`
    18     elif [ -e /etc/mandrake-release ]; then
    19         export ddir="mandrake"
    20         export dver=`awk '{print $3}' /etc/mandrake-release`
    21     elif [ -e /etc/redhat-release ]; then
    22         grep -q Enterprise /etc/redhat-release
    23         if [ $? -eq 0 ]; then
    24             export ddir="rhel"
    25             export dver=`awk '{print $7}' /etc/redhat-release`
    26         elif grep -q Fedora /etc/redhat-release ; then
    27             export ddir="fedora"
    28             grep -qi core /etc/redhat-release
    29             if [ $? -eq 0 ]; then
    30                 export dver=`awk '{print $4}' /etc/redhat-release`
    31             else
    32                 export dver=`awk '{print $3}' /etc/redhat-release`
    33             fi
    34         elif grep -q CentOS /etc/redhat-release ; then
    35             export ddir="centos"
    36             export dver=`awk '{print $3}' /etc/redhat-release | cut -d. -f1`
    37         else
    38             export ddir="redhat"
    39             export dver=`awk '{print $5}' /etc/redhat-release`
    40         fi
    41     elif [ -e /etc/SuSE-release ]; then
    42         grep -q Enterprise /etc/SuSE-release
    43         if [ $? -eq 0 ]; then
    44             export ddir="sles"
    45             export dver=`head -1 /etc/SuSE-release | awk '{print $5}'`
    46         elif grep -q openSUSE /etc/SuSE-release ; then
    47             export ddir="suse"
    48             export dver=`head -1 /etc/SuSE-release | awk '{print $2}'`
    49         else
    50             export ddir="suse"
    51             export dver=`head -1 /etc/SuSE-release | awk '{print $3}'`
    52         fi
    53     elif [ -e /etc/slackware-version ]; then
    54         export ddir="slackware"
    55         export dver=`awk '{print $2}' /etc/slackware-version | cut -d. -f1-2`
    56     elif [ -e /etc/gentoo-release ]; then
    57         export ddir="gentoo"
    58         export dver=`awk '{print $5}' /etc/gentoo-release | cut -d. -f1-2`
    59     elif [ -e /etc/debian_version ]; then
    60         export ddir="debian"
    61         export dver=`cat /etc/debian_version`
    62         # Debian assigns release names only once a release actually happens.
    63         # Debian does not distinguish between testing and unstable because
    64         # unstable today is what testing will be in about ten days time. So,
    65         # in case we encounter "tesing/unstable", we assume unstable, i.e. sid.
    66         # Note that for released versions, the numeric version will be contained
    67         # in debian_version, e.g. on a sarge system, the value will be '3.1'.
    68         if [ $dver = "testing/unstable" ]; then
    69             export dver = "sid"
    70         fi
    71         if [ -e /etc/lsb-release ]; then
    72             grep -qi ubuntu /etc/lsb-release
    73             if  [ $? -eq 0 ]; then
    74                 export ddir="ubuntu"
    75                 export dver=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d= -f2`
    76             fi
    77         fi
    78     elif [ -e /etc/motd ]; then
    79         head -1 /etc/motd | grep -q FreeBSD
    80         if [ $? -eq 0 ]; then
    81             export ddir="freebsd"
    82             export dver=`head -1 /etc/motd | awk '{print $2}' /etc/motd | cut -d- -f1`
    83         else
    84             export ddir="unknown"
    85             export dver=""
    86         fi
    87     else
    88         export ddir="unknown"
    89         export dver=""
    90     fi
    91 fi
     8require Exporter;
     9@ISA = qw(Exporter);
     10@EXPORT = qw(distro_init distro_get);
    9211
    93 #
    94 # Generate all other parameters
    95 #
    96 if [ $ddir = "debian" -o $ddir = "ubuntu" ]; then
    97     dfam="debian"
    98     dtype="deb"
    99     suf=".${ddir}${dver}"
    100 elif [ $ddir = "gentoo" ]; then
    101     dfam="gentoo"
    102     dtype="ebuild"
    103     dver1=`echo ${dver} | sed "s/\.//"`
    104     suf=".${ddir}${dver1}"
    105 elif [ $ddir = "slackware" ]; then
    106     dfam="slackware"
    107     dtype="tgz"
    108     suf=".${dfam}${dver}"
    109 elif [ $ddir = "sles" -o $ddir = "suse" ]; then
    110     dfam="suse"
    111     dtype="rpm"
    112     suf=".${ddir}${dver}"
    113 elif [ $ddir = "fedora" -o $ddir = "redhat" -o $ddir = "rhel" -o $ddir = "centos" ]; then
    114     dfam="redhat"
    115     dtype="rpm"
    116     dver1=`echo ${dver} | sed "s/\.//"`
    117     if [ $ddir = "fedora" ]; then
    118         suf=".fc${dver1}"
    119     elif [ $ddir = "centos" ]; then
    120         dver1=`echo ${dver} | sed "s/\.[0-9]//"`
    121         suf=".centos${dver1}"
    122     elif [ $ddir = "redhat" ]; then
    123         suf=".rh${dver1}"
    124     else
    125         suf=".rhel${dver1}"
    126     fi
    127 elif [ $ddir = "mandrake" ]; then
    128     dfam="mandriva"
    129     dtype="rpm"
    130     suf=".`echo $dver | sed 's/\.//'`mdk"
    131 elif [ $ddir = "mandriva" ]; then
    132     dfam="mandriva"
    133     dtype="rpm"
    134     suf=".`echo $dver | sed 's/\.//'`mdv"
    135 elif [ $ddir = "freebsd" ]; then
    136     dfam="freebsd"
    137     dtype="port"
    138     suf=".`echo $dver | sed 's/\.//'`fbsd"
    139 else
    140     dfam="unknown"
    141     dtype="unknown"
    142     suf="unknown"
    143 fi
     12use strict;
    14413
    145 export dfam
    146 export dtype
    147 export suf
     14sub distro_init {
    14815
    149 #
    150 # Additional exports and preparation for some distros
    151 #
     16my $ddir = shift;
     17my $dver = shift;
     18my $dfam = "unknown";
     19my $dtype = "unknown";
     20my $dsuf = "unknown";
    15221
    153 # Default
    154 export TOPBUILDDIR=${TOPDIR}/../build
     22# If we don't know which distribution we're on, then guess it
     23($ddir, $dver) = distro_get() if ((not defined $ddir) || (not defined $dver));
    15524
    156 if [ _"$dtype" = _"rpm" ]; then
    157     export TOPBUILDDIR=`rpmquery --eval '%{_topdir}' 2> /dev/null`
    158     export ARCH=`rpm --showrc | egrep "^build arch" | awk '{print $4}'`
    159     mkdir -p ${TOPBUILDDIR}/{RPMS,SRPMS,SPECS,SOURCES,BUILD}
    160     if [ $? -ne 0 ]; then
    161         echo "Please ensure that you can write into ${TOPBUILDDIR}"
    162         echo "Solution: setup _topdir in your ~/.rpmmacros or"
    163         echo "chown the ${TOPBUILDDIR} to your uid"
    164         exit -1
    165     fi
    166 elif [ _"$dtype" = _"deb" ]; then
    167     mkdir -p ${TOPBUILDDIR}
    168 elif [ _"$dtype" = _"port" ]; then
    169     mkdir -p ${TOPBUILDDIR}
    170 elif [ _"$dfam" = _"slackware" ]; then
    171     mkdir -p ${TOPBUILDDIR}/install
    172 elif [ _"$dtype" = _"ebuild" ]; then
    173     mkdir -p ${TOPBUILDDIR}/portage
    174 fi
     25if (($ddir =~ /debian/) ||
     26    ($ddir =~ /ubuntu/)) {
     27    $dfam="debian";
     28    $dtype="deb";
     29    $dsuf=".$ddir$dver";
     30} elsif ($ddir =~ /gentoo/) {
     31    $dfam="gentoo";
     32    $dtype="ebuild";
     33    my $dver1 = $dver;
     34    $dver1 =~ s/\.//;
     35    $dsuf=".$ddir$dver1";
     36} elsif ($ddir =~ /slackware/) {
     37    $dfam="slackware";
     38    $dtype="tgz";
     39    $dsuf=".$dfam$dver";
     40} elsif (($ddir =~ /suse/) ||
     41        ($ddir =~ /sles/)) {
     42    $dfam="suse";
     43    $dtype="rpm";
     44    $dsuf=".$ddir$dver";
     45} elsif (($ddir =~ /redhat/) ||
     46        ($ddir =~ /rhel/) ||
     47        ($ddir =~ /fedora/) ||
     48        ($ddir =~ /centos/)) {
     49    $dfam="redhat";
     50    $dtype="rpm";
     51    my $dver1 = $dver;
     52    $dver1 =~ s/\.//;
     53    if ($ddir =~ /fedora/) {
     54        $dsuf=".fc$dver1";
     55    } elsif ($ddir =~ /redhat/) {
     56        $dsuf=".rh$dver1";
     57    } else {
     58        $dsuf=".$ddir$dver1";
     59    }
     60} elsif (($ddir =~ /mandrake/) ||
     61        ($ddir =~ /mandriva/)) {
     62    $dfam="mandriva";
     63    $dtype="rpm";
     64    if ($ddir =~ /mandrake/) {
     65        my $dver1 = $dver;
     66        $dver1 =~ s/\.//;
     67        $dsuf=".mdk$dver1";
     68    } else {
     69        $dsuf=".mdv$dver";
     70    }
     71} elsif ($ddir =~ /freebsd/) {
     72    $dfam="freebsd";
     73    $dtype="port";
     74    my $dver1 = $dver;
     75    $dver1 =~ s/\.//;
     76    $dsuf=".$dfam$dver1";
     77} else {
     78    $dfam="unknown";
     79    $dtype="unknown";
     80    $dsuf="unknown";
     81}
     82
     83return($ddir, $dver, $dfam, $dtype, $dsuf);
     84}
     85
     86sub distro_get {
     87}
     881;
Note: See TracChangeset for help on using the changeset viewer.