-
Notifications
You must be signed in to change notification settings - Fork 0
/
finddisappeared
executable file
·77 lines (57 loc) · 1.92 KB
/
finddisappeared
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long qw(:config gnu_compat);
use File::Basename;
my $PROGRAM = basename $0;
my $VERSION = '@VERSION@';
######################################################################
# Find disappeared files. #
######################################################################
sub finddisappeared {
my $root = shift || '';
my $pkgdb = "$root/var/lib/pkg/db";
open my $fh, "<", $pkgdb
or die "$PROGRAM: couldn't open package database ($pkgdb): $!\n";
local $/ = ""; # read files paragraph-wise
while (<$fh>) {
my ($name, $version, @footprint) = split /\n/;
my @missing = grep ! -e "$root/$_", @footprint;
next unless @missing;
print map "$name: /$_\n", @missing;
}
close $fh;
}
######################################################################
# Command-line helpers. #
######################################################################
sub print_version {
print "$PROGRAM (pkgmaint) $VERSION\n";
}
sub print_help {
print <<EOF;
Usage: $PROGRAM [-hv] [-r rootdir]
Find files that are owned by package manager but somehow disappeared.
Mandatory arguments to long options are mandatory for short options too.
-r, --root=rootdir specify an alternate root directory
-v, --version print version and exit
-h, --help print help and exit
EOF
}
sub main {
my $help_ref = "Try '$PROGRAM --help' for more information.";
GetOptions(
"r|root=s" => \my $opt_root,
"v|version" => \my $opt_version,
"h|help" => \my $opt_help,
) or die "$help_ref\n";
print_version() and exit if $opt_version;
print_help() and exit if $opt_help;
die "$PROGRAM: invalid option -- '@ARGV'\n$help_ref\n" if @ARGV;
finddisappeared $opt_root;
}
######################################################################
main() if not caller();
1;
# vim: cc=72 tw=70
# End of file.