home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D2.iso / workshop / apache / files / ActivePerl-5.6.1.638-MSWin32-x86.msi / _a3b9295a63ccefb927cc8cdd0daaf31b < prev    next >
Encoding:
Text File  |  2004-04-13  |  35.4 KB  |  1,045 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.         print "HTML documentation will " . ($options{'REBUILDHTML'} ? "" : "not ") .
  411.             "be rebuilt after installing each package.\n";
  412.          return;
  413.     }
  414.  
  415.     my $value = shift @_;
  416.     if (command($option, "r|epository")) {
  417.         if ($value =~ /${prefix_pattern}remove/i) {
  418.             $value = join(" ", @_);
  419.             print "Location not specified.\n" and return 1 
  420.                 unless (defined $value);
  421.             PPM::RemoveRepository("repository" => $value);
  422.             %repositories = PPM::ListOfRepositories();
  423.         }
  424.         else {
  425.             my $location = shift @_;
  426.             print "Repository not specified.\n" and return 1
  427.                 unless (defined $value and defined $location);
  428.             PPM::AddRepository("repository" => $value,
  429.                 "location" => $location);
  430.             %repositories = PPM::ListOfRepositories();
  431.         }
  432.     }
  433.     else {
  434.         if (command($option, "c|onfirm")) {
  435.             $options{'CONFIRM'} = defined $value ? 
  436.                 ($value != 0) : ($options{'CONFIRM'} ? 0 : 1);
  437.             print "Commands will " . ($options{'CONFIRM'} ? "" : "not ") . 
  438.                 "be confirmed.\n";
  439.         }
  440.         elsif (command($option, "|save")) {
  441.             PPM::SetPPMOptions("options" => \%options, "save" => 1);
  442.             return 0;
  443.         }
  444.         elsif (command($option, "c|ase")) {
  445.             $options{'IGNORECASE'} = defined $value ? 
  446.                 ($value == 0) : ($options{'IGNORECASE'} ? 0 : 1);
  447.             print "Case-" . ($options{'IGNORECASE'} ? "in" : "") . 
  448.                 "sensitive searches will be performed.\n";
  449.         }
  450.         elsif (command($option, "r|oot")) {
  451.             my $old_root;
  452.             print "Directory not specified.\n" and return 1 unless ($value);
  453.             print "$PPM::PPMERR" and return 1
  454.                     unless ($old_root = PPM::chroot("location" => $value));
  455.             $options{'ROOT'} = $value;
  456.             print "Root is now $value [was $old_root].\n";
  457.         }
  458.         elsif (command($option, "|build")) {
  459.             print "Directory not specified.\n" and return 1 unless ($value);
  460.             print "Directory '$value' does not exist.\n" and return 1 
  461.                 unless (-d $value);
  462.             $options{'BUILDDIR'} = $value;
  463.             print "Build directory is now $value.\n";
  464.         }
  465.         elsif (command($option, "|force_install")) {
  466.             $options{'FORCE_INSTALL'} = defined $value ? ($value != 0) : 
  467.                 ($options{'FORCE_INSTALL'} ? 0 : 1);
  468.             print "Package installations will " .
  469.                   ($options{'FORCE_INSTALL'} ? "" : "not ") .
  470.                   "continue if a dependency cannot be installed.\n";
  471.         }
  472.         elsif (command($option, "c|lean")) {
  473.             $options{'CLEAN'} = defined $value ? 
  474.                 ($value != 0) : ($options{'CLEAN'} ? 0 : 1);
  475.             print "Temporary files will " . ($options{'CLEAN'} ? "" : "not ") . 
  476.                 "be deleted.\n";
  477.         }
  478.         elsif (command($option, "|downloadstatus")) {
  479.             print "Numeric value must be given.\n" and return 1
  480.                 unless (defined $value && $value =~ /^\d+$/);
  481.             $options{'DOWNLOADSTATUS'} = $value;
  482.             print "Download status will " . (($options{'DOWNLOADSTATUS'} > 0) ?
  483.                 "be updated every $options{'DOWNLOADSTATUS'} bytes.\n" : 
  484.                 "not be updated.\n");
  485.         }
  486.         elsif (command($option, "|more")) {
  487.             print "Numeric value must be given.\n" and return 1
  488.                 unless (defined $value && $value =~ /^\d+$/);
  489.             $options{'MORE'} = $value;
  490.             print "Screens will " . ($options{'MORE'} > 0 ? 
  491.                 "pause after $options{'MORE'} lines.\n" : "not pause.\n");
  492.         }
  493.         elsif (command($option, "|rebuildhtml")) {
  494.             $options{'REBUILDHTML'} = defined $value ? 
  495.                 ($value != 0) : ($options{'REBUILDHTML'} ? 0 : 1);
  496.             print "HTML documentation will " . 
  497.                 ($options{'REBUILDHTML'} ? "" : "not ") . "be rebuilt after installing packages.\n";
  498.         }
  499.         elsif (command($option, "trace|file")) {
  500.             print "Filename not specified.\n" and return 1 unless ($value);
  501.             $options{'TRACEFILE'} = $value;
  502.             print "Tracing info will be written to $options{'TRACEFILE'}.\n";
  503.         }
  504.         elsif (command($option, "trace")) {
  505.             print "Numeric value between 0 and 4 must be given.\n" and return 1
  506.                 unless (defined $value && 
  507.                     $value =~ /^\d+$/ && $value >= 0 && $value <= 4);
  508.             $options{'TRACE'} = $value;
  509.             print "Tracing info will " . ($options{'TRACE'} > 0 ? 
  510.                 "be written to $options{'TRACEFILE'}.\n" : "not be written.\n");
  511.         }
  512.         elsif (command($option, "|verbose")) {
  513.             $options{'VERBOSE'} = defined $value ? 
  514.                 ($value != 0) : ($options{'VERBOSE'} ? 0 : 1);
  515.             print "Query/search results will " . 
  516.                 ($options{'VERBOSE'} ? "" : "not ") . "be verbose.\n";
  517.         }
  518.         else {
  519.             print "Unknown or ambiguous option '$option'; see 'help set' for available options.\n";
  520.             return 1;
  521.         }
  522.         PPM::SetPPMOptions("options" => \%options);
  523.     }
  524.     return;
  525. }
  526.  
  527. sub search_PPDs
  528. {
  529.     my %argv = @_;
  530.     my @locations = $argv{'location'} || $location;
  531.     my $searchtag = $argv{'searchtag'};
  532.     my $ignorecase = defined $argv{'ignorecase'} ? 
  533.         $argv{'ignorecase'} : $options{'IGNORECASE'};
  534.     my $searchRE = $argv{'searchRE'};
  535.     if (defined $searchRE) {
  536.         eval { $searchRE =~ /$searchRE/ };
  537.         if ($@) {
  538.             print "'$searchRE': invalid regular expression.\n";
  539.             return;
  540.         }
  541.         $searchRE = "(?i)$searchRE" if $ignorecase;
  542.     }
  543.  
  544.     my %packages;
  545.     unless (defined $locations[0]) {
  546.         my %reps = PPM::ListOfRepositories;
  547.         @locations = values %reps;
  548.     }
  549.     foreach my $loc (@locations) {
  550.         my %summary;
  551.  
  552.         # see if the repository has server-side searching
  553.         if (defined $searchRE && (%summary = ServerSearch('location' => $loc, 
  554.                 'searchRE' => $searchRE, 'searchtag' => $searchtag))) {
  555.             # XXX: clean this up
  556.             foreach my $package (keys %{$summary{$loc}}) {
  557.                 $packages{$loc}{$package} = \%{$summary{$loc}{$package}};
  558.             }
  559.             next;
  560.         }
  561.  
  562.         # see if a summary file is available
  563.         %summary = RepositorySummary("location" => $loc);
  564.         if (%summary) {
  565.             foreach my $package (keys %{$summary{$loc}}) {
  566.                 next if (defined $searchtag && 
  567.                     $summary{$loc}{$package}{$searchtag} !~ /$searchRE/);
  568.                 next if (!defined $searchtag && 
  569.                     defined $searchRE && $package !~ /$searchRE/);
  570.                 $packages{$loc}{$package} = \%{$summary{$loc}{$package}};
  571.             }
  572.         }
  573.         else {
  574.             my %ppds = PPM::RepositoryPackages("location" => $loc);
  575.             # No summary: oh my, nothing but 'Net
  576.             foreach my $package (@{$ppds{$loc}}) {
  577.                 my %package_details = RepositoryPackageProperties(
  578.                     "package" => $package, "location" => $loc);
  579.                 next unless %package_details;
  580.                 next if (defined $searchtag && 
  581.                     $package_details{$searchtag} !~ /$searchRE/);
  582.                 next if (!defined $searchtag && 
  583.                     defined $searchRE && $package !~ /$searchRE/);
  584.                 $packages{$loc}{$package} = \%package_details;
  585.             }
  586.         }
  587.     }
  588.     return %packages;
  589. }
  590.  
  591. sub verify_packages
  592. {
  593.     my %argv = @_;
  594.     my @packages = @{$argv{'packages'}};
  595.     my $upgrade = $argv{'upgrade'};
  596.     my $force = $argv{'force'};
  597.     my $location = $argv{'location'} || $location;
  598.     unless ($packages[0]) {
  599.         my %info = QueryInstalledPackages();
  600.         @packages = sort keys %info;
  601.     }
  602.     my $failed = 0;
  603.  
  604.     my $package = shift @packages;
  605.     while ($package) {
  606.         my $status = VerifyPackage("package" => $package, 
  607.             "location" => $location, "upgrade" => $upgrade, "force" => $force);
  608.         if (defined $status) {
  609.             if ($status eq "0") {
  610.                 print "Package \'$package\' is up to date.\n";
  611.             }
  612.             elsif ($upgrade) {
  613.                 print "Package $package upgraded to version $status\n";
  614.             }
  615.             else {
  616.                 print "An upgrade to package \'$package\' is available.\n";
  617.             }
  618.         }
  619.         else {
  620.             # Couldn't find a PPD to compare it with.
  621.             # Hack: no warning if its on of the core PPM 
  622.             # modules (hardcoded below :)
  623.             my $no=0;
  624.             foreach my $corepackage (
  625.             "Compress-Zlib","Archive-Tar","Digest-MD5","File-CounterFile",
  626.             "Font-AFM","HTML-Parser","HTML-Tree","MIME-Base64","URI",
  627.             "libwww-perl","XML-Parser","SOAP-Lite","PPM","libnet",
  628.             "libwin32","HTML-Tagset"
  629.             )
  630.             {
  631.                 if ($corepackage eq $package) {
  632.                     $no=1;
  633.                     last;
  634.                 }
  635.             }
  636.         unless ($no) {
  637.         ++$failed;
  638.         print "While verifying package '$package': $PPM::PPMERR\n";
  639.         }
  640.         }
  641.         $package = shift @packages;
  642.     }
  643.     return $failed;
  644. }
  645.  
  646. sub genconfig
  647. {
  648. my $PerlDir = $Config{'prefix'};
  649. print <<"EOF";
  650. <PPMCONFIG>
  651.     <PPMVER>2,2,0,0</PPMVER>
  652.     <PLATFORM CPU="x86" OSVALUE="$Config{'osname'}" OSVERSION="0,0,0,0" />
  653.     <OPTIONS REBUILDHTML="0" BUILDDIR="$ENV{'TEMP'}" CLEAN="1" CONFIRM="1" DOWNLOADSTATUS="16384" FORCEINSTALL="1" IGNORECASE="1" MORE="0" ROOT="$PerlDir" TRACE="0" TRACEFILE="PPM.LOG" VERBOSE="1" />
  654.     <REPOSITORY LOCATION="http://www.ActiveState.com/cgibin/PPM/ppmserver.pl?urn:/PPMServer" NAME="ActiveState Package Repository" SUMMARYFILE="fetch_summary"/>
  655.     <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>
  656. </PPMCONFIG>
  657. EOF
  658. }
  659.  
  660. __DATA__
  661.  
  662. =head1 NAME
  663.  
  664. ppm2 - Perl Package Manager: locate, install, upgrade software packages.
  665.  
  666. =head1 SYNOPSIS
  667.  
  668.  ppm2 genconfig
  669.  ppm2 help [command]
  670.  ppm2 install [--location=location] package1 [... packageN]
  671.  ppm2 query [--case|nocase] [--abstract|author] PATTERN
  672.  ppm2 remove package1 [... packageN]
  673.  ppm2 search [--case|nocase] [--location=location] [--abstract|author] PATTERN
  674.  ppm2 set [option]
  675.  ppm2 verify [--location=location] [--upgrade] [--force] [package1 ... packageN]
  676.  ppm2 version
  677.  ppm2 [--location=location]
  678.  
  679. =head1 DESCRIPTION
  680.  
  681. PPM is a utility intended to simplify the tasks of locating, installing,
  682. upgrading and removing software packages.  It is a front-end to the
  683. functionality provided in PPM.pm.  It can determine if the most recent
  684. version of a software package is installed on a system, and can install
  685. or upgrade that package from a local or remote host.
  686.  
  687.     NOTE: This document describes PPM version 2.  There is a newer
  688.     version of PPM, which may be available on your system as 'ppm3'.
  689.     The default 'ppm' program may either be the same as 'ppm2' or
  690.     'ppm3' depending on your version of ActivePerl.
  691.  
  692. ppm2 runs in one of two modes: an interactive shell from which commands
  693. may be entered; and command-line mode, in which one specific action is
  694. performed per invocation of the program.
  695.  
  696. ppm2 uses files containing an extended form of the Open Software
  697. Description (OSD) specification for information about software packages.
  698. These description files, which are written in Extensible Markup
  699. Language (XML) code, are referred to as 'PPD' files.  Information about
  700. OSD can be found at the W3C web site (at the time of this writing,
  701. http://www.w3.org/TR/NOTE-OSD.html).  The extensions to OSD used by PPM
  702. are documented in PPM.ppd.
  703.  
  704. =head1 Using PPM
  705.  
  706. =over 4
  707.  
  708. =item Interactive mode
  709.  
  710. If ppm2 is invoked with no command specified, it is started in interactive
  711. mode.  If the '--location' argument is specified, it is used as the
  712. search location, otherwise the repositories specified in the PPM data file
  713. are used. 
  714.  
  715. The syntax of PPM commands is the same in interactive mode as it is in
  716. command-line mode.  The 'help' command lists the available commands.
  717.  
  718. ppm2 commands may be abbreviated to their shortest unique form.
  719.  
  720. =item Installing
  721.  
  722.  ppm2 install [--location=location] package1 [... packageN]
  723.  
  724. Installs the specified software packages. Attempts to install from the 
  725. URL or directory 'location' if the '--location' option is specfied. 
  726.  
  727. The 'package' arguments may be either package names ('foo'), pathnames 
  728. (p:/packages/foo.ppd) or URLs (http://www.ActiveState.com/packages/foo.ppd)
  729. to specific PPD files.
  730.  
  731. In the case where a package name is specified, and the '--location'
  732. option is not used, ppm2 will refer to the default repository locations.
  733.  
  734. See also: 'confirm' option.
  735.  
  736. =item Removing
  737.  
  738.  ppm2 remove package1 [... packageN]
  739.  
  740. Reads information from the PPD file for the named software package and
  741. removes the package from the system.
  742.  
  743. See also: 'confirm' option.
  744.  
  745. =item Verifying
  746.  
  747.  ppm2 verify [--location=location] [--upgrade] [--force] [package1 ... packageN]
  748.  
  749. Verifies that the currently installed packages are up to date.  If no
  750. packages are specified as arguments, all installed packages will be verified.
  751.  
  752. If the '--upgrade' option is specified, any package for which an upgrade 
  753. is available will be upgraded.  
  754.  
  755. If the '--location' option is specified, upgrades will be looked for at 
  756. the specified URL or directory.
  757.  
  758. If the '--force' option is specified, all currently installed packages will 
  759. be reinstalled regardless of whether they are out of date or not.
  760.  
  761. See also: 'confirm' option.
  762.  
  763. =item Querying
  764.  
  765.  ppm2 query [--case|nocase] [--abstract|author] PATTERN
  766.  
  767. Searches for 'PATTERN' (a regular expression) in the name of any installed 
  768. package.  If a search is successful, information about the matching 
  769. package(s) is displayed.  If 'PATTERN' is omitted, information about
  770. all installed packages will be displayed.
  771.  
  772. If either '--abstract' or '--author' is specified, PATTERN will be 
  773. searched for in the <ABSTRACT> or <AUTHOR> tags of the installed packages.
  774.  
  775. The '--case' and '--nocase' options can be used to override the default
  776. case-sensitivity search settings.
  777.  
  778. See also: 'case' option.
  779.  
  780. =item Searching
  781.  
  782.  ppm2 search [--case|nocase] [--location=location] [--abstract|author] PATTERN
  783.  
  784. Displays a list of any packages matching 'PATTERN' (a regular expression)
  785. available from the specified location.  If 'PATTERN' is omitted, information 
  786. about all available packages will be displayed.
  787.  
  788. If the '--location' option is specified, the specified URL or directory
  789. will be searched.  If '--location' is not specified, the repository location 
  790. as specified in the PPM data file will be searched.
  791.  
  792. If either '--abstract' or '--author' is specified, PATTERN will be 
  793. searched for in the <ABSTRACT> or <AUTHOR> tags of the available packages.
  794.  
  795. The '--case' and '--nocase' options can be used to override the default
  796. case-sensitivity search settings.
  797.  
  798. See also: 'case' option.
  799.  
  800. =item Error Recovery
  801.  
  802.  ppm2 genconfig
  803.  ppm2 getconfig
  804.  
  805. The genconfig command will print a valid PPM config file (ppm.xml) to STDOUT.
  806. This can be useful if the PPM config file ever gets damaged leaving PPM
  807. unusable.
  808.  
  809. If required, this command should be run from a shell prompt:
  810.  
  811.     C:\Perl\site\lib> ppm2 genconfig > ppm.xml
  812.  
  813. The getconfig command prints the location of the PPM configuration file
  814. used at PPM startup.
  815.  
  816. =item Options
  817.  
  818.  ppm2 set [option value]
  819.  
  820. Sets or displays current options.  With no arguments, current option
  821. settings are displayed.  For options that accept '1' or '0', specifying
  822. '1' sets the option, and '0' unsets it.
  823.  
  824. Available options:
  825.  
  826.     build DIRECTORY
  827.         - Changes the package build directory.
  828.  
  829.     case [1|0]
  830.         - Sets case-sensitive searches.  If one of '1' or '0' is
  831.           not specified, the current setting is toggled.
  832.  
  833.     clean [1|0]
  834.         - Sets removal of temporary files from package's build 
  835.           area, on successful installation of a package.  If one of
  836.           '1' or '0' is not specified, the current setting is
  837.           toggled.
  838.  
  839.     confirm [1|0]
  840.         - Sets confirmation of 'install', 'remove' and 'upgrade'.
  841.           If one of '1' or '0' is not specified, the current
  842.           setting is toggled.
  843.  
  844.     downloadstatus NUMBER
  845.         - If non-zero, updates the download status after each NUMBER 
  846.           of bytes transferred during an 'install'.  This can be
  847.           reassuring when installing a large package (e.g. Tk) over
  848.           a low-speed connection.
  849.  
  850.     force_install [1|0]
  851.         - Continue installing a package even if a dependency cannot
  852.           be installed.
  853.  
  854.     more NUMBER
  855.         - Causes output to pause after NUMBER lines have been
  856.           displayed.  Specifying '0' turns off this capability.
  857.  
  858.     rebuildhtml [1|0]
  859.         - Sets regeneration of HTML documentation after installing
  860.           a package.  If one of '1' or '0' is not specified, the
  861.       current setting is toggled.
  862.  
  863.     repository --remove NAME
  864.         - Removes the repository 'NAME' from the list of repositories.
  865.  
  866.     repository NAME LOCATION
  867.         - Adds a repository to the list of PPD repositories for this
  868.           session.  'NAME' is the name by which this repository will
  869.           be referred; 'LOCATION' is a URL or directory name.
  870.  
  871.     root DIRECTORY
  872.         - Changes the install root directory.  Packages will be
  873.           installed under this new root.
  874.  
  875.     save
  876.         - Saves the current options as default options for future
  877.           sessions.
  878.  
  879.     trace
  880.         - Tracing level--default is 1, maximum is 4, 0 indicates
  881.           no tracing.
  882.  
  883.     tracefile
  884.         - File to contain tracing information, default is 'PPM.LOG'.
  885.  
  886.     verbose [1|0]
  887.         - Display additional package information for 'query' and
  888.           'search' commands.
  889.  
  890. =head1 EXAMPLES
  891.  
  892. =over 4
  893.  
  894. =item ppm2
  895.  
  896. Starts ppm2 in interactive mode, using the repository locations specified
  897. in the PPM data file.  A session might look like this:
  898.  
  899.     [show all available packages]
  900.     PPM> search
  901.     Packages available from P:\PACKAGES:
  902.     bar [2.91 ] supplies bar methods for perl5.
  903.     bax [0.072] module for manipulation of bax archives.
  904.     baz [1.03 ] Interface to baz library
  905.     foo [2.23 ] Foo parser class
  906.     
  907.     [list what has already been installed]
  908.     PPM> query
  909.     bax [0.071] module for manipulation of bax archives.
  910.     baz [1.02 ] Interface to baz library
  911.     
  912.     [install a package]
  913.     PPM> install foo
  914.     Install package foo? (y/N): y
  915.     [...]
  916.     
  917.     [toggle confirmations]
  918.     PPM> set confirm
  919.     Commands will not be confirmed.
  920.     
  921.     [see if 'baz' is up-to-date]
  922.     PPM> verify baz
  923.     An upgrade to package 'baz' is available.
  924.     
  925.     [upgrade 'baz']
  926.     PPM> verify --upgrade baz
  927.     [...]
  928.     
  929.     [forced upgrade of 'baz']
  930.     PPM> verify --upgrade --force baz
  931.     [...]
  932.     
  933.     [toggle case-sensitive searches]
  934.     PPM> set case
  935.     Case-sensitive searches will be performed.
  936.     
  937.     [display all available packages beginning with 'b']
  938.     PPM> search ^b
  939.     bar [2.91 ] supplies bar methods for perl5.
  940.     bax [0.072] module for manipulation of bax archives.
  941.     baz [1.03 ] Interface to baz library
  942.     
  943.     [search for installed packages containing 'baz' in the ABSTRACT tag]
  944.     PPM> query --abstract baz
  945.     Matching packages found at P:\PACKAGES:
  946.     baz [1.03 ] Interface to baz library
  947.     PPM> quit
  948.  
  949. =item ppm2 install http://www.ActiveState.com/packages/foo.ppd
  950.  
  951. Installs the software package 'foo' based on the information in the PPD
  952. obtained from the specified URL.
  953.  
  954. =item ppm2 verify --upgrade foo
  955.  
  956. Compares the currently installed version of the software package 'foo'
  957. to the one available according to the PPD obtained from the location
  958. specified for this package in the PPM data file, and upgrades
  959. to a newer version if available.
  960.  
  961. =item ppm2 verify --location=P:\PACKAGES --upgrade foo
  962.  
  963. Compares the currently installed version of the software package 'foo'
  964. to the one available according to the PPD obtained from the specified
  965. directory, and upgrades to a newer version if available.
  966.  
  967. =item ppm2 verify --upgrade --force
  968.  
  969. Forces verification and reinstalls every installed package on the system, 
  970. using upgrade locations specified in the PPM data file.
  971.  
  972. =item ppm2 search --location=http://ppm.ActiveState.com/PPMpackages/5.6
  973.  
  974. Displays the packages with PPD files available at the specified location.
  975.  
  976. =item ppm2 search --location=P:\PACKAGES --author ActiveState
  977.  
  978. Searches the specified location for any package with an <AUTHOR> tag
  979. containing the string 'ActiveState'.  On a successful search, the package
  980. name and the matching string are displayed.
  981.  
  982. =back
  983.  
  984. =head1 ENVIRONMENT VARIABLES
  985.  
  986. =over 4
  987.  
  988. =item HTTP_proxy
  989.  
  990. If the environment variable 'HTTP_proxy' is set, then it will
  991. be used as the address of a proxy server for accessing the Internet.
  992.  
  993. The value should be of the form: 'http://proxy:port'.
  994.  
  995. =back
  996.  
  997. =head1 FILES
  998.  
  999. The following files are fully described in the 'Files' section of PPM:ppm.
  1000.  
  1001. =over 4
  1002.  
  1003. =item package.ppd
  1004.  
  1005. A description of a software package, in extended Open Software Description
  1006. (OSD) format.  More information on this file format can be found in
  1007. PPM::ppd.
  1008.  
  1009. =item ppm.xml - PPM data file.
  1010.  
  1011. An XML format file containing information about the local system,
  1012. specifics regarding the locations from which PPM obtains PPD files, and
  1013. the installation details for any package installed by ppm2.
  1014.  
  1015. This file usually resides in '[perl]/site/lib'.  If the environment 
  1016. variable 'PPM_DAT' is set, its value will be used as the full pathname
  1017. to a PPM data file.  If all else fails, ppm2 will look for a data file
  1018. in the current directory.
  1019.  
  1020. =back
  1021.  
  1022. =head1 AUTHOR
  1023.  
  1024. Murray Nesbitt
  1025.  
  1026. =head1 CREDITS
  1027.  
  1028. =over 4
  1029.  
  1030. =item *
  1031.  
  1032. The "geek-pit" at ActiveState.
  1033.  
  1034. =item *
  1035.  
  1036. Paul Kulchenko for his SOAP-Lite package, and for his enthusiastic
  1037. assistance in getting PPM to work with SOAP-Lite.
  1038.  
  1039. =back
  1040.  
  1041. =cut
  1042.  
  1043. __END__
  1044. :endofperl
  1045.