File: rtpengine-get-table

package info (click to toggle)
rtpengine 13.5.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,676 kB
  • sloc: ansic: 86,764; perl: 59,422; python: 3,193; sh: 1,030; makefile: 693; asm: 211
file content (51 lines) | stat: -rwxr-xr-x 1,124 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Long;
use Config::Tiny;

sub showusage {
    print <<HELP;
Usage: rtpengine-get-table <option>...

Options:
  -h, --help                print this help message.
  --config-file=<pathname>  use <pathname> as the config file.
  --config-section=<name>   use <section> instead of 'rtpengine'.
  --fallback-table=<index>  use <index> as fallback table instead of 0.
HELP
}

my %options = (
    'help'                => sub { showusage(); exit 0 },
    'config-file'         => '/etc/rtpengine/rtpengine.conf',
    'config-section'      => 'rtpengine',
    'fallback-table'      => -1,
);

Getopt::Long::Configure('require_order');

my $optret = GetOptions(\%options,
    'help|h',
    'config-file=s',
    'config-section=s',
    'fallback-table=i',
);

if (!$optret) {
    showusage();
    exit 1;
}

my $cfg = Config::Tiny->read($options{'config-file'});
if (not defined $cfg) {
    die "error: " . Config::Tiny->errstr . "\n";
}
my $cfg_section = $options{'config-section'};
my $table = $cfg->{$cfg_section}{table} // $options{'fallback-table'};

print "$table\n";

1;