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