Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/pkgviews]: src/usr.sbin/pkg_install Teach pkg_add(1) to add the package ...



details:   https://anonhg.NetBSD.org/src/rev/05ca42889ba1
branches:  pkgviews
changeset: 534252:05ca42889ba1
user:      jlam <jlam%NetBSD.org@localhost>
date:      Sun Aug 17 04:55:20 2003 +0000

description:
Teach pkg_add(1) to add the package to the default view when it's
finished copying the files into place.  Correctly distinguish between
"overwrite" and "pkgviews" packages to decide whether to add it to a
view.  Make pkg_add(1) understand three new flags to facilitate this
new behaviour:
------------------------------
OPTIONS
    -L      Don't add the package to any views after installation.

    -W viewbase
             Set viewbase as the base directory for the managed views.
             The default viewbase directory is set by pkg_view(1).

    -w view
            Set the view to which packages should be added after
            installation.  The default view is the empty view but may
            be overridden by the PKG_VIEW environment variable.

ENVIRONMENT
    PKG_VIEW
            The default view can be specified in the PKG_VIEW
            environment variable.
------------------------------
Also alphabetize the options and flags in both the source code and the
man page so they're easier to read.

Change the flags on pkg_view(1) to match similar flags in pkg_add(1),
so "-v" now means "be verbose" while the "-W" and "-w" flags set the
viewbase and view, respectively.  PKG_VIEWBASE may be set in the
environment to override the default viewbase value (/usr/pkg).  Drop
all references to "-p" and PREFIX (which are now "-W" and PKG_VIEWBASE).

Bump the pkg_install version to 20030809.

diffstat:

 usr.sbin/pkg_install/add/add.h        |   5 +-
 usr.sbin/pkg_install/add/main.c       |  77 +++++++++++++++++++++-------------
 usr.sbin/pkg_install/add/perform.c    |  57 ++++++++++++++++++++++---
 usr.sbin/pkg_install/add/pkg_add.1    |  31 ++++++++++++-
 usr.sbin/pkg_install/lib/lib.h        |   3 +-
 usr.sbin/pkg_install/lib/version.h    |   4 +-
 usr.sbin/pkg_install/view/pkg_view.1  |  30 +++++++------
 usr.sbin/pkg_install/view/pkg_view.sh |  31 +++++++++----
 8 files changed, 169 insertions(+), 69 deletions(-)

diffs (truncated from 575 to 300 lines):

diff -r 43c409c5d11f -r 05ca42889ba1 usr.sbin/pkg_install/add/add.h
--- a/usr.sbin/pkg_install/add/add.h    Sat Aug 16 22:11:22 2003 +0000
+++ b/usr.sbin/pkg_install/add/add.h    Sun Aug 17 04:55:20 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: add.h,v 1.5 2000/06/17 11:30:49 tron Exp $ */
+/* $NetBSD: add.h,v 1.5.6.1 2003/08/17 04:55:20 jlam Exp $ */
 
 /* from FreeBSD Id: add.h,v 1.8 1997/02/22 16:09:15 peter Exp  */
 
@@ -30,6 +30,9 @@
 }       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 -r 43c409c5d11f -r 05ca42889ba1 usr.sbin/pkg_install/add/main.c
--- a/usr.sbin/pkg_install/add/main.c   Sat Aug 16 22:11:22 2003 +0000
+++ b/usr.sbin/pkg_install/add/main.c   Sun Aug 17 04:55:20 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: main.c,v 1.25.2.2 2003/07/23 20:48:00 jlam Exp $       */
+/*     $NetBSD: main.c,v 1.25.2.3 2003/08/17 04:55:21 jlam Exp $       */
 
 #include <sys/cdefs.h>
 #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.25.2.2 2003/07/23 20:48:00 jlam Exp $");
+__RCSID("$NetBSD: main.c,v 1.25.2.3 2003/08/17 04:55:21 jlam Exp $");
 #endif
 #endif
 
@@ -37,9 +37,12 @@
 #include "add.h"
 #include "verify.h"
 
-static char Options[] = "IMRSVfhnp:s:t:uv";
+static char Options[] = "ILMRSVW: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 @@
 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,28 @@
        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 'L':
+                       NoView = TRUE;
+                       break;
+
+               case 'M':
+                       AddMode = MASTER;
+                       break;
+
+               case 'R':
+                       NoRecord = TRUE;
+                       break;
+
+               case 'n':
+                       Fake = TRUE;
                        Verbose = TRUE;
                        break;
 
@@ -80,21 +105,8 @@
                        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 +117,26 @@
                        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 -r 43c409c5d11f -r 05ca42889ba1 usr.sbin/pkg_install/add/perform.c
--- a/usr.sbin/pkg_install/add/perform.c        Sat Aug 16 22:11:22 2003 +0000
+++ b/usr.sbin/pkg_install/add/perform.c        Sun Aug 17 04:55:20 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: perform.c,v 1.70.2.3 2003/07/25 11:53:59 jlam Exp $    */
+/*     $NetBSD: perform.c,v 1.70.2.4 2003/08/17 04:55:21 jlam Exp $    */
 
 #include <sys/cdefs.h>
 #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.70.2.3 2003/07/25 11:53:59 jlam Exp $");
+__RCSID("$NetBSD: perform.c,v 1.70.2.4 2003/08/17 04:55:21 jlam Exp $");
 #endif
 #endif
 
@@ -67,15 +67,23 @@
 static int
 installprereq(const char *name, int *errc)
 {
+       char    *tmp;
        int     ret;
        ret = 0;
 
        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("env %s=%s %s/pkg_add -s %s %s%s%s %s%s %s%s%s %s%s",
+                       PKG_VIEW,
+                       (tmp = getenv(PKG_VIEW) ? tmp : ""),
                        BINDIR,
                        get_verification(),
+                       NoView ? "-L " : "",
+                       View ? "-w " : "",
+                       View ? View : "",
+                       Viewbase ? "-W " : "",
+                       Viewbase ? Viewbase : "",
                        Force ? "-f " : "",
                        Prefix ? "-p " : "",
                        Prefix ? Prefix : "",
@@ -114,6 +122,7 @@
        struct stat sb;
        int     inPlace;
        int     rc;
+       Boolean is_depoted_pkg = FALSE;
 
        errc = 0;
        zapLogDir = 0;
@@ -124,7 +133,7 @@
 
        /* make sure dbdir actually exists! */
        if (!(isdir(dbdir) || islinktodir(dbdir))) {
-               if (vsystem("/bin/mkdir -p -m 755 %s", dbdir)) {
+               if (vsystem("mkdir -p -m 755 %s", dbdir)) {
                        errx(EXIT_FAILURE, "Database-dir %s cannot be generated, aborting.",
                            dbdir);
                }
@@ -427,7 +436,7 @@
 
                                        if (Verbose)
                                                printf("pkg_delete '%s'\n", installed);
-                                       vsystem("pkg_delete '%s'\n", installed);
+                                       vsystem("%s/pkg_delete '%s'\n", BINDIR, installed);
                                        
                                } else {
                                        warnx("other version '%s' already installed", installed);
@@ -449,7 +458,7 @@
                        printf("Package `%s' conflicts with `%s'.\n", PkgName, p->name);
 
                /* was: */
-               /* if (!vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
+               /* if (!vsystem("%s/pkg_info -qe '%s'", BINDIR, 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);
@@ -467,7 +476,7 @@
                        continue;
                if (Verbose)
                        printf("Depends pre-scan: `%s' required.\n", p->name);
-               /* if (vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
+               /* if (vsystem("%s/pkg_info -qe '%s'", BINDIR, p->name)) { */
                if (findmatchingname(dbdir, p->name, note_whats_installed, installed) <= 0) {
                        /* 
                         * required pkg not found. look if it's available with a more liberal
@@ -682,8 +691,10 @@
                        move_file(".", DISPLAY_FNAME, LogDir);
                if (fexists(PRESERVE_FNAME))
                        move_file(".", PRESERVE_FNAME, LogDir);
-               if (fexists(VIEWS_FNAME))
+               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
@@ -755,6 +766,36 @@
                delete_package(FALSE, FALSE, &Plist);
 
 success:
+       /* Add the package to a default view. */
+       if (!NoView && is_depoted_pkg) {
+               if (Verbose) {
+                       printf("env %s=%s %s=%s %s/pkg_view %s%s %s%s %sadd %s\n",
+                               PKG_DBDIR,
+                               DEF_LOG_DIR,
+                               PKG_VIEW,
+                               (tmp = getenv(PKG_VIEW) ? tmp : ""),
+                               BINDIR,
+                               View ? "-w " : "",
+                               View ? View : "",
+                               Viewbase ? "-W " : "",
+                               Viewbase ? Viewbase : "",
+                               Verbose ? "-v " : "",
+                               PkgName);
+               }
+               vsystem("env %s=%s %s=%s %s/pkg_view %s%s %s%s %sadd %s",
+                               PKG_DBDIR,
+                               DEF_LOG_DIR,
+                               PKG_VIEW,
+                               (tmp = getenv(PKG_VIEW) ? tmp : ""),
+                               BINDIR,
+                               View ? "-w " : "",
+                               View ? View : "",
+                               Viewbase ? "-W " : "",
+                               Viewbase ? Viewbase : "",
+                               Verbose ? "-v " : "",
+                               PkgName);
+       }
+
        /* delete the packing list contents */
        free_plist(&Plist);
        leave_playpen(Home);
diff -r 43c409c5d11f -r 05ca42889ba1 usr.sbin/pkg_install/add/pkg_add.1
--- a/usr.sbin/pkg_install/add/pkg_add.1        Sat Aug 16 22:11:22 2003 +0000
+++ b/usr.sbin/pkg_install/add/pkg_add.1        Sun Aug 17 04:55:20 2003 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_add.1,v 1.33.4.1 2003/07/13 09:45:21 jlam Exp $
+.\" $NetBSD: pkg_add.1,v 1.33.4.2 2003/08/17 04:55:21 jlam Exp $
 .\"
 .\" FreeBSD install - a package for the installation and maintenance
 .\" of non-core utilities.
@@ -25,7 +25,10 @@
 .Nd a utility for installing and upgrading software package distributions
 .Sh SYNOPSIS



Home | Main Index | Thread Index | Old Index