From darcsis@gmail.com  Sun Mar  9 20:08:26 2008
Return-Path: <darcsis@gmail.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E36051065675
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  9 Mar 2008 20:08:25 +0000 (UTC)
	(envelope-from darcsis@gmail.com)
Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.178])
	by mx1.freebsd.org (Postfix) with ESMTP id 8D3808FC25
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  9 Mar 2008 20:08:25 +0000 (UTC)
	(envelope-from darcsis@gmail.com)
Received: by py-out-1112.google.com with SMTP id u52so2311645pyb.10
        for <FreeBSD-gnats-submit@freebsd.org>; Sun, 09 Mar 2008 13:08:25 -0700 (PDT)
Received: by 10.35.86.12 with SMTP id o12mr5798583pyl.13.1205093304529;
        Sun, 09 Mar 2008 13:08:24 -0700 (PDT)
Received: from gmail.com ( [123.117.35.115])
        by mx.google.com with ESMTPS id i34sm14249567wxd.15.2008.03.09.13.08.17
        (version=SSLv3 cipher=OTHER);
        Sun, 09 Mar 2008 13:08:20 -0700 (PDT)
Received: by gmail.com (sSMTP sendmail emulation); Mon, 10 Mar 2008 04:08:12 +0800
Message-Id: <47d443b4.2287460a.6dc6.ffff801e@mx.google.com>
Date: Mon, 10 Mar 2008 04:08:12 +0800
From: Denise H. G. <darcsis@gmail.com>
Reply-To: Denise H. G. <darcsis@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] teach `pkg_add' to accept PACKAGEROOT and PACKAGESITE via command line
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         121542
>Category:       bin
>Synopsis:       [patch] teach pkg_add(1) to accept PACKAGEROOT and PACKAGESITE via command line
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 09 20:10:00 UTC 2008
>Closed-Date:    Tue Sep 08 13:24:54 UTC 2009
>Last-Modified:  Tue Sep 08 13:24:54 UTC 2009
>Originator:     Denise H. G.
>Release:        FreeBSD 7.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD pluton.xbsd.name 7.0-STABLE FreeBSD 7.0-STABLE #0: Fri Mar 7 14:53:14 CST 2008 dhg@pluton.xbsd.name:/opt/obj/usr/src/sys/mibsd-SMP-ULE amd64


	
>Description:
a possible answer to the PR: http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/113393
>How-To-Repeat:
	
>Fix:

	

--- patch.diff begins here ---
diff -ruN pkg_install.orig/add/main.c pkg_install/add/main.c
--- pkg_install.orig/add/main.c	2008-03-10 04:00:23.000000000 +0800
+++ pkg_install/add/main.c	2008-03-10 03:45:21.000000000 +0800
@@ -27,7 +27,7 @@
 #include "lib.h"
 #include "add.h"
 
-static char Options[] = "hvIRfFnrp:P:SMt:C:K";
+static char Options[] = "hvIRfFnrp:P:SMt:C:Kz:Z:";
 
 char	*Prefix		= NULL;
 Boolean	PrefixRecursive	= FALSE;
@@ -88,7 +88,7 @@
 	{ 0, 0, NULL }
 };
 
-static char *getpackagesite(void);
+static char *getpackagesite(const char *, const char *);
 int getosreldate(void);
 
 static void usage __P((void));
@@ -99,6 +99,7 @@
     int ch, error;
     char **start;
     char *cp, *packagesite = NULL, *remotepkg = NULL, *ptr;
+	char *pkg_site = NULL, *pkg_root = NULL;
     static char temppackageroot[MAXPATHLEN];
     static char pkgaddpath[MAXPATHLEN];
 
@@ -169,6 +170,14 @@
 	    Chroot = optarg;
 	    break;
 
+	case 'z':
+		pkg_root = optarg;
+		break;
+
+	case 'Z':
+		pkg_site = optarg;
+		break;
+
 	case 'h':
 	case '?':
 	default:
@@ -187,7 +196,7 @@
 	for (ch = 0; *argv; ch++, argv++) {
 	    char temp[MAXPATHLEN];
     	    if (Remote) {
-		if ((packagesite = getpackagesite()) == NULL)
+		if ((packagesite = getpackagesite(pkg_root, pkg_site)) == NULL)
 		    errx(1, "package name too long");
 		if (strlcpy(temppackageroot, packagesite,
 		    sizeof(temppackageroot)) >= sizeof(temppackageroot))
@@ -271,12 +280,15 @@
 }
 
 static char *
-getpackagesite(void)
+getpackagesite(const char *pkg_root, const char *pkg_site)
 {
     int reldate, i;
     static char sitepath[MAXPATHLEN];
     struct utsname u;
 
+	if (pkg_site)
+	return pkg_site;
+
     if (getenv("PACKAGESITE")) {
 	if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath))
 	    >= sizeof(sitepath))
@@ -284,7 +296,12 @@
 	return sitepath;
     }
 
-    if (getenv("PACKAGEROOT")) {
+	if (pkg_root) {
+		if (strlcpy(sitepath, pkg_root, sizeof(sitepath))
+		>= sizeof(sitepath))
+		return NULL;
+    } else {
+	if (getenv("PACKAGEROOT")) {
 	if (strlcpy(sitepath, getenv("PACKAGEROOT"), sizeof(sitepath))
 	    >= sizeof(sitepath))
 	    return NULL;
@@ -293,6 +310,7 @@
 	    >= sizeof(sitepath))
 	    return NULL;
     }
+	}
 
     if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath))
 	>= sizeof(sitepath))
@@ -324,6 +342,6 @@
 {
     fprintf(stderr, "%s\n%s\n",
 	"usage: pkg_add [-vInfFrRMSK] [-t template] [-p prefix] [-P prefix] [-C chrootdir]",
-	"               pkg-name [pkg-name ...]");
+	"               [-z PACKAGEROOT] [-Z PACKAGESITE] pkg-name [pkg-name ...]");
     exit(1);
 }
diff -ruN pkg_install.orig/add/pkg_add.1 pkg_install/add/pkg_add.1
--- pkg_install.orig/add/pkg_add.1	2008-03-10 04:00:23.000000000 +0800
+++ pkg_install/add/pkg_add.1	2008-03-10 03:58:16.000000000 +0800
@@ -28,6 +28,8 @@
 .Op Fl p Ar prefix
 .Op Fl P Ar prefix
 .Op Fl C Ar chrootdir
+.Op Fl z Ar PACKAGEROOT
+.Op Fl Z Ar PACKAGESITE
 .Ar pkg-name Op Ar pkg-name ...
 .Sh DESCRIPTION
 The
@@ -245,6 +247,12 @@
 may be run inside
 .Ar chrootdir
 as a side effect.
+.It Fl z Ar PACKAGEROOT
+Specify a URL to override the environmental variable PACKAGEROOT
+via command line.
+.It Fl Z Ar PACKAGESITE
+Specify a complete URL (including path) to override the environmental
+variable PACKAGESITE via command line.
 .El
 .Pp
 One or more
--- patch.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->krion 
Responsible-Changed-By: remko 
Responsible-Changed-When: Mon Mar 10 16:27:34 UTC 2008 
Responsible-Changed-Why:  
Afair Krion worked on this 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121542 
Responsible-Changed-From-To: krion->portmgr 
Responsible-Changed-By: flz 
Responsible-Changed-When: Fri Jul 17 13:41:10 UTC 2009 
Responsible-Changed-Why:  
pkg_install is maintained by portmgr. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121542 
State-Changed-From-To: open->closed 
State-Changed-By: flz 
State-Changed-When: Tue Sep 8 13:22:41 UTC 2009 
State-Changed-Why:  
I don't see why this is needed, people can use the appropriate 
environment variables. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121542 
>Unformatted:
