From 1a174cde55c6b4ed2986d210391c101fe7899eb1 Mon Sep 17 00:00:00 2001 From: jlam Date: Tue, 2 Sep 2003 07:34:47 +0000 Subject: [PATCH] Merge src/usr.sbin/pkg_install on the pkgviews branch into the HEAD by running: cd src/usr.sbin/pkg_install cvs update -Pd -A cvs update -Pd -j pkgviews-base -j pkgviews --- usr.sbin/pkg_install/Makefile | 4 +- usr.sbin/pkg_install/Makefile.inc | 2 +- usr.sbin/pkg_install/README | 6 +- usr.sbin/pkg_install/add/add.h | 5 +- usr.sbin/pkg_install/add/extract.c | 4 +- usr.sbin/pkg_install/add/futil.c | 4 +- usr.sbin/pkg_install/add/main.c | 81 ++++--- usr.sbin/pkg_install/add/perform.c | 97 ++++++-- usr.sbin/pkg_install/add/pkg_add.1 | 66 +++++- usr.sbin/pkg_install/admin/main.c | 72 ++++-- usr.sbin/pkg_install/admin/pkg_admin.1 | 45 +++- usr.sbin/pkg_install/create/create.h | 3 +- usr.sbin/pkg_install/create/main.c | 17 +- usr.sbin/pkg_install/create/perform.c | 12 +- usr.sbin/pkg_install/create/pkg_create.1 | 27 ++- usr.sbin/pkg_install/create/pl.c | 4 +- usr.sbin/pkg_install/delete/main.c | 61 ++--- usr.sbin/pkg_install/delete/perform.c | 213 ++++++++++++++--- usr.sbin/pkg_install/delete/pkg_delete.1 | 27 ++- usr.sbin/pkg_install/info/info.h | 4 +- usr.sbin/pkg_install/info/main.c | 21 +- usr.sbin/pkg_install/info/perform.c | 24 +- usr.sbin/pkg_install/info/pkg_info.1 | 28 ++- usr.sbin/pkg_install/info/show.c | 42 +++- usr.sbin/pkg_install/lib/Makefile | 2 +- usr.sbin/pkg_install/lib/fexec.c | 2 +- usr.sbin/pkg_install/lib/file.c | 6 +- usr.sbin/pkg_install/lib/ftpio.c | 4 +- usr.sbin/pkg_install/lib/lib.h | 13 +- usr.sbin/pkg_install/lib/lpkg.c | 2 +- usr.sbin/pkg_install/lib/path.c | 4 +- usr.sbin/pkg_install/lib/path.h | 2 +- usr.sbin/pkg_install/lib/pen.c | 4 +- usr.sbin/pkg_install/lib/pkgdb.c | 41 +++- usr.sbin/pkg_install/lib/plist.c | 4 +- usr.sbin/pkg_install/lib/str.c | 4 +- usr.sbin/pkg_install/lib/version.h | 4 +- usr.sbin/pkg_install/view/Makefile | 6 + usr.sbin/pkg_install/view/linkfarm.1 | 144 ++++++++++++ usr.sbin/pkg_install/view/linkfarm.sh | 221 ++++++++++++++++++ usr.sbin/pkg_install/view/pkg_view.1 | 269 ++++++++++++++++++++++ usr.sbin/pkg_install/view/pkg_view.sh | 276 +++++++++++++++++++++++ 42 files changed, 1626 insertions(+), 251 deletions(-) create mode 100644 usr.sbin/pkg_install/view/Makefile create mode 100644 usr.sbin/pkg_install/view/linkfarm.1 create mode 100644 usr.sbin/pkg_install/view/linkfarm.sh create mode 100644 usr.sbin/pkg_install/view/pkg_view.1 create mode 100644 usr.sbin/pkg_install/view/pkg_view.sh diff --git a/usr.sbin/pkg_install/Makefile b/usr.sbin/pkg_install/Makefile index 156a113ab3a9..6d1045691761 100644 --- a/usr.sbin/pkg_install/Makefile +++ b/usr.sbin/pkg_install/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.5 2001/01/09 03:13:43 lukem Exp $ +# $NetBSD: Makefile,v 1.6 2003/09/02 07:34:47 jlam Exp $ # Original from FreeBSD, no rcs id. -SUBDIR=lib .WAIT add admin create delete info +SUBDIR=lib .WAIT add admin create delete info view .include diff --git a/usr.sbin/pkg_install/Makefile.inc b/usr.sbin/pkg_install/Makefile.inc index 8b8f0af7c497..663dcd7f7303 100644 --- a/usr.sbin/pkg_install/Makefile.inc +++ b/usr.sbin/pkg_install/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.23 2002/10/26 14:43:44 hubertf Exp $ +# $NetBSD: Makefile.inc,v 1.24 2003/09/02 07:34:47 jlam Exp $ # Original from FreeBSD, no rcs id. .include diff --git a/usr.sbin/pkg_install/README b/usr.sbin/pkg_install/README index 37d014e0531f..773f98344798 100644 --- a/usr.sbin/pkg_install/README +++ b/usr.sbin/pkg_install/README @@ -1,4 +1,4 @@ -# $NetBSD: README,v 1.6 2002/02/21 14:21:49 agc Exp $ +# $NetBSD: README,v 1.7 2003/09/02 07:34:48 jlam Exp $ # Original from FreeBSD, no rcs id. This is the pkg_install suite of tools for doing maintainance of @@ -11,8 +11,8 @@ FreeBSD again by Jordan, who then proceeded to add another couple of dozen features on top. Whee! :-) In another round of enhancements, NetBSD changes were added by -Alistair Crooks and Hubert Feyrer, Thorsten Frueauf and Christian E. -Hopps. +Alistair Crooks, Hubert Feyrer, Thorsten Frueauf, Christian E. Hopps, +and Johnny Lam. When making snapshots, please modify PKGTOOLS_VERSION in lib/version.h to that day's date. diff --git a/usr.sbin/pkg_install/add/add.h b/usr.sbin/pkg_install/add/add.h index 300fea245157..6d63fe634927 100644 --- a/usr.sbin/pkg_install/add/add.h +++ b/usr.sbin/pkg_install/add/add.h @@ -1,4 +1,4 @@ -/* $NetBSD: add.h,v 1.5 2000/06/17 11:30:49 tron Exp $ */ +/* $NetBSD: add.h,v 1.6 2003/09/02 07:34:49 jlam Exp $ */ /* from FreeBSD Id: add.h,v 1.8 1997/02/22 16:09:15 peter Exp */ @@ -30,6 +30,9 @@ typedef enum { } add_mode_t; extern char *Prefix; +extern char *View; +extern char *Viewbase; +extern Boolean NoView; extern Boolean NoInstall; extern Boolean NoRecord; extern Boolean Force; diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c index c0228ea27b5c..c870918e3409 100644 --- a/usr.sbin/pkg_install/add/extract.c +++ b/usr.sbin/pkg_install/add/extract.c @@ -1,11 +1,11 @@ -/* $NetBSD: extract.c,v 1.30 2003/07/14 06:00:44 itojun Exp $ */ +/* $NetBSD: extract.c,v 1.31 2003/09/02 07:34:49 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "FreeBSD - Id: extract.c,v 1.17 1997/10/08 07:45:35 charnier Exp"; #else -__RCSID("$NetBSD: extract.c,v 1.30 2003/07/14 06:00:44 itojun Exp $"); +__RCSID("$NetBSD: extract.c,v 1.31 2003/09/02 07:34:49 jlam Exp $"); #endif #endif diff --git a/usr.sbin/pkg_install/add/futil.c b/usr.sbin/pkg_install/add/futil.c index 3137a9e34c97..4e7b376c0521 100644 --- a/usr.sbin/pkg_install/add/futil.c +++ b/usr.sbin/pkg_install/add/futil.c @@ -1,11 +1,11 @@ -/* $NetBSD: futil.c,v 1.11 2003/08/25 10:35:28 tron Exp $ */ +/* $NetBSD: futil.c,v 1.12 2003/09/02 07:34:49 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: futil.c,v 1.7 1997/10/08 07:45:39 charnier Exp"; #else -__RCSID("$NetBSD: futil.c,v 1.11 2003/08/25 10:35:28 tron Exp $"); +__RCSID("$NetBSD: futil.c,v 1.12 2003/09/02 07:34:49 jlam Exp $"); #endif #endif diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c index 5c25942b2134..921640a48864 100644 --- a/usr.sbin/pkg_install/add/main.c +++ b/usr.sbin/pkg_install/add/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.30 2003/07/14 06:17:54 itojun Exp $ */ +/* $NetBSD: main.c,v 1.31 2003/09/02 07:34:49 jlam Exp $ */ #include #ifndef lint #if 0 static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.30 2003/07/14 06:17:54 itojun Exp $"); +__RCSID("$NetBSD: main.c,v 1.31 2003/09/02 07:34:49 jlam Exp $"); #endif #endif @@ -37,9 +37,12 @@ __RCSID("$NetBSD: main.c,v 1.30 2003/07/14 06:17:54 itojun Exp $"); #include "add.h" #include "verify.h" -static char Options[] = "IMRSVfhnp:s:t:uv"; +static char Options[] = "IK:LMRSVW:fhnp:s:t:uvw:"; char *Prefix = NULL; +char *View = NULL; +char *Viewbase = NULL; +Boolean NoView = FALSE; Boolean NoInstall = FALSE; Boolean NoRecord = FALSE; @@ -55,9 +58,10 @@ Boolean Replace = FALSE; static void usage(void) { - (void) fprintf(stderr, "%s\n%s\n", - "usage: pkg_add [-hVvInfRMSu] [-t template] [-p prefix]", - " [-s verification-type] pkg-name [pkg-name ...]"); + (void) fprintf(stderr, "%s\n%s\n%s\n", + "usage: pkg_add [-fhILMnRSuVv] [-p prefix] [-s verification-type]", + " [-t template] [-W viewbase] [-w view]", + " pkg-name [pkg-name ...]"); exit(1); } @@ -72,7 +76,32 @@ main(int argc, char **argv) setprogname(argv[0]); while ((ch = getopt(argc, argv, Options)) != -1) { switch (ch) { - case 'v': + case 'f': + Force = TRUE; + break; + + case 'I': + NoInstall = TRUE; + break; + + case 'K': + _pkgdb_setPKGDB_DIR(optarg); + break; + + case 'L': + NoView = TRUE; + break; + + case 'M': + AddMode = MASTER; + break; + + case 'R': + NoRecord = TRUE; + break; + + case 'n': + Fake = TRUE; Verbose = TRUE; break; @@ -80,21 +109,8 @@ main(int argc, char **argv) Prefix = optarg; break; - case 'I': - NoInstall = TRUE; - break; - - case 'R': - NoRecord = TRUE; - break; - - case 'f': - Force = TRUE; - break; - - case 'n': - Fake = TRUE; - Verbose = TRUE; + case 'S': + AddMode = SLAVE; break; case 's': @@ -105,21 +121,26 @@ main(int argc, char **argv) strlcpy(FirstPen, optarg, sizeof(FirstPen)); break; - case 'S': - AddMode = SLAVE; - break; - - case 'M': - AddMode = MASTER; + case 'u': + Replace = 1; break; case 'V': show_version(); /* NOTREACHED */ - case 'u': - Replace = 1; + case 'v': + Verbose = TRUE; break; + + case 'W': + Viewbase = optarg; + break; + + case 'w': + View = optarg; + break; + case 'h': case '?': default: diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index 7dee8ef2a48a..8c16e74e3bb5 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.85 2003/08/25 10:35:28 tron Exp $ */ +/* $NetBSD: perform.c,v 1.86 2003/09/02 07:34:50 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.85 2003/08/25 10:35:28 tron Exp $"); +__RCSID("$NetBSD: perform.c,v 1.86 2003/09/02 07:34:50 jlam Exp $"); #endif #endif @@ -37,7 +37,6 @@ __RCSID("$NetBSD: perform.c,v 1.85 2003/08/25 10:35:28 tron Exp $"); #include #include -#include static char LogDir[FILENAME_MAX]; static int zapLogDir; /* Should we delete LogDir? */ @@ -73,9 +72,14 @@ installprereq(const char *name, int *errc) if (Verbose) printf("Loading it from %s.\n", name); path_setenv("PKG_PATH"); - if (vsystem("%s/pkg_add -s %s %s%s%s %s%s", + if (vsystem("%s/pkg_add -s %s %s%s%s %s%s %s%s%s %s%s", BINDIR, get_verification(), + NoView ? "-L " : "", + View ? "-w " : "", + View ? View : "", + Viewbase ? "-W " : "", + Viewbase ? Viewbase : "", Force ? "-f " : "", Prefix ? "-p " : "", Prefix ? Prefix : "", @@ -105,7 +109,7 @@ pkg_do(const char *pkg) char replace_via[FILENAME_MAX]; char replace_to[FILENAME_MAX]; int replacing = 0; - char *where_to, *tmp, *extract; + char *where_to, *extract; char *dbdir; const char *exact; FILE *cfile; @@ -114,22 +118,13 @@ pkg_do(const char *pkg) struct stat sb; int inPlace; int rc; + Boolean is_depoted_pkg = FALSE; errc = 0; zapLogDir = 0; LogDir[0] = '\0'; strlcpy(playpen, FirstPen, sizeof(playpen)); inPlace = 0; - dbdir = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR; - - /* make sure dbdir actually exists! */ - if (!(isdir(dbdir) || islinktodir(dbdir))) { - if (fexec("mkdir", "-m", "755", "-p", dbdir, NULL)) { - errx(EXIT_FAILURE, - "Database-dir %s cannot be generated, aborting.", - dbdir); - } - } /* Are we coming in for a second pass, everything already extracted? * (Slave mode) */ @@ -167,8 +162,7 @@ pkg_do(const char *pkg) warnx("Package %s will not be extracted", pkg); goto bomb; } - } - else { /* local */ + } else { /* local */ if (!IS_STDIN(pkg)) { /* not stdin */ if (!ispkgpattern(pkg)) { @@ -286,8 +280,33 @@ pkg_do(const char *pkg) /* Protect against old packages with bogus @name fields */ PkgName = (p = find_plist(&Plist, PLIST_NAME)) ? p->name : "anonymous"; - /* See if this package (exact version) is already registered */ + if (fexists(VIEWS_FNAME)) + is_depoted_pkg = TRUE; + + dbdir = _pkgdb_getPKGDB_DIR(); (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", dbdir, PkgName); + + /* check if the dbdir is wrong because this is a depoted package */ + if (is_depoted_pkg) { + if ((p = find_plist(&Plist, PLIST_CWD))) { + if (strcmp(p->name, LogDir) != 0) { + warnx("%s is not the depot directory for %s.", + dbdir, PkgName); + goto success; + } + } + } + + /* make sure dbdir actually exists! */ + if (!(isdir(dbdir) || islinktodir(dbdir))) { + if (fexec("mkdir", "-m", "755", "-p", dbdir, NULL)) { + errx(EXIT_FAILURE, + "Database-dir %s cannot be generated, aborting.", + dbdir); + } + } + + /* See if this package (exact version) is already registered */ if ((isdir(LogDir) || islinktodir(LogDir)) && !Force) { warnx("package `%s' already recorded as installed", PkgName); goto success; /* close enough for government work */ @@ -426,10 +445,17 @@ ignore_replace_depends_check: replacing = 1; } - if (Verbose) - printf("pkg_delete '%s'\n", installed); - (void) fexec("pkg_delete", installed, NULL); - + if (Verbose) { + printf("%s/pkg_delete -K %s '%s'\n", + BINDIR, + dbdir, + installed); + } + vsystem("%s/pkg_delete -K %s '%s'\n", + BINDIR, + dbdir, + installed); + } else { warnx("other version '%s' already installed", installed); @@ -448,7 +474,6 @@ ignore_replace_depends_check: continue; if (Verbose) printf("Package `%s' conflicts with `%s'.\n", PkgName, p->name); - if (findmatchingname(dbdir, p->name, note_whats_installed, installed) > 0) { warnx("Conflicting package `%s'installed, please use\n" "\t\"pkg_delete %s\" first to remove it!", installed, installed); @@ -680,6 +705,10 @@ ignore_replace_depends_check: move_file(".", DISPLAY_FNAME, LogDir); if (fexists(PRESERVE_FNAME)) move_file(".", PRESERVE_FNAME, LogDir); + if (fexists(VIEWS_FNAME)) { + is_depoted_pkg = TRUE; + move_file(".", VIEWS_FNAME, LogDir); + } /* register dependencies */ /* we could save some cycles here if we remembered what we @@ -739,6 +768,28 @@ ignore_replace_depends_check: warnx("cannot open %s as display file", buf); } + /* Add the package to a default view. */ + if (!Fake && !NoView && is_depoted_pkg) { + if (Verbose) { + printf("%s/pkg_view %s%s %s%s %sadd %s\n", + BINDIR, + View ? "-w " : "", + View ? View : "", + Viewbase ? "-W " : "", + Viewbase ? Viewbase : "", + Verbose ? "-v " : "", + PkgName); + } + vsystem("%s/pkg_view %s%s %s%s %sadd %s", + BINDIR, + View ? "-w " : "", + View ? View : "", + Viewbase ? "-W " : "", + Viewbase ? Viewbase : "", + Verbose ? "-v " : "", + PkgName); + } + goto success; bomb: diff --git a/usr.sbin/pkg_install/add/pkg_add.1 b/usr.sbin/pkg_install/add/pkg_add.1 index b8f1392f1b3e..e921ad6aa19d 100644 --- a/usr.sbin/pkg_install/add/pkg_add.1 +++ b/usr.sbin/pkg_install/add/pkg_add.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_add.1,v 1.42 2003/07/25 12:14:10 salo Exp $ +.\" $NetBSD: pkg_add.1,v 1.43 2003/09/02 07:34:51 jlam Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -25,7 +25,13 @@ .Nd a utility for installing and upgrading software package distributions .Sh SYNOPSIS .Nm -.Op Fl fIMnRSuVv +.Op Fl fILMnRSuVv +.Bk -words +.Op Fl K Ar pkg_dbdir +.Ek +.Bk -words +.Op Fl p Ar prefix +.Ek .Bk -words .Op Fl s Ar verification-type .Ek @@ -33,7 +39,10 @@ .Op Fl t Ar template .Ek .Bk -words -.Op Fl p Ar prefix +.Op Fl W Ar viewbase +.Ek +.Bk -words +.Op Fl w Ar view .Ek .Ar \fR[ftp://[\fIuser\fR[:\fIpassword]\fR@]\fIhost\fR[:\fIport\fR]][/\fIpath/\fR]pkg-name ... .Sh DESCRIPTION @@ -105,6 +114,17 @@ will still try to find and auto-install missing prerequisite packages, a failure to find one will not be fatal. .It Fl I If an installation script exists for a given package, do not execute it. +.It Fl K Ar pkg_dbdir +Set +.Ar pkg_dbdir +as the package database directory. +If this option isn't specified, then the package database directory is +taken from the value of the environment variable +.Ev PKG_DBDIR +if it's set, otherwise it defaults to +.Pa /var/db/pkg . +.It Fl L +Don't add the package to any views after installation. .It Fl M Run in .Cm MASTER @@ -223,6 +243,22 @@ See below for a more detailed description of the process. Print version number and exit. .It Fl v Turn on verbose output. +.It Fl W Ar viewbase +Set +.Ar viewbase +as the base directory for the managed views. +The default +.Ar viewbase +directory is set by +.Xr pkg_view 1 . +.It Fl w Ar view +Set the +.Ar view +to which packages should be added after installation. +The default +.Ar view +is set by +.Xr pkg_view 1 . .El .Pp One or more @@ -398,10 +434,13 @@ for subsequent possible use by Any package dependencies are recorded in the other packages' .Pa /var/db/pkg/\*[Lt]other-pkg\*[Gt]/+REQUIRED_BY file -(if the environment variable PKG_DBDIR is set, this overrides the -.Pa /var/db/pkg/ +(if an alternate package database directory is specified, then it +overrides the +.Pa /var/db/pkg path shown above). .It +If the package is a depoted package, then add it to the default view. +.It The staging area is deleted and the program terminates. .It Finally, if we were upgrading a package, any @@ -426,7 +465,16 @@ is installed, even if the user might change it with the flag to .Cm pkg_add . .Sh ENVIRONMENT -.Ss PKG_PATH +.Bl -tag -width PKG_TMPDIR +.It Ev PKG_DBDIR +If the +.Fl K +flag isn't given, then +.Ev PKG_DBDIR +is the location of the package database directory. +The default package database directory is +.Pa /var/db/pkg . +.It Ev PKG_PATH The value of the .Ev PKG_PATH is used if a given package can't be found, it's usually set to @@ -437,13 +485,11 @@ Each entry consists of a directory name or URL. The current directory may be indicated implicitly by an empty directory name, or explicitly by a single period. FTP URLs may not end with a slash. -.Ss PKG_DBDIR -Where to register packages instead of -.Pa /var/db/pkg . -.Ss PKG_TMPDIR +.It Ev PKG_TMPDIR Staging directory for installing packages, defaults to /var/tmp. Set to directory with lots of free disk if you run out of space when installing a binary package. +.El .Sh EXAMPLES In all cases, .Nm diff --git a/usr.sbin/pkg_install/admin/main.c b/usr.sbin/pkg_install/admin/main.c index c16f5a6911c2..7febc1c28610 100644 --- a/usr.sbin/pkg_install/admin/main.c +++ b/usr.sbin/pkg_install/admin/main.c @@ -1,8 +1,8 @@ -/* $NetBSD: main.c,v 1.36 2003/06/05 13:15:43 agc Exp $ */ +/* $NetBSD: main.c,v 1.37 2003/09/02 07:34:51 jlam Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: main.c,v 1.36 2003/06/05 13:15:43 agc Exp $"); +__RCSID("$NetBSD: main.c,v 1.37 2003/09/02 07:34:51 jlam Exp $"); #endif /* @@ -47,6 +47,10 @@ __RCSID("$NetBSD: main.c,v 1.36 2003/06/05 13:15:43 agc Exp $"); #include "lib.h" +#define DEFAULT_SFX ".t[bg]z" /* default suffix for ls{all,best} */ + +static const char Options[] = "K:s:V"; + void usage(void); int filecnt; @@ -338,21 +342,44 @@ lspattern_fn(const char *pkg, void *vp) int main(int argc, char *argv[]) { + int ch; + char sfx[FILENAME_MAX]; + Boolean use_default_sfx = TRUE; + setprogname(argv[0]); if (argc < 2) usage(); - if (strcmp(argv[1], "-V") == 0) { + while ((ch = getopt(argc, argv, Options)) != -1) + switch (ch) { + case 'K': + _pkgdb_setPKGDB_DIR(optarg); + break; - show_version(); - /* NOTREACHED */ + case 's': + (void) strlcpy(sfx, optarg, sizeof(sfx)); + use_default_sfx = FALSE; + break; - } else if (strcasecmp(argv[1], "pmatch") == 0) { + case 'V': + show_version(); + /* NOTREACHED */ + + default: + usage(); + /* NOTREACHED */ + } + argc -= optind; + argv += optind; + + if (use_default_sfx) + (void) snprintf(sfx, sizeof(sfx), "%s", DEFAULT_SFX); + + if (strcasecmp(argv[0], "pmatch") == 0) { char *pattern, *pkg; - argv++; /* argv[0] */ argv++; /* "pmatch" */ pattern = argv[0]; @@ -368,14 +395,13 @@ main(int argc, char *argv[]) return 1; } - } else if (strcasecmp(argv[1], "rebuild") == 0) { + } else if (strcasecmp(argv[0], "rebuild") == 0) { rebuild(); printf("Done.\n"); - } else if (strcasecmp(argv[1], "check") == 0) { + } else if (strcasecmp(argv[0], "check") == 0) { - argv++; /* argv[0] */ argv++; /* "check" */ if (*argv != NULL) { @@ -429,11 +455,10 @@ main(int argc, char *argv[]) } printf("Done.\n"); - } else if (strcasecmp(argv[1], "lsall") == 0) { + } else if (strcasecmp(argv[0], "lsall") == 0) { int saved_wd; - argv++; /* argv[0] */ - argv++; /* "check" */ + argv++; /* "lsall" */ /* preserve cwd */ saved_wd=open(".", O_RDONLY); @@ -449,7 +474,7 @@ main(int argc, char *argv[]) dir = dirname_of(*argv); basep = basename_of(*argv); - snprintf(base, sizeof(base), "%s.t[bg]z", basep); + snprintf(base, sizeof(base), "%s%s", basep, sfx); fchdir(saved_wd); rc = chdir(dir); @@ -467,11 +492,10 @@ main(int argc, char *argv[]) close(saved_wd); - } else if (strcasecmp(argv[1], "lsbest") == 0) { + } else if (strcasecmp(argv[0], "lsbest") == 0) { int saved_wd; - argv++; /* argv[0] */ - argv++; /* "check" */ + argv++; /* "lsbest" */ /* preserve cwd */ saved_wd=open(".", O_RDONLY); @@ -488,7 +512,7 @@ main(int argc, char *argv[]) dir = dirname_of(*argv); basep = basename_of(*argv); - snprintf(base, sizeof(base), "%s.t[bg]z", basep); + snprintf(base, sizeof(base), "%s%s", basep, sfx); fchdir(saved_wd); rc = chdir(dir); @@ -508,15 +532,15 @@ main(int argc, char *argv[]) close(saved_wd); - } else if (strcasecmp(argv[1], "list") == 0 || - strcasecmp(argv[1], "dump") == 0) { + } else if (strcasecmp(argv[0], "list") == 0 || + strcasecmp(argv[0], "dump") == 0) { pkgdb_dump(); } #ifdef PKGDB_DEBUG - else if (strcasecmp(argv[1], "del") == 0 || - strcasecmp(argv[1], "delete") == 0) { + else if (strcasecmp(argv[0], "del") == 0 || + strcasecmp(argv[0], "delete") == 0) { int rc; @@ -533,7 +557,7 @@ main(int argc, char *argv[]) pkgdb_close(); - } else if (strcasecmp(argv[1], "add") == 0) { + } else if (strcasecmp(argv[0], "add") == 0) { int rc; @@ -568,7 +592,7 @@ main(int argc, char *argv[]) void usage(void) { - printf("usage: pkg_admin [-V] command args ...\n" + printf("usage: pkg_admin [-V] [-s sfx] command args ...\n" "Where 'commands' and 'args' are:\n" " rebuild - rebuild pkgdb from +CONTENTS files\n" " check [pkg ...] - check md5 checksum of installed files\n" diff --git a/usr.sbin/pkg_install/admin/pkg_admin.1 b/usr.sbin/pkg_install/admin/pkg_admin.1 index 46cc816bcce6..d594c155dd24 100644 --- a/usr.sbin/pkg_install/admin/pkg_admin.1 +++ b/usr.sbin/pkg_install/admin/pkg_admin.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_admin.1,v 1.20 2002/09/26 01:41:51 wiz Exp $ +.\" $NetBSD: pkg_admin.1,v 1.21 2003/09/02 07:34:52 jlam Exp $ .\" .\" Copyright (c) 1999-2002 Hubert Feyrer. All rights reserved. .\" @@ -37,6 +37,12 @@ .Sh SYNOPSIS .Nm .Op Fl V +.Bk -words +.Op Fl K Ar pkg_dbdir +.Ek +.Bk -words +.Op Fl s Ar sfx_pattern +.Ek .Ar command Op args ... .Sh DESCRIPTION This command performs various administrative tasks around the @@ -45,8 +51,24 @@ Packages System. Available commands are: .Pp .Bl -tag -width check +.It Fl K Ar pkg_dbdir +Set +.Ar pkg_dbdir +as the package database directory. +If this option isn't specified, then the package database directory is +taken from the value of the environment variable +.Ev PKG_DBDIR +if it's set, otherwise it defaults to +.Pa /var/db/pkg . .It Fl V Print version number and exit. +.It Fl s Ar sfx_pattern +Set the shell glob pattern for package suffices when matching package +names for +.Cm lsall +and +.Cm lsbest . +The default pattern is ".t[bg]z". .It Cm check Op Ar pkg ... Use this command to check the files belonging to some or all of the packages installed on the local machine against their MD5 checksum @@ -84,15 +106,15 @@ yui# cd /usr/pkgsrc/packages/i386ELF/All/ yui# ls unzip* unzip-5.40.tgz unzip-5.41.tgz yui# pkg_admin lsall 'unzip*' -unzip-5.40.tgz -unzip-5.41.tgz +/usr/pkgsrc/packages/i386ELF/All/unzip-5.40.tgz +/usr/pkgsrc/packages/i386ELF/All/unzip-5.41.tgz yui# pkg_admin lsall 'unzip\*[Ge]5.40' -unzip-5.40.tgz -unzip-5.41.tgz +/usr/pkgsrc/packages/i386ELF/All/unzip-5.40.tgz +/usr/pkgsrc/packages/i386ELF/All/unzip-5.41.tgz yui# pkg_admin lsall 'unzip\*[Ge]5.41' -unzip-5.41.tgz +/usr/pkgsrc/packages/i386ELF/All/unzip-5.41.tgz yui# pkg_admin lsbest 'unzip\*[Ge]5.40' -unzip-5.41.tgz +/usr/pkgsrc/packages/i386ELF/All/unzip-5.41.tgz yui# pkg_admin lsall /usr/pkgsrc/packages/i386ELF/All/'{mit,unproven}-pthread*' /usr/pkgsrc/packages/i386ELF/All/mit-pthreads-1.60b6.tgz /usr/pkgsrc/packages/i386ELF/All/unproven-pthreads-0.15.tgz @@ -120,9 +142,14 @@ Needs to be run as root. .Pp .El .Sh ENVIRONMENT -.Bl -tag -width PKG_DBDIR -compact +.Bl -tag -width indent -compact .It Ev PKG_DBDIR -Where to register packages instead of +If the +.Fl K +flag isn't given, then +.Ev PKG_DBDIR +is the location of the package database directory. +The default package database directory is .Pa /var/db/pkg . .El .Sh FILES diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h index b5d6744b483d..6e62e030b2c2 100644 --- a/usr.sbin/pkg_install/create/create.h +++ b/usr.sbin/pkg_install/create/create.h @@ -1,4 +1,4 @@ -/* $NetBSD: create.h,v 1.17 2003/01/10 11:55:45 agc Exp $ */ +/* $NetBSD: create.h,v 1.18 2003/09/02 07:34:53 jlam Exp $ */ /* from FreeBSD Id: create.h,v 1.13 1997/10/08 07:46:19 charnier Exp */ @@ -51,6 +51,7 @@ extern int PlistOnly; extern int RelativeLinks; extern int ReorderDirs; extern int update_pkgdb; +extern int create_views; void check_list(char *, package_t *, const char *); void copy_plist(char *, package_t *); diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c index 2f95829dd5d7..c189388e5423 100644 --- a/usr.sbin/pkg_install/create/main.c +++ b/usr.sbin/pkg_install/create/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.25 2003/07/14 06:17:55 itojun Exp $ */ +/* $NetBSD: main.c,v 1.26 2003/09/02 07:34:53 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: main.c,v 1.17 1997/10/08 07:46:23 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.25 2003/07/14 06:17:55 itojun Exp $"); +__RCSID("$NetBSD: main.c,v 1.26 2003/09/02 07:34:53 jlam Exp $"); #endif #endif @@ -24,7 +24,7 @@ __RCSID("$NetBSD: main.c,v 1.25 2003/07/14 06:17:55 itojun Exp $"); #include "lib.h" #include "create.h" -static const char Options[] = "B:C:D:FI:L:OP:RS:UVX:b:c:d:f:hi:k:lm:n:p:r:s:t:v"; +static const char Options[] = "B:C:D:EFI:K:L:OP:RS:UVX:b:c:d:f:hi:k:lm:n:p:r:s:t:v"; char *Prefix = NULL; char *Comment = NULL; @@ -48,6 +48,7 @@ char *realprefix = NULL; char PlayPen[FILENAME_MAX]; size_t PlayPenSize = sizeof(PlayPen); int update_pkgdb = 1; +int create_views = 0; int Dereference = 0; int PlistOnly = 0; int RelativeLinks = 0; @@ -58,7 +59,7 @@ static void usage(void) { fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", - "usage: pkg_create [-ORUhlVv] [-P dpkgs] [-C cpkgs] [-p prefix] [-f contents]", + "usage: pkg_create [-ORUEhlVv] [-P dpkgs] [-C cpkgs] [-p prefix] [-f contents]", " [-i iscript] [-k dscript] [-r rscript] [-t template]", " [-X excludefile] [-D displayfile] [-m mtreefile]", " [-b build-version-file] [-B build-info-file]", @@ -81,6 +82,10 @@ main(int argc, char **argv) Verbose = TRUE; break; + case 'E': + create_views = 1; + break; + case 'I': realprefix = optarg; break; @@ -125,6 +130,10 @@ main(int argc, char **argv) Install = optarg; break; + case 'K': + _pkgdb_setPKGDB_DIR(optarg); + break; + case 'k': DeInstall = optarg; break; diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index f4c0f0003265..93a813ba4aaf 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.37 2003/08/10 12:27:08 grant Exp $ */ +/* $NetBSD: perform.c,v 1.38 2003/09/02 07:34:53 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.37 2003/08/10 12:27:08 grant Exp $"); +__RCSID("$NetBSD: perform.c,v 1.38 2003/09/02 07:34:53 jlam Exp $"); #endif #endif @@ -138,6 +138,9 @@ make_dist(const char *home, const char *pkg, const char *suffix, const package_t if (Preserve) { (void) fprintf(totar, "%s\n", PRESERVE_FNAME); } + if (create_views) { + (void) fprintf(totar, "%s\n", VIEWS_FNAME); + } for (p = plist->head; p; p = p->next) { if (p->type == PLIST_FILE) { @@ -387,6 +390,11 @@ pkg_perform(lpkg_head_t *pkgs) add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, PRESERVE_FNAME); } + if (create_views) { + write_file(VIEWS_FNAME, ""); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, VIEWS_FNAME); + } /* Finally, write out the packing list */ fp = fopen(CONTENTS_FNAME, "w"); diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1 index 919109f89717..93de6b6bc530 100644 --- a/usr.sbin/pkg_install/create/pkg_create.1 +++ b/usr.sbin/pkg_install/create/pkg_create.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_create.1,v 1.36 2003/06/26 10:09:05 wiz Exp $ +.\" $NetBSD: pkg_create.1,v 1.37 2003/09/02 07:34:54 jlam Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -32,7 +32,7 @@ .Nd a utility for creating software package distributions .Sh SYNOPSIS .Nm -.Op Fl hlORUVv +.Op Fl EhlORUVv .Bk -words .Op Fl B Ar build-info-file .Ek @@ -43,6 +43,9 @@ .Op Fl D Ar displayfile .Ek .Bk -words +.Op Fl K Ar pkg_dbdir +.Ek +.Bk -words .Op Fl P Ar dpkgs .Ek .Bk -words @@ -52,9 +55,6 @@ .Op Fl b Ar build-version-file .Ek .Bk -words -.Op Fl f Ar contents -.Ek -.Bk -words .Op Fl i Ar iscript .Ek .Bk -words @@ -156,13 +156,15 @@ Fetch long description for package from file or, if preceded by .Cm - , the argument itself. -.It Fl f Ar packinglist +.It Fl E +Add an empty views file to the package. +.It Fl f Ar packlist Fetch ``packing list'' for package from the file -.Ar packinglist +.Ar packlist or .Cm stdin if -.Ar packinglist +.Ar packlist is a .Cm - (dash). @@ -178,6 +180,15 @@ Set to be the install procedure for the package. This can be any executable program (or shell script). It will be invoked automatically when the package is later installed. +.It Fl K Ar pkg_dbdir +Set +.Ar pkg_dbdir +as the package database directory. +If this option isn't specified, then the package database directory is +taken from the value of the environment variable +.Ev PKG_DBDIR +if it's set, otherwise it defaults to +.Pa /var/db/pkg . .It Fl k Ar dscript Set .Ar dscript diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c index 73ee55a02278..6f0993a3cb84 100644 --- a/usr.sbin/pkg_install/create/pl.c +++ b/usr.sbin/pkg_install/create/pl.c @@ -1,11 +1,11 @@ -/* $NetBSD: pl.c,v 1.27 2003/07/14 06:17:55 itojun Exp $ */ +/* $NetBSD: pl.c,v 1.28 2003/09/02 07:34:54 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: pl.c,v 1.11 1997/10/08 07:46:35 charnier Exp"; #else -__RCSID("$NetBSD: pl.c,v 1.27 2003/07/14 06:17:55 itojun Exp $"); +__RCSID("$NetBSD: pl.c,v 1.28 2003/09/02 07:34:54 jlam Exp $"); #endif #endif diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c index 8e35cbea72d1..77f939f09629 100644 --- a/usr.sbin/pkg_install/delete/main.c +++ b/usr.sbin/pkg_install/delete/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.28 2003/06/25 23:12:42 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.29 2003/09/02 07:34:55 jlam Exp $ */ #include #ifndef lint #if 0 static char *rcsid = "from FreeBSD Id: main.c,v 1.11 1997/10/08 07:46:48 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.28 2003/06/25 23:12:42 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.29 2003/09/02 07:34:55 jlam Exp $"); #endif #endif @@ -35,7 +35,7 @@ __RCSID("$NetBSD: main.c,v 1.28 2003/06/25 23:12:42 hubertf Exp $"); #include "lib.h" #include "delete.h" -static char Options[] = "DFORVdfhnp:rv"; +static char Options[] = "DFK:ORVdfhnp:rv"; char *Prefix = NULL; char *ProgramPath = NULL; @@ -67,22 +67,6 @@ main(int argc, char **argv) while ((ch = getopt(argc, argv, Options)) != -1) switch (ch) { - case 'v': - Verbose = TRUE; - break; - - case 'f': - Force += 1; - break; - - case 'F': - File2Pkg = TRUE; - break; - - case 'p': - Prefix = optarg; - break; - case 'D': NoDeInstall = TRUE; break; @@ -91,27 +75,47 @@ main(int argc, char **argv) CleanDirs = TRUE; break; + case 'F': + File2Pkg = TRUE; + break; + + case 'f': + Force += 1; + break; + + case 'K': + _pkgdb_setPKGDB_DIR(optarg); + break; + case 'n': Fake = TRUE; Verbose = TRUE; break; - case 'r': - Recurse_up = TRUE; - break; - - case 'R': - Recurse_down = TRUE; - break; - case 'O': OnlyDeleteFromPkgDB = TRUE; break; + case 'p': + Prefix = optarg; + break; + + case 'R': + Recurse_down = TRUE; + break; + + case 'r': + Recurse_up = TRUE; + break; + case 'V': show_version(); /* NOTREACHED */ + case 'v': + Verbose = TRUE; + break; + case 'h': case '?': default: @@ -151,9 +155,8 @@ main(int argc, char **argv) } } else { char *dbdir; - char *tmp; - dbdir = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR; + dbdir = _pkgdb_getPKGDB_DIR(); if (**argv == '/' && strncmp(*argv, dbdir, strlen(dbdir)) == 0) { *argv += strlen(dbdir) + 1; if ((*argv)[strlen(*argv) - 1] == '/') { diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index e4b7cb464ad8..838f3d715106 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.42 2003/09/01 17:43:23 tron Exp $ */ +/* $NetBSD: perform.c,v 1.43 2003/09/02 07:34:55 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.42 2003/09/01 17:43:23 tron Exp $"); +__RCSID("$NetBSD: perform.c,v 1.43 2003/09/02 07:34:55 jlam Exp $"); #endif #endif @@ -114,12 +114,10 @@ undepend(const char *deppkgname, void *vp) char fname[FILENAME_MAX], ftmp[FILENAME_MAX]; char fbuf[FILENAME_MAX]; FILE *fp, *fpwr; - char *tmp; int s; (void) snprintf(fname, sizeof(fname), "%s/%s/%s", - (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, - deppkgname, REQUIRED_BY_FNAME); + _pkgdb_getPKGDB_DIR(), deppkgname, REQUIRED_BY_FNAME); fp = fopen(fname, "r"); if (fp == NULL) { warnx("couldn't open dependency file `%s'", fname); @@ -165,6 +163,92 @@ undepend(const char *deppkgname, void *vp) return 0; } +/* + * Remove the current view's package dbdir from the +VIEWS file of the + * depoted package named by pkgname. + */ +static int +unview(const char *pkgname) +{ + char fname[FILENAME_MAX], ftmp[FILENAME_MAX]; + char fbuf[FILENAME_MAX]; + char dbdir[FILENAME_MAX]; + FILE *fp, *fpwr; + int s; + int cc; + + (void) snprintf(dbdir, sizeof(dbdir), "%s", _pkgdb_getPKGDB_DIR()); + + /* Get the depot directory. */ + (void) snprintf(fname, sizeof(fname), "%s/%s/%s", + dbdir, pkgname, DEPOT_FNAME); + if ((fp = fopen(fname, "r")) == NULL) { + warnx("unable to open `%s' file", fname); + return -1; + } + if (fgets(fbuf, sizeof(fbuf), fp) == NULL) { + (void) fclose(fp); + warnx("empty depot file `%s'", fname); + return -1; + } + if (fbuf[cc = strlen(fbuf) - 1] == '\n') { + fbuf[cc] = 0; + } + fclose(fp); + + /* + * Copy the contents of the +VIEWS file into a temp file, but + * skip copying the name of the current view's package dbdir. + */ + (void) snprintf(fname, sizeof(fname), "%s/%s", fbuf, VIEWS_FNAME); + if ((fp = fopen(fname, "r")) == NULL) { + warnx("unable to open `%s' file", fname); + return -1; + } + (void) snprintf(ftmp, sizeof(ftmp), "%s.XXXXXX", fname); + if ((s = mkstemp(ftmp)) == -1) { + (void) fclose(fp); + warnx("unable to open `%s' temp file", ftmp); + return -1; + } + if ((fpwr = fdopen(s, "w")) == NULL) { + (void) close(s); + (void) remove(ftmp); + (void) fclose(fp); + warnx("unable to fdopen `%s' temp file", ftmp); + return -1; + } + while (fgets(fbuf, sizeof(fbuf), fp) != NULL) { + if (fbuf[cc = strlen(fbuf) - 1] == '\n') { + fbuf[cc] = 0; + } + if (strcmp(fbuf, dbdir) != 0) { + (void) fputs(fbuf, fpwr); + (void) putc('\n', fpwr); + } + } + (void) fclose(fp); + if (fchmod(s, 0644) == FAIL) { + (void) fclose(fpwr); + (void) remove(ftmp); + warnx("unable to change permissions of `%s' temp file", ftmp); + return -1; + } + if (fclose(fpwr) == EOF) { + (void) remove(ftmp); + warnx("unable to close `%s' temp file", ftmp); + return -1; + } + + /* Rename the temp file to the +VIEWS file */ + if (rename(ftmp, fname) == -1) { + (void) remove(ftmp); + warnx("unable to rename `%s' to `%s'", ftmp, fname); + return -1; + } + return 0; +} + /* * Delete from directory 'home' all packages on lpkg_list. * If tryall is set, ignore errors from pkg_delete(1). @@ -174,7 +258,6 @@ require_delete(char *home, int tryall) { lpkg_t *lpp; int rv, fail; - char *tmp; int oldcwd; /* save cwd */ @@ -182,8 +265,7 @@ require_delete(char *home, int tryall) if (oldcwd == -1) err(EXIT_FAILURE, "cannot open \".\""); - (void) snprintf(pkgdir, sizeof(pkgdir), "%s", - (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR); + (void) snprintf(pkgdir, sizeof(pkgdir), "%s", _pkgdb_getPKGDB_DIR()); /* walk list of things to delete */ fail = 0; @@ -275,7 +357,7 @@ require_find_recursive_up(lpkg_t *thislpp) lpkg_head_t reqq; lpkg_t *lpp = NULL; FILE *cfile; - char *nl, *tmp; + char *nl; /* see if we are on the find queue -- circular dependency */ if ((lpp = find_on_queue(&lpfindq, thislpp->lp_name))) { @@ -286,7 +368,7 @@ require_find_recursive_up(lpkg_t *thislpp) TAILQ_INIT(&reqq); (void) snprintf(pkgdir, sizeof(pkgdir), "%s/%s", - (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, thislpp->lp_name); + _pkgdb_getPKGDB_DIR(), thislpp->lp_name); /* change to package's dir */ if (chdir(pkgdir) == FAIL) { @@ -390,7 +472,6 @@ require_find_recursive_down(lpkg_t *thislpp, package_t *plist) while ((lpp = TAILQ_FIRST(&reqq))) { FILE *cfile; package_t rPlist; - char *tmp; /* remove a direct req from our queue */ TAILQ_REMOVE(&reqq, lpp, lp_link); @@ -400,7 +481,7 @@ require_find_recursive_down(lpkg_t *thislpp, package_t *plist) rPlist.tail = NULL; /* prepare for recursion */ - chdir ((tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR); + chdir(_pkgdb_getPKGDB_DIR()); if (ispkgpattern(lpp->lp_name)) { char installed[FILENAME_MAX]; if (findmatchingname(".", lpp->lp_name, note_whats_installed, installed) != 1) { @@ -512,17 +593,20 @@ require_print(void) static int pkg_do(char *pkg) { - FILE *cfile; - char home[FILENAME_MAX]; - plist_t *p; - char *tmp; + plist_t *p; + FILE *cfile; + FILE *fp; + char home[FILENAME_MAX]; + char view[FILENAME_MAX]; + int cc; + Boolean is_depoted_pkg = FALSE; /* Reset some state */ if (Plist.head) free_plist(&Plist); - (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, - pkg); + (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", + _pkgdb_getPKGDB_DIR(), pkg); if (!fexists(LogDir) || !isdir(LogDir)) { { /* Check if the given package name matches something @@ -548,6 +632,11 @@ pkg_do(char *pkg) warnx("unable to change directory to %s! deinstall failed", LogDir); return 1; } + if (!fexists(CONTENTS_FNAME)) { + warnx("package '%s' is not installed, %s missing", pkg, CONTENTS_FNAME); + if (!Force) + return 1; + } if (fexists(PRESERVE_FNAME)) { printf("Package `%s' is marked as not for deletion\n", pkg); if (Force <= 1) { @@ -574,6 +663,28 @@ pkg_do(char *pkg) } else require_delete(home, 0); } + if (!isemptyfile(VIEWS_FNAME)) { + /* This package has instances in other views */ + /* Delete them from the views */ + if ((fp = fopen(VIEWS_FNAME, "r")) == NULL) { + warnx("unable to open '%s' file", VIEWS_FNAME); + return 1; + } + while (fgets(view, sizeof(view), fp) != NULL) { + if (view[cc = strlen(view) - 1] == '\n') { + view[cc] = 0; + } + if (Verbose) { + printf("Deleting package %s instance from `%s' view\n", pkg, view); + } + if (vsystem("%s -K %s %s", ProgramPath, view, pkg) != 0) { + warnx("unable to delete package %s from view %s", pkg, view); + (void) fclose(fp); + return 1; + } + } + (void) fclose(fp); + } sanity_check(LogDir); cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { @@ -602,7 +713,24 @@ pkg_do(char *pkg) return 1; } } - if (!NoDeInstall && fexists(DEINSTALL_FNAME)) { + /* + * Ensure that we don't do VIEW-DEINSTALL action for old packages + * or for the package in its depot directory. + */ + if (!NoDeInstall && fexists(DEINSTALL_FNAME) && fexists(DEPOT_FNAME)) { + if (Fake) { + printf("Would execute view de-install script at this point (arg: VIEW-DEINSTALL).\n"); + } else { + vsystem("%s +x %s", CHMOD_CMD, DEINSTALL_FNAME); /* make sure */ + if (vsystem("./%s %s VIEW-DEINSTALL", DEINSTALL_FNAME, pkg)) { + warnx("view deinstall script returned error status"); + if (!Force) { + return 1; + } + } + } + } + if (!NoDeInstall && fexists(DEINSTALL_FNAME) && !fexists(DEPOT_FNAME)) { if (Fake) printf("Would execute de-install script at this point (arg: DEINSTALL).\n"); else { @@ -621,15 +749,26 @@ pkg_do(char *pkg) "couldn't entirely delete package `%s'\n" "(perhaps the packing list is incorrectly specified?)", pkg); } - /* Remove this package from the +REQUIRED_BY list of the packages this depends on */ - for (p = Plist.head; p; p = p->next) { - if (p->type != PLIST_PKGDEP) - continue; + if (!isemptyfile(DEPOT_FNAME)) { if (Verbose) - printf("Attempting to remove dependency on package `%s'\n", p->name); + printf("Attempting to remove the %s registration on package `%s'\n", VIEWS_FNAME, pkg); if (!Fake) - findmatchingname((tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, - p->name, undepend, pkg); + (void) unview(pkg); + } + /* + * If this isn't a package in a view, then remove this package + * from the +REQUIRED_BY list of the packages this depends on. + */ + if (!fexists(DEPOT_FNAME)) { + for (p = Plist.head; p; p = p->next) { + if (p->type != PLIST_PKGDEP) + continue; + if (Verbose) + printf("Attempting to remove dependency on package `%s'\n", p->name); + if (!Fake) + findmatchingname(_pkgdb_getPKGDB_DIR(), + p->name, undepend, pkg); + } } if (Recurse_down) { /* Also remove the packages further down, now that there's @@ -641,7 +780,7 @@ pkg_do(char *pkg) require_delete(home, 1); } - if (!NoDeInstall && fexists(DEINSTALL_FNAME)) { + if (!NoDeInstall && fexists(DEINSTALL_FNAME) && !fexists(DEPOT_FNAME)) { if (Fake) printf("Would execute post-de-install script at this point (arg: POST-DEINSTALL).\n"); else { @@ -653,16 +792,28 @@ pkg_do(char *pkg) } } } + if (fexists(VIEWS_FNAME)) + is_depoted_pkg = TRUE; + /* Change out of LogDir before we remove it. * Do not fail here, as the package is not yet completely deleted! */ if (chdir(home) == FAIL) warnx("Oops - removed current working directory. Oh, well."); if (!Fake) { /* Finally nuke the +-files and the pkgdb-dir (/var/db/pkg/foo) */ - if (fexec(REMOVE_CMD, "-r", LogDir, NULL)) { - warnx("couldn't remove log entry in %s, deinstall failed", LogDir); - if (!Force) - return 1; + if (is_depoted_pkg) { + (void) vsystem("%s %s/+*", REMOVE_CMD, LogDir); + if (isemptydir(LogDir)) + (void) vsystem("%s %s", RMDIR_CMD, LogDir); + else + warnx("%s is not empty", LogDir); + return 0; + } else { + if (fexec(REMOVE_CMD, "-r", LogDir, NULL)) { + warnx("couldn't remove log entry in %s, deinstall failed", LogDir); + if (!Force) + return 1; + } } } return 0; diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1 index 435651912e19..0c051bfb52a2 100644 --- a/usr.sbin/pkg_install/delete/pkg_delete.1 +++ b/usr.sbin/pkg_install/delete/pkg_delete.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_delete.1,v 1.29 2003/07/04 12:17:32 wiz Exp $ +.\" $NetBSD: pkg_delete.1,v 1.30 2003/09/02 07:34:56 jlam Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -27,6 +27,9 @@ .Nm .Op Fl DdFfnORrVv .Bk -words +.Op Fl K Ar pkg_dbdir +.Ek +.Bk -words .Op Fl p Ar prefix .Ek .Ar pkg-name ... @@ -99,6 +102,15 @@ instead of the package-name. .It Fl f Force removal of the package, even if a dependency is recorded or the deinstall or require script fails. +.It Fl K Ar pkg_dbdir +Set +.Ar pkg_dbdir +as the package database directory. +If this option isn't specified, then the package database directory is +taken from the value of the environment variable +.Ev PKG_DBDIR +if it's set, otherwise it defaults to +.Pa /var/db/pkg . .It Fl n Don't actually deinstall a package, just report the steps that would be taken if it were. @@ -139,7 +151,11 @@ Turn on verbose output. does pretty much what it says. It examines installed package records in .Pa /var/db/pkg/\*[Lt]pkg-name\*[Gt] , -deletes the package contents, and finally removes the package records. +deletes the package contents, and finally removes the package records +(if an alternate package database directory is specified, then it +overrides the +.Pa /var/db/pkg +path shown above). .Pp If a package is required by other installed packages, .Nm @@ -197,6 +213,12 @@ script is called as: .Bd -filled -offset indent -compact .Cm deinstall .Ar \*[Lt]pkg-name\*[Gt] +.Ar VIEW-DEINSTALL +.Ed +before removing the package from a view, and as: +.Bd -filled -offset indent -compact +.Cm deinstall +.Ar \*[Lt]pkg-name\*[Gt] .Ar DEINSTALL .Ed before deleting all files and as: @@ -207,6 +229,7 @@ before deleting all files and as: .Ed after deleting them. Passing the keywords +.Ar VIEW-DEINSTALL , .Ar DEINSTALL and .Ar POST-DEINSTALL diff --git a/usr.sbin/pkg_install/info/info.h b/usr.sbin/pkg_install/info/info.h index 1b55b10170f4..4f8edfb68bb1 100644 --- a/usr.sbin/pkg_install/info/info.h +++ b/usr.sbin/pkg_install/info/info.h @@ -1,4 +1,4 @@ -/* $NetBSD: info.h,v 1.13 2002/06/09 13:23:45 yamt Exp $ */ +/* $NetBSD: info.h,v 1.14 2003/09/02 07:34:57 jlam Exp $ */ /* from FreeBSD Id: info.h,v 1.10 1997/02/22 16:09:40 peter Exp */ @@ -50,6 +50,7 @@ #define SHOW_DEPENDS 0x04000 #define SHOW_PKG_SIZE 0x08000 #define SHOW_ALL_SIZE 0x10000 +#define SHOW_BLD_DEPENDS 0x20000 extern int Flags; extern Boolean AllInstalled; @@ -66,6 +67,7 @@ extern void show_file(char *, char *); extern void show_plist(char *, package_t *, pl_ent_t); extern void show_files(char *, package_t *); extern void show_depends(char *, package_t *); +extern void show_bld_depends(char *, package_t *); extern void show_index(char *, char *); #endif /* _INST_INFO_H_INCLUDE */ diff --git a/usr.sbin/pkg_install/info/main.c b/usr.sbin/pkg_install/info/main.c index d57df63ea2a9..de0338a9e1a1 100644 --- a/usr.sbin/pkg_install/info/main.c +++ b/usr.sbin/pkg_install/info/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.36 2003/06/19 08:54:29 agc Exp $ */ +/* $NetBSD: main.c,v 1.37 2003/09/02 07:34:57 jlam Exp $ */ #include #ifndef lint #if 0 static char *rcsid = "from FreeBSD Id: main.c,v 1.14 1997/10/08 07:47:26 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.36 2003/06/19 08:54:29 agc Exp $"); +__RCSID("$NetBSD: main.c,v 1.37 2003/09/02 07:34:57 jlam Exp $"); #endif #endif @@ -38,7 +38,7 @@ __RCSID("$NetBSD: main.c,v 1.36 2003/06/19 08:54:29 agc Exp $"); #include "lib.h" #include "info.h" -static const char Options[] = "aBbcDde:fFhIikLl:mnpqRrsSvV"; +static const char Options[] = "aBbcDde:fFhIiK:kLl:mNnpqRrsSvV"; int Flags = 0; Boolean AllInstalled = FALSE; @@ -55,7 +55,7 @@ static void usage(void) { fprintf(stderr, "%s\n%s\n%s\n", - "usage: pkg_info [-BbcDdFfIikLmnpqRrSsVvh] [-e package] [-l prefix]", + "usage: pkg_info [-BbcDdFfIikLmNnpqRrSsVvh] [-e package] [-l prefix]", " pkg-name [pkg-name ...]", " pkg_info -a [flags]"); exit(1); @@ -115,6 +115,10 @@ main(int argc, char **argv) Flags |= SHOW_INSTALL; break; + case 'K': + _pkgdb_setPKGDB_DIR(optarg); + break; + case 'k': Flags |= SHOW_DEINSTALL; break; @@ -131,6 +135,10 @@ main(int argc, char **argv) Flags |= SHOW_MTREE; break; + case 'N': + Flags |= SHOW_BLD_DEPENDS; + break; + case 'n': Flags |= SHOW_DEPENDS; break; @@ -164,7 +172,7 @@ main(int argc, char **argv) /* Reasonable definition of 'everything' */ Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL | SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE | - SHOW_REQBY | SHOW_DEPENDS | SHOW_PKG_SIZE | SHOW_ALL_SIZE; + SHOW_REQBY | SHOW_BLD_DEPENDS | SHOW_DEPENDS | SHOW_PKG_SIZE | SHOW_ALL_SIZE; break; case 'V': @@ -244,9 +252,8 @@ main(int argc, char **argv) errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); } else { char *dbdir; - char *tmp; - dbdir = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR; + dbdir = _pkgdb_getPKGDB_DIR(); if (**argv == '/' && strncmp(*argv, dbdir, strlen(dbdir)) == 0) { *argv += strlen(dbdir) + 1; if ((*argv)[strlen(*argv) - 1] == '/') { diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c index c362ab8c733a..f0dcca70c93c 100644 --- a/usr.sbin/pkg_install/info/perform.c +++ b/usr.sbin/pkg_install/info/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.46 2003/07/14 06:17:55 itojun Exp $ */ +/* $NetBSD: perform.c,v 1.47 2003/09/02 07:34:58 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.46 2003/07/14 06:17:55 itojun Exp $"); +__RCSID("$NetBSD: perform.c,v 1.47 2003/09/02 07:34:58 jlam Exp $"); #endif #endif @@ -118,11 +118,8 @@ pkg_do(char *pkg) * It's not an uninstalled package, try and find it among the * installed */ - char *tmp; - (void) snprintf(log_dir, sizeof(log_dir), "%s/%s", - (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, - pkg); + _pkgdb_getPKGDB_DIR(), pkg); if (!fexists(log_dir) || !isdir(log_dir)) { { /* Check if the given package name matches @@ -185,6 +182,9 @@ pkg_do(char *pkg) if (Flags & SHOW_DEPENDS) { show_depends("Requires:\n", &plist); } + if (Flags & SHOW_BLD_DEPENDS) { + show_bld_depends("Built using:\n", &plist); + } if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME)) { show_file("Required by:\n", REQUIRED_BY_FNAME); } @@ -313,19 +313,19 @@ int pkg_perform(lpkg_head_t *pkghead) { struct dirent *dp; - char *tmp; + char *dbdir; DIR *dirp; int err_cnt = 0; signal(SIGINT, cleanup); - tmp = _pkgdb_getPKGDB_DIR(); + dbdir = _pkgdb_getPKGDB_DIR(); /* Overriding action? */ if (CheckPkg) { - err_cnt += CheckForPkg(CheckPkg, tmp); + err_cnt += CheckForPkg(CheckPkg, dbdir); } else if (AllInstalled) { - if (!(isdir(tmp) || islinktodir(tmp))) + if (!(isdir(dbdir) || islinktodir(dbdir))) return 1; if (File2Pkg) { @@ -335,7 +335,7 @@ pkg_perform(lpkg_head_t *pkghead) } else { /* Show all packges with description */ - if ((dirp = opendir(tmp)) != (DIR *) NULL) { + if ((dirp = opendir(dbdir)) != (DIR *) NULL) { while ((dp = readdir(dirp)) != (struct dirent *) NULL) { char tmp2[FILENAME_MAX]; @@ -344,7 +344,7 @@ pkg_perform(lpkg_head_t *pkghead) continue; (void) snprintf(tmp2, sizeof(tmp2), "%s/%s", - tmp, dp->d_name); + dbdir, dp->d_name); if (isfile(tmp2)) continue; diff --git a/usr.sbin/pkg_install/info/pkg_info.1 b/usr.sbin/pkg_install/info/pkg_info.1 index 7c70d2cb7ef8..7158ca41f9dc 100644 --- a/usr.sbin/pkg_install/info/pkg_info.1 +++ b/usr.sbin/pkg_install/info/pkg_info.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_info.1,v 1.32 2002/11/14 09:40:23 agc Exp $ +.\" $NetBSD: pkg_info.1,v 1.33 2003/09/02 07:34:58 jlam Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -25,11 +25,14 @@ .Nd a utility for displaying information on software packages .Sh SYNOPSIS .Nm -.Op Fl BbcDdFfhIikLmnpqRrSsVv +.Op Fl BbcDdFfhIikLmNnpqRrSsVv .Bk -words .Op Fl e Ar package .Ek .Bk -words +.Op Fl K Ar pkg_dbdir +.Ek +.Bk -words .Op Fl l Ar prefix .Ek .Ar pkg-name ... @@ -152,6 +155,15 @@ Show the packing list instructions for each package. Show the index entry for each package. .It Fl i Show the install script (if any) for each package. +.It Fl K Ar pkg_dbdir +Set +.Ar pkg_dbdir +as the package database directory. +If this option isn't specified, then the package database directory is +taken from the value of the environment variable +.Ev PKG_DBDIR +if it's set, otherwise it defaults to +.Pa /var/db/pkg . .It Fl k Show the de-install script (if any) for each package. .It Fl L @@ -170,6 +182,8 @@ organize it. This lets you add a special token to the start of each field. .It Fl m Show the mtree file (if any) for each package. +.It Fl N +Show which packages each package was built with (exact dependencies), if any. .It Fl n Show which packages each package needs (depends upon), if any. .It Fl p @@ -195,11 +209,13 @@ Turn on verbose output. .Sh ENVIRONMENT .Bl -tag -width PKG_DBDIR .It Ev PKG_DBDIR -The standard package database directory, -.Pa /var/db/pkg , -can be overridden by specifying an alternative directory in the +If the +.Fl K +flag isn't given, then .Ev PKG_DBDIR -environment variable. +is the location of the package database directory. +The default package database directory is +.Pa /var/db/pkg . .It Ev PKG_PATH This can be used to specify a semicolon-separated list of paths and URLs to search for package files. diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c index 5fef58d9d2eb..8bcb05fb1f7d 100644 --- a/usr.sbin/pkg_install/info/show.c +++ b/usr.sbin/pkg_install/info/show.c @@ -1,11 +1,11 @@ -/* $NetBSD: show.c,v 1.26 2003/06/05 17:58:05 agc Exp $ */ +/* $NetBSD: show.c,v 1.27 2003/09/02 07:34:59 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: show.c,v 1.11 1997/10/08 07:47:38 charnier Exp"; #else -__RCSID("$NetBSD: show.c,v 1.26 2003/06/05 17:58:05 agc Exp $"); +__RCSID("$NetBSD: show.c,v 1.27 2003/09/02 07:34:59 jlam Exp $"); #endif #endif @@ -282,3 +282,41 @@ show_depends(char *title, package_t *plist) printf("\n"); } + +/* + * Show exact dependencies (packages this pkg was built with) + */ +void +show_bld_depends(char *title, package_t *plist) +{ + plist_t *p; + int nodepends; + + nodepends = 1; + for (p = plist->head; p && nodepends; p = p->next) { + switch (p->type) { + case PLIST_BLDDEP: + nodepends = 0; + break; + default: + break; + } + } + if (nodepends) + return; + + if (!Quiet) { + printf("%s%s", InfoPrefix, title); + } + for (p = plist->head; p; p = p->next) { + switch (p->type) { + case PLIST_BLDDEP: + printf("%s\n", p->name); + break; + default: + break; + } + } + + printf("\n"); +} diff --git a/usr.sbin/pkg_install/lib/Makefile b/usr.sbin/pkg_install/lib/Makefile index 368ebef81c92..1ec378054254 100644 --- a/usr.sbin/pkg_install/lib/Makefile +++ b/usr.sbin/pkg_install/lib/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.20 2003/08/24 21:10:47 tron Exp $ +# $NetBSD: Makefile,v 1.21 2003/09/02 07:34:59 jlam Exp $ # Original from FreeBSD, no rcs id. NOLINT= # defined diff --git a/usr.sbin/pkg_install/lib/fexec.c b/usr.sbin/pkg_install/lib/fexec.c index fac50bffd0c6..a3ba46defde0 100644 --- a/usr.sbin/pkg_install/lib/fexec.c +++ b/usr.sbin/pkg_install/lib/fexec.c @@ -47,7 +47,7 @@ #include "lib.h" #ifndef lint -__RCSID("$NetBSD: fexec.c,v 1.3 2003/08/25 10:52:23 tron Exp $"); +__RCSID("$NetBSD: fexec.c,v 1.4 2003/09/02 07:35:00 jlam Exp $"); #endif static int vfcexec(const char *, const char *, va_list); diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 061e4bb9ce9f..65a3f4823725 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,11 +1,11 @@ -/* $NetBSD: file.c,v 1.62 2003/07/14 06:00:45 itojun Exp $ */ +/* $NetBSD: file.c,v 1.63 2003/09/02 07:35:00 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp"; #else -__RCSID("$NetBSD: file.c,v 1.62 2003/07/14 06:00:45 itojun Exp $"); +__RCSID("$NetBSD: file.c,v 1.63 2003/09/02 07:35:00 jlam Exp $"); #endif #endif @@ -31,8 +31,6 @@ __RCSID("$NetBSD: file.c,v 1.62 2003/07/14 06:00:45 itojun Exp $"); #include "lib.h" -#include - #include #include #include diff --git a/usr.sbin/pkg_install/lib/ftpio.c b/usr.sbin/pkg_install/lib/ftpio.c index 64329e48e4b3..ad408366b37d 100644 --- a/usr.sbin/pkg_install/lib/ftpio.c +++ b/usr.sbin/pkg_install/lib/ftpio.c @@ -1,8 +1,8 @@ -/* $NetBSD: ftpio.c,v 1.52 2003/07/14 06:17:56 itojun Exp $ */ +/* $NetBSD: ftpio.c,v 1.53 2003/09/02 07:35:01 jlam Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: ftpio.c,v 1.52 2003/07/14 06:17:56 itojun Exp $"); +__RCSID("$NetBSD: ftpio.c,v 1.53 2003/09/02 07:35:01 jlam Exp $"); #endif /* diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 094bc99f495d..4d610043a20d 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $NetBSD: lib.h,v 1.54 2003/08/25 10:23:41 tron Exp $ */ +/* $NetBSD: lib.h,v 1.55 2003/09/02 07:35:02 jlam Exp $ */ /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ @@ -89,14 +89,6 @@ #define CHGRP_CMD "chgrp" #endif -/* Where we put logging information by default, else ${PKG_DBDIR} if set */ -#ifndef DEF_LOG_DIR -#define DEF_LOG_DIR "/var/db/pkg" -#endif - -/* just in case we change the environment variable name */ -#define PKG_DBDIR "PKG_DBDIR" - /* The names of our "special" files */ #define CONTENTS_FNAME "+CONTENTS" #define COMMENT_FNAME "+COMMENT" @@ -112,6 +104,8 @@ #define SIZE_PKG_FNAME "+SIZE_PKG" #define SIZE_ALL_FNAME "+SIZE_ALL" #define PRESERVE_FNAME "+PRESERVE" +#define VIEWS_FNAME "+VIEWS" +#define DEPOT_FNAME "+DEPOT" #define CMD_CHAR '@' /* prefix for extended PLIST cmd */ @@ -292,6 +286,7 @@ int pkgdb_remove(const char *); int pkgdb_remove_pkg(const char *); char *_pkgdb_getPKGDB_FILE(char *, unsigned); char *_pkgdb_getPKGDB_DIR(void); +void _pkgdb_setPKGDB_DIR(const char *); /* List of packages functions */ lpkg_t *alloc_lpkg(const char *); diff --git a/usr.sbin/pkg_install/lib/lpkg.c b/usr.sbin/pkg_install/lib/lpkg.c index a75c8bf2462a..b078c98f1c0b 100644 --- a/usr.sbin/pkg_install/lib/lpkg.c +++ b/usr.sbin/pkg_install/lib/lpkg.c @@ -1,4 +1,4 @@ -/* $NetBSD: lpkg.c,v 1.4 2003/01/05 21:27:31 agc Exp $ */ +/* $NetBSD: lpkg.c,v 1.5 2003/09/02 07:35:02 jlam Exp $ */ /* * Copyright (c) 1999 Christian E. Hopps diff --git a/usr.sbin/pkg_install/lib/path.c b/usr.sbin/pkg_install/lib/path.c index 640581e43e58..74bddebd7224 100644 --- a/usr.sbin/pkg_install/lib/path.c +++ b/usr.sbin/pkg_install/lib/path.c @@ -1,4 +1,4 @@ -/* $NetBSD: path.c,v 1.5 2003/01/05 21:27:32 agc Exp $ */ +/* $NetBSD: path.c,v 1.6 2003/09/02 07:35:03 jlam Exp $ */ /*- * Copyright (c)2002 YAMAMOTO Takashi, @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: path.c,v 1.5 2003/01/05 21:27:32 agc Exp $"); +__RCSID("$NetBSD: path.c,v 1.6 2003/09/02 07:35:03 jlam Exp $"); #endif #include diff --git a/usr.sbin/pkg_install/lib/path.h b/usr.sbin/pkg_install/lib/path.h index d5d979d41998..49ae3e7c2fad 100644 --- a/usr.sbin/pkg_install/lib/path.h +++ b/usr.sbin/pkg_install/lib/path.h @@ -1,4 +1,4 @@ -/* $NetBSD: path.h,v 1.3 2002/08/29 21:46:34 abs Exp $ */ +/* $NetBSD: path.h,v 1.4 2003/09/02 07:35:03 jlam Exp $ */ /*- * Copyright (c)2002 YAMAMOTO Takashi, diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 59cc46d3d779..abfe9664388e 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -1,11 +1,11 @@ -/* $NetBSD: pen.c,v 1.29 2003/08/25 10:23:06 tron Exp $ */ +/* $NetBSD: pen.c,v 1.30 2003/09/02 07:35:03 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: pen.c,v 1.25 1997/10/08 07:48:12 charnier Exp"; #else -__RCSID("$NetBSD: pen.c,v 1.29 2003/08/25 10:23:06 tron Exp $"); +__RCSID("$NetBSD: pen.c,v 1.30 2003/09/02 07:35:03 jlam Exp $"); #endif #endif diff --git a/usr.sbin/pkg_install/lib/pkgdb.c b/usr.sbin/pkg_install/lib/pkgdb.c index ec7c53e7b13c..61fcdfb562b8 100644 --- a/usr.sbin/pkg_install/lib/pkgdb.c +++ b/usr.sbin/pkg_install/lib/pkgdb.c @@ -1,8 +1,8 @@ -/* $NetBSD: pkgdb.c,v 1.14 2003/03/15 20:49:27 agc Exp $ */ +/* $NetBSD: pkgdb.c,v 1.15 2003/09/02 07:35:04 jlam Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: pkgdb.c,v 1.14 2003/03/15 20:49:27 agc Exp $"); +__RCSID("$NetBSD: pkgdb.c,v 1.15 2003/09/02 07:35:04 jlam Exp $"); #endif /* @@ -46,7 +46,19 @@ __RCSID("$NetBSD: pkgdb.c,v 1.14 2003/03/15 20:49:27 agc Exp $"); #define PKGDB_FILE "pkgdb.byfile.db" /* indexed by filename */ -static DB *pkgdbp; +/* + * Where we put logging information by default if PKG_DBDIR is unset. + */ +#ifndef DEF_LOG_DIR +#define DEF_LOG_DIR "/var/db/pkg" +#endif + +/* just in case we change the environment variable name */ +#define PKG_DBDIR "PKG_DBDIR" + +static DB *pkgdbp; +static char *pkgdb_dir = NULL; +static char pkgdb_cache[FILENAME_MAX]; /* * Open the pkg-database @@ -236,11 +248,24 @@ _pkgdb_getPKGDB_FILE(char *buf, unsigned size) char * _pkgdb_getPKGDB_DIR(void) { - char *tmp; - static char *cache = NULL; + char *tmp; - if (cache == NULL) - cache = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR; + if (pkgdb_dir == NULL) { + if ((tmp = getenv(PKG_DBDIR))) + _pkgdb_setPKGDB_DIR(tmp); + else + _pkgdb_setPKGDB_DIR(DEF_LOG_DIR); + } - return cache; + return pkgdb_dir; +} + +/* + * Set the first place we look for where pkgdb is stored. + */ +void +_pkgdb_setPKGDB_DIR(const char *dir) +{ + (void) snprintf(pkgdb_cache, sizeof(pkgdb_cache), "%s", dir); + pkgdb_dir = pkgdb_cache; } diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index b68e62937759..efe997f2e1eb 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -1,11 +1,11 @@ -/* $NetBSD: plist.c,v 1.39 2003/07/14 06:17:56 itojun Exp $ */ +/* $NetBSD: plist.c,v 1.40 2003/09/02 07:35:04 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp"; #else -__RCSID("$NetBSD: plist.c,v 1.39 2003/07/14 06:17:56 itojun Exp $"); +__RCSID("$NetBSD: plist.c,v 1.40 2003/09/02 07:35:04 jlam Exp $"); #endif #endif diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c index e3503d3e9ec2..77e53052e1bf 100644 --- a/usr.sbin/pkg_install/lib/str.c +++ b/usr.sbin/pkg_install/lib/str.c @@ -1,11 +1,11 @@ -/* $NetBSD: str.c,v 1.42 2003/01/05 21:27:34 agc Exp $ */ +/* $NetBSD: str.c,v 1.43 2003/09/02 07:35:04 jlam Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp"; #else -__RCSID("$NetBSD: str.c,v 1.42 2003/01/05 21:27:34 agc Exp $"); +__RCSID("$NetBSD: str.c,v 1.43 2003/09/02 07:35:04 jlam Exp $"); #endif #endif diff --git a/usr.sbin/pkg_install/lib/version.h b/usr.sbin/pkg_install/lib/version.h index 3e0fbd1851a1..c675db1f6ad6 100644 --- a/usr.sbin/pkg_install/lib/version.h +++ b/usr.sbin/pkg_install/lib/version.h @@ -1,4 +1,4 @@ -/* $NetBSD: version.h,v 1.27 2003/04/23 10:02:24 seb Exp $ */ +/* $NetBSD: version.h,v 1.28 2003/09/02 07:35:05 jlam Exp $ */ /* * Copyright (c) 2001 Thomas Klausner. All rights reserved. @@ -33,6 +33,6 @@ #ifndef _INST_LIB_VERSION_H_ #define _INST_LIB_VERSION_H_ -#define PKGTOOLS_VERSION "20030423" +#define PKGTOOLS_VERSION "20030823" #endif /* _INST_LIB_VERSION_H_ */ diff --git a/usr.sbin/pkg_install/view/Makefile b/usr.sbin/pkg_install/view/Makefile new file mode 100644 index 000000000000..7f229fa8cc06 --- /dev/null +++ b/usr.sbin/pkg_install/view/Makefile @@ -0,0 +1,6 @@ +# $NetBSD: Makefile,v 1.2 2003/09/02 07:35:06 jlam Exp $ + +SCRIPTS= linkfarm.sh pkg_view.sh +MAN= linkfarm.1 pkg_view.1 + +.include diff --git a/usr.sbin/pkg_install/view/linkfarm.1 b/usr.sbin/pkg_install/view/linkfarm.1 new file mode 100644 index 000000000000..e7226cf12166 --- /dev/null +++ b/usr.sbin/pkg_install/view/linkfarm.1 @@ -0,0 +1,144 @@ +.\" $NetBSD: linkfarm.1,v 1.2 2003/09/02 07:35:07 jlam Exp $ +.\" +.\" Copyright (c) 2003 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd July 13, 2003 +.Dt LINKFARM 1 +.Os +.Sh NAME +.Nm linkfarm +.Nd a utility for managing symbolic links to package files +.Sh SYNOPSIS +.Nm +.Op Ar options +.Ar package +.Sh DESCRIPTION +The +.Nm +command is used to manage a "linkfarm", a directory tree of symbolic links in +.Ar target +to the files in the +.Ar package +sub-directory of +.Ar stowdir . +The default action is to create a linkfarm to a package. +.Pp +The following command-line options are supported: +.Bl -tag -width indent +.It Fl c +Check whether a package contains a linkfarm in +.Ar target . +If +.Ar package +has no symbolic links in +.Ar target +that correspond to its files, then return 0, otherwise return 1. +.It Fl D +Delete the linkfarm for +.Ar package . +.It Fl d Ar stowdir +Set +.Ar stowdir +as the directory in which +.Ar package +can be found. +The default +.Ar stowdir +is the +.Pa packages +sub-directory in the default +.Ar target +directory. +.It Fl n +Don't actually execute the commands for removing and creating the symbolic +links and directories. +.It Fl R +Delete and re-create the linkfarm for +.Ar package . +.It Fl s Ar subdir +The root of the package hierarchy for the linkfarm is the +.Ar subdir +sub-directory in the package. +By default, assume the root of the package hierarchy is simply the +.Ar package +directory. +.It Fl t Ar target +Set +.Ar target +as the directory in which to create and delete the linkfarm for +.Ar package . +The default +.Ar target +directory is +.Pa /usr/pkg +but may be overridden by the +.Ev LOCALBASE +environment variable. +.It Fl V +Print version number and exit. +.It Fl v +Turn on verbose output. +Specifying +.Fl v +multiple times increases the level of verbosity. +.El +.Sh ENVIRONMENT +.Bl -tag -width indent +.It Ev LOCALBASE +The standard packages directory, +.Pa /usr/pkg , +can be overridden by specifying an alternative directory in the +.Ev LOCALBASE +environment variable. This affects the default +.Ar target +and +.Ar stowdir +directories. +.It Ev PLIST_IGNORE_FILES +This can be used to specify files in +.Ar package +that should ignored when creating and deleting symbolic links in +.Ar target . +.Ev PLIST_IGNORE_FILES +is a space-separated list of shell glob patterns that match files relative +to the +.Ar package +directory, and it defaults to "info/dir *[~#] *.OLD *.orig *,v". +.El +.Sh SEE ALSO +.Xr lndir 1 , +.Xr pkg_view 1 +.Sh AUTHORS +The +.Nm +utility was written by +.An Alistair G. Crooks Aq agc@netbsd.org . diff --git a/usr.sbin/pkg_install/view/linkfarm.sh b/usr.sbin/pkg_install/view/linkfarm.sh new file mode 100644 index 000000000000..cfa4694065d0 --- /dev/null +++ b/usr.sbin/pkg_install/view/linkfarm.sh @@ -0,0 +1,221 @@ +#! /bin/sh + +# $NetBSD: linkfarm.sh,v 1.2 2003/09/02 07:35:07 jlam Exp $ + +# +# Copyright (c) 2002 Alistair G. Crooks. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by Alistair G. Crooks. +# 4. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# set -x + +# set up program definitions +findprog=/usr/bin/find +grepprog=/usr/bin/grep +lnprog=/bin/ln +mkdirprog=/bin/mkdir +pkginfoprog=/usr/sbin/pkg_info +rmprog=/bin/rm +rmdirprog=/bin/rmdir +sedprog=/usr/bin/sed +sortprog=/usr/bin/sort + +usage() { + echo 'Usage: linkfarm [options] package' + exit 1 +} + +version() { + $pkginfoprog -V + exit 0 +} + +checkdir() { + if [ ! -d "$1" ]; then + echo "linkfarm: \`$1' doesn't exist" + exit 1 + fi +} + +ignorefiles=${PLIST_IGNORE_FILES:-"info/dir *[~#] *.OLD *.orig *,v"} +linktype=-s + +# default action: create a linkfarm in $target from $stowdir/$1 +# i.e. linkfarm --target=${prefix}/${view} --dir=${prefix}/packages $1 +# +doit="" +target=${LOCALBASE:-/usr/pkg} +stowdir=${target}/packages +subdir="" +verbose=0 + +# default action is to create +check=no +delete=no +create=yes + +# process args - can't use getopt(1) because of '--' style args +while [ $# -gt 0 ]; do + case "$1" in + -D) delete=yes; create=no ;; + -R) delete=yes; create=yes ;; + -V) version ;; + -c) check=yes; doit=":" ;; + -d) stowdir=$2; shift ;; + -d*) stowdir=`echo $1 | $sedprog -e 's|-d||'` ;; + -s) subdir=$2; shift ;; + -s*) subdir=`echo $1 | $sedprog -e 's|-s||'` ;; + -t) target=$2; shift ;; + -t*) target=`echo $1 | $sedprog -e 's|-t||'` ;; + -n) doit=":" ;; + -v) verbose=`expr $verbose + 1` ;; + + --delete) delete=yes; create=no ;; + --dir=*) stowdir=`echo $1 | $sedprog -e 's|--dir=||'` ;; + --restow) delete=yes; create=yes ;; + --subdir=*) subdir=`echo $1 | $sedprog -e 's|--subdir=||'` ;; + --target=*) target=`echo $1 | $sedprog -e 's|--target=||'` ;; + --version) version ;; + + --) shift; break ;; + *) break ;; + esac + shift +done + +# set the package name +package=$1 + +# make sure stowdir has a full pathname +case $stowdir in +/*) ;; +*) stowdir=`pwd`/$stowdir ;; +esac + +# Set the directory from which we symlink. +case $subdir in +"") fromdir=$stowdir/$package ;; +*) fromdir=$stowdir/$package/$subdir ;; +esac + +# Set the directory to which we symlink. +case $target in +/*) todir=$target ;; +*) todir=`pwd`/$target ;; +esac + +# if we're checking the entries, check, then exit +case $check in +yes) + checkdir $fromdir + (cd $fromdir; + ex=0; + for f in `$findprog . ! -type d -print`; do + newf=`echo $f | $sedprog -e 's|^\./||'` + if [ -e $todir/$newf ]; then + ignore=no + for i in $ignorefiles; do + case $newf in + $i) ignore=yes; break ;; + esac + done + case $ignore in + no) + echo "${newf}"; ex=1 ;; + esac + fi + done + exit $ex) || exit 1 + ;; +esac + +# if we need to get rid of old linkfarms, do it +case $delete in +yes) + checkdir $fromdir + (cd $fromdir; + for f in `$findprog . ! -type d -print`; do + newf=`echo $f | $sedprog -e 's|^\./||'` + ignore=no + for i in $ignorefiles; do + case $newf in + $i) ignore=yes; break ;; + esac + done + case $ignore in + no) + if [ $verbose -gt 0 ]; then + echo "$rmprog $todir/$newf" + fi + $doit $rmprog $todir/$f ;; + esac + done + for d in `$findprog . -type d -print | $sortprog -r`; do + if [ $verbose -gt 0 ]; then + echo "$rmdirprog $todir/$d" + fi + $doit $rmdirprog $todir/$d > /dev/null 2>&1 + done) + ;; +esac + +# if we need to create new linkfarms, do it +case $create in +yes) + checkdir $fromdir + (cd $fromdir; + for d in `$findprog . -type d -print`; do + newd=`echo $d | $sedprog -e 's|^\./||'` + case "$d" in + "") continue ;; + esac + if [ $verbose -gt 0 ]; then + echo "$mkdirprog -p $todir/$newd" + fi + $doit $mkdirprog -p $todir/$newd > /dev/null 2>&1 + done + for f in `$findprog . ! -type d -print`; do + newf=`echo $f | $sedprog -e 's|^\./||'` + ignore=no + for i in $ignorefiles; do + case $newf in + $i) ignore=yes; break ;; + esac + done + case $ignore in + no) + if [ $verbose -gt 0 ]; then + echo "$lnprog ${linktype} $fromdir/$newf $todir/$newf" + fi + $doit $lnprog ${linktype} $fromdir/$newf $todir/$newf ;; + esac + done) + ;; +esac + +exit 0 diff --git a/usr.sbin/pkg_install/view/pkg_view.1 b/usr.sbin/pkg_install/view/pkg_view.1 new file mode 100644 index 000000000000..28a77db46a80 --- /dev/null +++ b/usr.sbin/pkg_install/view/pkg_view.1 @@ -0,0 +1,269 @@ +.\" $NetBSD: pkg_view.1,v 1.2 2003/09/02 07:35:08 jlam Exp $ +.\" +.\" Copyright (c) 2003 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd July 13, 2003 +.Dt PKG_VIEW 1 +.Os +.Sh NAME +.Nm pkg_view +.Nd a utility for managing package views +.Sh SYNOPSIS +.Nm +.Op Ar options +.Ar command +.Ar package ... +.Sh DESCRIPTION +The +.Nm +command is used to add and delete packages in +.Ar stowdir +into a +.Ar view +in the +.Ar viewbase +directory. +.Sh WARNING +.Bf -emphasis +Since the +.Nm +command may execute scripts or programs contained within a package file, +your system may be susceptible to ``Trojan horses'' or other subtle +attacks from miscreants who create dangerous package files. +.Pp +You are advised to verify the competence and identity of those who +provide installable package files. +For extra protection, use the +.Fl M +flag to extract the package file, and inspect its contents and scripts +to ensure it poses no danger to your system's integrity. +Pay particular attention to any +INSTALL, +DEINSTALL, +REQUIRE +or +MTREE_DIRS files, and inspect the +CONTENTS file for +.Cm @cwd , +.Cm @mode +(check for setuid), +.Cm @dirrm , +.Cm @exec , +and +.Cm @unexec +directives, and/or use the +.Xr pkg_info 1 +command to examine the package file. +.Ef +.Sh OPTIONS +The following command-line options are supported: +.Bl -tag -width indent +.It Fl d Ar stowdir +Set +.Ar stowdir +as the directory in which the installed packages can be found. +If this option isn't specified, then the +.Ar stowdir +is taken from the value of the environment variable +.Ev DEPOTBASE +if it's set, otherwise the default +.Ar stowdir +is the +.Pa packages +directory under +.Ar viewbase . +.It Fl i Ar ignore +Add +.Ar ignore +to the list of files in +.Ar package +that should ignored when adding or removing the package from +.Ar view . +.It Fl k Ar pkg_dbdir +Set +.Ar pkg_dbdir +as the package database directory for the default (empty) view. +If this option isn't specified, then the package database directory is +taken from the value of the environment variable +.Ev PKG_DBDIR , +otherwise it defaults to +.Pa /var/db/pkg . +.It Fl n +Don't actually execute the commands for manipulating the depoted packages. +.It Fl V +Print the version number and exit. +.It Fl v +Turn on verbose output. +Specifying +.Fl v +multiple times increases the level of verbosity. +.It Fl W Ar viewbase +Set +.Ar viewbase +as the directory in which all the views are managed. +The default +.Ar viewbase +directory is +.Pa /usr/pkg +but may be overridden by the +.Ev LOCALBASE +environment variable. +.It Fl w Ar view +Set +.Ar view +as the directory in +.Ar viewbase +in which the packages should be added or removed. +The default +.Ar view +is the empty view but may be overridden by the +.Ev PKG_VIEW +environment variable. +.El +.Pp +The following commands are supported: +.Bl -tag -width indent +.It Ar add +Add the listed packages into +.Ar view . +.It Ar check +Check whether the listed packages are present in +.Ar view . +If they are not present, then return 0, otherwise return 1. +.It Ar delete +Delete the listed packages from +.Ar view . +.El +.Sh ENVIRONMENT +.Bl -tag -width indent +.It Ev DEPOTBASE +This is the location of the +.Ar stowdir +directory inside which all depoted packages are kept. +The default +.Ar stowdir +is the +.Pa packages +directory under +.Ar viewbase . +.It Ev LOCALBASE +This is the location of the +.Ar viewbase +directory in which all the views are managed. +The default +.Ar viewbase +directory is +.Pa /usr/pkg . +.It Ev PKG_DBDIR +If the +.Fl k +flag isn't given, then the value of the environment variable +.Ev PKG_DBDIR +is the package database directory for the default view, +otherwise it defaults to +.Pa /var/db/pkg . +.It Ev PLIST_IGNORE_FILES +This can be used to specify files in +.Ar package +that should ignored when adding or removing the package from +.Ar view . +.Ev PLIST_IGNORE_FILES +is a space-separated list of shell glob patterns that match files relative +to the +.Ar package +directory, and it defaults to "info/dir *[~#] *.OLD *.orig *,v". +This is overridden by any +.Ev _PLIST_IGNORE_FILES +setting in a package's +.Ar build-info-file +(see +.Xr pkg_create 1 +) if it exists. +.It Ev PKG_VIEW +The default view can be specified in the +.Ev PKG_VIEW +environment variable. +.El +.Sh FILES +.Bl -tag -width indent +.It Pa //+INSTALL +If the package contains an +.Ar install +script (see +.Xr pkg_create 1 ) , +then after the package is added into a view, the script is executed +with the following arguments: +.Bl -tag -width package +.It Ar package +The name of the package being installed. +.It Cm VIEW-INSTALL +Keyword denoting that the script is to perform any actions needed after +the package is added to a view. +.El +.Pp +If the +.Ar install +script exits with a non-zero status code, the installation is terminated. +.It Pa //+DEINSTALL +If the package contains an +.Ar deinstall +script (see +.Xr pkg_create 1 ) , +then before the package is removed from a view, the script is executed +with the following arguments: +.Bl -tag -width package +.It Ar package +The name of the package being installed. +.It Cm VIEW-DEINSTALL +Keyword denoting that the script is to perform any actions needed before +the package is removed from a view. +.El +.Pp +If the +.Ar deinstall +script exits with a non-zero status code, the de-installation is terminated. +.El +.Pp +The +.Ar install +and +.Ar deinstall +scripts are called with the environment variable +.Ev PKG_PREFIX +set to the path to the +.Ar view +directory. +.Sh SEE ALSO +.Xr linkfarm 1 , +.Xr pkg_delete 1 +.Sh AUTHORS +The +.Nm +utility was written by +.An Alistair G. Crooks Aq agc@netbsd.org . +.Sh BUGS +Only the empty view is supported. diff --git a/usr.sbin/pkg_install/view/pkg_view.sh b/usr.sbin/pkg_install/view/pkg_view.sh new file mode 100644 index 000000000000..33714ac58e6f --- /dev/null +++ b/usr.sbin/pkg_install/view/pkg_view.sh @@ -0,0 +1,276 @@ +#! /bin/sh + +# $NetBSD: pkg_view.sh,v 1.2 2003/09/02 07:35:08 jlam Exp $ + +# +# Copyright (c) 2001 Alistair G. Crooks. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by Alistair G. Crooks. +# 4. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# set -x + +# set up program definitions +chmodprog=/bin/chmod +cmpprog=/usr/bin/cmp +cpprog=/bin/cp +envprog=/usr/bin/env +findprog=/usr/bin/find +grepprog=/usr/bin/grep +linkfarmprog=/usr/sbin/linkfarm +lnprog=/bin/ln +mkdirprog=/bin/mkdir +paxprog=/bin/pax +pkginfoprog=/usr/sbin/pkg_info +rmprog=/bin/rm +rmdirprog=/bin/rmdir +sedprog=/usr/bin/sed +touchprog=/usr/bin/touch + +usage() { + echo 'Usage: pkg_view [-n] [-v] [-i ignore] [-k pkg_dbdir_dflt] [-w viewname] [-d stowdir] [-W viewbase] add|check|delete pkgname...' + exit 1 +} + +version() { + $pkginfoprog -V + exit 0 +} + +checkpkg() { + if [ ! -d "$2/$1" ]; then + echo "pkg_view: \`$1' doesn't exist in \`$2'" 1>&2 + exit 1 + fi +} + +######################################### +# Initialization and Options Processing # +######################################### + +doit="" +stowdir="" +viewbase=${LOCALBASE:-/usr/pkg} +view=${PKG_VIEW:-""} +dflt_ignorefiles=${PLIST_IGNORE_FILES:-"info/dir *[~#] *.OLD *.orig *,v"} +dflt_pkg_dbdir=${PKG_DBDIR:-/var/db/pkg} +ignorefiles="" +verbose=0 + +while [ $# -gt 0 ]; do + case "$1" in + -d) stowdir=$2; shift ;; + -d*) stowdir=`echo $1 | $sedprog -e 's|^-d||'` ;; + -i) ignorefiles="$ignorefiles $2"; shift ;; + -i*) ignorefiles="$ignorefiles `echo $1 | $sedprog -e 's|^-i||'`" ;; + -k) dflt_pkg_dbdir="$2"; shift ;; + -k*) dflt_pkg_dbdir=`echo $1 | $sedprog -e 's|^-k||'` ;; + -n) doit=":" ;; + -V) version ;; + -v) verbose=`expr $verbose + 1` ;; + -W) viewbase=$2; shift ;; + -W*) viewbase=`echo $1 | $sedprog -e 's|^-p||'` ;; + -w) view=$2; shift ;; + --view=*) view=`echo $1 | $sedprog -e 's|--view=||'` ;; + --) shift; break ;; + *) break ;; + esac + shift +done + +if [ $# -lt 1 ]; then + usage +fi + +# echoN will actually give output if ${verbose} > N. +echo1=":" +echo2=":" +if [ ${verbose} -gt 0 ]; then echo1=echo; fi +if [ ${verbose} -gt 1 ]; then echo2=echo; fi + +action="" +case "$1" in +add) action=add ;; +check) action=check ;; +delete|rm) action=delete ;; +*) usage ;; +esac +shift + +# XXX Only support the standard view for now. +case "$view" in +"") ;; +*) echo "pkg_view: only the standard view is supported" 1>&2 + exit 1 + ;; +esac + +# if standard view, put package info into ${dflt_pkg_dbdir} +# if not standard view, put package info into view's pkgdb +case "$view" in +"") + pkg_dbdir=${dflt_pkg_dbdir} + targetdir=${viewbase} + viewstr="the standard view" + ;; +*) + pkg_dbdir=${viewbase}/${view}/.pkgdb + targetdir=${viewbase}/${view} + viewstr="view \"${view}\"" + ;; +esac + +# Use stowdir if it's given, else fall back to ${DEPOTBASE} or else +# default to ${viewbase}/packages. +# +depot_pkg_dbdir=${stowdir:-${DEPOTBASE:-${viewbase}/packages}} + +case "${depot_pkg_dbdir}" in +${pkg_dbdir}) + echo "pkg_view: the depot and the view package database directories are the same" 1>&2 + exit 1 + ;; +esac + +########################## +# Shell helper functions # +########################## + +# symlinks check|add|delete +# +# Calls linkfarm(1) to check, add or delete the symlink farm in +# ${targetdir}. We also ignore the right set of files when doing the +# linkfarm operations. +# +symlinks() { + pkg=$2 + case "$1" in + add) linkfarmflags="" ;; + check) linkfarmflags="-c" ;; + delete) linkfarmflags="-D" ;; + esac + if [ -f ${depot_pkg_dbdir}/$pkg/+BUILD_INFO ]; then + ignore=`$grepprog "^_PLIST_IGNORE_FILES=" ${depot_pkg_dbdir}/$pkg/+BUILD_INFO | $sedprog -e 's|^_PLIST_IGNORE_FILES=[ ]*||'` + fi + case "$ignore" in + "") ignore="${dflt_ignorefiles}" ;; + esac + dbs=`(cd ${depot_pkg_dbdir}/$pkg; echo +*)` + ignore="${ignore} ${ignorefiles} $dbs" + $doit $envprog PLIST_IGNORE_FILES="${ignore}" $linkfarmprog $linkfarmflags --target=${targetdir} --dir=${depot_pkg_dbdir} $pkg +} + +############# +# Main Loop # +############# + +while [ $# -gt 0 ]; do + case $action in + add) + checkpkg $1 ${depot_pkg_dbdir} + if [ -f ${pkg_dbdir}/$1/+DEPOT ]; then + echo "pkg_view: \`$1' already exists in $viewstr" 1>&2 + exit 1 + fi + $echo1 "Adding $1 to ${targetdir}." + symlinks add $1 + $doit $mkdirprog -p ${depot_pkg_dbdir}/$1 + temp=${depot_pkg_dbdir}/$1/+VIEWS.$$ + $doit $touchprog ${depot_pkg_dbdir}/$1/+VIEWS + $doit $cpprog ${depot_pkg_dbdir}/$1/+VIEWS ${temp} + case "$doit" in + "") ($grepprog -v '^'${pkg_dbdir}'$' ${temp} || true; echo ${pkg_dbdir}) > ${depot_pkg_dbdir}/$1/+VIEWS ;; + esac + $doit $rmprog ${temp} + $doit $mkdirprog -p ${pkg_dbdir}/$1 + # + # Copy all of the metadata files except for +VIEWS, + # which is only for the depoted package, and + # +REQUIRED_BY, which is irrelevant for a package in + # a view. + # + case "$doit" in + "") (cd ${depot_pkg_dbdir}/$1; $paxprog -rwpe '-s|\./\+VIEWS$||' '-s|\./\+REQUIRED_BY$||' ./+* ${pkg_dbdir}/$1) + $sedprog -e 's|'${depot_pkg_dbdir}/$1'|'${targetdir}'|g' < ${depot_pkg_dbdir}/$1/+CONTENTS > ${pkg_dbdir}/$1/+CONTENTS + echo "${depot_pkg_dbdir}/$1" > ${pkg_dbdir}/$1/+DEPOT + ;; + esac + if [ -f ${pkg_dbdir}/$1/+INSTALL ]; then + $doit $chmodprog +x ${pkg_dbdir}/$1/+INSTALL + $doit $envprog -i PKG_PREFIX=${targetdir} ${pkg_dbdir}/$1/+INSTALL $1 VIEW-INSTALL + ec=$? + if [ $ec != 0 ]; then + echo "pkg_view: install script returned an error." 1>&2 + exit $ec + fi + fi + ;; + check) + checkpkg $1 ${depot_pkg_dbdir} + $echo1 "Checking $1 in ${targetdir}." + symlinks check $1 + exit $? + ;; + delete) + checkpkg $1 ${depot_pkg_dbdir} + if [ ! -f ${pkg_dbdir}/$1/+DEPOT ]; then + echo "pkg_view: \`$1' doesn't exist in $viewstr" 1>&2 + exit 1 + fi + $echo1 "Deleting $1 from ${targetdir}." + if [ -f ${pkg_dbdir}/$1/+REQUIRED_BY ]; then + if $cmpprog -s ${pkg_dbdir}/$1/+REQUIRED_BY /dev/null; then + : # not really required by another pkg + else + (echo "pkg_view: \`$1' is required by other packages:" + $sedprog -e 's|^| |' ${pkg_dbdir}/$1/+REQUIRED_BY) 1>&2 + exit 1 + fi + fi + if [ -f ${pkg_dbdir}/$1/+DEINSTALL ]; then + $doit $chmodprog +x ${pkg_dbdir}/$1/+DEINSTALL + $doit $envprog -i PKG_PREFIX=${targetdir} ${pkg_dbdir}/$1/+DEINSTALL $1 VIEW-DEINSTALL + ec=$? + if [ $ec != 0 ]; then + echo "pkg_view: de-install script returned an error." 1>&2 + exit $ec + fi + fi + symlinks delete $1 + temp=${depot_pkg_dbdir}/$1/+VIEWS.$$ + $doit $cpprog ${depot_pkg_dbdir}/$1/+VIEWS ${temp} + case "$doit" in + "") ($grepprog -v '^'${pkg_dbdir}'$' ${temp} || true) > ${depot_pkg_dbdir}/$1/+VIEWS ;; + esac + $doit $rmprog ${temp} + $doit $rmprog -rf ${pkg_dbdir}/$1 + ;; + esac + shift +done + +exit 0