From nobody@FreeBSD.org  Fri Apr 16 19:42:32 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 98DE81065678
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 16 Apr 2010 19:42:32 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 87D548FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 16 Apr 2010 19:42:32 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o3GJgWQo049306
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 16 Apr 2010 19:42:32 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o3GJgWhO049305;
	Fri, 16 Apr 2010 19:42:32 GMT
	(envelope-from nobody)
Message-Id: <201004161942.o3GJgWhO049305@www.freebsd.org>
Date: Fri, 16 Apr 2010 19:42:32 GMT
From: Emil <the_mix_room@hotmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: pkg_add doesn't fetch packages from other architectures
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         145763
>Category:       bin
>Synopsis:       pkg_add(1) doesn't fetch packages from other architectures
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 16 19:50:01 UTC 2010
>Closed-Date:    Wed May 28 15:17:56 UTC 2014
>Last-Modified:  Wed May 28 15:17:56 UTC 2014
>Originator:     Emil
>Release:        8.0-RELEASE
>Organization:
>Environment:
>Description:
pkg_add cannot be used to fetch packages from other architectures than the own. For use with embedded image generation tools, like nanobsd, this is a limitation, as it means that one must fetch all desired packages manually. Which is time consuming and error-prone. Cross-compilation is possible, so this is one of the few obstacles to be circumvented in order to have a fully automated build process.

I propose adding a new switch (-A,--architecture) to rewrite the URL to the package repository in order to allow fetching of other architecture packages.

This feature should be used with caution as it will potentially overwrite the installed packages with wrong ones.  


>How-To-Repeat:
run pkg_add on a machine of a different architecture than the desired embedded target
>Fix:
See attached diff-file

Patch attached with submission follows:

*** main.c.bak.20100414	2009-12-26 19:15:51.000000000 +0100
--- /usr/src/usr.sbin/pkg_install/add/main.c	2010-04-14 18:38:15.000000000 +0200
***************
*** 95,108 ****
  	{ 0, 0, NULL }
  };
  
  static char *getpackagesite(void);
  int getosreldate(void);
  
  static void usage(void);
  
! static char opts[] = "hviIRfFnrp:P:SMt:C:K";
  static struct option longopts[] = {
  	{ "chroot",	required_argument,	NULL,		'C' },
  	{ "dry-run",	no_argument,		NULL,		'n' },
  	{ "force",	no_argument,		NULL,		'f' },
  	{ "help",	no_argument,		NULL,		'h' },
--- 95,109 ----
  	{ 0, 0, NULL }
  };
  
  static char *getpackagesite(void);
  int getosreldate(void);
+ char* architecture;
  
  static void usage(void);
  
! static char opts[] = "hviIRfFnrp:P:SMt:C:KA:";
  static struct option longopts[] = {
  	{ "chroot",	required_argument,	NULL,		'C' },
  	{ "dry-run",	no_argument,		NULL,		'n' },
  	{ "force",	no_argument,		NULL,		'f' },
  	{ "help",	no_argument,		NULL,		'h' },
***************
*** 114,123 ****
--- 115,125 ----
  	{ "prefix",	required_argument,	NULL,		'p' },
  	{ "remote",	no_argument,		NULL,		'r' },
  	{ "template",	required_argument,	NULL,		't' },
  	{ "slave",	no_argument,		NULL,		'S' },
  	{ "verbose",	no_argument,		NULL,		'v' },
+ 	{ "architecture", required_argument,	NULL,		'A' },
  	{ NULL,		0,			NULL,		0 }
  };
  
  int
  main(int argc, char **argv)
***************
*** 125,134 ****
--- 127,140 ----
      int ch, error;
      char **start;
      char *cp, *packagesite = NULL, *remotepkg = NULL, *ptr;
      static char temppackageroot[MAXPATHLEN];
      static char pkgaddpath[MAXPATHLEN];
+ 	struct utsname u;
+ 
+ 	uname(&u);
+ 	architecture = u.machine;
  
      if (*argv[0] != '/' && strchr(argv[0], '/') != NULL)
  	PkgAddCmd = realpath(argv[0], pkgaddpath);
      else
  	PkgAddCmd = argv[0];
***************
*** 196,205 ****
--- 202,214 ----
  	    break;
  
  	case 'i':
  	    IgnoreDeps = TRUE;
  	    break;
+ 	case 'A':
+ 		architecture = optarg;
+ 		break; 
  
  	case 'h':
  	default:
  	    usage();
  	    break;
***************
*** 297,307 ****
  static char *
  getpackagesite(void)
  {
      int reldate, i;
      static char sitepath[MAXPATHLEN];
-     struct utsname u;
  
      if (getenv("PACKAGESITE")) {
  	if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath))
  	    >= sizeof(sitepath))
  	    return NULL;
--- 306,315 ----
***************
*** 320,331 ****
  
      if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath))
  	>= sizeof(sitepath))
  	return NULL;
  
!     uname(&u);
!     if (strlcat(sitepath, u.machine, 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) {
--- 328,338 ----
  
      if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath))
  	>= sizeof(sitepath))
  	return NULL;
  
!     if (strlcat(sitepath, architecture, 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) {


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->flz 
Responsible-Changed-By: tabthorpe 
Responsible-Changed-When: Wed Apr 21 17:28:57 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145763 
Responsible-Changed-From-To: flz->portmgr 
Responsible-Changed-By: tabthorpe 
Responsible-Changed-When: Wed Apr 21 17:57:09 UTC 2010 
Responsible-Changed-Why:  
Assign to portmgr 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145763 
State-Changed-From-To: open->closed 
State-Changed-By: bapt 
State-Changed-When: Wed May 28 15:17:55 UTC 2014 
State-Changed-Why:  
pkg_install is not being worked on anymore 

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