diff --exclude=CVS -ruN src/usr.sbin/pkg_install/add/add.h perforce/flz_pkg_install/usr.sbin/pkg_install/add/add.h --- src/usr.sbin/pkg_install/add/add.h Sat Nov 12 12:45:01 2005 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/add/add.h Sun Jan 8 17:54:36 2006 @@ -29,6 +29,7 @@ extern Boolean PrefixRecursive; extern Boolean NoInstall; extern Boolean NoRecord; +extern Boolean KeepPackage; extern char *Mode; extern char *Owner; extern char *Group; diff --exclude=CVS -ruN src/usr.sbin/pkg_install/add/main.c perforce/flz_pkg_install/usr.sbin/pkg_install/add/main.c --- src/usr.sbin/pkg_install/add/main.c Sat Nov 12 12:45:01 2005 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/add/main.c Sun Jan 8 17:54:36 2006 @@ -27,7 +27,7 @@ #include "lib.h" #include "add.h" -static char Options[] = "hvIRfnrp:P:SMt:C:"; +static char Options[] = "hvIRfnrp:P:SMt:C:K"; char *Prefix = NULL; Boolean PrefixRecursive = FALSE; @@ -35,6 +35,7 @@ Boolean NoInstall = FALSE; Boolean NoRecord = FALSE; Boolean Remote = FALSE; +Boolean KeepPackage = FALSE; char *Mode = NULL; char *Owner = NULL; @@ -131,9 +132,12 @@ Force = TRUE; break; + case 'K': + KeepPackage = TRUE; + break; + case 'n': Fake = TRUE; - Verbose = TRUE; break; case 'r': @@ -317,7 +321,7 @@ usage() { fprintf(stderr, "%s\n%s\n", - "usage: pkg_add [-vInrfRMS] [-t template] [-p prefix] [-P prefix] [-C chrootdir]", + "usage: pkg_add [-vInrfRMSK] [-t template] [-p prefix] [-P prefix] [-C chrootdir]", " pkg-name [pkg-name ...]"); exit(1); } diff --exclude=CVS -ruN src/usr.sbin/pkg_install/add/perform.c perforce/flz_pkg_install/usr.sbin/pkg_install/add/perform.c --- src/usr.sbin/pkg_install/add/perform.c Sat Nov 12 12:45:01 2005 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/add/perform.c Sun Jan 8 17:54:36 2006 @@ -102,7 +102,7 @@ else { /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */ if (isURL(pkg)) { - if (!(Home = fileGetURL(NULL, pkg))) { + if (!(Home = fileGetURL(NULL, pkg, KeepPackage))) { warnx("unable to fetch '%s' by URL", pkg); return 1; } @@ -334,7 +339,7 @@ ++code; } } - else if ((cp = fileGetURL(pkg, p->name)) != NULL) { + else if ((cp = fileGetURL(pkg, p->name, KeepPackage)) != NULL) { if (Verbose) printf("Finished loading %s over FTP.\n", p->name); if (!fexists("+CONTENTS")) { @@ -547,8 +552,11 @@ fputs(buf, stdout); putc('\n', stdout); (void) fclose(fp); - } else - warnx("cannot open %s as display file", buf); + } else { + if (!Fake) { + warnx("cannot open %s as display file", buf); + } + } } goto success; diff --exclude=CVS -ruN src/usr.sbin/pkg_install/add/pkg_add.1 perforce/flz_pkg_install/usr.sbin/pkg_install/add/pkg_add.1 --- src/usr.sbin/pkg_install/add/pkg_add.1 Fri Nov 18 11:54:34 2005 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/add/pkg_add.1 Sun Jan 8 17:54:36 2006 @@ -15,7 +15,7 @@ .\" .\" $FreeBSD: src/usr.sbin/pkg_install/add/pkg_add.1,v 1.68 2005/11/18 10:54:34 ru Exp $ .\" -.Dd November 12, 2005 +.Dd January 8, 2006 .Dt PKG_ADD 1 .Os .Sh NAME @@ -23,7 +23,7 @@ .Nd a utility for installing software package distributions .Sh SYNOPSIS .Nm -.Op Fl vInfrRMS +.Op Fl vInfrRMSK .Op Fl t Ar template .Op Fl p Ar prefix .Op Fl P Ar prefix @@ -83,6 +83,10 @@ .Ev PKG_PATH . .It Fl v Turn on verbose output. +.It Fl K +Keep any downloaded package in +.Ev PKGDIR +if it is defined or in current directory by default. .It Fl I If any installation scripts (pre-install or post-install) exist for a given package, do not execute them. @@ -519,6 +523,12 @@ .Fl r option is invoked. Thus it should be a complete URL to the remote package file(s). +.Pp +The environment variable +.Ev PKGDIR +Specifies an alternative location to save downloaded packages to when +.Fl K +option is used. .Sh FILES .Bl -tag -width /var/db/pkg -compact .It Pa /var/tmp diff --exclude=CVS -ruN src/usr.sbin/pkg_install/info/info.h perforce/flz_pkg_install/usr.sbin/pkg_install/info/info.h --- src/usr.sbin/pkg_install/info/info.h Mon Oct 18 07:34:54 2004 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/info/info.h Sun Jan 8 17:54:36 2006 @@ -64,6 +64,7 @@ extern int Flags; extern Boolean QUIET; extern Boolean UseBlkSz; +extern Boolean KeepPackage; extern char *InfoPrefix; extern char PlayPen[]; extern char *CheckPkg; diff --exclude=CVS -ruN src/usr.sbin/pkg_install/info/main.c perforce/flz_pkg_install/usr.sbin/pkg_install/info/main.c --- src/usr.sbin/pkg_install/info/main.c Mon Oct 10 10:38:21 2005 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/info/main.c Sun Jan 8 17:54:36 2006 @@ -26,7 +26,7 @@ #include "info.h" #include -static char Options[] = "abcdDe:EfgGhiIjkl:LmoO:pPqQrRst:vVW:xX"; +static char Options[] = "abcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:vVW:xX"; int Flags = 0; match_t MatchType = MATCH_GLOB; @@ -36,6 +36,7 @@ char PlayPen[FILENAME_MAX]; char *CheckPkg = NULL; char *LookUpOrigin = NULL; +Boolean KeepPackage = FALSE; struct which_head *whead; static void usage __P((void)); @@ -122,6 +123,10 @@ Flags |= SHOW_DEINSTALL; break; + case 'K': + KeepPackage = TRUE; + break; + case 'r': Flags |= SHOW_DEPEND; break; @@ -261,7 +266,7 @@ usage() { fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n", - "usage: pkg_info [-bcdDEfgGiIjkLmopPqQrRsvVxX] [-e package] [-l prefix]", + "usage: pkg_info [-bcdDEfgGiIjkKLmopPqQrRsvVxX] [-e package] [-l prefix]", " [-t template] -a | pkg-name ...", " pkg_info [-qQ] -W filename", " pkg_info [-qQ] -O origin", diff --exclude=CVS -ruN src/usr.sbin/pkg_install/info/perform.c perforce/flz_pkg_install/usr.sbin/pkg_install/info/perform.c --- src/usr.sbin/pkg_install/info/perform.c Tue Jun 29 20:59:18 2004 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/info/perform.c Sun Jan 8 17:54:36 2006 @@ -100,7 +100,7 @@ int code = 0; if (isURL(pkg)) { - if ((cp = fileGetURL(NULL, pkg)) != NULL) { + if ((cp = fileGetURL(NULL, pkg, KeepPackage)) != NULL) { strcpy(fname, cp); isTMP = TRUE; } diff --exclude=CVS -ruN src/usr.sbin/pkg_install/info/pkg_info.1 perforce/flz_pkg_install/usr.sbin/pkg_install/info/pkg_info.1 --- src/usr.sbin/pkg_install/info/pkg_info.1 Wed Nov 23 11:31:59 2005 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/info/pkg_info.1 Sun Jan 8 17:54:36 2006 @@ -17,7 +17,7 @@ .\" @(#)pkg_info.1 .\" $FreeBSD: src/usr.sbin/pkg_install/info/pkg_info.1,v 1.55 2005/11/23 10:31:59 krion Exp $ .\" -.Dd November 23, 2005 +.Dd January 8, 2006 .Dt PKG_INFO 1 .Os .Sh NAME @@ -25,7 +25,7 @@ .Nd a utility for displaying information on software packages .Sh SYNOPSIS .Nm -.Op Fl bcdDEfgGijIkLmopPqQrRsvVxX +.Op Fl bcdDEfgGijIkKLmopPqQrRsvVxX .Op Fl e Ar package .Op Fl l Ar prefix .Op Fl t Ar template @@ -106,6 +106,10 @@ Show the requirements script (if any) for each package. .It Fl k Show the de-install script (if any) for each package. +.It Fl K +Keep any downloaded package in +.Ev PKGDIR +if it is defined or in current directory by default. .It Fl r Show the list of packages on which each package depends. .It Fl R @@ -242,6 +246,8 @@ .It Ev PKG_PATH Specifies an alternative package location, if a given package cannot be found. +.It Ev PKGDIR +Specifies an alternative location to save downloaded packages to. .El .Sh FILES .Bl -tag -width /var/db/pkg -compact diff --exclude=CVS -ruN src/usr.sbin/pkg_install/lib/lib.h perforce/flz_pkg_install/usr.sbin/pkg_install/lib/lib.h --- src/usr.sbin/pkg_install/lib/lib.h Tue Jun 14 17:05:43 2005 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/lib/lib.h Sun Jan 8 17:54:36 2006 @@ -172,7 +172,7 @@ Boolean isempty(const char *); Boolean issymlink(const char *); Boolean isURL(const char *); -char *fileGetURL(const char *, const char *); +char *fileGetURL(const char *, const char *, int); char *fileFindByPath(const char *, const char *); char *fileGetContents(const char *); void write_file(const char *, const char *); diff --exclude=CVS -ruN src/usr.sbin/pkg_install/lib/url.c perforce/flz_pkg_install/usr.sbin/pkg_install/lib/url.c --- src/usr.sbin/pkg_install/lib/url.c Tue Jun 29 21:06:42 2004 +++ perforce/flz_pkg_install/usr.sbin/pkg_install/lib/url.c Sun Jan 8 17:54:36 2006 @@ -24,24 +24,27 @@ #include "lib.h" #include #include +#include #include +#include /* * Try and fetch a file by URL, returning the directory name for where * it's unpacked, if successful. */ char * -fileGetURL(const char *base, const char *spec) +fileGetURL(const char *base, const char *spec, int keep_package) { - char *cp, *rp; + char *cp, *rp, *tmp; char fname[FILENAME_MAX]; char pen[FILENAME_MAX]; + char pkg[FILENAME_MAX]; char buf[8192]; FILE *ftp; pid_t tpid; int pfd[2], pstat, r, w = 0; char *hint; - int fd; + int fd, pkgfd = 0; rp = NULL; /* Special tip that sysinstall left for us */ @@ -95,6 +98,19 @@ else strcpy(fname, spec); + if (keep_package) { + tmp = getenv("PKGDIR"); + strlcpy(pkg, tmp ? tmp : ".", sizeof(pkg)); + tmp = basename(fname); + strlcat(pkg, "/", sizeof(pkg)); + strlcat(pkg, tmp, sizeof(pkg)); + if ((pkgfd = open(pkg, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) { + printf("Error: Unable to open %s\n", pkg); + perror("open"); + return NULL; + } + } + if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) { printf("Error: FTP Unable to get %s: %s\n", fname, fetchLastErrString); @@ -138,10 +154,18 @@ break; if ((w = write(pfd[1], buf, r)) != r) break; + if (keep_package) { + if ((w = write(pkgfd, buf, r)) != r) + break; + } } if (ferror(ftp)) warn("warning: error reading from server"); fclose(ftp); + close(pkgfd); + if (keep_package) { + close(pkgfd); + } close(pfd[1]); if (w == -1) warn("warning: error writing to tar");