#!/usr/bin/perl -w
#
# Project Builder Distribution Checker
#
# $Id$
#
# Copyright B. Cornec 2007-2016
# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
# Provided under the GPL v2
use strict 'vars';
use Getopt::Long qw(:config auto_abbrev no_ignore_case);
use Data::Dumper;
use lib qw (lib);
#use lib '/usr/share/perl5'; # mandatory for opensuse
use ProjectBuilder::Version;
use ProjectBuilder::Distribution;
use ProjectBuilder::Base;
=pod
=head1 NAME
pb, aka project-builder.org - builds packages for your projects
=head1 DESCRIPTION
pb helps you build various packages directly from your project sources.
pbdistrocheck is a command from the pb project providing the same type of services as lsb_release, but extended.
=head1 SYNOPSIS
pbdistrocheck [-h][-d][-v][-l [-c][-i][-r][-a]][-s] [distro-ver-arch]
=head1 OPTIONS
=over 4
=item B<-h|--help>
Prints this help
=item B<-v|--verbose>
Print a brief help message and exits.
=item B<-a|--all>
Print all parameters
=item B<-s|--short>
Generate a short format user friendly, comma separated allowing parsing
=item B<-l|--lsb>
Generate an LSB compliant output
=item B<-d|--description>
Print only description (LSB only)
=item B<-r|--release>
Print only release (LSB only)
=item B<-c|--codename>
Print only codename (LSB only)
=item B<-i|--id>
Print only distribution identificator (LSB only)
=item B<-a|--all>
Print all LSB fields
=back
=head1 ARGUMENTS
Arguments are optional. If none given, analyzes the underlying operating system
If one is given, it should have the format osname-version-architecture, and in that case pbdistrocheck will provide all the information related to that OS needed by pb.
=head1 WEB SITES
The main Web site of the project is available at L. Bug reports should be filled using the trac instance of the project at L.
=head1 USER MAILING LIST
Cf: L for announces and L for the development of the pb project.
=head1 CONFIGURATION FILES
Uses the main /etc/pb/pb.yml (or /usr/local/etc/pb/pb.yml if installed from files) configuration file to give its answers.
=head1 AUTHORS
The Project-Builder.org team L lead by Bruno Cornec L.
=head1 COPYRIGHT
Project-Builder.org is distributed under the GPL v2.0 license
described in the file C included with the distribution.
=cut
my %opts; # CLI Options
my ($projectver,$projectrev) = pb_version_init();
my $appname = "pbgetparam";
# Initialize the syntax string
pb_syntax_init("$appname Version $projectver-$projectrev\n");
GetOptions(
"verbose|v+" => \$opts{'v'},
"version" => \$opts{'version'},
"man" => \$opts{'man'},
"help|h" => \$opts{'h'},
"short|s" => \$opts{'s'},
"description|d" => \$opts{'d'},
"id|i" => \$opts{'i'},
"release|r" => \$opts{'r'},
"codename|c" => \$opts{'c'},
"all|a" => \$opts{'a'},
"lsb|l" => \$opts{'l'},
);
if (defined $opts{'h'}) {
pb_syntax(0,1);
}
if (defined $opts{'version'}) {
pb_syntax(0,0);
}
if (defined $opts{'man'}) {
pb_syntax(0,2);
}
if (defined $opts{'v'}) {
$pbdebug = $opts{'v'};
}
pb_log_init($pbdebug, \*STDOUT);
my $dist = shift @ARGV || undef ;
my $pbos = pb_distro_get_context($dist);
my $sep = "\n";
if (defined $opts{'l'}) {
# Simulate lsb_release output
my ($l,$i,$d,$r,$c) = pb_distro_getlsb($opts{'s'});
$sep = " " if (defined $opts{'s'});
print $l.$sep;
print $i.$sep if (defined $opts{'i'} or defined $opts{'a'});
print $d.$sep if (defined $opts{'d'} or defined $opts{'a'});
print $r.$sep if (defined $opts{'r'} or defined $opts{'a'});
$sep = "" if (defined $opts{'s'});
print $c.$sep if (defined $opts{'c'} or defined $opts{'a'});
print "\n" if (defined $opts{'s'});
} else {
$sep = "," if (defined $opts{'s'});
if (not defined $opts{'s'}) {
$pbos->{'os'} = "OS:\t$pbos->{'os'}";
$pbos->{'name'} = "Name:\t$pbos->{'name'}";
$pbos->{'version'} = "Ver:\t$pbos->{'version'}";
$pbos->{'family'} = "Family:\t$pbos->{'family'}";
$pbos->{'type'} = "Type:\t$pbos->{'type'}";
$pbos->{'suffix'} = "Suffix:\t$pbos->{'suffix'}";
$pbos->{'update'} = "Update:\t$pbos->{'update'}";
$pbos->{'install'} = "Install:\t$pbos->{'install'}";
$pbos->{'arch'} = "Arch:\t$pbos->{'arch'}";
print "Project-Builder tuple:\n";
}
print join($sep,($pbos->{'os'}, $pbos->{'name'}, $pbos->{'version'}, $pbos->{'arch'}, $pbos->{'type'}, $pbos->{'family'}, $pbos->{'suffix'}, $pbos->{'update'}, $pbos->{'install'}))."\n";
}