home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Topware / activeperl / ActivePerl / Perl / bin / ppm2.bat < prev    next >
Encoding:
DOS Batch File  |  2002-12-01  |  34.5 KB  |  1,027 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!/usr/bin/perl
  14. #line 15
  15.  
  16. use Getopt::Long;
  17. use File::Basename;
  18. use Config;
  19. use strict;
  20.  
  21. use PPM;
  22.  
  23. $PPM::VERSION = "2.2.0";
  24.  
  25. my %help;
  26.  
  27. # mapping of POD sections to command topics
  28. my %topic = (
  29.     'Error Recovery' => 'genconfig',
  30.     'Installing'     => 'install',
  31.     'Querying'       => 'query',
  32.     'Removing'       => 'remove',
  33.     'Searching'      => 'search',
  34.     'Summarizing'    => 'summary',
  35.     'Verifying'      => 'verify',
  36.     'Synopsis'       => 'usage',
  37.     'Options'        => 'set',
  38. );
  39.  
  40. $help{'help'} = <<'EOT';
  41. Commands:
  42.     exit              - leave the program.
  43.     help [command]    - prints this screen, or help on 'command'.
  44.     install PACKAGES  - installs specified PACKAGES.
  45.     quit              - leave the program.
  46.     query [options]   - query information about installed packages.
  47.     remove PACKAGES   - removes the specified PACKAGES from the system.
  48.     search [options]  - search information about available packages.
  49.     set [options]     - set/display current options.
  50.     verify [options]  - verifies current install is up to date.
  51.     version           - displays PPM version number
  52.  
  53. EOT
  54.  
  55. # Build the rest of the online help from the POD
  56. $/ = "\n=";
  57. while (<DATA>) {
  58.     next unless my ($topic,$text) = /^(?:item|head[12]) ([^\n]+)\n\n(.*)=/s;
  59.     next unless $topic{$topic};
  60.     ($help{$topic{$topic}} = "\n$text"); # =~ s/\n *([^\n])/\n    $1/sg;
  61. }
  62. $/ = "\n";
  63.  
  64. # Need to do this here, because the user's config file is probably
  65. # hosed.
  66. if ($#ARGV == 0 && $ARGV[0] eq 'genconfig') {
  67.     &genconfig;
  68.     exit 0;
  69. }
  70.  
  71. if ($#ARGV == 0 && $ARGV[0] eq 'getconfig') {
  72.     print $PPM::PPMdat;
  73.     exit 0;
  74. }
  75.  
  76. my %options = PPM::GetPPMOptions();
  77. my $location;
  78.  
  79. my $moremsg = "[Press return to continue or 'q' to quit] ";
  80. my $interactive = 0;
  81.  
  82. my %repositories = PPM::ListOfRepositories();
  83.  
  84. my $prefix_pattern = $^O eq "MSWin32" ? '(--|-|\+|/)' : '(--|-|\+)';
  85.  
  86. $PPM::PPMShell = 1;
  87.  
  88. Getopt::Long::Configure("prefix_pattern=$prefix_pattern");
  89.  
  90. if ($#ARGV == -1 || ($#ARGV == 0 && $ARGV[0] =~ /^${prefix_pattern}location/)) {
  91.     my $prompt = 'PPM> ';
  92.     $interactive = 1;
  93.     GetOptions("location=s" => \$location);
  94.  
  95.     print "PPM interactive shell ($PPM::VERSION) - type 'help' for available commands.\n";
  96.     $| = 1;
  97.     while () {
  98.         print $prompt;
  99.         last unless defined ($_ = <> );
  100.         chomp;
  101.         s/^\s+//;
  102.         @ARGV = split(/\s+/, $_);
  103.         next unless @ARGV;
  104.         # exit/quit
  105.         if (command($ARGV[0], "qu|it") or command($ARGV[0], "|exit")) {
  106.             print "Quit!\n";
  107.             last;
  108.         }
  109.         exec_command();
  110.     }
  111.     exit 0;
  112. }
  113.  
  114. exit exec_command();
  115.  
  116. sub exec_command
  117. {
  118.     my $cmd = lc shift @ARGV;
  119.  
  120.     for (@ARGV) {
  121.         s/::/-/g;
  122.     }
  123.  
  124.     # help
  125.     if (command($cmd, "|help")) {
  126.         help(@ARGV);
  127.     return 0;
  128.     }
  129.     # query
  130.     elsif (command($cmd, "qu|ery")) {
  131.         GetOptions("case!" => \my $case, "abstract" => \my $abstract, 
  132.         "author" => \my $author );
  133.  
  134.         my %summary = InstalledPackageProperties();
  135.         if (@ARGV) {
  136.             my $searchtag;
  137.             if ($abstract || $author) {
  138.                 $searchtag = ($abstract ? 'ABSTRACT' : 'AUTHOR');
  139.             }
  140.             my $RE = shift @ARGV;
  141.             eval { $RE =~ /$RE/ };
  142.             if ($@) {
  143.                 print "'$RE': invalid regular expression.\n";
  144.                 return 1;
  145.             } 
  146.             $case = !$options{'IGNORECASE'} unless defined $case;
  147.             $RE = "(?i)$RE" if ($case == 0);
  148.             foreach(keys %summary) {
  149.                 if ($searchtag) {
  150.                     delete $summary{$_} unless $summary{$_}{$searchtag} =~ /$RE/;
  151.                 }
  152.                 else {
  153.                     delete $summary{$_} unless /$RE/;
  154.                 }
  155.             }
  156.         }
  157.         print_formatted(1, %summary);
  158.     return 0;
  159.     }
  160.     # install
  161.     elsif (command($cmd, "in|stall")) {
  162.         my $location = $location;
  163.         GetOptions("location=s" => \$location);
  164.         unless (@ARGV) {
  165.             if (!$interactive && -d "blib" && -f "Makefile") {
  166.                 return if InstallPackage(location => $location);
  167.                 print "Error installing blib: $PPM::PPMERR\n";
  168.                 return 1;
  169.             }
  170.             print "Package not specified.\n";
  171.             return 1;
  172.         }
  173.  
  174.         my %installed = InstalledPackageProperties();
  175.         foreach my $package (@ARGV) {
  176.             $package =~ s/::/-/g;
  177.             if (my $pkg = (grep {/^$package$/i} keys %installed)[0]) {
  178.                 my $version = $installed{$pkg}{'VERSION'};
  179.                 $version =~ s/(,0)*$//;
  180.                 $version =~ tr/,/./;
  181.                 print "Version $version of '$pkg' is already installed.\n" .
  182.                       "Remove it, or use 'verify --upgrade $pkg'.\n";
  183.                 next;
  184.             }
  185.             elsif ($interactive && $options{'CONFIRM'}) {
  186.                 print "Install package '$package?' (y/N): ";
  187.                 next unless <> =~ /^[yY]/;
  188.             }
  189.             print "Installing package '$package'...\n";
  190.             if(!InstallPackage("package" => $package, "location" => $location)) {
  191.                 print "Error installing package '$package': $PPM::PPMERR\n";
  192.         return 1;
  193.             }
  194.         }
  195.     return 0;
  196.     }
  197.     # remove
  198.     elsif (command($cmd, "|remove")) {
  199.         unless (@ARGV) {
  200.             print "Package not specified.\n";
  201.             return 1;
  202.         }
  203.         foreach my $package (@ARGV) {
  204.             $package =~ s/::/-/g;
  205.             if ($interactive && $options{'CONFIRM'}) {
  206.                 print "Remove package '$package?' (y/N): ";
  207.                 next unless <> =~ /[yY]/;
  208.             }
  209.             unless (RemovePackage("package" => $package)) {
  210.                 print "Error removing $package: $PPM::PPMERR\n";
  211.             }
  212.         }
  213.     return 0;
  214.     }
  215.     # search
  216.     elsif (command($cmd, "se|arch")) {
  217.         my (%summary, $searchtag);
  218.         my $location = $location;
  219.         GetOptions("case!" => \my $case, "location=s" => \$location, 
  220.             "abstract" => \my $abstract, "author" => \my $author );
  221.         my $searchRE = shift @ARGV;
  222.         if (defined $searchRE) {
  223.             eval { $searchRE =~ /$searchRE/ };
  224.             if ($@) {
  225.                 print "'$searchRE': invalid regular expression.\n";
  226.                 return 1;
  227.             }
  228.         }
  229.         $case = !$options{'IGNORECASE'} unless defined $case;
  230.         if ($abstract || $author) {
  231.             $searchtag = ($abstract ? 'ABSTRACT' : 'AUTHOR');
  232.         }
  233.         %summary = search_PPDs("location" => $location, "ignorecase" => !$case,
  234.             "searchtag" => $searchtag, "searchRE" => $searchRE);
  235.         foreach (keys %summary) {
  236.             print "Packages available from $_:\n";
  237.             print_formatted(2, %{$summary{$_}});
  238.         }
  239.     return 0;
  240.     }
  241.     # set
  242.     elsif (command($cmd, "se|t")) {
  243.         unless (set(@ARGV) || $interactive) {
  244.             PPM::SetPPMOptions("options" => \%options, "save" => 1);
  245.         }
  246.     return 0;
  247.     }
  248.     # verify
  249.     elsif (command($cmd, "ver|ify")) {
  250.         my $location = $location;
  251.         GetOptions("force" => \my $force, "location=s" => \$location, 
  252.             "upgrade" => \my $upgrade);
  253.         if ($interactive && $upgrade && $options{'CONFIRM'}) {
  254.             printf "Upgrade package%s? (y/N): ", @ARGV == 1 ? " '$ARGV[0]'" : "s";
  255.             return 0 unless <> =~ /^[yY]/;
  256.         }
  257.         return verify_packages("packages" => \@ARGV, "location" => $location, 
  258.             "upgrade" => $upgrade, "force" => $force);
  259.     }
  260.     elsif (command($cmd, "ver|sion")) {
  261.         print "$PPM::VERSION\n";
  262.     return 0;
  263.     }
  264.     elsif ($cmd eq "purge") {
  265.         my %summary = InstalledPackageProperties();
  266.         foreach(keys %summary) {
  267.             print "Purging $_\n";
  268.             RemovePackage("package" => $_, "force" => 1);
  269.         }
  270.     return 0;
  271.     }
  272.     elsif ($cmd eq 'refresh') {
  273.         my %summary = InstalledPackageProperties();
  274.     my $status = 0;
  275.         foreach(keys %summary) {
  276.             print "Refreshing $_\n";
  277.             if (!InstallPackage("package" => $_)) {
  278.                 print "Error installing package '$_': $PPM::PPMERR\n";
  279.         ++$status;
  280.             }
  281.         }
  282.     return $status;
  283.     }
  284.     else {
  285.         print "Unknown or ambiguous command '$cmd'; type 'help' for commands.\n";
  286.     return 1;
  287.     }
  288. }
  289.  
  290. sub help {
  291.     my $topic = @_ && $help{lc $_[0]} ? lc $_[0] : 'help';
  292.     my $help = $help{$topic};
  293.     $help =~ s/^(\s*)ppm\s+/$1/mg if $interactive;
  294.     print $help;
  295. }
  296.  
  297. sub more
  298. {
  299.     my ($lines) = shift @_;
  300.     if (++$$lines >= $options{'MORE'}) {
  301.         print $moremsg;
  302.         $_ = <>;
  303.         $$lines = $_ eq "q\n" ? -1 : 1;
  304.     }
  305. }
  306.  
  307. # This nasty piece of business splits $pattern into a required prefix 
  308. # and a "match any of this substring" suffix.  E.g. "in|stall" will
  309. # match a $cmd of "ins", "inst", ..., "install".
  310. sub command
  311. {
  312.     my ($cmd, $pattern) = @_;
  313.     my @pattern = split(/\|/, $pattern);
  314.     if ($pattern[1]) {
  315.         my @optchars = split(//, $pattern[1]);
  316.         # build up a "foo(b|ba|bar)" string
  317.         $pattern = "$pattern[0](";
  318.         $pattern[1] = shift @optchars;
  319.         $pattern[1] .= "|$pattern[1]$_" foreach @optchars;
  320.         $pattern .= "$pattern[1])";
  321.     }
  322.     return ($cmd =~ /^${pattern}$/i);
  323. }
  324.  
  325. # This routine prints the output for query and search
  326. # in a nicely formatted way, if $options{'VERBOSE'} is set.
  327. sub print_formatted
  328. {
  329.     my ($lines, %summary) = @_;
  330.     my $package;
  331.  
  332.     unless ($options{'VERBOSE'}) {
  333.         foreach $package (sort keys %summary) {
  334.             print "$package\n";
  335.             &more(\$lines) if $options{'MORE'} && $interactive;
  336.             last if $lines == -1;
  337.         }
  338.         return;
  339.     }
  340.  
  341.     my ($maxname, $maxversion) = (0, 0);
  342.     # find the longest package name and version strings, so we can
  343.     # format them nicely
  344.     $maxname < length($_) and $maxname = length($_) for keys %summary;
  345.     foreach $package (keys %summary) {
  346.         $summary{$package}{'VERSION'} =~ s/(,0)*$//;
  347.         $summary{$package}{'VERSION'} =~ tr/,/./;
  348.         $maxversion = length $summary{$package}{'VERSION'} > $maxversion ? 
  349.             length $summary{$package}{'VERSION'} : $maxversion;
  350.     }
  351.     my $columns = $ENV{COLUMNS} ? $ENV{COLUMNS} : 80;
  352.     my $namefield = "@" . "<" x ($maxname - 1);
  353.     my $versionfield = "@" . "<" x ($maxversion - 1);
  354.     my $abstractfield = "^" . "<" x ($columns - (6 + $maxname + $maxversion));
  355.     my $abstractpad = " " x ($maxname + $maxversion + 3);
  356.  
  357.     foreach $package (sort keys %summary) {
  358.         eval "format STDOUT = \n"
  359.                    . "$namefield [$versionfield] $abstractfield\n"
  360.                    . '$package, $summary{$package}{VERSION}, $summary{$package}{ABSTRACT}'
  361.                    . "\n"
  362.                    . "$abstractpad $abstractfield~~\n"
  363.                    . '$summary{$package}{ABSTRACT}' 
  364.                    . "\n"
  365.                    . ".\n";
  366.  
  367.         my $diff = $-;
  368.         write;
  369.         $diff -= $-;
  370.         $lines += ($diff - 1) if $diff > 1;
  371.         &more(\$lines) if $options{'MORE'} && $interactive;
  372.         last if $lines == -1;
  373.     }
  374. }
  375.  
  376. sub set
  377. {
  378.     my $option = lc shift @_; 
  379.  
  380.     unless ($option) {
  381.         print "Commands will " . ($options{'CONFIRM'} ? "" : "not ") . 
  382.             "be confirmed.\n";
  383.         print "Temporary files will " . ($options{'CLEAN'} ? "" : "not ") .
  384.             "be deleted.\n";
  385.         print "Download status will " . (($options{'DOWNLOADSTATUS'} > 0) ?
  386.             "be updated every $options{'DOWNLOADSTATUS'} bytes.\n" : 
  387.             "not be updated.\n");
  388.         print "Case-" . ($options{'IGNORECASE'} ? "in" : "") . 
  389.             "sensitive searches will be performed.\n";
  390.         print "Package installations will " . 
  391.             ($options{'FORCE_INSTALL'} ? "" : "not ") .
  392.                "continue if a dependency cannot be installed.\n";
  393.         print "Tracing info will " . (($options{'TRACE'} > 0 ) ? 
  394.             "be written to '$options{'TRACEFILE'}'.\n" : "not be written.\n");
  395.         print "Screens will " . ($options{'MORE'} > 0 ? 
  396.             "pause after $options{'MORE'} lines.\n" : "not pause.\n");
  397.         print "Query/search results will " . 
  398.             ($options{'VERBOSE'} ? "" : "not ") . "be verbose.\n";
  399.         if (defined $location) { print "Current PPD repository: $location\n"; }
  400.         else {
  401.             print "Current PPD repository paths:\n";
  402.             foreach $_ (keys %repositories) {
  403.                 print "\t$_: $repositories{$_}\n";
  404.             }
  405.         }
  406.         print "Packages will be installed under: $options{'ROOT'}\n" 
  407.             if ($options{'ROOT'});
  408.         print "Packages will be built under: $options{'BUILDDIR'}\n" 
  409.             if ($options{'BUILDDIR'});
  410.         return;
  411.     }
  412.  
  413.     my $value = shift @_;
  414.     if (command($option, "r|epository")) {
  415.         if ($value =~ /${prefix_pattern}remove/i) {
  416.             $value = join(" ", @_);
  417.             print "Location not specified.\n" and return 1 
  418.                 unless (defined $value);
  419.             PPM::RemoveRepository("repository" => $value);
  420.             %repositories = PPM::ListOfRepositories();
  421.         }
  422.         else {
  423.             my $location = shift @_;
  424.             print "Repository not specified.\n" and return 1
  425.                 unless (defined $value and defined $location);
  426.             PPM::AddRepository("repository" => $value,
  427.                 "location" => $location);
  428.             %repositories = PPM::ListOfRepositories();
  429.         }
  430.     }
  431.     else {
  432.         if (command($option, "c|onfirm")) {
  433.             $options{'CONFIRM'} = defined $value ? 
  434.                 ($value != 0) : ($options{'CONFIRM'} ? 0 : 1);
  435.             print "Commands will " . ($options{'CONFIRM'} ? "" : "not ") . 
  436.                 "be confirmed.\n";
  437.         }
  438.         elsif (command($option, "|save")) {
  439.             PPM::SetPPMOptions("options" => \%options, "save" => 1);
  440.             return 0;
  441.         }
  442.         elsif (command($option, "c|ase")) {
  443.             $options{'IGNORECASE'} = defined $value ? 
  444.                 ($value == 0) : ($options{'IGNORECASE'} ? 0 : 1);
  445.             print "Case-" . ($options{'IGNORECASE'} ? "in" : "") . 
  446.                 "sensitive searches will be performed.\n";
  447.         }
  448.         elsif (command($option, "r|oot")) {
  449.             my $old_root;
  450.             print "Directory not specified.\n" and return 1 unless ($value);
  451.             print "$PPM::PPMERR" and return 1
  452.                     unless ($old_root = PPM::chroot("location" => $value));
  453.             $options{'ROOT'} = $value;
  454.             print "Root is now $value [was $old_root].\n";
  455.         }
  456.         elsif (command($option, "|build")) {
  457.             print "Directory not specified.\n" and return 1 unless ($value);
  458.             print "Directory '$value' does not exist.\n" and return 1 
  459.                 unless (-d $value);
  460.             $options{'BUILDDIR'} = $value;
  461.             print "Build directory is now $value.\n";
  462.         }
  463.         elsif (command($option, "|force_install")) {
  464.             $options{'FORCE_INSTALL'} = defined $value ? ($value != 0) : 
  465.                 ($options{'FORCE_INSTALL'} ? 0 : 1);
  466.             print "Package installations will " .
  467.                   ($options{'FORCE_INSTALL'} ? "" : "not ") .
  468.                   "continue if a dependency cannot be installed.\n";
  469.         }
  470.         elsif (command($option, "c|lean")) {
  471.             $options{'CLEAN'} = defined $value ? 
  472.                 ($value != 0) : ($options{'CLEAN'} ? 0 : 1);
  473.             print "Temporary files will " . ($options{'CLEAN'} ? "" : "not ") . 
  474.                 "be deleted.\n";
  475.         }
  476.         elsif (command($option, "|downloadstatus")) {
  477.             print "Numeric value must be given.\n" and return 1
  478.                 unless (defined $value && $value =~ /^\d+$/);
  479.             $options{'DOWNLOADSTATUS'} = $value;
  480.             print "Download status will " . (($options{'DOWNLOADSTATUS'} > 0) ?
  481.                 "be updated every $options{'DOWNLOADSTATUS'} bytes.\n" : 
  482.                 "not be updated.\n");
  483.         }
  484.         elsif (command($option, "|more")) {
  485.             print "Numeric value must be given.\n" and return 1
  486.                 unless (defined $value && $value =~ /^\d+$/);
  487.             $options{'MORE'} = $value;
  488.             print "Screens will " . ($options{'MORE'} > 0 ? 
  489.                 "pause after $options{'MORE'} lines.\n" : "not pause.\n");
  490.         }
  491.         elsif (command($option, "trace|file")) {
  492.             print "Filename not specified.\n" and return 1 unless ($value);
  493.             $options{'TRACEFILE'} = $value;
  494.             print "Tracing info will be written to $options{'TRACEFILE'}.\n";
  495.         }
  496.         elsif (command($option, "trace")) {
  497.             print "Numeric value between 0 and 4 must be given.\n" and return 1
  498.                 unless (defined $value && 
  499.                     $value =~ /^\d+$/ && $value >= 0 && $value <= 4);
  500.             $options{'TRACE'} = $value;
  501.             print "Tracing info will " . ($options{'TRACE'} > 0 ? 
  502.                 "be written to $options{'TRACEFILE'}.\n" : "not be written.\n");
  503.         }
  504.         elsif (command($option, "|verbose")) {
  505.             $options{'VERBOSE'} = defined $value ? 
  506.                 ($value != 0) : ($options{'VERBOSE'} ? 0 : 1);
  507.             print "Query/search results will " . 
  508.                 ($options{'VERBOSE'} ? "" : "not ") . "be verbose.\n";
  509.         }
  510.         else {
  511.             print "Unknown or ambiguous option '$option'; see 'help set' for available options.\n";
  512.             return 1;
  513.         }
  514.         PPM::SetPPMOptions("options" => \%options);
  515.     }
  516.     return;
  517. }
  518.  
  519. sub search_PPDs
  520. {
  521.     my %argv = @_;
  522.     my @locations = $argv{'location'} || $location;
  523.     my $searchtag = $argv{'searchtag'};
  524.     my $ignorecase = defined $argv{'ignorecase'} ? 
  525.         $argv{'ignorecase'} : $options{'IGNORECASE'};
  526.     my $searchRE = $argv{'searchRE'};
  527.     if (defined $searchRE) {
  528.         eval { $searchRE =~ /$searchRE/ };
  529.         if ($@) {
  530.             print "'$searchRE': invalid regular expression.\n";
  531.             return;
  532.         }
  533.         $searchRE = "(?i)$searchRE" if $ignorecase;
  534.     }
  535.  
  536.     my %packages;
  537.     unless (defined $locations[0]) {
  538.         my %reps = PPM::ListOfRepositories;
  539.         @locations = values %reps;
  540.     }
  541.     foreach my $loc (@locations) {
  542.         my %summary;
  543.  
  544.         # see if the repository has server-side searching
  545.         if (defined $searchRE && (%summary = ServerSearch('location' => $loc, 
  546.                 'searchRE' => $searchRE, 'searchtag' => $searchtag))) {
  547.             # XXX: clean this up
  548.             foreach my $package (keys %{$summary{$loc}}) {
  549.                 $packages{$loc}{$package} = \%{$summary{$loc}{$package}};
  550.             }
  551.             next;
  552.         }
  553.  
  554.         # see if a summary file is available
  555.         %summary = RepositorySummary("location" => $loc);
  556.         if (%summary) {
  557.             foreach my $package (keys %{$summary{$loc}}) {
  558.                 next if (defined $searchtag && 
  559.                     $summary{$loc}{$package}{$searchtag} !~ /$searchRE/);
  560.                 next if (!defined $searchtag && 
  561.                     defined $searchRE && $package !~ /$searchRE/);
  562.                 $packages{$loc}{$package} = \%{$summary{$loc}{$package}};
  563.             }
  564.         }
  565.         else {
  566.             my %ppds = PPM::RepositoryPackages("location" => $loc);
  567.             # No summary: oh my, nothing but 'Net
  568.             foreach my $package (@{$ppds{$loc}}) {
  569.                 my %package_details = RepositoryPackageProperties(
  570.                     "package" => $package, "location" => $loc);
  571.                 next unless %package_details;
  572.                 next if (defined $searchtag && 
  573.                     $package_details{$searchtag} !~ /$searchRE/);
  574.                 next if (!defined $searchtag && 
  575.                     defined $searchRE && $package !~ /$searchRE/);
  576.                 $packages{$loc}{$package} = \%package_details;
  577.             }
  578.         }
  579.     }
  580.     return %packages;
  581. }
  582.  
  583. sub verify_packages
  584. {
  585.     my %argv = @_;
  586.     my @packages = @{$argv{'packages'}};
  587.     my $upgrade = $argv{'upgrade'};
  588.     my $force = $argv{'force'};
  589.     my $location = $argv{'location'} || $location;
  590.     unless ($packages[0]) {
  591.         my %info = QueryInstalledPackages();
  592.         @packages = sort keys %info;
  593.     }
  594.     my $failed = 0;
  595.  
  596.     my $package = shift @packages;
  597.     while ($package) {
  598.         my $status = VerifyPackage("package" => $package, 
  599.             "location" => $location, "upgrade" => $upgrade, "force" => $force);
  600.         if (defined $status) {
  601.             if ($status eq "0") {
  602.                 print "Package \'$package\' is up to date.\n";
  603.             }
  604.             elsif ($upgrade) {
  605.                 print "Package $package upgraded to version $status\n";
  606.             }
  607.             else {
  608.                 print "An upgrade to package \'$package\' is available.\n";
  609.             }
  610.         }
  611.         else {
  612.             # Couldn't find a PPD to compare it with.
  613.             # Hack: no warning if its on of the core PPM 
  614.             # modules (hardcoded below :)
  615.             my $no=0;
  616.             foreach my $corepackage (
  617.             "Compress-Zlib","Archive-Tar","Digest-MD5","File-CounterFile",
  618.             "Font-AFM","HTML-Parser","HTML-Tree","MIME-Base64","URI",
  619.             "libwww-perl","XML-Parser","SOAP-Lite","PPM","libnet",
  620.             "libwin32","HTML-Tagset"
  621.             )
  622.             {
  623.                 if ($corepackage eq $package) {
  624.                     $no=1;
  625.                     last;
  626.                 }
  627.             }
  628.         unless ($no) {
  629.         ++$failed;
  630.         print "While verifying package '$package': $PPM::PPMERR\n";
  631.         }
  632.         }
  633.         $package = shift @packages;
  634.     }
  635.     return $failed;
  636. }
  637.  
  638. sub genconfig
  639. {
  640. my $PerlDir = $Config{'prefix'};
  641. print <<"EOF";
  642. <PPMCONFIG>
  643.     <PPMVER>2,2,0,0</PPMVER>
  644.     <PLATFORM CPU="x86" OSVALUE="$Config{'osname'}" OSVERSION="0,0,0,0" />
  645.     <OPTIONS BUILDDIR="$ENV{'TEMP'}" CLEAN="1" CONFIRM="1" DOWNLOADSTATUS="16384" FORCEINSTALL="1" IGNORECASE="1" MORE="0" ROOT="$PerlDir" TRACE="0" TRACEFILE="PPM.LOG" VERBOSE="1" />
  646.     <REPOSITORY LOCATION="http://www.ActiveState.com/cgibin/PPM/ppmserver.pl?urn:/PPMServer" NAME="ActiveState Package Repository" SUMMARYFILE="fetch_summary"/>
  647.     <PPMPRECIOUS>Compress-Zlib;Archive-Tar;Digest-MD5;File-CounterFile;Font-AFM;HTML-Parser;HTML-Tree;MIME-Base64;URI;libwww-perl;XML-Parser;SOAP-Lite;PPM;libnet;libwin32</PPMPRECIOUS>
  648. </PPMCONFIG>
  649. EOF
  650. }
  651.  
  652. __DATA__
  653.  
  654. =head1 NAME
  655.  
  656. PPM - Perl Package Manager: locate, install, upgrade software packages.
  657.  
  658. =head1 SYNOPSIS
  659.  
  660.  ppm genconfig
  661.  ppm help [command]
  662.  ppm install [--location=location] package1 [... packageN]
  663.  ppm query [--case|nocase] [--abstract|author] PATTERN
  664.  ppm remove package1 [... packageN]
  665.  ppm search [--case|nocase] [--location=location] [--abstract|author] PATTERN
  666.  ppm set [option]
  667.  ppm verify [--location=location] [--upgrade] [--force] [package1 ... packageN]
  668.  ppm version
  669.  ppm [--location=location]
  670.  
  671. =head1 DESCRIPTION
  672.  
  673. ppm is a utility intended to simplify the tasks of locating, installing,
  674. upgrading and removing software packages.  It is a front-end to the
  675. functionality provided in PPM.pm.  It can determine if the most recent
  676. version of a software package is installed on a system, and can install
  677. or upgrade that package from a local or remote host.
  678.  
  679. ppm runs in one of two modes: an interactive shell from which commands
  680. may be entered; and command-line mode, in which one specific action is
  681. performed per invocation of the program.
  682.  
  683. ppm uses files containing an extended form of the Open Software
  684. Description (OSD) specification for information about software packages.
  685. These description files, which are written in Extensible Markup
  686. Language (XML) code, are referred to as 'PPD' files.  Information about
  687. OSD can be found at the W3C web site (at the time of this writing,
  688. http://www.w3.org/TR/NOTE-OSD.html).  The extensions to OSD used by ppm
  689. are documented in PPM.ppd.
  690.  
  691. =head1 Using PPM
  692.  
  693. =over 4
  694.  
  695. =item Interactive mode
  696.  
  697. If ppm is invoked with no command specified, it is started in interactive
  698. mode.  If the '--location' argument is specified, it is used as the
  699. search location, otherwise the repositories specified in the PPM data file
  700. are used. 
  701.  
  702. The syntax of PPM commands is the same in interactive mode as it is in
  703. command-line mode.  The 'help' command lists the available commands.
  704.  
  705. ppm commands may be abbreviated to their shortest unique form.
  706.  
  707. =item Installing
  708.  
  709.  ppm install [--location=location] package1 [... packageN]
  710.  
  711. Installs the specified software packages. Attempts to install from the 
  712. URL or directory 'location' if the '--location' option is specfied. 
  713.  
  714. The 'package' arguments may be either package names ('foo'), pathnames 
  715. (p:/packages/foo.ppd) or URLs (http://www.ActiveState.com/packages/foo.ppd)
  716. to specific PPD files.
  717.  
  718. In the case where a package name is specified, and the '--location'
  719. option is not used, ppm will refer to the default repository locations.
  720.  
  721. See also: 'confirm' option.
  722.  
  723. =item Removing
  724.  
  725.  ppm remove package1 [... packageN]
  726.  
  727. Reads information from the PPD file for the named software package and
  728. removes the package from the system.
  729.  
  730. See also: 'confirm' option.
  731.  
  732. =item Verifying
  733.  
  734.  ppm verify [--location=location] [--upgrade] [--force] [package1 ... packageN]
  735.  
  736. Verifies that the currently installed packages are up to date.  If no
  737. packages are specified as arguments, all installed packages will be verified.
  738.  
  739. If the '--upgrade' option is specified, any package for which an upgrade 
  740. is available will be upgraded.  
  741.  
  742. If the '--location' option is specified, upgrades will be looked for at 
  743. the specified URL or directory.
  744.  
  745. If the '--force' option is specified, all currently installed packages will 
  746. be reinstalled regardless of whether they are out of date or not.
  747.  
  748. See also: 'confirm' option.
  749.  
  750. =item Querying
  751.  
  752.  ppm query [--case|nocase] [--abstract|author] PATTERN
  753.  
  754. Searches for 'PATTERN' (a regular expression) in the name of any installed 
  755. package.  If a search is successful, information about the matching 
  756. package(s) is displayed.  If 'PATTERN' is omitted, information about
  757. all installed packages will be displayed.
  758.  
  759. If either '--abstract' or '--author' is specified, PATTERN will be 
  760. searched for in the <ABSTRACT> or <AUTHOR> tags of the installed packages.
  761.  
  762. The '--case' and '--nocase' options can be used to override the default
  763. case-sensitivity search settings.
  764.  
  765. See also: 'case' option.
  766.  
  767. =item Searching
  768.  
  769.  ppm search [--case|nocase] [--location=location] [--abstract|author] PATTERN
  770.  
  771. Displays a list of any packages matching 'PATTERN' (a regular expression)
  772. available from the specified location.  If 'PATTERN' is omitted, information 
  773. about all available packages will be displayed.
  774.  
  775. If the '--location' option is specified, the specified URL or directory
  776. will be searched.  If '--location' is not specified, the repository location 
  777. as specified in the PPM data file will be searched.
  778.  
  779. If either '--abstract' or '--author' is specified, PATTERN will be 
  780. searched for in the <ABSTRACT> or <AUTHOR> tags of the available packages.
  781.  
  782. The '--case' and '--nocase' options can be used to override the default
  783. case-sensitivity search settings.
  784.  
  785. See also: 'case' option.
  786.  
  787. =item Error Recovery
  788.  
  789.  ppm genconfig
  790.  ppm getconfig
  791.  
  792. The genconfig command will print a valid PPM config file (ppm.xml) to STDOUT.
  793. This can be useful if the PPM config file ever gets damaged leaving PPM
  794. unusable.
  795.  
  796. If required, this command should be run from a shell prompt:
  797.  
  798.     C:\Perl\site\lib> ppm genconfig > ppm.xml
  799.  
  800. The getconfig command prints the location of the PPM configuration file
  801. used at PPM startup.
  802.  
  803. =item Options
  804.  
  805.  ppm set [option value]
  806.  
  807. Sets or displays current options.  With no arguments, current option
  808. settings are displayed.  For options that accept '1' or '0', specifying
  809. '1' sets the option, and '0' unsets it.
  810.  
  811. Available options:
  812.  
  813.     build DIRECTORY
  814.         - Changes the package build directory.
  815.  
  816.     case [1|0]
  817.         - Sets case-sensitive searches.  If one of '1' or '0' is
  818.           not specified, the current setting is toggled.
  819.  
  820.     clean [1|0]
  821.         - Sets removal of temporary files from package's build 
  822.           area, on successful installation of a package.  If one of
  823.           '1' or '0' is not specified, the current setting is
  824.           toggled.
  825.  
  826.     confirm [1|0]
  827.         - Sets confirmation of 'install', 'remove' and 'upgrade'.
  828.           If one of '1' or '0' is not specified, the current
  829.           setting is toggled.
  830.  
  831.     downloadstatus NUMBER
  832.         - If non-zero, updates the download status after each NUMBER 
  833.           of bytes transferred during an 'install'.  This can be
  834.           reassuring when installing a large package (e.g. Tk) over
  835.           a low-speed connection.
  836.  
  837.     force_install [1|0]
  838.         - Continue installing a package even if a dependency cannot
  839.           be installed.
  840.  
  841.     more NUMBER
  842.         - Causes output to pause after NUMBER lines have been
  843.           displayed.  Specifying '0' turns off this capability.
  844.  
  845.     set repository --remove NAME
  846.         - Removes the repository 'NAME' from the list of repositories.
  847.  
  848.     set repository NAME LOCATION
  849.         - Adds a repository to the list of PPD repositories for this
  850.           session.  'NAME' is the name by which this repository will
  851.           be referred; 'LOCATION' is a URL or directory name.
  852.  
  853.     root DIRECTORY
  854.         - Changes the install root directory.  Packages will be
  855.           installed under this new root.
  856.  
  857.     save
  858.         - Saves the current options as default options for future
  859.           sessions.
  860.  
  861.     trace
  862.         - Tracing level--default is 1, maximum is 4, 0 indicates
  863.           no tracing.
  864.  
  865.     tracefile
  866.         - File to contain tracing information, default is 'PPM.LOG'.
  867.  
  868.     verbose [1|0]
  869.         - Display additional package information for 'query' and
  870.           'search' commands.
  871.  
  872. =head1 EXAMPLES
  873.  
  874. =over 4
  875.  
  876. =item ppm
  877.  
  878. Starts ppm in interactive mode, using the repository locations specified
  879. in the PPM data file.  A session might look like this:
  880.  
  881.     [show all available packages]
  882.     PPM> search
  883.     Packages available from P:\PACKAGES:
  884.     bar [2.91 ] supplies bar methods for perl5.
  885.     bax [0.072] module for manipulation of bax archives.
  886.     baz [1.03 ] Interface to baz library
  887.     foo [2.23 ] Foo parser class
  888.     
  889.     [list what has already been installed]
  890.     PPM> query
  891.     bax [0.071] module for manipulation of bax archives.
  892.     baz [1.02 ] Interface to baz library
  893.     
  894.     [install a package]
  895.     PPM> install foo
  896.     Install package foo? (y/N): y
  897.     [...]
  898.     
  899.     [toggle confirmations]
  900.     PPM> set confirm
  901.     Commands will not be confirmed.
  902.     
  903.     [see if 'baz' is up-to-date]
  904.     PPM> verify baz
  905.     An upgrade to package 'baz' is available.
  906.     
  907.     [upgrade 'baz']
  908.     PPM> verify --upgrade baz
  909.     [...]
  910.     
  911.     [forced upgrade of 'baz']
  912.     PPM> verify --upgrade --force baz
  913.     [...]
  914.     
  915.     [toggle case-sensitive searches]
  916.     PPM> set case
  917.     Case-sensitive searches will be performed.
  918.     
  919.     [display all available packages beginning with 'b']
  920.     PPM> search ^b
  921.     bar [2.91 ] supplies bar methods for perl5.
  922.     bax [0.072] module for manipulation of bax archives.
  923.     baz [1.03 ] Interface to baz library
  924.     
  925.     [search for installed packages containing 'baz' in the ABSTRACT tag]
  926.     PPM> query --abstract baz
  927.     Matching packages found at P:\PACKAGES:
  928.     baz [1.03 ] Interface to baz library
  929.     PPM> quit
  930.  
  931. =item ppm install http://www.ActiveState.com/packages/foo.ppd
  932.  
  933. Installs the software package 'foo' based on the information in the PPD
  934. obtained from the specified URL.
  935.  
  936. =item ppm verify --upgrade foo
  937.  
  938. Compares the currently installed version of the software package 'foo'
  939. to the one available according to the PPD obtained from the location
  940. specified for this package in the PPM data file, and upgrades
  941. to a newer version if available.
  942.  
  943. =item ppm verify --location=P:\PACKAGES --upgrade foo
  944.  
  945. Compares the currently installed version of the software package 'foo'
  946. to the one available according to the PPD obtained from the specified
  947. directory, and upgrades to a newer version if available.
  948.  
  949. =item ppm verify --upgrade --force
  950.  
  951. Forces verification and reinstalls every installed package on the system, 
  952. using upgrade locations specified in the PPM data file.
  953.  
  954. =item ppm search --location=http://ppm.ActiveState.com/PPMpackages/5.8plus
  955.  
  956. Displays the packages with PPD files available at the specified location.
  957.  
  958. =item ppm search --location=P:\PACKAGES --author ActiveState
  959.  
  960. Searches the specified location for any package with an <AUTHOR> tag
  961. containing the string 'ActiveState'.  On a successful search, the package
  962. name and the matching string are displayed.
  963.  
  964. =back
  965.  
  966. =head1 ENVIRONMENT VARIABLES
  967.  
  968. =over 4
  969.  
  970. =item HTTP_proxy
  971.  
  972. If the environment variable 'HTTP_proxy' is set, then it will
  973. be used as the address of a proxy server for accessing the Internet.
  974.  
  975. The value should be of the form: 'http://proxy:port'.
  976.  
  977. =back
  978.  
  979. =head1 FILES
  980.  
  981. The following files are fully described in the 'Files' section of PPM:ppm.
  982.  
  983. =over 4
  984.  
  985. =item package.ppd
  986.  
  987. A description of a software package, in extended Open Software Description
  988. (OSD) format.  More information on this file format can be found in
  989. PPM::ppd.
  990.  
  991. =item ppm.xml - PPM data file.
  992.  
  993. An XML format file containing information about the local system,
  994. specifics regarding the locations from which PPM obtains PPD files, and
  995. the installation details for any package installed by ppm.
  996.  
  997. This file usually resides in '[perl]/site/lib'.  If the environment 
  998. variable 'PPM_DAT' is set, its value will be used as the full pathname
  999. to a PPM data file.  If all else fails, ppm will look for a data file
  1000. in the current directory.
  1001.  
  1002. =back
  1003.  
  1004. =head1 AUTHOR
  1005.  
  1006. Murray Nesbitt, E<lt>F<murray@ActiveState.com>E<gt>
  1007.  
  1008. =head1 CREDITS
  1009.  
  1010. =over 4
  1011.  
  1012. =item *
  1013.  
  1014. The "geek-pit" at ActiveState.
  1015.  
  1016. =item *
  1017.  
  1018. Paul Kulchenko for his SOAP-Lite package, and for his enthusiastic
  1019. assistance in getting PPM to work with SOAP-Lite.
  1020.  
  1021. =back
  1022.  
  1023. =cut
  1024.  
  1025. __END__
  1026. :endofperl
  1027.