]> piware.de Git - bin.git/blob - backup-getfiles
postinst-setup: do not trash shadow group
[bin.git] / backup-getfiles
1 #!/usr/bin/perl
2
3 # (c) 2002 Martin Pitt (martin@piware.de)
4 # This software is protected by the terms and conditions of the GNU
5 # General Public License (see http://www.gnu.org/copyleft/gpl.html for
6 # details).
7
8 use Getopt::Std;
9
10 # filelist( $d )
11 # generate a recursive list of files in $d; honors per-directory
12 # configuration files .pibackuprc
13 sub filelist {
14     my $d = shift;
15     $d .= '/' if ( substr( $d, -1 ) ne '/' );
16
17     # look for exclude file
18     my @excl;
19     if( -r $d.'.pibackuprc' ) {
20         open( EXCL, $d.'.pibackuprc' ) or die "Error: could not open $d.pibackuprc";
21         while( <EXCL> ) {
22             chomp;
23             push @excl, glob $d.$_;
24         }
25         close EXCL;
26     }
27
28     # open and traverse dir
29     local *DIR;
30     opendir( DIR, $d ) or print STDERR "Could not open directory $d\n" && return; 
31
32 FILE:
33     while( defined( $f = readdir DIR ) ) {
34         next if $f eq '.' || $f eq '..';
35
36         foreach ( @excl ) { next FILE if $d.$f eq $_; }
37
38         if( !( -l $d.$f ) && -d _ ) {
39             filelist( $d.$f );
40         } else {
41             if( !$newer || ( ( lstat _ )[9] >= $newer ) ) {
42                 print "$d$f$term";
43             }
44         }
45     }
46     closedir DIR;
47 }
48
49 getopts( '0n:' );
50
51 if( $opt_n ) {
52     $newer = ( lstat $opt_n )[9];  # mtime
53 }
54
55 $term = $opt_0 ? "\0" : "\n";
56
57 $dir = $ARGV[0] || $ENV{'HOME'} || '/';
58 foreach (glob $dir) {
59     if (-d $_) {
60         filelist $_;
61     } else {
62         print "$_$term";
63     }
64 }