From owner-freebsd-chat Thu Feb 18 15:30:39 1999 Delivered-To: freebsd-chat@freebsd.org Received: from nothing-going-on.demon.co.uk (nothing-going-on.demon.co.uk [193.237.89.66]) by hub.freebsd.org (Postfix) with ESMTP id 939E211B0B for ; Thu, 18 Feb 1999 15:29:07 -0800 (PST) (envelope-from nik@nothing-going-on.demon.co.uk) Received: (from nik@localhost) by nothing-going-on.demon.co.uk (8.8.8/8.8.8) id WAA28848; Thu, 18 Feb 1999 22:53:26 GMT (envelope-from nik) Date: Thu, 18 Feb 1999 22:53:25 +0000 From: Nik Clayton To: Matt Meola Cc: chat@FreeBSD.ORG Subject: Re: Port upgrade check/report tool Message-ID: <19990218225325.A28239@catkin.nothing-going-on.org> References: <19990218185752.EAVE3226200.mta2-rme@wocker> <199902182208.PAA09529@ima2wk6.ima2> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=1yeeQ81UyVL57Vl7 X-Mailer: Mutt 0.95.1i In-Reply-To: <199902182208.PAA09529@ima2wk6.ima2>; from Matt Meola on Thu, Feb 18, 1999 at 03:08:26PM -0700 Organization: Nik at home, where there's nothing going on Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=us-ascii > > > 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 --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="pkg_version.diff" --- 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 -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 () { ($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 () { - ($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 + +. + ; --1yeeQ81UyVL57Vl7-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message