#native_company# #native_desc#
#native_cta#

List RPMs

By Grant Walters
on March 20, 2002

Version: 1.0

Type: Full Script

Category: Other

License: GNU General Public License

Description: Display RPM’s in database with relevant parts selected by option, ie… Name-Version … (requires Support Functions snippet)

#!/cmi/bin/php -q
<?
/*
 $Id$
 $Name:  $

 Script to list the rpm database with whichever bits are wanted
		-a = archive
		-r = release
		-v = version
		-s = add .rpm to end of each file
		-t = titles/ headings;

 Package will always be produced in the correct display order
    NAME-VERSION-RELEASE.ARCH.rpm

*/

$site = "";

@include("./phpcode/functions.php3"); // Standard includes
if ($php_errmsg) { die ($php_errmsg."n"); }

$command    = "/bin/rpm -qa ";
$rpm_package = array();
$rpm_package_count = 0;
$titles=0;

function usage() {
  echo "usage: list_rpms [ [-h] | [-a] [-r] [-v] [-s] [-v] ]nn";
  echo "   Where:n";
  echo "      -a = archiven";
  echo "      -r = releasen";
  echo "      -v = versionn";
  echo "      -s = add .rpm to end of each filen";
  echo "      -t = titles/headingsn";
  exit;
}

$options = WCDS_getopts();

if ($options) {
  $command = $command."--qf "%{NAME}";
  $extras=array();
	while (list($parameter,$value)=each($options)) {
	  switch ($value) {
	    case "-h":
	      usage();
	      break;;
	    case "-v":
	      $extras[0] = "-%{VERSION}";
	      break;
	    case "-r":
	      $extras[1] .= "-%{RELEASE}";
	      break;
	    case "-a":
	      $extras[2] .= "-%{ARCH}";
	      break;
	    case "-s":
	      $extras[3] .= ".rpm";
	      break;
	    case "-t":
	      $titles = 1;
	      break;
	  }
	}
  $command = $command.$extras[0].$extras[1].$extras[2].$extras[3]."n"";
}

if ($titles) { WCDS_scr("Listing Current RPM's"); }
if ($titles) { WCDS_scr(str_repeat("=",80)); }
if ($titles) { WCDS_scr("RPM: Obtaining List ... ",1); }
$rpm = popen($command,"r");
if ($rpm) {
  if ($titles) { WCDS_scr("Got It"); }
  $rpm_package_count=0;
  while (!feof($rpm)) {
    $item = chop(fgets($rpm,512));
    if ("$item" <> "" ) {
      $rpm_package[] = $item;
      $rpm_package_count++;
    }
  }
  asort($rpm_package);
  pclose($rpm);
	while ( list ($key,$file) = each ($rpm_package)) {
    if ($titles) { WCDS_scr("  => $file",0); } else { WCDS_scr($file); }
	}
  if ($titles) { WCDS_scr(str_repeat("=",80)); }
  if ($titles) { WCDS_scr("Count = $rpm_package_count"); }
} else {
  WCDS_err("Can't Obtain List from pipe");
}

/*
 $Log$
*/
?>