| 1 |
#! /usr/bin/perl |
| 2 |
use warnings; |
| 3 |
use strict; |
| 4 |
use integer; |
| 5 |
use FindBin; |
| 6 |
use lib $FindBin::RealBin; |
| 7 |
use Def; |
| 8 |
$/ = ''; |
| 9 |
|
| 10 |
# This script checks that you have all the standard- and higher-priority |
| 11 |
# packages listed in the Packages file fully installed on your system, |
| 12 |
# and that you have the right versions installed. Any you do not have |
| 13 |
# properly installed, it prints the names of to stdout, one per line. |
| 14 |
|
| 15 |
our $usage = <<END; |
| 16 |
usage: $0 [-1qh] [Packages-file] |
| 17 |
-1 exit nonzero if any packages are missing |
| 18 |
-q quiet: do not print the names of missing packages to stdout |
| 19 |
(note: the -q opt does not suppress error messages on stderr) |
| 20 |
-h print this help message |
| 21 |
END |
| 22 |
|
| 23 |
my $any_missing = ''; |
| 24 |
|
| 25 |
my %opt; |
| 26 |
for my $i ( reverse 0 .. $#ARGV ) { |
| 27 |
my( $o ) = $ARGV[$i] =~ /^-(.+)/; |
| 28 |
next unless defined $o; |
| 29 |
splice @ARGV, $i, 1; |
| 30 |
$opt{ substr $o, $_, 1 } = 1 for 0 .. length($o)-1; |
| 31 |
} |
| 32 |
$opt{h} || $opt{'?'} and print( $usage ), exit; |
| 33 |
|
| 34 |
while (<>) { |
| 35 |
my( $pkg ) = /^${Def::Package}: (\S+)\s*$/m |
| 36 |
or warn "$0: can find no Package field in\n$_"; |
| 37 |
my( $pri ) = /^${Def::Priority}: (\S+)\s*$/m |
| 38 |
or warn "$0: can find no Priority field in\n$_"; |
| 39 |
my( $ver ) = /^${Def::Version}: (\S+)\s*$/m |
| 40 |
or warn "$0: can find no Version field in\n$_"; |
| 41 |
next if $pri eq 'optional' || $pri eq 'extra'; |
| 42 |
my $dpkg_s = `dpkg -s $pkg 2>/dev/null`; |
| 43 |
my $dpkg_err = $?; |
| 44 |
my( $instver ) = $dpkg_s =~ /^Version: (\S+)\s*$/m; |
| 45 |
next if !$dpkg_err && |
| 46 |
$dpkg_s =~ /^Status: install ok installed$/m && |
| 47 |
defined($instver) && $instver eq $ver; |
| 48 |
print "$pkg\n" unless $opt{q}; |
| 49 |
$any_missing = '1'; |
| 50 |
} |
| 51 |
|
| 52 |
exit 1 if $opt{1} && $any_missing; |
| 53 |
|