blob: e7205680a7745219f665f3bc12bf41e93d420d57 (
plain)
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
52
53
54
55
56
57
|
package Dahdi::Config::Defaults;
#
# Written by Oron Peled <oron@actcom.co.il>
# Copyright (C) 2007, Xorcom
# This program is free software; you can redistribute and/or
# modify it under the same terms as Perl itself.
#
# $Id$
#
use strict;
# Use the shell to source a file and expand a given list
# of variables.
sub do_source($@) {
my $file = shift;
my @vars = @_;
my @output = `env -i sh -ec '. $file; export @vars; for i in @vars; do eval echo \$i=\\\$\$i; done'`;
die "$0: Sourcing '$file' exited with $?" if $?;
my %vars;
foreach my $line (@output) {
chomp $line;
my ($k, $v) = split(/=/, $line, 2);
$vars{$k} = $v if grep /^$k$/, @vars;
}
return %vars;
}
sub source_vars {
my @vars = @_;
my $default_file;
my %system_files = (
"/etc/default/zaptel" => 'Debian and friends',
"/etc/sysconfig/zaptel" => 'Red Hat and friends',
"/etc/dahdi/defaults" => 'Dahdi generic',
);
if(defined $ENV{DAHDI_DEFAULTS}) {
$default_file = $ENV{DAHDI_DEFAULTS};
} else {
foreach my $f (keys %system_files) {
if(-r $f) {
if(defined $default_file) {
die "An '$f' collides with '$default_file'";
}
$default_file = $f;
}
}
}
if (! $default_file) {
return ("", ());
}
my %vars = Dahdi::Config::Defaults::do_source($default_file, @vars);
return ($default_file, %vars);
}
1;
|