From owner-freebsd-bugs@FreeBSD.ORG Mon Nov 12 23:20:02 2012 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3EE7FE95 for ; Mon, 12 Nov 2012 23:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 167A08FC13 for ; Mon, 12 Nov 2012 23:20:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id qACNK1cr041252 for ; Mon, 12 Nov 2012 23:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id qACNK152041251; Mon, 12 Nov 2012 23:20:01 GMT (envelope-from gnats) Resent-Date: Mon, 12 Nov 2012 23:20:01 GMT Resent-Message-Id: <201211122320.qACNK152041251@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Byron Young Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BA758E86 for ; Mon, 12 Nov 2012 23:18:54 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id A2BE18FC08 for ; Mon, 12 Nov 2012 23:18:54 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qACNIs00022011 for ; Mon, 12 Nov 2012 23:18:54 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.5/8.14.5/Submit) id qACNIsds022010; Mon, 12 Nov 2012 23:18:54 GMT (envelope-from nobody) Message-Id: <201211122318.qACNIsds022010@red.freebsd.org> Date: Mon, 12 Nov 2012 23:18:54 GMT From: Byron Young To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: bin/173589: [PATCH] usr.sbin/pkg_install/add X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Nov 2012 23:20:02 -0000 >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: