Define classes using lsb release

From Cfwiki

Revision as of 03:08, 2 December 2006 by Lemsx1 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Using LSB variables as classes

This is an overview on how to define classes using lsb variables found in /etc/lsb-release or from the lsb_release command.


In a nutshell:

Create a file called module:lsb_classes with the following content:

 #!/usr/bin/perl -w
  use strict;
  $|++;
  # ensure that our path env var has the proper paths we need
  $ENV{'PATH'} = "/bin:/usr/bin";
  my $lsb_release = "/bin/lsb_release";
  foreach my $_path (split(/:/,$ENV{'PATH'}))
  {
    if ( -x "$_path/lsb_release" )
    {
        $lsb_release = "$_path/lsb_release";
    }
  }
  # opening the file lsb-release is a lot faster!
  open(LSB,"</etc/lsb-release") or open(LSB,"$lsb_release -a|") or exit(0);
  while(<LSB>)
  {
    chomp();
    if ( /codename/i )
    {
        s/[[:alnum:]_-]+(:|=)[[:blank:]]*//i;
        s/\./_/g;               # use _ for .'s
        # remove all strange chars left
        s/[[:blank:]]//g;     
        s/[^[:alnum:]_-]//g;     
        print "+".lc($_)."\n" if ( ! /^[[:blank:]]*$/);
    }
  }

Then edit your cfengine files to include this module

 control: 
   actionsequence = (
       module:lsb_classes
   )
   AddInstallables = ( dapper sid 1_3 )
 shellcommands:
   dapper::
      "/bin/echo 'I am a dapper system'"
Personal tools