summaryrefslogtreecommitdiff
path: root/xpp/perl_modules/Dahdi/Config
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2008-06-19 17:34:36 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2008-06-19 17:34:36 +0000
commitda10e87bd6c69c4374de470b7b286c36c823fdc2 (patch)
tree8ae3ddc2b5eff066497697c0c6ec1bc7ee6433ad /xpp/perl_modules/Dahdi/Config
parentc1ae88873823bdc2d884f72cc2b06eab017b97b1 (diff)
XPP tools rename: part 2.
Removed obsolete astribank_hook (not needed) and print_modes (moved to kernel). git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@4416 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/perl_modules/Dahdi/Config')
-rw-r--r--xpp/perl_modules/Dahdi/Config/Defaults.pm57
1 files changed, 57 insertions, 0 deletions
diff --git a/xpp/perl_modules/Dahdi/Config/Defaults.pm b/xpp/perl_modules/Dahdi/Config/Defaults.pm
new file mode 100644
index 0000000..e720568
--- /dev/null
+++ b/xpp/perl_modules/Dahdi/Config/Defaults.pm
@@ -0,0 +1,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;