/[metamod]/trunk/lsconf
ViewVC logotype

Contents of /trunk/lsconf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2779 - (show annotations) (download)
Tue Apr 7 15:02:33 2015 UTC (5 years, 4 months ago) by geira
File size: 6351 byte(s)
fixes in installation routines:
- no longer breaks when trying to create existing db users
- now disables default apache site-enabled
docs updated
1 #!/usr/bin/perl -w
2
3 =begin LICENCE
4
5 ----------------------------------------------------------------------------
6 METAMOD - Web portal for metadata search and upload
7
8 Copyright (C) 2013 met.no
9
10 Contact information:
11 Norwegian Meteorological Institute
12 Box 43 Blindern
13 0313 OSLO
14 NORWAY
15 email: geira@met.no
16
17 This file is part of METAMOD
18
19 METAMOD is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
23
24 METAMOD is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with METAMOD; if not, write to the Free Software
31 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 ----------------------------------------------------------------------------
33
34 =end LICENCE
35
36 =cut
37
38 use strict;
39 use warnings FATAL => qw( all );
40
41 use FindBin qw($Bin);
42 use lib "$Bin/common/lib";
43 use Metamod::Config;
44 use Metamod::Config::Sanity qw(check);
45 use Getopt::Long;
46 use Data::Dumper;
47 use Term::ANSIColor;
48 use Pod::Usage;
49
50 our $VERSION = do { my @r = (q$LastChangedRevision: 2617 $ =~ /\d+/g); sprintf "0.%d", @r };
51
52 #Getopt::Long::Configure ("bundling");
53 my %opt;
54 $opt{color} = -t STDOUT; # use IO::Interactive::Tiny instead - FIXME
55 GetOptions(\%opt,
56 'help', # for dummies
57 'default!', # set in default_config - change to string param
58 'custom!', # set in master_config - "
59 'environment!', # set in environment - "
60 'duplicates!', # same value set in default and master_config - "
61 'color|x!', # use colors
62 'split', # split var into key-value pairs
63 'flags!', # show flag indicator
64 'check', # run sanity check
65 'version', # run sanity check
66 'config=s', # use config file
67 ) or pod2usage(2);
68 #print STDERR Dumper \%opt;
69
70 pod2usage(1) if $opt{help};
71
72 # find config file
73 Metamod::Config->config_found($opt{config}) or pod2usage(2);
74 my $mm_config = Metamod::Config->new($opt{config}, { nolog => 1 } );
75 check_conf($mm_config) if $opt{check};
76
77 # check color output
78 if (defined $opt{color}) {
79 $ENV{ANSI_COLORS_DISABLED} = 1 unless $opt{color};
80 }
81 #$opt{flags} = ! $opt{color} unless defined $opt{flags}; # use def prefix unless colorized
82
83 # process argument
84 my $var = shift @ARGV;
85 my $vars;
86 my $vflags = $mm_config->getallflags();
87
88 if ( !defined($var) || $var =~ /(.+)\*$/ ) {
89 $vars = $mm_config->getall();
90 if ($var) { # wildcard
91 foreach (keys %$vars) { # delete vars not starting with $var
92 #printf "- $1 in $_? %d\n", index( $_, $1);
93 delete $vars->{$_} unless index( $_, $1) == 0;
94 }
95 }
96 } else {
97 missing($var) unless $mm_config->has($var);
98 if ($opt{split}) {
99 $vars = $mm_config->split($var); # hashes get separated into one var per key
100 $vars = { $var => $vars } if ref $vars ne 'HASH'; # arrays are just a list
101 } else {
102 $vars = { $var => $mm_config->get($var) };
103 }
104 }
105 #print STDERR Dumper $vars;
106
107 # print output
108 foreach (sort keys %$vars) {
109 my $val = $$vars{$_};
110 my $f = $vflags->{$_} || 0;
111 # compare truthinesses
112 next if defined $opt{default} && ( ($f & 1) xor $opt{default} );
113 next if defined $opt{custom} && ( ($f & 2) xor $opt{custom} );
114 next if defined $opt{environment} && ( ($f & 4) xor $opt{environment} );
115 next if defined $opt{duplicates} && ( ($f & 128) xor $opt{duplicates} );
116
117 printf "%08b ", $f if $opt{flags};
118 print color $f & 1 ? 'bold green' : 'bold red'; # green if default, else red
119 print $_, color 'reset';
120 print ' = ', color $f & 128 ? 'bright_red' : $f & 2 ? 'bright_yellow' : 'bright_blue'; # blue if default/generated, yellow if local, red if duplicate
121 print ref $val ? '[ ' . join(', ', @$val) . ' ]' : $val;
122 print "\n", color 'reset';
123 }
124
125 sub missing {
126 my $var = shift or die;
127 print STDERR "Variable $var is not defined\n";
128 exit (1);
129 }
130
131 sub check_conf {
132 my $conf = shift;
133 Metamod::Config::Sanity::check($conf);
134 exit;
135 }
136
137 =head1 NAME
138
139 B<lsconf.pl> - list METAMOD config variables
140
141 =head1 DESCRIPTION
142
143 Given a variable name as parameter, list the computed value (optionally parsed as a key-value pair if the --split option is used).
144 With no arguments, list all variables alphabetically.
145 Variable may end in '*' wildcard. --spilt can only be used with a single variable.
146
147 =head1 USAGE
148
149 lsconf [--help] [--config <file>] [--split] [--[no]color] [--[no]default] [--[no]environment] [--[no]flags] [--[no]custom] [--check] [variable]
150
151 =head1 ARGUMENTS
152
153 (Optional) a variable name to display, or all if none given. Wildcards (*) are accepted at the end of the string.
154
155 =head1 OPTIONS
156
157 =head2 help
158
159 What you're reading here
160
161 =head2 config <file>
162
163 Use specified config file (overrides envvar C<METAMOD_MASTER_CONFIG>)
164
165 =head2 split
166
167 Split key-value pairs variables. Only works when a single variable name is given as argument.
168
169 =head2 [no]color
170
171 Toggles color display according to flags (default on if terminal). Values are:
172
173 =over 4
174
175 =item Key:
176
177 green if default, else red
178
179 =item Value:
180
181 blue if default/generated, yellow if local, red if duplicate
182
183 =back
184
185 TIP: To show colored output in a pager, use C<lsconf --color|less -R>
186
187 =head2 [no]default
188
189 Only show variables [not] defined in default_config
190
191 =head2 [no]flags
192
193 Show flags as prefix instead of color (default opposite of color)
194
195 =head2 [no]custom
196
197 Only show variables updated in master_config
198
199 =head2 [no]environment
200
201 Only show variables updated in environment
202
203 =head2 check
204
205 Run sanity tests on config
206
207 =head1 EXAMPLES
208
209 $ lsconf --nocustom --nodefault # show only variables not defined in default or config (i.e. only computed/environment variables)
210
211 =head1 LICENSE
212
213 Copyright (C) 2013 The Norwegian Meteorological Institute.
214
215 METAMOD is free software; you can redistribute it and/or modify
216 it under the terms of the GNU General Public License as published by
217 the Free Software Foundation; either version 2 of the License, or
218 (at your option) any later version.
219
220 =cut

Properties

Name Value
svn:executable *

svn@met.no
ViewVC Help
Powered by ViewVC 1.1.5