File Coverage

install-radius-db.PL
Criterion Covered Total %
statement 18 40 45.0
branch 7 20 35.0
condition 0 3 0.0
subroutine 1 1 100.0
pod n/a
total 26 64 40.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2             # $Id: install-radius-db.PL,v 1.2 2004/12/18 04:51:17 andrew Exp $
3 1         195922 my $source_dir = 'raddb';
4 1         4 my $raddb_dir = '/etc/raddb';
5              
6 1 50       74 unless (-w $raddb_dir) {
7             # Cannot write to the raddb directory
8 0 0       0 unless (-x $raddb_dir) {
9             # Perhaps it just does not exists, so it can be created?
10 0         0 my @path = split('/', $raddb_dir);
11 0         0 pop(@path);
12 0         0 my $up = join('/', @path);
13 0 0 0     0 unless (-w $up and mkdir($raddb_dir) ) {
14 0         0 print STDERR "$raddb_dir directory does not exists and cannot be created\n";
15 0         0 print STDERR "Default RADIUS dictionaries are not installed.\n";
16 0         0 exit(0);
17             } else {
18 0         0 print "Created $raddb_dir\n";
19             }
20             } else {
21 0         0 print STDERR "Cannot copy the dictionary files in $raddb_dir\n";
22 0         0 print STDERR "Default RADIUS dictionaries are not installed.\n";
23 0         0 exit(0);
24             }
25             }
26 1         17 print "Installing the RADIUS dictionaries in $raddb_dir\n";
27 1         64 opendir(D, $source_dir);
28 1         45 while ($_ = readdir(D)) {
29 18 100       40 next if m/^\./;
30 16         39 my $dest = join('/', (split('/', $raddb_dir), $_));
31 16         25 print "Copying $_ to $dest ";
32 16         30 my $res = copyFile($source_dir.'/'.$_, $dest);
33 16 50       36 print $res ? ($res > 0 ? "- done." : "- ignored.") : "- error!";
    50          
34 16         49 print "\n";
35             }
36 1         16 closedir(D);
37              
38 1         0 exit(0);
39              
40             sub copyFile {
41 16     16   22 my ($f1, $f2) = @_;
42 16 50       157 unless (-f $f1) {
43 0         0 return -1;
44             }
45 16 50       182 if (-e $f2) {
46 16         29 return -1;
47             }
48 0 0         open(F1, $f1) or return;
49 0 0         unless (open(F2,">$f2")) {
50 0           close(F1); return;
  0            
51             }
52 0           while () {
53 0           print F2 $_;
54             }
55 0           close(F1); close(F2);
  0            
56 0           return 1;
57             }