Changeset 191 for trunk


Ignore:
Timestamp:
07/13/15 21:14:26 (9 years ago)
Author:
kdeugau
Message:

/trunk

Review, revise, and update automatic OS detection with much input from
Neal Gompa. Legacy Unbuntu verions have been refined, current LTS
releases and Debian releases have been added, and now that sanity has
prevailed we can get the base OS, OS release, and OS version all from
a handy file.

Note that debbuild diverges from rpmbuild in that it provides a
reasonable default for %{dist}, similar to usage found in RHEL and
Fedora packages (eg "el6" or "fc20"). rpmbuild relies on --define's
in the build environment call to set this. If specified with --define,
the command line argument will take precedence over the autodetection,
although the custom %{debver} and %{debdist} macros will remain as set
from the autodetection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/debbuild

    r190 r191  
    142142# /etc/debian-version and/or version of base-files package
    143143my %distmap = (
    144         "3.1.9ubuntu7.1"        => "dapper",
    145         "4ubuntu2"      => "feisty",
     144# legacy Unbuntu
     145        "3.1.9ubuntu"   => "dapper",
     146        "6.06"          => "dapper",
     147        "4ubuntu"       => "feisty",
     148        "7.04"          => "fiesty",
     149        "4.0.1ubuntu"   => "hardy",
     150        "8.04"          => "hardy",
     151# Note we do NOT support identification of "subrelease" versions (ie semimajor updates
     152# to a given release).  If your dependencies are really that tight, and you can't rely
     153# on the versions of the actual dependencies, you're already in over your head, and
     154# should probably only ship a tarballed installer.
     155# only supporting LTS releases
     156# base-files version doesn't map to the Ubuntu version the way Debian versions do, thus the doubled entries
     157#       Ubuntu 12.04.5 LTS (Precise Pangolin)
     158        "6.5ubuntu"     => "precise",
     159        "12.04"         => "precise",
     160#       Ubuntu 14.04.2 LTS (Trusty Tahr)
     161        "7.2ubuntu"     => "trusty",
     162        "14.04"         => "trusty",
     163# Debian releases
    146164        "3.0"   => "woody",
    147165        "3.1"   => "sarge",
    148166        "4"     => "etch",
    149167        "5"     => "lenny",
    150         "6.0"   => "squeeze",
    151         "7.0"   => "wheezy",
    152         "8.0"   => "jessie",
    153         "99"    => "sid");
     168        "6"     => "squeeze",
     169        "7"     => "wheezy",
     170        "8"     => "jessie",
     171        "9"     => "stretch",
     172        "99"    => "sid",
     173);
     174
     175# Map Ubuntu base-files versions to the nominal public versions
     176
     177my %ubnt_vermap = (
     178        "6.5ubuntu6"    => "12.04",
     179        "7.2ubuntu5"    => "14.04",
     180);
     181
    154182# Enh.  There doesn't seem to be any better way to do this...  :(
    155183{
     
    157185#  my $releasever = qx { cat /etc/debian_version };
    158186#  chomp $releasever;
     187  my $basefiles;
    159188  my $basever;
    160 
    161   if ( ! -e '/usr/bin/dpkg-query' ) {
     189  my $baseos;
     190
     191  # Funny thing how files like this have become useful...
     192  # Check for /etc/os-release.  If that doesn't exist, try /etc/lsb-release.  If that doesn't exist,
     193  # check for existence of dpkg-query, and either call it Debian Woody (if missing), or fall through
     194  # to guessing based on the version of the base-files package.
     195  if (-e '/etc/os-release') {
     196    open OSREL, "</etc/os-release";
     197    # Look for ID and VERSION_ID lines.
     198    while (<OSREL>) {
     199      $baseos = $1 if /^ID=(\w+)/;
     200      $basever = $1 if /^VERSION_ID="?([\d.]+)/;
     201    }
     202    close OSREL;
     203
     204  } elsif (-e '/etc/lsb-release') {
     205    open LSBREL, "</etc/lsb-release";
     206    # Look for DISTRIB_ID and DISTRIB_RELEASE lines.
     207    # We could also theoretically extract the dist codename, but since we have to hand-map
     208    # it in so many other cases there's little point.
     209    while (<LSBREL>) {
     210      $baseos = $1 if /^DISTRIB_ID=(\w+)/;
     211      $basever = $1 if /^DISTRIB_RELEASE=([\d.]+)/;
     212    }
     213    close LSBREL;
     214
     215  } elsif ( ! -e '/usr/bin/dpkg-query' ) {
    162216    # call it woody, since sarge and newer have dpkg-query, and we don't much care about obsolete^n releases
    163217    $basever = "3.0";
     218    $baseos = 'debian';
     219
    164220  } else {
    165 
    166221# *eyeroll*  there *really* has to be a better way to go about this.  You
    167222# can't sanely build packages for multiple distro targets if you can't
     
    171226# releases would be...  exponentially more painful.
    172227
     228    my $majver;
    173229    # for the lazy copy-paster:  dpkg-query --showformat '${version}\n' -W base-files
    174230    # avoid shellisms
     
    177233      close BASEGETTER;
    178234
    179       ($basever) = ($basever =~ /^(\d(?:\.\d)?)/);
    180     }
    181 
     235      if ($basever =~ /ubuntu/) {
     236        # Ubuntu, at least until they upset their versioning scheme again
     237        # note that we remap the basefiles version to the public release number, to match the
     238        # behaviour for Debian, and to match the unofficial standard for RHEL/Centos etc and Fedora
     239        ($basefiles,$basever) = ($basever =~ /^(([\d.]+)ubuntu)\d/);
     240        $baseos = 'ubuntu';
     241      } else {
     242        # Debian, or more "pure" derivative
     243        $baseos = 'debian';
     244        ($basever,$majver) = ($basever =~ /^((\d+)(?:\.\d)?)/);
     245        if ($majver > 3) {
     246          $basever = $majver;
     247        }
     248      }
     249    }
     250
     251    if (!$basever) {
     252      # Your llama is on fire
     253      $basever = '99';
     254      print "Warning:  couldn't autodetect OS version, assuming sid/unstable\n";
     255    }
    182256  } # got dpkg-query?
    183257
     258  # Set some legacy globals.
    184259  $specglobals{"debdist"} = $distmap{$basever};
    185260  $specglobals{"debver"} = $basever;   # this may have trouble with Ubuntu versions?
     261
     262  # Set the standard generic OS-class globals;
     263  $baseos = lc($baseos);
     264  $specglobals{"ubuntu"} = $basever if $baseos eq 'ubuntu';
     265  $specglobals{"debian"} = $basever if $baseos eq 'debian';
     266
     267  # Default %{dist} to something marginally sane.  Note this should be overrideable by --define.
     268  # This has been chosen to most closely follow the usage in RHEL/CentOS and Fedora, ie "el5" or "fc20".
     269  $specglobals{"dist"} = $baseos.$basever;
    186270
    187271} # done trying to set debian dist/version
     
    657741      my $output = expandmacros($1, 'gp');
    658742      print "$output";
     743      next LINE;
    659744    }
    660745
Note: See TracChangeset for help on using the changeset viewer.