3 # lbs-util: Tool for managing LBS archives.
5 # Usage: lbs-util <repository> <cmd> <args>
10 # --verify-snapshot <snapshot>
13 use LBS qw(parse_headers);
14 use Term::ReadPassword;
17 return if exists $ENV{LBS_GPG_PASSPHRASE};
18 $ENV{LBS_GPG_PASSPHRASE} = read_password('Passphrase: ');
21 die "Too few arguments!\n" unless scalar(@ARGV) >= 2;
22 die "Must specify a repository!\n" unless -d $ARGV[0];
24 my $store = new LBS::Store $ARGV[0];
26 my @args = @ARGV[2 .. $#ARGV];
28 if ($cmd eq "--list-snapshots") {
29 foreach ($store->list_snapshots()) {
32 } elsif ($cmd eq "--list-segments") {
33 foreach ($store->list_segments()) {
36 } elsif ($cmd eq "--verify-snapshot") {
39 my $snapshot = $store->load_snapshot($args[0]);
40 my %info = parse_headers($snapshot);
41 print "Root: $info{Root}\n";
43 my $metadata = new LBS::MetadataParser $store, $info{Root};
44 while ((my %item = $metadata->get_item())) {
45 print $item{name}, "\n";
46 if ($item{type} eq '-') {
48 my $verifier = new LBS::ChecksumVerifier $item{checksum};
49 foreach (split /\s+/, $item{data}) {
50 my $data = $store->load_ref($_);
51 $verifier->add($data);
52 $size += length($data);
54 if (!$verifier->verify() || $size != $item{size}) {
55 fprintf STDERR "Verification failure for $item{name}\n";
60 die "Unknown command: $cmd\n";