Index: version/main.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pkg_install/version/main.c,v retrieving revision 1.2.2.1 diff -u -r1.2.2.1 main.c --- version/main.c 11 Aug 2004 16:16:24 -0000 1.2.2.1 +++ version/main.c 12 Aug 2004 14:11:06 -0000 @@ -25,12 +25,13 @@ #include "version.h" #include -static char Options[] = "dhl:L:s:XtTv"; +static char Options[] = "cdhl:L:s:XtTv"; char *LimitChars = NULL; char *PreventChars = NULL; char *MatchName = NULL; Boolean RegexExtended = FALSE; +Boolean ShowCommands = FALSE; static void usage __P((void)); @@ -54,6 +55,11 @@ Verbose = TRUE; break; + case 'c': + ShowCommands = TRUE; + LimitChars = "name); + origin = ie->origin; } } } if (latest == NULL) - show_version(plist.name, NULL, plist.origin); + show_version(plist.name, NULL, plist.origin, origin); else - show_version(plist.name, latest, "index"); + show_version(plist.name, latest, "index", origin); } if (latest != NULL) free(latest); @@ -238,11 +251,13 @@ * You get when you try to match perl output in C ;-). */ void -show_version(const char *installed, const char *latest, const char *source) +show_version(const char *installed, const char *latest, const char *source, const char *origin) { char *ch, tmp[PATH_MAX]; const char *ver; int cmp = 0; + char versionCode = '\0'; + char comment[1024] = ""; if (!installed || strlen(installed) == 0) return; @@ -252,58 +267,67 @@ ch[0] = '\0'; } if (latest == NULL) { - if (source == NULL && OUTPUT('!')) { - printf("%-34s !", tmp); - if (Verbose) - printf(" Comparison failed"); - printf("\n"); - } else if (source != NULL && OUTPUT('?')) { - printf("%-34s ?", tmp); - if (Verbose) - printf(" orphaned: %s", source); - printf("\n"); + if (ShowCommands) + return; + if (source == NULL) { + versionCode = '?'; + snprintf(comment, sizeof(comment), "unknown in index"); + } else if (source != NULL) { + versionCode = '?'; + snprintf(comment, sizeof(comment), "orphaned: %s", source); } } else if (strchr(latest,'|') != NULL) { - if (OUTPUT('*')) { - printf("%-34s *", tmp); - if (Verbose) { - strlcpy(tmp, latest, PATH_MAX); - ch = strchr(tmp, '|'); - ch[0] = '\0'; - - ver = strrchr(tmp, '-'); - ver = ver ? &ver[1] : tmp; - printf(" multiple versions (index has %s", ver); - do { - ver = strrchr(&ch[1], '-'); - ver = ver ? &ver[1] : &ch[1]; - if ((ch = strchr(&ch[1], '|')) != NULL) - ch[0] = '\0'; - printf(", %s", ver); - } while (ch != NULL); - printf(")"); - } - printf("\n"); - } + versionCode = '*'; + strlcpy(tmp, latest, PATH_MAX); + ch = strchr(tmp, '|'); + ch[0] = '\0'; + + ver = strrchr(tmp, '-'); + ver = ver ? &ver[1] : tmp; + snprintf(comment, sizeof(comment), "multiple versions (index has %s", ver); + do { + ver = strrchr(&ch[1], '-'); + ver = ver ? &ver[1] : &ch[1]; + if ((ch = strchr(&ch[1], '|')) != NULL) + ch[0] = '\0'; + strlcat(comment, ", ", sizeof(comment)); + strlcat(comment, ver, sizeof(comment)); + } while (ch != NULL); + strlcat(comment, ")", sizeof(comment)); } else { cmp = version_cmp(installed, latest); ver = strrchr(latest, '-'); ver = ver ? &ver[1] : latest; - if (cmp < 0 && OUTPUT('<')) { - printf("%-34s <", tmp); - if (Verbose) - printf(" needs updating (%s has %s)", source, ver); - printf("\n"); - } else if (cmp == 0 && OUTPUT('=')) { - printf("%-34s =", tmp); - if (Verbose) - printf(" up-to-date with %s", source); - printf("\n"); - } else if (cmp > 0 && OUTPUT('>')) { - printf("%-34s >", tmp); - if (Verbose) - printf(" succeeds %s (%s has %s)", source, source, ver); + if (cmp < 0) { + versionCode = '<'; + snprintf(comment, sizeof(comment), "needs updating (%s has %s)", source, ver); + } else if (cmp == 0) { + versionCode = '='; + snprintf(comment, sizeof(comment), "up-to-date with %s", source); + } else if (cmp > 0) { + versionCode = '>'; + snprintf(comment, sizeof(comment), "succeeds %s (%s has %s)", source, source, ver); + } + } + if (OUTPUT(versionCode)) { + if (ShowCommands) { + if (origin == NULL) + return; + printf("#\n"); + printf("# %.33s\n", tmp); + printf("# %s\n", comment); + printf("#\n"); + printf("cd %s/%s\n", PORTS_DIR, origin); + printf("make clean && make && pkg_delete -f %s\n", installed); + printf("make install clean\n"); printf("\n"); + } else if (Verbose) { + printf("%-34.34s %c %s\n", installed, versionCode, comment); + } else { + if((ch = strrchr(installed, '-')) != NULL && ch - installed < 34) + printf("%-34.*s %c\n", ch - installed, installed, versionCode); + else + printf("%-34.34s %c\n", installed, versionCode); } } } Index: version/pkg_version.1 =================================================================== RCS file: /home/ncvs/src/usr.sbin/pkg_install/version/pkg_version.1,v retrieving revision 1.5.2.15 diff -u -r1.5.2.15 pkg_version.1 --- version/pkg_version.1 11 Aug 2004 16:16:24 -0000 1.5.2.15 +++ version/pkg_version.1 13 Aug 2004 11:13:20 -0000 @@ -32,7 +32,7 @@ .Nd summarize installed versions of packages .Sh SYNOPSIS .Nm -.Op Fl hv +.Op Fl chv .Op Fl l Ar limchar .Op Fl L Ar limchar .Oo @@ -116,6 +116,21 @@ .Nm utility supports several command-line arguments: .Bl -tag -width indent +.It Fl c +Enable commands output. Commands output includes the commands you should +type to update your installed packages to the latest versions in the ports +system. +This feature does +.Bf Em +not +.Ef +constitute an automated packages updating system. +The output of this command +.Bf Em +must +.Ef +be edited, in order to avoid destroying dependencies between installed +packages. .It Fl h Print help message. .It Fl l @@ -185,10 +200,6 @@ .Pa /usr/ports/INDEX is used. .El -.Sh COMPATIBILITY -The -.Fl c -option has been deprecated and is no longer supported. .Sh SEE ALSO .Xr fetch 1 , .Xr pkg_add 1 , @@ -213,6 +224,21 @@ .Pp .Dl % pkg_version http://www.FreeBSD.org/ports/INDEX .Pp +The command below generates a file of commands to run to update the installed +files. +These commands must +.Bf Em +not +.Ef +be run without suitable editing. +They should be treated as suggestions, and may need to be reordered +to account for dependencies between installed packages, or may need to +be disregarded if multiple versions of an installed package can coexist. +Blindly running the output of this command may leave a system in an +unusable state. +.Pp +.Dl % pkg_version -c > do_update +.Pp The following command compares two package version strings: .Pp .Dl % pkg_version -t 1.5 1.5.1 @@ -230,3 +256,16 @@ .An Doug Barton Aq DougB@gorean.org , .An Akinori MUSHA Aq knu@FreeBSD.org , .An Oliver Eikemeier Aq eik@FreeBSD.org +.Sh BUGS +The commands output feature is +.Bf Em +not +.Ef +an automated ports/packages updating system. +It does not even attempt to handle dependencies between installed +packages correctly, and can produce incorrect results if multiple +versions of a package can coexist on a system. +.Pp +Commands output assumes you install new software using the ports system, +rather than using +.Xr pkg_add 1 . Index: version/version.h =================================================================== RCS file: /home/ncvs/src/usr.sbin/pkg_install/version/version.h,v retrieving revision 1.3.2.1 diff -u -r1.3.2.1 version.h --- version/version.h 11 Aug 2004 16:16:24 -0000 1.3.2.1 +++ version/version.h 12 Aug 2004 09:45:00 -0000 @@ -41,6 +41,7 @@ extern char *PreventChars; extern char *MatchName; extern Boolean RegexExtended; +extern Boolean ShowCommands; extern int version_match(char *, const char *);