From 7127030e00014e2ace91dfc0bf5337407054a589 Mon Sep 17 00:00:00 2001 From: krion Date: Sat, 12 Nov 2005 11:45:01 +0000 Subject: Add -P flag, it does the same as the -p option, except that the given prefix is also used recursively for the dependency packages, if any. If the -P flag appears after any -p flag on the command line, it overrides it's effect, causing pkg_add to use the given prefix recursively. PR: bin/75742 Submitted by: Frerich Raabe MFC after: 3 days --- usr.sbin/pkg_install/add/add.h | 1 + usr.sbin/pkg_install/add/main.c | 11 ++++++++-- usr.sbin/pkg_install/add/perform.c | 9 ++++++-- usr.sbin/pkg_install/add/pkg_add.1 | 42 +++++++++++++++++++++++++++++++------- 4 files changed, 52 insertions(+), 11 deletions(-) (limited to 'usr.sbin/pkg_install') diff --git a/usr.sbin/pkg_install/add/add.h b/usr.sbin/pkg_install/add/add.h index d27877a..c8e8456 100644 --- a/usr.sbin/pkg_install/add/add.h +++ b/usr.sbin/pkg_install/add/add.h @@ -26,6 +26,7 @@ typedef enum { NORMAL, MASTER, SLAVE } add_mode_t; extern char *Prefix; +extern Boolean PrefixRecursive; extern Boolean NoInstall; extern Boolean NoRecord; extern char *Mode; diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c index cad422b..37e0a17 100644 --- a/usr.sbin/pkg_install/add/main.c +++ b/usr.sbin/pkg_install/add/main.c @@ -27,9 +27,10 @@ __FBSDID("$FreeBSD$"); #include "lib.h" #include "add.h" -static char Options[] = "hvIRfnrp:SMt:C:"; +static char Options[] = "hvIRfnrp:P:SMt:C:"; char *Prefix = NULL; +Boolean PrefixRecursive = FALSE; char *Chroot = NULL; Boolean NoInstall = FALSE; Boolean NoRecord = FALSE; @@ -110,6 +111,12 @@ main(int argc, char **argv) case 'p': Prefix = optarg; + PrefixRecursive = FALSE; + break; + + case 'P': + Prefix = optarg; + PrefixRecursive = TRUE; break; case 'I': @@ -310,7 +317,7 @@ static void usage() { fprintf(stderr, "%s\n%s\n", - "usage: pkg_add [-vInrfRMS] [-t template] [-p prefix] [-C chrootdir]", + "usage: pkg_add [-vInrfRMS] [-t template] [-p prefix] [-P prefix] [-C chrootdir]", " pkg-name [pkg-name ...]"); exit(1); } diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index a2225c2..56a06b1 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -297,6 +297,11 @@ pkg_do(char *pkg) char path[FILENAME_MAX], *cp = NULL; if (!Fake) { + char prefixArg[2 + MAXPATHLEN]; /* "-P" + Prefix */ + if (PrefixRecursive) { + strlcpy(prefixArg, "-P", sizeof(prefixArg)); + strlcat(prefixArg, Prefix, sizeof(prefixArg)); + } if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) { const char *ext; @@ -315,7 +320,7 @@ pkg_do(char *pkg) if (cp) { if (Verbose) printf("Loading it from %s.\n", cp); - if (vsystem("%s %s'%s'", PkgAddCmd, Verbose ? "-v " : "", cp)) { + if (vsystem("%s %s %s '%s'", PkgAddCmd, Verbose ? "-v " : "", PrefixRecursive ? prefixArg : "", cp)) { warnx("autoload of dependency '%s' failed%s", cp, Force ? " (proceeding anyway)" : "!"); if (!Force) @@ -338,7 +343,7 @@ pkg_do(char *pkg) if (!Force) ++code; } - else if (vsystem("(pwd; /bin/cat +CONTENTS) | %s %s-S", PkgAddCmd, Verbose ? "-v " : "")) { + else if (vsystem("(pwd; /bin/cat +CONTENTS) | %s %s %s -S", PkgAddCmd, Verbose ? "-v" : "", PrefixRecursive ? prefixArg : "")) { warnx("pkg_add of dependency '%s' failed%s", p->name, Force ? " (proceeding anyway)" : "!"); if (!Force) diff --git a/usr.sbin/pkg_install/add/pkg_add.1 b/usr.sbin/pkg_install/add/pkg_add.1 index d2ae1af..914900b 100644 --- a/usr.sbin/pkg_install/add/pkg_add.1 +++ b/usr.sbin/pkg_install/add/pkg_add.1 @@ -15,7 +15,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 1, 2004 +.Dd November 12, 2005 .Dt PKG_ADD 1 .Os .Sh NAME @@ -26,6 +26,7 @@ .Op Fl vInfrRMS .Op Fl t Ar template .Op Fl p Ar prefix +.Op Fl P Ar prefix .Op Fl C Ar chrootdir .Ar pkg-name Op Ar pkg-name ... .Sh DESCRIPTION @@ -127,7 +128,29 @@ modes (see the .Fl M and .Fl S -options). +options). If the +.Fl p +flag appears after any +.Fl P +flag on the command line, it overrides it's effect, causing +.Nm +not to use the given +.Ar prefix +recursively. +.It Fl P Ar prefix +Does the same as the +.Fl p +option, except that the given +.Ar prefix +is also used recursively for the dependency packages, if any. If the +.Fl P +flag appears after any +.Fl p +flag on the command line, it overrides it's effect, causing +.Nm +to use the given +.Ar prefix +recursively. .It Fl t Ar template Use .Ar template @@ -358,9 +381,10 @@ where .Pa prefix is either the prefix specified with the .Fl p -flag or, if no -.Fl p -flag was specified, the name of the first directory named by a +or +.Fl P +flag or, +if neither flag was specified, the name of the first directory named by a .Cm @cwd directive within this package. .It @@ -421,12 +445,16 @@ All the scripts are called with the environment variable .Ev PKG_PREFIX set to the installation prefix (see the .Fl p -option above). +and +.Fl P +options above). This allows a package author to write a script that reliably performs some action on the directory where the package is installed, even if the user might change it with the .Fl p -flag to +or +.Fl P +flags to .Cm pkg_add . .Sh ENVIRONMENT The value of the -- cgit v1.1