source: ProjectBuilder/devel/pb-modules/bin/pbdistrocheck

Last change on this file was 2496, checked in by Bruno Cornec, 4 years ago

call pb_conf_init before using conf files

File size: 4.6 KB
Line 
1#!/usr/bin/perl -w
2#
3# Project Builder Distribution Checker
4#
5# $Id$
6#
7# Copyright B. Cornec 2007-today
8# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
9# Provided under the GPL v2
10
11use strict 'vars';
12use Getopt::Long qw(:config auto_abbrev no_ignore_case);
13use Data::Dumper;
14use lib qw (lib);
15#use lib '/usr/share/perl5'; # mandatory for opensuse
16use ProjectBuilder::Version;
17use ProjectBuilder::Distribution;
18use ProjectBuilder::Base;
19use ProjectBuilder::Conf;
20
21=pod
22
23=head1 NAME
24
25pb, aka project-builder.org - builds packages for your projects
26
27=head1 DESCRIPTION
28
29pb helps you build various packages directly from your project sources.
30pbdistrocheck is a command from the pb project providing the same type of services as lsb_release, but extended.
31
32=head1 SYNOPSIS
33
34pbdistrocheck [-h][-d][-v][-l [-c][-i][-r][-a]][-s] [distro-ver-arch]
35
36=head1 OPTIONS
37
38=over 4
39
40=item B<-h|--help>
41
42Prints this help
43
44=item B<-v|--verbose>
45
46Print a brief help message and exits.
47
48=item B<-a|--all>
49
50Print all parameters
51
52=item B<-s|--short>
53
54Generate a short format user friendly, comma separated allowing parsing
55
56=item B<-l|--lsb>
57
58Generate an LSB compliant output
59
60=item B<-d|--description>
61
62Print only description (LSB only)
63
64=item B<-r|--release>
65
66Print only release (LSB only)
67
68=item B<-c|--codename>
69
70Print only codename (LSB only)
71
72=item B<-i|--id>
73
74Print only distribution identificator (LSB only)
75
76=item B<-a|--all>
77
78Print all LSB fields
79
80=back
81
82=head1 ARGUMENTS
83
84Arguments are optional. If none given, analyzes the underlying operating system
85If 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.
86
87=head1 WEB SITES
88
89The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
90
91=head1 USER MAILING LIST
92
93Cf: L<http://www.mondorescue.org/sympa/info/pb-announce> for announces and L<http://www.mondorescue.org/sympa/info/pb-devel> for the development of the pb project.
94
95=head1 CONFIGURATION FILES
96
97Uses the main /etc/pb/pb.yml (or /usr/local/etc/pb/pb.yml if installed from files) configuration file to give its answers.
98
99=head1 AUTHORS
100
101The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
102
103=head1 COPYRIGHT
104
105Project-Builder.org is distributed under the GPL v2.0 license
106described in the file C<COPYING> included with the distribution.
107
108=cut
109
110my %opts; # CLI Options
111
112my ($projectbuilderver,$projectbuilderrev,$projectbuilderconfver) = pb_version_init();
113my $appname = "pbdistrocheck";
114
115# Initialize the syntax string
116
117pb_syntax_init("$appname Version $projectbuilderver-$projectbuilderrev\n");
118pb_temp_init();
119pb_conf_init($appname);
120
121GetOptions(
122 "verbose|v+" => \$opts{'v'},
123 "version" => \$opts{'version'},
124 "man" => \$opts{'man'},
125 "help|h" => \$opts{'h'},
126 "short|s" => \$opts{'s'},
127 "description|d" => \$opts{'d'},
128 "id|i" => \$opts{'i'},
129 "release|r" => \$opts{'r'},
130 "codename|c" => \$opts{'c'},
131 "all|a" => \$opts{'a'},
132 "lsb|l" => \$opts{'l'},
133);
134if (defined $opts{'h'}) {
135 pb_syntax(0,1);
136}
137if (defined $opts{'version'}) {
138 pb_syntax(0,0);
139}
140if (defined $opts{'man'}) {
141 pb_syntax(0,2);
142}
143if (defined $opts{'v'}) {
144 $pbdebug = $opts{'v'};
145}
146pb_log_init($pbdebug, \*STDOUT);
147
148my $dist = shift @ARGV || undef ;
149my $pbos = pb_distro_get_context($dist);
150my $sep = "\n";
151if (defined $opts{'l'}) {
152 # Simulate lsb_release output
153 my ($l,$i,$d,$r,$c) = pb_distro_getlsb($opts{'s'});
154 $sep = " " if (defined $opts{'s'});
155 print $l.$sep;
156 print $i.$sep if (defined $opts{'i'} or defined $opts{'a'});
157 print $d.$sep if (defined $opts{'d'} or defined $opts{'a'});
158 print $r.$sep if (defined $opts{'r'} or defined $opts{'a'});
159 $sep = "" if (defined $opts{'s'});
160 print $c.$sep if (defined $opts{'c'} or defined $opts{'a'});
161 print "\n" if (defined $opts{'s'});
162} else {
163 $sep = "," if (defined $opts{'s'});
164 if (not defined $opts{'s'}) {
165 $pbos->{'os'} = "OS:\t$pbos->{'os'}";
166 $pbos->{'name'} = "Name:\t$pbos->{'name'}";
167 $pbos->{'version'} = "Ver:\t$pbos->{'version'}";
168 $pbos->{'family'} = "Family:\t$pbos->{'family'}";
169 $pbos->{'type'} = "Type:\t$pbos->{'type'}";
170 $pbos->{'suffix'} = "Suffix:\t$pbos->{'suffix'}";
171 $pbos->{'update'} = "Update:\t$pbos->{'update'}";
172 $pbos->{'install'} = "Install:\t$pbos->{'install'}";
173 $pbos->{'arch'} = "Arch:\t$pbos->{'arch'}";
174 print "Project-Builder tuple:\n";
175 }
176 print join($sep,($pbos->{'os'}, $pbos->{'name'}, $pbos->{'version'}, $pbos->{'arch'}, $pbos->{'type'}, $pbos->{'family'}, $pbos->{'suffix'}, $pbos->{'update'}, $pbos->{'install'}))."\n";
177}
Note: See TracBrowser for help on using the repository browser.