bin/173589: [PATCH] usr.sbin/pkg_install/add
Byron Young
bky at bkyoung.com
Mon Nov 12 23:20:02 UTC 2012
>Number: 173589
>Category: bin
>Synopsis: [PATCH] usr.sbin/pkg_install/add
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Mon Nov 12 23:20:00 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator: Byron Young
>Release: 9.1-PRERELEASE
>Organization:
>Environment:
>Description:
pkg_add(1) contains logic to deduce the correct ports repository based on machine architecture and OSVERSION. Adding a simple command line switch (-d) would provide a consistent (with /usr/ports/Mk) means of obtaining this information.
Example:
pkg_add -d
would output
i386/packages-9.0-release
on an i386 9.0-RELEASE machine.
NOTE: no additional correspondence required! Just delete when required. Thanks.
>How-To-Repeat:
Not a problem report!
>Fix:
No problem to fix!
Patch attached with submission follows:
diff --git main.c main.c
index 670230b..8885145 100644
--- main.c
+++ main.c
@@ -38,6 +38,7 @@ Boolean Remote = FALSE;
Boolean KeepPackage = FALSE;
Boolean FailOnAlreadyInstalled = TRUE;
Boolean IgnoreDeps = FALSE;
+Boolean PrintDirectory = FALSE;
char *Mode = NULL;
char *Owner = NULL;
@@ -104,13 +105,15 @@ struct {
};
static char *getpackagesite(void);
+static char *getpackagedirectory(void);
int getosreldate(void);
static void usage(void);
-static char opts[] = "hviIRfFnrp:P:SMt:C:K";
+static char opts[] = "hviIRdfFnrp:P:SMt:C:K";
static struct option longopts[] = {
{ "chroot", required_argument, NULL, 'C' },
+ { "directory", no_argument, NULL, 'd' },
{ "dry-run", no_argument, NULL, 'n' },
{ "force", no_argument, NULL, 'f' },
{ "help", no_argument, NULL, 'h' },
@@ -207,6 +210,10 @@ main(int argc, char **argv)
IgnoreDeps = TRUE;
break;
+ case 'd':
+ PrintDirectory = TRUE;
+ break;
+
case 'h':
default:
usage();
@@ -216,6 +223,16 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
+ if ( PrintDirectory ) {
+ char * pdir = getpackagedirectory();
+ if (pdir) {
+ fprintf(stdout,"%s",pdir);
+ exit (0);
+ } else {
+ exit (1);
+ }
+ }
+
if (AddMode != SLAVE) {
pkgs = (char **)malloc((argc+1) * sizeof(char *));
for (ch = 0; ch <= argc; pkgs[ch++] = NULL) ;
@@ -364,11 +381,39 @@ getpackagesite(void)
}
+static char *
+getpackagedirectory(void)
+{
+ int reldate, i;
+ static char sitepath[MAXPATHLEN];
+ int archmib[] = { CTL_HW, HW_MACHINE_ARCH };
+ char arch[64];
+ size_t archlen = sizeof(arch);
+
+ if (sysctl(archmib, 2, arch, &archlen, NULL, 0) == -1)
+ return NULL;
+ arch[archlen-1] = 0;
+ if (strlcat(sitepath, arch, sizeof(sitepath)) >= sizeof(sitepath))
+ return NULL;
+
+ reldate = getosreldate();
+ for(i = 0; releases[i].directory != NULL; i++) {
+ if (reldate >= releases[i].lowver && reldate <= releases[i].hiver) {
+ if (strlcat(sitepath, releases[i].directory, sizeof(sitepath))
+ >= sizeof(sitepath))
+ return NULL;
+ break;
+ }
+ }
+ return sitepath;
+
+}
+
static void
usage(void)
{
fprintf(stderr, "%s\n%s\n",
- "usage: pkg_add [-viInfFrRMSK] [-t template] [-p prefix] [-P prefix] [-C chrootdir]",
+ "usage: pkg_add [-viInfdFrRMSK] [-t template] [-p prefix] [-P prefix] [-C chrootdir]",
" pkg-name [pkg-name ...]");
exit(1);
}
diff --git pkg_add.1 pkg_add.1
index 57edb63..f3d52e0 100644
--- pkg_add.1
+++ pkg_add.1
@@ -87,6 +87,8 @@ Turn on verbose output.
Keep any downloaded package in
.Ev PKGDIR
if it is defined or in current directory by default.
+.It Fl d , -directory
+Output ARCH/PACKAGES subdirectory and immediately exit.
.It Fl i , -no-deps
Install the package without fetching and installing
dependencies.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list