Add a new option for pkg_add, -r.

The remote option allows for automatic package fetching and installation
using the package repository found on wcarchive. Naturally, this site
can be overridden with a enviornment variable.

This code uses getobjformat() and getosreldate(). This means when some event
causes the package to be fetched to change (such as e-day) the logic also
needs to be changed.

Sorta reviewed by:	jkh
Code suggestions:	peter, jkh, eivind, msmith
This commit is contained in:
Bill Fumerola 1999-01-17 01:22:55 +00:00
parent 3f58aadfc4
commit ab13b06dc0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=42740
2 changed files with 67 additions and 5 deletions

View File

@ -1,6 +1,6 @@
#ifndef lint
static const char rcsid[] =
"$Id: main.c,v 1.17 1998/09/08 10:42:19 jkh Exp $";
"$Id: main.c,v 1.18 1998/09/14 19:22:59 jkh Exp $";
#endif
/*
@ -26,14 +26,16 @@ static const char rcsid[] =
#include <err.h>
#include <sys/param.h>
#include <objformat.h>
#include "lib.h"
#include "add.h"
static char Options[] = "hvIRfnp:SMt:";
static char Options[] = "hvIRfnrp:SMt:";
char *Prefix = NULL;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
Boolean Remote = FALSE;
char *Mode = NULL;
char *Owner = NULL;
@ -47,6 +49,9 @@ add_mode_t AddMode = NORMAL;
char pkgnames[MAX_PKGS][MAXPATHLEN];
char *pkgs[MAX_PKGS];
static char *getpackagesite(char *);
int getosreldate(void);
static void usage __P((void));
int
@ -56,6 +61,10 @@ main(int argc, char **argv)
char **start;
char *cp;
char *remotepkg = NULL, *ptr;
static char binformat[1024];
static char packageroot[MAXPATHLEN] = "ftp://ftp.FreeBSD.org/pub/FreeBSD/";
start = argv;
while ((ch = getopt(argc, argv, Options)) != -1) {
switch(ch) {
@ -84,6 +93,10 @@ main(int argc, char **argv)
Verbose = TRUE;
break;
case 'r':
Remote = TRUE;
break;
case 't':
strcpy(FirstPen, optarg);
break;
@ -116,10 +129,23 @@ main(int argc, char **argv)
/* Get all the remaining package names, if any */
for (ch = 0; *argv; ch++, argv++) {
if (Remote) {
if (getenv("PACKAGESITE") == NULL) {
getobjformat(binformat, sizeof(binformat), &argc, argv);
strcat(packageroot, getpackagesite(binformat));
}
else
strcpy(packageroot, (getenv("PACKAGESITE")));
remotepkg = strcat(packageroot, *argv);
if (!((ptr = strrchr(remotepkg, '.')) && ptr[1] == 't' && ptr[2] == 'g' && ptr[3] == 'z' && !ptr[4]))
strcat(remotepkg, ".tgz");
}
if (!strcmp(*argv, "-")) /* stdin? */
pkgs[ch] = "-";
else if (isURL(*argv)) /* preserve URLs */
pkgs[ch] = strcpy(pkgnames[ch], *argv);
else if ((Remote) && isURL(remotepkg))
pkgs[ch] = strcpy(pkgnames[ch], remotepkg);
else { /* expand all pathnames to fullnames */
if (fexists(*argv)) /* refers to a file directly */
pkgs[ch] = realpath(*argv, pkgnames[ch]);
@ -156,11 +182,33 @@ main(int argc, char **argv)
return 0;
}
char
*getpackagesite(char binform[1024])
{
int reldate;
reldate = getosreldate();
if (reldate == 300005)
return("packages-3.0/Latest/");
else if (30004 > reldate >= 300000)
return("packages-current-aout/Latest/");
else if (30004 < reldate) {
if (strcmp(binform, "elf") != 0)
return("packages-current-aout/Latest/");
else
return("packages-current/Latest/");
}
return(0);
}
static void
usage()
{
fprintf(stderr, "%s\n%s\n",
"usage: pkg_add [-vInfRMS] [-t template] [-p prefix]",
"usage: pkg_add [-vInrfRMS] [-t template] [-p prefix]",
" pkg-name [pkg-name ...]");
exit(1);
}

View File

@ -15,7 +15,7 @@
.\"
.\"
.\" @(#)pkg_add.1
.\" $Id: pkg_add.1,v 1.26 1998/07/14 08:27:58 jkoshy Exp $
.\" $Id: pkg_add.1,v 1.27 1998/12/16 13:59:29 jkh Exp $
.\"
.Dd November 25, 1994
.Dt pkg_add 1
@ -25,7 +25,7 @@
.Nd a utility for installing software package distributions
.Sh SYNOPSIS
.Nm
.Op Fl vInfRMS
.Op Fl vInfrRMS
.Op Fl t Ar template
.Op Fl p Ar prefix
.Ar pkg-name [pkg-name ...]
@ -87,6 +87,9 @@ would be taken if it was.
Do not record the installation of a package. This means
that you cannot deinstall it later, so only use this option if
you know what you are doing!
.It Fl r
Use the remote fetching feature. This will determine the appropriate
objformat and release and then fetch and install the package.
.It Fl f
Force installation to proceed even if prerequisite packages are not
installed or the requirements script fails. Although
@ -393,6 +396,17 @@ will use the first of
or
.Pa /usr/tmp
with sufficient space.
.Pp
The enviornment variable
.Ev PACKAGESITE
specifies an alternate location for
.Nm
to fetch from. This variable subverts the automatic directory logic
that
.Nm
uses when the
.Fl r
option is invoked.
.Sh FILES
.Bl -tag -width /var/db/pkg -compact
.It Pa /var/tmp