summaryrefslogtreecommitdiff
path: root/kernel/xpp/utils/zaptel_drivers
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/xpp/utils/zaptel_drivers')
-rwxr-xr-xkernel/xpp/utils/zaptel_drivers151
1 files changed, 150 insertions, 1 deletions
diff --git a/kernel/xpp/utils/zaptel_drivers b/kernel/xpp/utils/zaptel_drivers
index d7904c0..5ace08b 100755
--- a/kernel/xpp/utils/zaptel_drivers
+++ b/kernel/xpp/utils/zaptel_drivers
@@ -3,7 +3,156 @@ use strict;
use File::Basename;
BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/zconf"); }
+use Errno;
+use Getopt::Std;
use Zaptel::Hardware;
+my %opts;
+my $etc_modules = '/etc/modules';
+my $zaptel_redhat = '/etc/sysconfig/zaptel';
+my $zaptel_debian = '/etc/default/zaptel';
+my $zaptel_conffile;
+
+getopts('vdM', \%opts) || die "$0: Bad options\n";
+
+if(-f $zaptel_redhat) {
+ $zaptel_conffile = $zaptel_redhat;
+} elsif(-f $zaptel_debian) {
+ $zaptel_conffile = $zaptel_debian;
+ $opts{'d'} = 1 if $opts{'M'};
+} else {
+ die "$0: Could not find '$zaptel_redhat' nor '$zaptel_debian'\n";
+}
+
my $hardware = Zaptel::Hardware->scan;
-print join("\n", $hardware->drivers),"\n";
+
+sub update_zaptel_distro(@) {
+ my @driver_list = @_;
+ my $varname = 'MODULES';
+ my $newfile = "${zaptel_conffile}.new";
+ my $backupfile = "${zaptel_conffile}.bak";
+
+ print "Updating $zaptel_conffile\n" if $opts{'v'};
+ open(NEWFILE, ">$newfile") || die "$0: Failed to open '$newfile': $!\n";
+ open(BACKUPFILE, ">$backupfile") || die "$0: Failed to open '$backupfile': $!\n";
+ if(open(IN, $zaptel_conffile)) {
+ while(my $line = <IN>) {
+ print BACKUPFILE $line;
+ chomp $line;
+ next if $line =~ /^${varname}=/; # Skip old defs.
+ print NEWFILE "$line\n";
+ }
+ close IN;
+ } elsif(defined($!{ENOENT})) {
+ print "Creating $zaptel_conffile\n" if $opts{'v'};
+ } else {
+ die "$0: Failed opening '$zaptel_conffile': $!\n";
+ }
+ print NEWFILE "${varname}='@driver_list'\n";
+ close NEWFILE;
+ close BACKUPFILE;
+ rename($newfile, $zaptel_conffile) ||
+ die "$0: rename($newfile, $zaptel_conffile) failed: $!\n";
+}
+
+# This is for Debian.
+sub update_etc_modules(@) {
+ my @driver_list = @_;
+ my $newfile = "${etc_modules}.new";
+ my $backupfile = "${etc_modules}.bak";
+ # Just to make module loading order deterministic.
+ my @module_order = qw(
+ wct4xxp
+ wcte12xp
+ wcte11xp
+ wct1xxp
+ wanpipe
+ tor2
+ torisa
+ qozap
+ vzaphfc
+ zaphfc
+ ztgsm
+ wctdm24xxp
+ wctdm
+ opvxa1200
+ wcfxo
+ pciradio
+ wcusb
+ xpp_usb
+ ystdm8xx
+ zma8xx
+ );
+
+ open(NEWFILE, ">$newfile") || die "$0: Failed to open '$newfile': $!\n";
+ open(BACKUPFILE, ">$backupfile") || die "$0: Failed to open '$backupfile': $!\n";
+ if(open(IN, $etc_modules)) {
+ print "Updating $etc_modules\n" if $opts{'v'};
+ while(my $line = <IN>) {
+ print BACKUPFILE $line;
+ chomp $line;
+ next if grep(/^\s*${line}\s*$/, @module_order, @driver_list);
+ print NEWFILE "$line\n";
+ }
+ close IN;
+ } elsif(defined($!{ENOENT})) {
+ print "Creating $etc_modules\n" if $opts{'v'};
+ } else {
+ die "$0: Failed opening '$etc_modules': $!\n";
+ }
+ foreach my $d (@module_order) {
+ print NEWFILE "$d\n" if grep($d eq $_, @driver_list);
+ }
+ close NEWFILE;
+ close BACKUPFILE;
+ rename($newfile, $etc_modules) ||
+ die "$0: rename($newfile, $etc_modules) failed: $!\n";
+}
+
+if($opts{'d'}) {
+ update_etc_modules($hardware->drivers);
+}
+if($opts{'M'}) {
+ update_zaptel_distro($hardware->drivers);
+}
+
+if(!$opts{'d'} && !$opts{'M'}) {
+ print join("\n", $hardware->drivers),"\n";
+}
+
+__END__
+
+=head1 NAME
+
+zaptel_drivers - Show drivers required for installed zaptel devices.
+
+=head1 SYNOPSIS
+
+zaptel_drivers [-vdM]
+
+=head1 DESCRIPTION
+
+This script shows by default the list of drivers required for currently
+installed zaptel devices.
+
+Options:
+
+=over 4
+
+=item -v
+
+Verbose
+
+=item -d
+
+Generate /etc/modules for Debian systems.
+
+=item -M
+
+Generate distribution dependent module configuration file:
+ /etc/sysconfig/zaptel # For RedHat like systems
+ /etc/default/zaptel # For Debian like systems
+
+On debian systems, specifying this option turns on the '-d' option as well.
+
+=back