Date: Thu, 18 Feb 1999 22:53:25 +0000 From: Nik Clayton <nik@nothing-going-on.demon.co.uk> To: Matt Meola <mmeola@uswest.com> Cc: chat@FreeBSD.ORG Subject: Re: Port upgrade check/report tool Message-ID: <19990218225325.A28239@catkin.nothing-going-on.org> In-Reply-To: <199902182208.PAA09529@ima2wk6.ima2>; from Matt Meola on Thu, Feb 18, 1999 at 03:08:26PM -0700 References: <19990218185752.EAVE3226200.mta2-rme@wocker> <199902182208.PAA09529@ima2wk6.ima2>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
> > > On Thu, Feb 18, 1999 at 10:47:04PM +1100, gcross@netspace.net.au wrote:
> > > > I haven't found a tool that will look at the current ports index file,
> > > > then look at the ports installed on my system and tell me which ports
> > > > are now out-of-date and need upgrading.
ports/sysutils/pkg_version does the thing.
If you apply the attached patch (which has been sent to the author) you
get a new "-c" flag which prints out the commands you need to run to update
the applications that are out of date.
N
--
Bagel: The carbohydrate with the hole
[-- Attachment #2 --]
--- pkg_version.org Sat Jan 2 12:18:40 1999
+++ pkg_version Sat Jan 2 13:27:03 1999
@@ -43,8 +43,10 @@
#$indexFile = "ftp://ftp.freebsd.org/pub/FreeBSD/ports-current/INDEX";
$IndexFile = 'file:/usr/ports/INDEX';
+$ShowCommandsFlag = 0;
$DebugFlag = 0;
$VerboseFlag = 0;
+$CommentChar = "#";
#
# CompareVersions
@@ -89,49 +91,23 @@
}
#
-# GetName
+# GetNameAndVersion
#
-# Try to get the "name" of a package, which is basically everything before
-# what we think is its version number.
+# Get the name and version number of a package. Returns a two element
+# array, first element is name, second element is version number.
#
-sub GetName {
+sub GetNameAndVersion {
local($string);
$string = $_[0];
- # If no hyphens, we assume the whole thing is the name.
- if ($string !~ m/-/) {
- return $string;
- }
- else {
- # Truncate the string until we've eaten exactly one hyphen.
- # What's left at the start of the string is the package name.
- while ((chop $string) ne '-') { }
- return $string;
- }
-}
+ # If no hyphens then no version number
+ return ($string, "") if $string !~ /-/;
-#
-# GetVersion
-#
-# Try to get the version number of a package.
-#
-sub GetVersion {
- local($string);
- $string = $_[0];
-
- # If no hyphens, assume no version number
- if ($string !~ m/-/) {
- return "";
- }
- else {
- # Gobble the string from the start until we've eaten all
- # of the hyphens. What's left at the end of the string is
- # the version number.
- while ($string =~ m/-/) {
- $string =~ s/.*-//;
- }
- return $string;
- }
+ # Match (and group) everything in between two hyphens. Because the
+ # regexp is 'greedy', the first .* will try and match everything up
+ # to (but not including) the last hyphen
+ $string =~ /(.*)-(.*)/;
+ return ($1, $2);
}
#
@@ -144,7 +120,8 @@
pkg_version $Version
Bruce A. Mah <bmah\@ca.sandia.gov>
-Usage: pkg_version [-d debug] [-h] [-v] [index]
+Usage: pkg_version [-c] [-d debug] [-h] [-v] [index]
+-c Show commands to update installed packages
-d debug Debugging output (debug controls level of output)
-h Help (this message)
-v Verbose output
@@ -156,10 +133,13 @@
#
# Parse command-line arguments, deal with them
#
-if (!getopts('dhv') || ($opt_h)) {
+if (!getopts('cdhv') || ($opt_h)) {
&PrintHelp();
exit;
}
+if ($opt_c) {
+ $ShowCommandsFlag = $opt_c;
+}
if ($opt_d) {
$DebugFlag = $opt_d;
}
@@ -194,8 +174,7 @@
open CURRENT, "$CurrentPackagesCommand|";
while (<CURRENT>) {
($packageString, $rest) = split;
- $packageName = &GetName($packageString);
- $packageVersion = &GetVersion($packageString);
+ ($packageName, $packageVersion) = &GetNameAndVersion($packageString);
$currentPackages{$packageName}{'name'} = $packageName;
if (defined $currentPackages{$packageName}{'version'}) {
$currentPackages{$packageName}{'version'} .= "," . $packageVersion;
@@ -213,10 +192,10 @@
open INDEX, "$IndexPackagesCommand|";
while (<INDEX>) {
- ($packageString, $rest) = split(/\|/);
- $packageName = &GetName($packageString);
- $packageVersion = &GetVersion($packageString);
+ ($packageString, $packagePath, $rest) = split(/\|/);
+ ($packageName, $packageVersion) = &GetNameAndVersion($packageString);
$indexPackages{$packageName}{'name'} = $packageName;
+ $indexPackages{$packageName}{'path'} = $packagePath;
if (defined $indexPackages{$packageName}{'version'}) {
$indexPackages{$packageName}{'version'} .= "," . $packageVersion;
}
@@ -231,13 +210,10 @@
# Produce reports
#
foreach $packageName (sort keys %currentPackages) {
+ $~ = "STDOUT_VERBOSE" if $VerboseFlag;
+ $~ = "STDOUT_COMMANDS" if $ShowCommandsFlag;
- if ($VerboseFlag) {
- printf "%-20s ", "$packageName-$currentPackages{$packageName}{'version'}";
- }
- else {
- printf "%-20s ", "$packageName";
- }
+ $packageNameVer = "$packageName-$currentPackages{$packageName}{'version'}";
if (defined $indexPackages{$packageName}{'version'}) {
@@ -247,53 +223,82 @@
$indexRefcount = $indexPackages{$packageName}{'refcount'};
$currentRefcount = $currentPackages{$packageName}{'refcount'};
+ $packagePath = $indexPackages{$packageName}{'path'};
+
if (($indexRefcount > 1) || ($currentRefcount > 1)) {
- print "?";
- if ($VerboseFlag) {
- printf " multiple versions (index has %s)",
- "$indexPackages{$packageName}{'version'}";
- }
+ $versionCode = "?";
+ $Comment = "multiple versions (index has $indexVersion)";
}
else {
$rc = &CompareVersions($currentVersion, $indexVersion);
-
+
if ($rc == 0) {
- print "=";
- if ($VerboseFlag) {
- print " up-to-date";
- }
+ next if $ShowCommandsFlag;
+ $versionCode = "=";
+ $Comment = "up-to-date";
}
elsif ($rc < 0) {
- print "<";
- if ($VerboseFlag) {
- printf " needs updating (index has %s)",
- "$indexPackages{$packageName}{'version'}";
- }
+ $versionCode = "<";
+ $Comment = "needs updating (index has $indexVersion)"
}
elsif ($rc > 0) {
- print ">";
- if ($VerboseFlag) {
- printf " succeeds index (index has %s)",
- "$indexPackages{$packageName}{'version'}";
- }
+ next if $ShowCommandsFlag;
+ $versionCode = ">";
+ $Comment = "succeeds index (index has $indexVersion)";
}
else {
- print "?";
- if ($VerboseFlag) {
- printf " Comparison failed.";
- }
+ $versionCode = "?";
+ $Comment = "Comparison failed";
}
}
}
else {
- printf "?";
- if ($VerboseFlag) {
- printf " unknown in index";
- }
+ $versionCode = "?";
+ $Comment = "unknown in index";
}
- print "\n";
-
+ write;
}
+exit 0;
+
+#
+# Formats
+#
+# $CommentChar is in the formats because you can't put a literal '#' in
+# a format specification
+
+# General report (no output flags)
+format STDOUT =
+@<<<<<<<<<<<<<<<<<<<<<<<<< @<
+$packageName, $versionCode
+.
+ ;
+
+# Verbose report (-v flag)
+format STDOUT_VERBOSE =
+@<<<<<<<<<<<<<<<<<<<<<<<<< @< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+$packageNameVer, $versionCode, $Comment
+.
+ ;
+
+# Report that includes commands to update program (-c flag)
+format STDOUT_COMMANDS =
+@<
+$CommentChar
+@< @<<<<<<<<<<<<<<<<<<<<<<<<
+$CommentChar, $packageName
+@< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+$CommentChar, $Comment
+@<
+$CommentChar
+cd @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+$packagePath
+make
+pkg_delete -f @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+ $packageNameVer
+make install
+
+.
+ ;
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990218225325.A28239>
