summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwiz <wiz@pkgsrc.org>2005-11-05 13:20:08 +0000
committerwiz <wiz@pkgsrc.org>2005-11-05 13:20:08 +0000
commitd69676ddee60f4f73997c688b7b12755a76b7c7c (patch)
tree0a66e315cc993f09a7949014978677c009cc3c1f
parent0de3b301dc9f246683b833c2705632ee08e679c0 (diff)
downloadpkgsrc-d69676ddee60f4f73997c688b7b12755a76b7c7c.tar.gz
Sync with base system as of Sat Nov 5 13:19:32 UTC 2005.
Welcome to 20051103! Now with "automatic" support.
-rw-r--r--pkgtools/pkg_install/files/add/add.h3
-rw-r--r--pkgtools/pkg_install/files/add/main.c13
-rw-r--r--pkgtools/pkg_install/files/add/perform.c21
-rw-r--r--pkgtools/pkg_install/files/add/pkg_add.132
-rw-r--r--pkgtools/pkg_install/files/add/pkg_add.cat121
-rw-r--r--pkgtools/pkg_install/files/admin/main.c130
-rw-r--r--pkgtools/pkg_install/files/admin/pkg_admin.119
-rw-r--r--pkgtools/pkg_install/files/admin/pkg_admin.cat112
-rw-r--r--pkgtools/pkg_install/files/bpm/bpm.sh.in2
-rw-r--r--pkgtools/pkg_install/files/info/info.h12
-rw-r--r--pkgtools/pkg_install/files/info/main.c35
-rw-r--r--pkgtools/pkg_install/files/info/perform.c69
-rw-r--r--pkgtools/pkg_install/files/info/pkg_info.135
-rw-r--r--pkgtools/pkg_install/files/info/pkg_info.cat116
-rw-r--r--pkgtools/pkg_install/files/info/show.c49
-rw-r--r--pkgtools/pkg_install/files/lib/automatic.c80
-rw-r--r--pkgtools/pkg_install/files/lib/config.h193
-rw-r--r--pkgtools/pkg_install/files/lib/dewey.c282
-rw-r--r--pkgtools/pkg_install/files/lib/dewey.h19
-rw-r--r--pkgtools/pkg_install/files/lib/lib.h20
-rw-r--r--pkgtools/pkg_install/files/lib/nbcompat.h0
-rw-r--r--pkgtools/pkg_install/files/lib/plist.c17
-rw-r--r--pkgtools/pkg_install/files/lib/str.c285
-rw-r--r--pkgtools/pkg_install/files/lib/var.c239
-rw-r--r--pkgtools/pkg_install/files/lib/version.h4
-rwxr-xr-xpkgtools/pkg_install/files/pi2nbcompat141
-rwxr-xr-xpkgtools/pkg_install/files/pkg_install2nbcompat4
27 files changed, 1317 insertions, 436 deletions
diff --git a/pkgtools/pkg_install/files/add/add.h b/pkgtools/pkg_install/files/add/add.h
index 327d51cc123..42b4f030311 100644
--- a/pkgtools/pkg_install/files/add/add.h
+++ b/pkgtools/pkg_install/files/add/add.h
@@ -1,4 +1,4 @@
-/* $NetBSD: add.h,v 1.4 2004/12/09 20:10:34 erh Exp $ */
+/* $NetBSD: add.h,v 1.5 2005/11/05 13:20:09 wiz Exp $ */
/* from FreeBSD Id: add.h,v 1.8 1997/02/22 16:09:15 peter Exp */
@@ -36,6 +36,7 @@ extern Boolean NoView;
extern Boolean NoInstall;
extern Boolean NoRecord;
extern Boolean Force;
+extern Boolean Automatic;
extern int Replace;
extern char *Mode;
extern char *Owner;
diff --git a/pkgtools/pkg_install/files/add/main.c b/pkgtools/pkg_install/files/add/main.c
index ee6f14bb274..f24a4db02f7 100644
--- a/pkgtools/pkg_install/files/add/main.c
+++ b/pkgtools/pkg_install/files/add/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.8 2004/12/29 12:16:56 agc Exp $ */
+/* $NetBSD: main.c,v 1.9 2005/11/05 13:20:09 wiz Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.8 2004/12/29 12:16:56 agc Exp $");
+__RCSID("$NetBSD: main.c,v 1.9 2005/11/05 13:20:09 wiz Exp $");
#endif
#endif
@@ -49,7 +49,7 @@ __RCSID("$NetBSD: main.c,v 1.8 2004/12/29 12:16:56 agc Exp $");
#include "add.h"
#include "verify.h"
-static char Options[] = "IK:LMRSVW:fhnp:s:t:uvw:";
+static char Options[] = "AIK:LMRSVW:fhnp:s:t:uvw:";
char *Prefix = NULL;
char *View = NULL;
@@ -57,6 +57,7 @@ char *Viewbase = NULL;
Boolean NoView = FALSE;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
+Boolean Automatic = FALSE;
char *Mode = NULL;
char *Owner = NULL;
@@ -71,7 +72,7 @@ static void
usage(void)
{
(void) fprintf(stderr, "%s\n%s\n%s\n",
- "usage: pkg_add [-fhILMnRSuVv] [-p prefix] [-s verification-type]",
+ "usage: pkg_add [-AfhILMnRSuVv] [-p prefix] [-s verification-type]",
" [-t template] [-W viewbase] [-w view]",
" pkg-name [pkg-name ...]");
exit(1);
@@ -88,6 +89,10 @@ main(int argc, char **argv)
setprogname(argv[0]);
while ((ch = getopt(argc, argv, Options)) != -1) {
switch (ch) {
+ case 'A':
+ Automatic = TRUE;
+ break;
+
case 'f':
Force = TRUE;
break;
diff --git a/pkgtools/pkg_install/files/add/perform.c b/pkgtools/pkg_install/files/add/perform.c
index fa57c4ffb40..047853de2dd 100644
--- a/pkgtools/pkg_install/files/add/perform.c
+++ b/pkgtools/pkg_install/files/add/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.33 2005/07/25 13:13:00 hubertf Exp $ */
+/* $NetBSD: perform.c,v 1.34 2005/11/05 13:20:09 wiz Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.33 2005/07/25 13:13:00 hubertf Exp $");
+__RCSID("$NetBSD: perform.c,v 1.34 2005/11/05 13:20:09 wiz Exp $");
#endif
#endif
@@ -191,7 +191,8 @@ installprereq(const char *name, int *errc, int doupdate)
Viewbase ? "-W" : "", Viewbase ? Viewbase : "",
Force ? "-f" : "",
Prefix ? "-p" : "", Prefix ? Prefix : "",
- Verbose ? "-v" : "", name, NULL)) {
+ Verbose ? "-v" : "",
+ "-A", name, NULL)) {
warnx("autoload of dependency `%s' failed%s",
name, Force ? " (proceeding anyway)" : "!");
if (!Force)
@@ -346,6 +347,7 @@ pkg_do(const char *pkg, lpkg_head_t *pkgs)
* take up once it's unpacked. I've noticed that most packages
* compress an average of 75%, so multiply by 4 for good measure.
*/
+
needed = 4 * (uint64_t) sb.st_size;
if (!inPlace && min_free(playpen) < needed) {
warnx("projected size of %" PRIu64 " bytes exceeds available free space\n"
@@ -497,7 +499,15 @@ pkg_do(const char *pkg, lpkg_head_t *pkgs)
/* See if this package (exact version) is already registered */
if ((isdir(LogDir) || islinktodir(LogDir)) && !Force) {
- warnx("package `%s' already recorded as installed", PkgName);
+ if (!Automatic && is_automatic_installed(LogDir)) {
+ mark_as_automatic_installed(LogDir, 0);
+ warnx("package `%s' was already installed as "
+ "dependency, now marked as installed manually",
+ PkgName);
+ } else {
+ warnx("package `%s' already recorded as installed",
+ PkgName);
+ }
goto success; /* close enough for government work */
}
@@ -941,6 +951,8 @@ ignore_replace_depends_check:
warnx("cannot properly close file %s", contents);
}
}
+ if (Automatic)
+ mark_as_automatic_installed(LogDir, 1);
if (Verbose)
printf("Package %s registered in %s\n", PkgName, LogDir);
}
@@ -1064,4 +1076,3 @@ pkg_perform(lpkg_head_t *pkgs)
return err_cnt;
}
-
diff --git a/pkgtools/pkg_install/files/add/pkg_add.1 b/pkgtools/pkg_install/files/add/pkg_add.1
index 93e354d11d1..438b56070c0 100644
--- a/pkgtools/pkg_install/files/add/pkg_add.1
+++ b/pkgtools/pkg_install/files/add/pkg_add.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_add.1,v 1.15 2005/07/18 09:14:04 hubertf Exp $
+.\" $NetBSD: pkg_add.1,v 1.16 2005/11/05 13:20:09 wiz Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@@ -17,7 +17,7 @@
.\"
.\" @(#)pkg_add.1
.\"
-.Dd July 13, 2005
+.Dd November 1, 2005
.Dt PKG_ADD 1
.Os
.Sh NAME
@@ -25,25 +25,13 @@
.Nd a utility for installing and upgrading software package distributions
.Sh SYNOPSIS
.Nm
-.Op Fl fILMnRSuVv
-.Bk -words
+.Op Fl AfILMnRSuVv
.Op Fl K Ar pkg_dbdir
-.Ek
-.Bk -words
.Op Fl p Ar prefix
-.Ek
-.Bk -words
.Op Fl s Ar verification-type
-.Ek
-.Bk -words
.Op Fl t Ar template
-.Ek
-.Bk -words
.Op Fl W Ar viewbase
-.Ek
-.Bk -words
.Op Fl w Ar view
-.Ek
.Ar \fR[[ftp|http]://[\fIuser\fR[:\fIpassword]\fR@]\fIhost\fR[:\fIport\fR]][/\fIpath/\fR]pkg-name ...
.Sh DESCRIPTION
The
@@ -114,6 +102,20 @@ will search them in each directory named by the
environment variable.
Any dependencies required by the installed package will be searched
in the same location that the original package was installed from.
+.It Fl A
+Mark package as installed automatically, as dependency of another
+package.
+You can use
+.Dl Ic pkg_admin set automatic=YES
+to mark packages this way after installation, and
+.Dl Ic pkg_admin unset automatic
+to remove the mark.
+If you
+.Nm
+a package without specifying
+.Fl A
+after it had already been automatically installed, the mark is
+removed.
.It Fl f
Force installation to proceed even if prerequisite packages are not
installed or the requirements script fails.
diff --git a/pkgtools/pkg_install/files/add/pkg_add.cat1 b/pkgtools/pkg_install/files/add/pkg_add.cat1
index 5745786212e..81120512dd6 100644
--- a/pkgtools/pkg_install/files/add/pkg_add.cat1
+++ b/pkgtools/pkg_install/files/add/pkg_add.cat1
@@ -1,11 +1,11 @@
PKG_ADD(1) NetBSD General Commands Manual PKG_ADD(1)
NNAAMMEE
- ppkkgg__aadddd - a utility for installing and upgrading software package distri-
- butions
+ ppkkgg__aadddd -- a utility for installing and upgrading software package dis-
+ tributions
SSYYNNOOPPSSIISS
- ppkkgg__aadddd [--ffIILLMMnnRRSSuuVVvv] [--KK _p_k_g___d_b_d_i_r] [--pp _p_r_e_f_i_x] [--ss _v_e_r_i_f_i_c_a_t_i_o_n_-_t_y_p_e]
+ ppkkgg__aadddd [--AAffIILLMMnnRRSSuuVVvv] [--KK _p_k_g___d_b_d_i_r] [--pp _p_r_e_f_i_x] [--ss _v_e_r_i_f_i_c_a_t_i_o_n_-_t_y_p_e]
[--tt _t_e_m_p_l_a_t_e] [--WW _v_i_e_w_b_a_s_e] [--ww _v_i_e_w]
[[ftp|http]://[_u_s_e_r[:_p_a_s_s_w_o_r_d_]@]_h_o_s_t[:_p_o_r_t]][/_p_a_t_h_/]pkg-name ...
@@ -45,6 +45,15 @@ OOPPTTIIOONNSS
required by the installed package will be searched in the same
location that the original package was installed from.
+ --AA Mark package as installed automatically, as dependency of another
+ package. You can use
+ ppkkgg__aaddmmiinn sseett aauuttoommaattiicc==YYEESS
+ to mark packages this way after installation, and
+ ppkkgg__aaddmmiinn uunnsseett aauuttoommaattiicc
+ to remove the mark. If you ppkkgg__aadddd a package without specifying
+ --AA after it had already been automatically installed, the mark is
+ removed.
+
--ff Force installation to proceed even if prerequisite packages are
not installed or the requirements script fails. Although ppkkgg__aadddd
will still try to find and auto-install missing prerequisite
@@ -214,9 +223,7 @@ TTEECCHHNNIICCAALL DDEETTAAIILLSS
7. The package build information from _+_B_U_I_L_D___I_N_F_O is then checked
for IGNORE_RECOMMENDED. If the package was built with depen-
- dency recommendations ignored, installation will be aborted.
- This behavior is overridable with the --ff flag and the
- PKG_IGNORE_RECOMMENDED environment variable.
+ dency recommendations ignored, a warning will be issued.
8. If the package contains a _r_e_q_u_i_r_e script (see pkg_create(1)),
it is executed with the following arguments:
@@ -380,4 +387,4 @@ BBUUGGSS
Sure to be others.
-NetBSD 2.0 May 7, 2005 NetBSD 2.0
+NetBSD 3.0 November 1, 2005 NetBSD 3.0
diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c
index 75af64029a7..e552edd6d37 100644
--- a/pkgtools/pkg_install/files/admin/main.c
+++ b/pkgtools/pkg_install/files/admin/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.18 2005/03/11 21:20:15 rillig Exp $ */
+/* $NetBSD: main.c,v 1.19 2005/11/05 13:20:09 wiz Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.18 2005/03/11 21:20:15 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.19 2005/11/05 13:20:09 wiz Exp $");
#endif
/*
@@ -68,6 +68,9 @@ __RCSID("$NetBSD: main.c,v 1.18 2005/03/11 21:20:15 rillig Exp $");
#if HAVE_STDIO_H
#include <stdio.h>
#endif
+#if HAVE_STRING_H
+#include <string.h>
+#endif
#include "lib.h"
@@ -81,10 +84,11 @@ int pkgcnt;
static int quiet;
static int checkpattern_fn(const char *, void *);
+static void set_unset_variable(char **, Boolean);
/* print usage message and exit */
static void
-usage(const char *prog)
+usage(void)
{
(void) fprintf(stderr, "usage: %s [-bqSV] [-d lsdir] [-K pkg_dbdir] [-s sfx] command args ...\n"
"Where 'commands' and 'args' are:\n"
@@ -92,6 +96,8 @@ usage(const char *prog)
" check [pkg ...] - check md5 checksum of installed files\n"
" add pkg ... - add pkg files to database\n"
" delete pkg ... - delete file entries for pkg in database\n"
+ " set variable=value pkg ... - set installation variable for package\n"
+ " unset variable pkg ... - unset installation variable for package\n"
#ifdef PKGDB_DEBUG
" addkey key value - add key and value\n"
" delkey key - delete reference to key\n"
@@ -100,7 +106,7 @@ usage(const char *prog)
" lsbest /path/to/pkgpattern - list pkgs matching the pattern best\n"
" dump - dump database\n"
" pmatch pattern pkg - returns true if pkg matches pattern, otherwise false\n",
- prog);
+ getprogname());
exit(EXIT_FAILURE);
}
@@ -444,7 +450,6 @@ lsbasepattern_fn(const char *pkg, void *vp)
int
main(int argc, char *argv[])
{
- const char *prog;
Boolean use_default_sfx = TRUE;
Boolean show_basename_only = FALSE;
char lsdir[MaxPathSize];
@@ -452,10 +457,10 @@ main(int argc, char *argv[])
char *lsdirp = NULL;
int ch;
- setprogname(prog = argv[0]);
+ setprogname(argv[0]);
if (argc < 2)
- usage(prog);
+ usage();
while ((ch = getopt(argc, argv, Options)) != -1)
switch (ch) {
@@ -491,7 +496,7 @@ main(int argc, char *argv[])
break;
default:
- usage(prog);
+ usage();
/* NOTREACHED */
}
@@ -499,7 +504,7 @@ main(int argc, char *argv[])
argv += optind;
if (argc <= 0) {
- usage(prog);
+ usage();
}
if (use_default_sfx)
@@ -512,7 +517,7 @@ main(int argc, char *argv[])
argv++; /* "pmatch" */
if (argv[0] == NULL || argv[1] == NULL) {
- usage(prog);
+ usage();
}
pattern = argv[0];
@@ -690,6 +695,12 @@ main(int argc, char *argv[])
delete1pkg(*argv);
argv++;
}
+ } else if (strcasecmp(argv[0], "set") == 0) {
+ argv++; /* "set" */
+ set_unset_variable(argv, FALSE);
+ } else if (strcasecmp(argv[0], "unset") == 0) {
+ argv++; /* "unset" */
+ set_unset_variable(argv, TRUE);
}
#ifdef PKGDB_DEBUG
else if (strcasecmp(argv[0], "delkey") == 0) {
@@ -734,12 +745,109 @@ main(int argc, char *argv[])
}
#endif
else {
- usage(prog);
+ usage();
}
return 0;
}
+struct varval {
+ char *variable;
+ char *value;
+};
+
+static int
+set_installed_info_var(const char *name, void *ud)
+{
+ char filename[BUFSIZ];
+ struct varval *varval;
+
+ varval = ud;
+
+ (void)snprintf(filename, sizeof(filename), "%s/%s", name,
+ INSTALLED_INFO_FNAME);
+
+ return var_set(filename, varval->variable, varval->value);
+}
+
+static void
+set_unset_variable(char **argv, Boolean unset)
+{
+ struct varval varval;
+ int ret = 0;
+ char *eq;
+ char *variable;
+
+ if (argv[0] == NULL || argv[1] == NULL)
+ usage();
+
+ variable = NULL;
+
+ if (unset) {
+ varval.variable = argv[0];
+ varval.value = NULL;
+ } else {
+ eq = NULL;
+ if ((eq=strchr(argv[0], '=')) == NULL)
+ usage();
+
+ variable = malloc(eq-argv[0]+1);
+ strlcpy(variable, argv[0], eq-argv[0]+1);
+
+ varval.variable = variable;
+ varval.value = eq+1;
+
+ if (strcmp(variable, AUTOMATIC_VARNAME) == 0 &&
+ strcasecmp(varval.value, "yes") != 0 &&
+ strcasecmp(varval.value, "no") != 0) {
+ errx(EXIT_FAILURE,
+ "unknown value `%s' for " AUTOMATIC_VARNAME,
+ varval.value);
+ }
+ }
+ if (strcspn(varval.variable, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+ != strlen(varval.variable)) {
+ free(variable);
+ errx(EXIT_FAILURE,
+ "variable name must not contain uppercase letters");
+ }
+
+ chdir(_pkgdb_getPKGDB_DIR());
+ argv++;
+ while (*argv != NULL) {
+ if (ispkgpattern(*argv)) {
+ if (findmatchingname(_pkgdb_getPKGDB_DIR(),
+ *argv, set_installed_info_var,
+ &varval) <= 0) {
+ warnx("no matching pkg for `%s'", *argv);
+ ret++;
+ }
+ } else if (isdir(*argv) || islinktodir(*argv))
+ set_installed_info_var(*argv, &varval);
+ else {
+ /* try 'pkg-[0-9]*' */
+ char try[MaxPathSize];
+
+ snprintf(try, sizeof(try), "%s-[0-9]*", *argv);
+ if (findmatchingname(_pkgdb_getPKGDB_DIR(),
+ try, set_installed_info_var,
+ &varval) <= 0) {
+ warnx("cannot find package %s", *argv);
+ ret++;
+ }
+ }
+
+ argv++;
+ }
+
+ if (ret > 0)
+ exit(EXIT_FAILURE);
+
+ free(variable);
+
+ return;
+}
+
void
cleanup(int signo)
{
diff --git a/pkgtools/pkg_install/files/admin/pkg_admin.1 b/pkgtools/pkg_install/files/admin/pkg_admin.1
index 20a78681910..d553cea1eaa 100644
--- a/pkgtools/pkg_install/files/admin/pkg_admin.1
+++ b/pkgtools/pkg_install/files/admin/pkg_admin.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_admin.1,v 1.10 2005/05/30 13:23:31 wiz Exp $
+.\" $NetBSD: pkg_admin.1,v 1.11 2005/11/05 13:20:09 wiz Exp $
.\"
.\" Copyright (c) 1999-2002 Hubert Feyrer. All rights reserved.
.\"
@@ -28,7 +28,7 @@
.\" (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 August 13, 2004
+.Dd November 1, 2005
.Dt PKG_ADMIN 1
.Os
.Sh NAME
@@ -37,14 +37,9 @@
.Sh SYNOPSIS
.Nm
.Op Fl bqSV
-.Nb -words
.Op Fl d Ar lsdir
-.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
@@ -200,7 +195,17 @@ and
.Xr pkg_create 1 .
.Pp
Needs to be run as root.
+.It Cm set Ar variable=value pkg ...
+Set variable with information about the installed package.
+Use
+.Cm unset
+to remove a variable.
.Pp
+Packages that are not installed directly by the user but pulled in as
+dependencies are marked by setting
+.Dq automatic=YES .
+.It Cm unset Ar variable pkg ...
+Remove an installation variable.
.El
.Sh ENVIRONMENT
.Bl -tag -width indent -compact
diff --git a/pkgtools/pkg_install/files/admin/pkg_admin.cat1 b/pkgtools/pkg_install/files/admin/pkg_admin.cat1
index 6e234121468..913b5ca31a9 100644
--- a/pkgtools/pkg_install/files/admin/pkg_admin.cat1
+++ b/pkgtools/pkg_install/files/admin/pkg_admin.cat1
@@ -121,6 +121,16 @@ OOPPTTIIOONNSS
Needs to be run as root.
+ sseett _v_a_r_i_a_b_l_e_=_v_a_l_u_e _p_k_g _._._.
+ Set variable with information about the installed package. Use
+ uunnsseett to remove a variable.
+
+ Packages that are not installed directly by the user but pulled
+ in as dependencies are marked by setting ``automatic=YES''.
+
+ uunnsseett _v_a_r_i_a_b_l_e _p_k_g _._._.
+ Remove an installation variable.
+
EENNVVIIRROONNMMEENNTT
PKG_DBDIR
If the --KK flag isn't given, then PKG_DBDIR is the location of the
@@ -141,4 +151,4 @@ HHIISSTTOORRYY
AAUUTTHHOORRSS
The ppkkgg__aaddmmiinn command was written by Hubert Feyrer.
-NetBSD 3.0 August 13, 2004 NetBSD 3.0
+NetBSD 3.0 November 1, 2005 NetBSD 3.0
diff --git a/pkgtools/pkg_install/files/bpm/bpm.sh.in b/pkgtools/pkg_install/files/bpm/bpm.sh.in
index 4c03c23a91f..9c62823c1e5 100644
--- a/pkgtools/pkg_install/files/bpm/bpm.sh.in
+++ b/pkgtools/pkg_install/files/bpm/bpm.sh.in
@@ -1,6 +1,6 @@
#! /bin/sh
#
-# $NetBSD: bpm.sh.in,v 1.2 2004/08/20 20:09:53 jlam Exp $
+# $NetBSD: bpm.sh.in,v 1.3 2005/11/05 13:20:09 wiz Exp $
#
# Copyright (c) 2003 Alistair G. Crooks. All rights reserved.
#
diff --git a/pkgtools/pkg_install/files/info/info.h b/pkgtools/pkg_install/files/info/info.h
index fcd87cc4754..6a654465167 100644
--- a/pkgtools/pkg_install/files/info/info.h
+++ b/pkgtools/pkg_install/files/info/info.h
@@ -1,4 +1,4 @@
-/* $NetBSD: info.h,v 1.8 2005/05/30 13:23:32 wiz Exp $ */
+/* $NetBSD: info.h,v 1.9 2005/11/05 13:20:09 wiz Exp $ */
/* from FreeBSD Id: info.h,v 1.10 1997/02/22 16:09:40 peter Exp */
@@ -53,8 +53,14 @@
#define SHOW_BLD_DEPENDS 0x20000
#define SHOW_BI_VAR 0x40000
+enum which {
+ WHICH_ALL,
+ WHICH_USER,
+ WHICH_LIST
+};
+
extern int Flags;
-extern Boolean AllInstalled;
+enum which Which;
extern Boolean File2Pkg;
extern Boolean Quiet;
extern char *InfoPrefix;
@@ -65,7 +71,7 @@ extern char *CheckPkg;
extern size_t termwidth;
extern lpkg_head_t pkgs;
-extern void show_file(char *, char *, char *);
+extern void show_file(char *, char *, char *, Boolean);
extern void show_var(const char *, const char *);
extern void show_plist(char *, package_t *, pl_ent_t);
extern void show_files(char *, package_t *);
diff --git a/pkgtools/pkg_install/files/info/main.c b/pkgtools/pkg_install/files/info/main.c
index 729b16dff01..eb4bee90b0c 100644
--- a/pkgtools/pkg_install/files/info/main.c
+++ b/pkgtools/pkg_install/files/info/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.13 2005/02/10 23:51:18 grant Exp $ */
+/* $NetBSD: main.c,v 1.14 2005/11/05 13:20:09 wiz Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.13 2005/02/10 23:51:18 grant Exp $");
+__RCSID("$NetBSD: main.c,v 1.14 2005/11/05 13:20:09 wiz Exp $");
#endif
#endif
@@ -50,10 +50,10 @@ __RCSID("$NetBSD: main.c,v 1.13 2005/02/10 23:51:18 grant Exp $");
#include "lib.h"
#include "info.h"
-static const char Options[] = ".aBbcDde:fFhIiK:kLl:mNnpQ:qRrsSvV";
+static const char Options[] = ".aBbcDde:fFhIiK:kLl:mNnpQ:qRrsSuvV";
int Flags = 0;
-Boolean AllInstalled = FALSE;
+enum which Which = WHICH_LIST;
Boolean File2Pkg = FALSE;
Boolean Quiet = FALSE;
char *InfoPrefix = "";
@@ -69,8 +69,8 @@ usage(void)
{
fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: pkg_info [-BbcDdFfhIikLmNnpqRrSsVv] [-e package] [-K pkg_dbdir] [-l prefix]",
- " pkg-name [pkg-name ...]",
- " pkg_info -a [flags]",
+ " pkg-name [...]",
+ " pkg_info [-a | -u] [flags]",
" pkg_info -Q variable pkg-name [pkg-name ...]");
exit(1);
}
@@ -89,7 +89,7 @@ main(int argc, char **argv)
break;
case 'a':
- AllInstalled = TRUE;
+ Which = WHICH_ALL;
break;
case 'B':
@@ -189,6 +189,10 @@ main(int argc, char **argv)
Flags |= SHOW_ALL_SIZE;
break;
+ case 'u':
+ Which = WHICH_USER;
+ break;
+
case 'v':
Verbose = TRUE;
/* Reasonable definition of 'everything' */
@@ -212,13 +216,20 @@ main(int argc, char **argv)
argv += optind;
if (argc == 0 && !Flags && !CheckPkg) {
- /* No argument or flags specified - assume -Ia */
+ /* No argument or relevant flags specified - assume -I */
Flags = SHOW_INDEX;
- AllInstalled = TRUE;
+ /* assume -a if neither -u nor -a is given */
+ if (Which == WHICH_LIST)
+ Which = WHICH_ALL;
+ }
+
+ if (argc != 0 && Which != WHICH_LIST) {
+ warnx("can't use both -a/-u and package name");
+ usage();
}
/* Don't do FTP stuff when operating on all pkgs */
- if (AllInstalled && getenv("PKG_PATH") != 0) {
+ if (Which != WHICH_LIST && getenv("PKG_PATH") != 0) {
warnx("disabling PKG_PATH when operating on all packages.");
unsetenv("PKG_PATH");
}
@@ -251,7 +262,7 @@ main(int argc, char **argv)
TAILQ_INIT(&pkgs);
/* Get all the remaining package names, if any */
- if (File2Pkg && !AllInstalled)
+ if (File2Pkg && Which == WHICH_LIST)
if (!pkgdb_open(ReadOnly)) {
err(EXIT_FAILURE, "cannot open pkgdb");
}
@@ -294,7 +305,7 @@ main(int argc, char **argv)
pkgdb_close();
/* If no packages, yelp */
- if (TAILQ_FIRST(&pkgs) == NULL && !AllInstalled && !CheckPkg)
+ if (TAILQ_FIRST(&pkgs) == NULL && Which == WHICH_LIST && !CheckPkg)
warnx("missing package name(s)"), usage();
if (isatty(STDOUT_FILENO)) {
diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c
index 80dab8bf518..18c39a20627 100644
--- a/pkgtools/pkg_install/files/info/perform.c
+++ b/pkgtools/pkg_install/files/info/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.22 2005/05/30 13:23:32 wiz Exp $ */
+/* $NetBSD: perform.c,v 1.23 2005/11/05 13:20:09 wiz Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.22 2005/05/30 13:23:32 wiz Exp $");
+__RCSID("$NetBSD: perform.c,v 1.23 2005/11/05 13:20:09 wiz Exp $");
#endif
#endif
@@ -122,7 +122,12 @@ pkg_do(char *pkg)
strcat(flist, DESC_FNAME); strcat(flist, " ");
if (Flags & SHOW_MTREE) { strcat(flist, MTREE_FNAME); strcat(flist, " "); }
if (Flags & SHOW_BUILD_VERSION) { strcat(flist, BUILD_VERSION_FNAME); strcat(flist, " "); }
- if (Flags & SHOW_BUILD_INFO) { strcat(flist, BUILD_INFO_FNAME); strcat(flist, " "); }
+ if (Flags & SHOW_BUILD_INFO) {
+ strcat(flist, BUILD_INFO_FNAME);
+ strcat(flist, " ");
+ strcat(flist, INSTALLED_INFO_FNAME);
+ strcat(flist, " ");
+ }
if (Flags & SHOW_PKG_SIZE) { strcat(flist, SIZE_PKG_FNAME); strcat(flist, " "); }
if (Flags & SHOW_ALL_SIZE) { strcat(flist, SIZE_ALL_FNAME); strcat(flist, " "); }
#if 0
@@ -188,7 +193,11 @@ pkg_do(char *pkg)
(void) snprintf(tmp, sizeof(tmp), "%-19s ", pkg);
show_index(pkg, tmp, COMMENT_FNAME);
} else if (Flags & SHOW_BI_VAR) {
- show_var(BUILD_INFO_FNAME, BuildInfoVariable);
+ if (strcspn(BuildInfoVariable, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+ == strlen(BuildInfoVariable))
+ show_var(INSTALLED_INFO_FNAME, BuildInfoVariable);
+ else
+ show_var(BUILD_INFO_FNAME, BuildInfoVariable);
} else {
FILE *fp;
package_t plist;
@@ -213,7 +222,7 @@ pkg_do(char *pkg)
}
}
if (Flags & SHOW_COMMENT) {
- show_file(pkg, "Comment:\n", COMMENT_FNAME);
+ show_file(pkg, "Comment:\n", COMMENT_FNAME, TRUE);
}
if (Flags & SHOW_DEPENDS) {
show_depends("Requires:\n", &plist);
@@ -222,28 +231,33 @@ pkg_do(char *pkg)
show_bld_depends("Built using:\n", &plist);
}
if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME)) {
- show_file(pkg, "Required by:\n", REQUIRED_BY_FNAME);
+ show_file(pkg, "Required by:\n",
+ REQUIRED_BY_FNAME, TRUE);
}
if (Flags & SHOW_DESC) {
- show_file(pkg, "Description:\n", DESC_FNAME);
+ show_file(pkg, "Description:\n", DESC_FNAME, TRUE);
}
if ((Flags & SHOW_DISPLAY) && fexists(DISPLAY_FNAME)) {
- show_file(pkg, "Install notice:\n", DISPLAY_FNAME);
+ show_file(pkg, "Install notice:\n",
+ DISPLAY_FNAME, TRUE);
}
if (Flags & SHOW_PLIST) {
show_plist("Packing list:\n", &plist, PLIST_SHOW_ALL);
}
if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME)) {
- show_file(pkg, "Install script:\n", INSTALL_FNAME);
+ show_file(pkg, "Install script:\n",
+ INSTALL_FNAME, TRUE);
}
if ((Flags & SHOW_DEINSTALL) && fexists(DEINSTALL_FNAME)) {
- show_file(pkg, "De-Install script:\n", DEINSTALL_FNAME);
+ show_file(pkg, "De-Install script:\n",
+ DEINSTALL_FNAME, TRUE);
}
if ((Flags & SHOW_REQUIRE) && fexists(REQUIRE_FNAME)) {
- show_file(pkg, "Require script:\n", REQUIRE_FNAME);
+ show_file(pkg, "Require script:\n",
+ REQUIRE_FNAME, TRUE);
}
if ((Flags & SHOW_MTREE) && fexists(MTREE_FNAME)) {
- show_file(pkg, "mtree file:\n", MTREE_FNAME);
+ show_file(pkg, "mtree file:\n", MTREE_FNAME, TRUE);
}
if (Flags & SHOW_PREFIX) {
show_plist("Prefix(s):\n", &plist, PLIST_CWD);
@@ -252,16 +266,27 @@ pkg_do(char *pkg)
show_files("Files:\n", &plist);
}
if ((Flags & SHOW_BUILD_VERSION) && fexists(BUILD_VERSION_FNAME)) {
- show_file(pkg, "Build version:\n", BUILD_VERSION_FNAME);
+ show_file(pkg, "Build version:\n",
+ BUILD_VERSION_FNAME, TRUE);
}
- if ((Flags & SHOW_BUILD_INFO) && fexists(BUILD_INFO_FNAME)) {
- show_file(pkg, "Build information:\n", BUILD_INFO_FNAME);
+ if (Flags & SHOW_BUILD_INFO) {
+ if (fexists(BUILD_INFO_FNAME)) {
+ show_file(pkg, "Build information:\n",
+ BUILD_INFO_FNAME,
+ !fexists(INSTALLED_INFO_FNAME));
+ }
+ if (fexists(INSTALLED_INFO_FNAME)) {
+ show_file(pkg, "Installed information:\n",
+ INSTALLED_INFO_FNAME, TRUE);
+ }
}
if ((Flags & SHOW_PKG_SIZE) && fexists(SIZE_PKG_FNAME)) {
- show_file(pkg, "Size of this package in bytes: ", SIZE_PKG_FNAME);
+ show_file(pkg, "Size of this package in bytes: ",
+ SIZE_PKG_FNAME, TRUE);
}
if ((Flags & SHOW_ALL_SIZE) && fexists(SIZE_ALL_FNAME)) {
- show_file(pkg, "Size in bytes including required pkgs: ", SIZE_ALL_FNAME);
+ show_file(pkg, "Size in bytes including required pkgs: ",
+ SIZE_ALL_FNAME, TRUE);
}
if (!Quiet) {
if (fexists(PRESERVE_FNAME)) {
@@ -360,17 +385,15 @@ pkg_perform(lpkg_head_t *pkghead)
/* Overriding action? */
if (CheckPkg) {
err_cnt += CheckForPkg(CheckPkg, dbdir);
- } else if (AllInstalled) {
+ } else if (Which != WHICH_LIST) {
if (!(isdir(dbdir) || islinktodir(dbdir)))
return 1;
if (File2Pkg) {
-
/* Show all files with the package they belong to */
pkgdb_dump();
-
} else {
- /* Show all packges with description */
+ /* Show all packages with description */
if ((dirp = opendir(dbdir)) != (DIR *) NULL) {
while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
char tmp2[MaxPathSize];
@@ -384,7 +407,9 @@ pkg_perform(lpkg_head_t *pkghead)
if (isfile(tmp2))
continue;
- err_cnt += pkg_do(dp->d_name);
+ if (Which == WHICH_ALL
+ || !is_automatic_installed(tmp2))
+ err_cnt += pkg_do(dp->d_name);
}
(void) closedir(dirp);
}
diff --git a/pkgtools/pkg_install/files/info/pkg_info.1 b/pkgtools/pkg_install/files/info/pkg_info.1
index 5377f0590ea..30a34fe95fd 100644
--- a/pkgtools/pkg_install/files/info/pkg_info.1
+++ b/pkgtools/pkg_install/files/info/pkg_info.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_info.1,v 1.16 2005/05/30 13:23:32 wiz Exp $
+.\" $NetBSD: pkg_info.1,v 1.17 2005/11/05 13:20:09 wiz Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@@ -17,7 +17,7 @@
.\"
.\" @(#)pkg_info.1
.\"
-.Dd May 30, 2005
+.Dd November 1, 2005
.Dt PKG_INFO 1
.Os
.Sh NAME
@@ -26,24 +26,15 @@
.Sh SYNOPSIS
.Nm
.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 ...
.Nm
-.Bk -words
-.Op Fl a Ar flags
-.Ek
+.Op Fl a | Fl u
+.Op flags
.Nm
-.Bk -words
.Op Fl Q Ar variable
-.Ek
.Ar pkg-name ...
.Sh DESCRIPTION
The
@@ -69,9 +60,19 @@ The following command-line options are supported:
.Bl -tag -width indent
.It Fl a
Show information for all currently installed packages.
+See also
+.Fl u .
.It Fl B
Show some of the important definitions used when building
-the binary package (the "Build information") for each package.
+the binary package (the
+.Dq Build information )
+for each package.
+Additionally, any installation information variables
+(lowercase) can be queried, too.
+In particular,
+.Ar automatic
+tells if a package was installed automatically
+as a dependency of another package.
.It Fl b
Show the
.Nx
@@ -168,6 +169,12 @@ in bytes.
.It Fl s
Show the size of this package in bytes.
The size is calculated by adding up the size of each file of the package.
+.It Fl u
+Show information for all user-installed packages.
+Automatically installed packages (as dependencies
+of other packages) are not displayed.
+See also
+.Fl a .
.It Fl V
Print version number and exit.
.It Fl v
diff --git a/pkgtools/pkg_install/files/info/pkg_info.cat1 b/pkgtools/pkg_install/files/info/pkg_info.cat1
index c6e73baee83..3f06a949d33 100644
--- a/pkgtools/pkg_install/files/info/pkg_info.cat1
+++ b/pkgtools/pkg_install/files/info/pkg_info.cat1
@@ -6,7 +6,7 @@ NNAAMMEE
SSYYNNOOPPSSIISS
ppkkgg__iinnffoo [--BBbbccDDddFFffhhIIiikkLLmmNNnnppqqRRrrSSssVVvv] [--ee _p_a_c_k_a_g_e] [--KK _p_k_g___d_b_d_i_r]
[--ll _p_r_e_f_i_x] _p_k_g_-_n_a_m_e _._._.
- ppkkgg__iinnffoo [--aa _f_l_a_g_s]
+ ppkkgg__iinnffoo [--aa | --uu] [flags]
ppkkgg__iinnffoo [--QQ _v_a_r_i_a_b_l_e] _p_k_g_-_n_a_m_e _._._.
DDEESSCCRRIIPPTTIIOONN
@@ -22,10 +22,14 @@ DDEESSCCRRIIPPTTIIOONN
The following command-line options are supported:
- --aa Show information for all currently installed packages.
+ --aa Show information for all currently installed packages. See also
+ --uu.
--BB Show some of the important definitions used when building the
- binary package (the "Build information") for each package.
+ binary package (the ``Build information'') for each package.
+ Additionally, any installation information variables (lowercase)
+ can be queried, too. In particular, _a_u_t_o_m_a_t_i_c tells if a package
+ was installed automatically as a dependency of another package.
--bb Show the NetBSD RCS Id strings from the files used in the con-
struction of the binary package (the "Build version") for each
@@ -103,6 +107,10 @@ DDEESSCCRRIIPPTTIIOONN
--ss Show the size of this package in bytes. The size is calculated
by adding up the size of each file of the package.
+ --uu Show information for all user-installed packages. Automatically
+ installed packages (as dependencies of other packages) are not
+ displayed. See also --aa.
+
--VV Print version number and exit.
--vv Turn on verbose output.
@@ -184,4 +192,4 @@ AAUUTTHHOORRSS
NetBSD wildcard dependency processing, pkgdb, depends displaying,
pkg size display etc.
-NetBSD 3.0 May 30, 2005 NetBSD 3.0
+NetBSD 3.0 November 1, 2005 NetBSD 3.0
diff --git a/pkgtools/pkg_install/files/info/show.c b/pkgtools/pkg_install/files/info/show.c
index 8dc6ac36a2f..7b1b6aaf14f 100644
--- a/pkgtools/pkg_install/files/info/show.c
+++ b/pkgtools/pkg_install/files/info/show.c
@@ -1,4 +1,4 @@
-/* $NetBSD: show.c,v 1.8 2005/05/30 13:23:32 wiz Exp $ */
+/* $NetBSD: show.c,v 1.9 2005/11/05 13:20:09 wiz Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.8 2005/05/30 13:23:32 wiz Exp $");
+__RCSID("$NetBSD: show.c,v 1.9 2005/11/05 13:20:09 wiz Exp $");
#endif
#endif
@@ -107,7 +107,7 @@ static const show_t showv[] = {
};
void
-show_file(char *pkg, char *title, char *fname)
+show_file(char *pkg, char *title, char *fname, Boolean separator)
{
FILE *fp;
char line[1024];
@@ -128,49 +128,20 @@ show_file(char *pkg, char *title, char *fname)
if (append_nl)
printf("\n");
}
- printf("\n"); /* just in case */
+ if (!Quiet || separator) {
+ printf("\n"); /* just in case */
+ }
}
void
show_var(const char *fname, const char *variable)
{
- FILE *fp;
- char *line;
- size_t len;
- size_t varlen;
+ char *value;
- fp = fopen(fname, "r");
- if (!fp) {
- warnx("show_var: can't open '%s' for reading", fname);
- return;
+ if ((value=var_get(fname, variable)) != NULL) {
+ (void) printf("%s\n", value);
+ free(value);
}
-
- varlen = strlen(variable);
- if (varlen > 0) {
- while ((line = fgetln(fp, &len)) != (char *) NULL) {
- /*
- * We expect lines to look like one of the following
- * forms:
- * VAR=value
- * VAR= value
- * We print out the value of VAR, or nothing if it
- * doesn't exist.
- */
- if (line[len - 1] == '\n')
- line[len - 1] = '\0';
- if (strncmp(variable, line, varlen) == 0) {
- line += varlen;
- if (*line != '=')
- continue;
- ++line;
- if (*line == ' ')
- ++line;
- (void) printf("%s\n", line);
- }
- }
- }
- (void) fclose(fp);
- return;
}
void
diff --git a/pkgtools/pkg_install/files/lib/automatic.c b/pkgtools/pkg_install/files/lib/automatic.c
new file mode 100644
index 00000000000..9cd04786205
--- /dev/null
+++ b/pkgtools/pkg_install/files/lib/automatic.c
@@ -0,0 +1,80 @@
+/* $NetBSD: automatic.c,v 1.1 2005/11/05 13:20:09 wiz Exp $ */
+
+/*-
+ * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * 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. 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: automatic.c,v 1.1 2005/11/05 13:20:09 wiz Exp $");
+#endif
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include "lib.h"
+
+Boolean
+is_automatic_installed(const char *path)
+{
+ char filename[BUFSIZ];
+ char *value;
+ Boolean ret;
+
+ (void)snprintf(filename, sizeof(filename), "%s/%s", path,
+ INSTALLED_INFO_FNAME);
+
+ value = var_get(filename, AUTOMATIC_VARNAME);
+
+ if (value && strcasecmp(value, "yes") == 0)
+ ret = TRUE;
+ else
+ ret = FALSE;
+
+ free(value);
+
+ return ret;
+}
+
+int
+mark_as_automatic_installed(const char *path, int value)
+{
+ char filename[BUFSIZ];
+
+ (void)snprintf(filename, sizeof(filename), "%s/%s", path,
+ INSTALLED_INFO_FNAME);
+
+ return var_set(filename, AUTOMATIC_VARNAME,
+ value ? "yes" : NULL);
+}
diff --git a/pkgtools/pkg_install/files/lib/config.h b/pkgtools/pkg_install/files/lib/config.h
new file mode 100644
index 00000000000..1ae1cbe105e
--- /dev/null
+++ b/pkgtools/pkg_install/files/lib/config.h
@@ -0,0 +1,193 @@
+/* lib/config.h. Generated by configure. */
+/* lib/config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if you have the <assert.h> header file. */
+#define HAVE_ASSERT_H 1
+
+/* Define to 1 if you have the `chflags' function. */
+#define HAVE_CHFLAGS 1
+
+/* Define to 1 if you have the <ctype.h> header file. */
+#define HAVE_CTYPE_H 1
+
+/* Define to 1 if you have the <db1/db.h> header file. */
+/* #undef HAVE_DB1_DB_H */
+
+/* Define to 1 if you have the `dbopen' function. */
+#define HAVE_DBOPEN 1
+
+/* Define to 1 if you have the <db.h> header file. */
+#define HAVE_DB_H 1
+
+/* Define to 1 if you have the <dirent.h> header file. */
+#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <err.h> header file. */
+#define HAVE_ERR_H 1
+
+/* Define to 1 if you have the <fnctl.h> header file. */
+/* #undef HAVE_FNCTL_H */
+
+/* Define to 1 if you have the <fnmatch.h> header file. */
+#define HAVE_FNMATCH_H 1
+
+/* Define to 1 if you have the `getrlimit' function. */
+#define HAVE_GETRLIMIT 1
+
+/* Define to 1 if you have the <glob.h> header file. */
+#define HAVE_GLOB_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `db1' library (-ldb1). */
+/* #undef HAVE_LIBDB1 */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <md5.h> header file. */
+#define HAVE_MD5_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <pwd.h> header file. */
+#define HAVE_PWD_H 1
+
+/* Define to 1 if you have the <regex.h> header file. */
+#define HAVE_REGEX_H 1
+
+/* Define to 1 if you have the `setrlimit' function. */
+#define HAVE_SETRLIMIT 1
+
+/* Define to 1 if you have the <signal.h> header file. */
+#define HAVE_SIGNAL_H 1
+
+/* Define to 1 if you have the <stdarg.h> header file. */
+#define HAVE_STDARG_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/cdefs.h> header file. */
+#define HAVE_SYS_CDEFS_H 1
+
+/* Define to 1 if you have the <sys/file.h> header file. */
+#define HAVE_SYS_FILE_H 1
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#define HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/mount.h> header file. */
+#define HAVE_SYS_MOUNT_H 1
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#define HAVE_SYS_POLL_H 1
+
+/* Define to 1 if you have the <sys/queue.h> header file. */
+#define HAVE_SYS_QUEUE_H 1
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#define HAVE_SYS_RESOURCE_H 1
+
+/* Define to 1 if you have the <sys/signal.h> header file. */
+#define HAVE_SYS_SIGNAL_H 1
+
+/* Define to 1 if you have the <sys/statvfs.h> header file. */
+#define HAVE_SYS_STATVFS_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/utsname.h> header file. */
+#define HAVE_SYS_UTSNAME_H 1
+
+/* Define to 1 if you have the <sys/vfs.h> header file. */
+/* #undef HAVE_SYS_VFS_H */
+
+/* Define to 1 if you have the <sys/wait.h> header file. */
+#define HAVE_SYS_WAIT_H 1
+
+/* Define to 1 if you have the <termcap.h> header file. */
+#define HAVE_TERMCAP_H 1
+
+/* Define to 1 if you have the <termios.h> header file. */
+#define HAVE_TERMIOS_H 1
+
+/* Define to 1 if you have the `tgetent' function. */
+#define HAVE_TGETENT 1
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `vfork' function. */
+#define HAVE_VFORK 1
+
+/* Define to 1 if you have the <vis.h> header file. */
+#define HAVE_VIS_H 1
+
+/* Defined when PRIu64 is missing or broken */
+/* #undef NEED_PRI_MACRO */
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "grant@NetBSD.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "pkg_install"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "pkg_install 20050607"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "pkg_install"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "20050607"
+
+/* The size of a `int', as computed by sizeof. */
+#define SIZEOF_INT 4
+
+/* The size of a `long', as computed by sizeof. */
+#define SIZEOF_LONG 4
+
+/* The size of a `long long', as computed by sizeof. */
+#define SIZEOF_LONG_LONG 8
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+#if !HAVE_VFORK
+# define vfork fork
+#endif
+
diff --git a/pkgtools/pkg_install/files/lib/dewey.c b/pkgtools/pkg_install/files/lib/dewey.c
new file mode 100644
index 00000000000..2fbd9c84088
--- /dev/null
+++ b/pkgtools/pkg_install/files/lib/dewey.c
@@ -0,0 +1,282 @@
+/* $NetBSD: dewey.c,v 1.1 2005/11/05 13:20:09 wiz Exp $ */
+
+/*
+ * FreeBSD install - a package for the installation and maintainance
+ * of non-core utilities.
+ *
+ * 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.
+ *
+ * Jordan K. Hubbard
+ * 18 July 1993
+ *
+ * Miscellaneous string utilities.
+ *
+ */
+
+#include <assert.h>
+#include <ctype.h>
+#include <err.h>
+#include <fnmatch.h>
+#include <inttypes.h>
+#include <string.h>
+
+#include "defs.h"
+#include "dewey.h"
+
+#define PKG_PATTERN_MAX 1024
+typedef int (*matchfn) (const char *, void *);
+
+/* do not modify these values, or things will NOT work */
+enum {
+ Alpha = -3,
+ Beta = -2,
+ RC = -1,
+ Dot = 0,
+ Patch = 1
+};
+
+/* this struct defines a version number */
+typedef struct arr_t {
+ unsigned c; /* # of version numbers */
+ unsigned size; /* size of array */
+ int *v; /* array of decimal numbers */
+ int netbsd; /* any "nb" suffix */
+} arr_t;
+
+/* this struct describes a test */
+typedef struct test_t {
+ const char *s; /* string representation */
+ unsigned len; /* length of string */
+ int t; /* enumerated type of test */
+} test_t;
+
+
+/* the tests that are recognised. */
+ const test_t tests[] = {
+ { "<=", 2, DEWEY_LE },
+ { "<", 1, DEWEY_LT },
+ { ">=", 2, DEWEY_GE },
+ { ">", 1, DEWEY_GT },
+ { "==", 2, DEWEY_EQ },
+ { "!=", 2, DEWEY_NE },
+ { NULL, 0, 0 }
+};
+
+ const test_t modifiers[] = {
+ { "alpha", 5, Alpha },
+ { "beta", 4, Beta },
+ { "pre", 3, RC },
+ { "rc", 2, RC },
+ { "pl", 2, Dot },
+ { "_", 1, Dot },
+ { ".", 1, Dot },
+ { NULL, 0, 0 }
+};
+
+
+
+/* locate the test in the tests array */
+int
+dewey_mktest(int *op, const char *test)
+{
+ const test_t *tp;
+
+ for (tp = tests ; tp->s ; tp++) {
+ if (strncasecmp(test, tp->s, tp->len) == 0) {
+ *op = tp->t;
+ return tp->len;
+ }
+ }
+ return -1;
+}
+
+/*
+ * make a component of a version number.
+ * '.' encodes as Dot which is '0'
+ * '_' encodes as 'patch level', or 'Dot', which is 0.
+ * 'pl' encodes as 'patch level', or 'Dot', which is 0.
+ * 'alpha' encodes as 'alpha version', or Alpha, which is -3.
+ * 'beta' encodes as 'beta version', or Beta, which is -2.
+ * 'rc' encodes as 'release candidate', or RC, which is -1.
+ * 'nb' encodes as 'netbsd version', which is used after all other tests
+ */
+static int
+mkcomponent(arr_t *ap, const char *num)
+{
+ static const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
+ const test_t *modp;
+ int n;
+ const char *cp;
+
+ if (*num == 0) {
+ return 0;
+ }
+ ALLOC(int, ap->v, ap->size, ap->c, 62, "mkver", exit(EXIT_FAILURE));
+ if (isdigit((unsigned char)*num)) {
+ for (cp = num, n = 0 ; isdigit((unsigned char)*num) ; num++) {
+ n = (n * 10) + (*num - '0');
+ }
+ ap->v[ap->c++] = n;
+ return (int)(num - cp);
+ }
+ for (modp = modifiers ; modp->s ; modp++) {
+ if (strncasecmp(num, modp->s, modp->len) == 0) {
+ ap->v[ap->c++] = modp->t;
+ return modp->len;
+ }
+ }
+ if (strncasecmp(num, "nb", 2) == 0) {
+ for (cp = num, num += 2, n = 0 ; isdigit((unsigned char)*num) ; num++) {
+ n = (n * 10) + (*num - '0');
+ }
+ ap->netbsd = n;
+ return (int)(num - cp);
+ }
+ if (isalpha((unsigned char)*num)) {
+ ap->v[ap->c++] = Dot;
+ cp = strchr(alphas, tolower((unsigned char)*num));
+ ALLOC(int, ap->v, ap->size, ap->c, 62, "mkver", exit(EXIT_FAILURE));
+ ap->v[ap->c++] = (int)(cp - alphas) + 1;
+ return 1;
+ }
+ return 1;
+}
+
+/* make a version number string into an array of comparable 64bit ints */
+static int
+mkversion(arr_t *ap, const char *num)
+{
+ (void) memset(ap, 0, sizeof(arr_t));
+ while (*num) {
+ num += mkcomponent(ap, num);
+ }
+ return 1;
+}
+
+#define DIGIT(v, c, n) (((n) < (c)) ? v[n] : 0)
+
+/* compare the result against the test we were expecting */
+static int
+result(int cmp, int tst)
+{
+ switch(tst) {
+ case DEWEY_LT:
+ return cmp < 0;
+ case DEWEY_LE:
+ return cmp <= 0;
+ case DEWEY_GT:
+ return cmp > 0;
+ case DEWEY_GE:
+ return cmp >= 0;
+ case DEWEY_EQ:
+ return cmp == 0;
+ case DEWEY_NE:
+ return cmp != 0;
+ default:
+ return 0;
+ }
+}
+
+/* do the test on the 2 vectors */
+static int
+vtest(arr_t *lhs, int tst, arr_t *rhs)
+{
+ int cmp;
+ int c;
+ int i;
+
+ for (i = 0, c = MAX(lhs->c, rhs->c) ; i < c ; i++) {
+ if ((cmp = DIGIT(lhs->v, lhs->c, i) - DIGIT(rhs->v, rhs->c, i)) != 0) {
+ return result(cmp, tst);
+ }
+ }
+ return result(lhs->netbsd - rhs->netbsd, tst);
+}
+
+/*
+ * Compare two dewey decimal numbers
+ */
+int
+dewey_cmp(const char *lhs, int op, const char *rhs)
+{
+ arr_t right;
+ arr_t left;
+
+ (void) memset(&left, 0, sizeof(left));
+ if (!mkversion(&left, lhs)) {
+ return 0;
+ }
+ (void) memset(&right, 0, sizeof(right));
+ if (!mkversion(&right, rhs)) {
+ return 0;
+ }
+ return vtest(&left, op, &right);
+}
+
+/*
+ * Perform dewey match on "pkg" against "pattern".
+ * Return 1 on match, 0 otherwise
+ */
+int
+dewey_match(const char *pattern, const char *pkg)
+{
+ const char *version;
+ const char *sep, *sep2;
+ int op, op2;
+ int n;
+
+ /* compare names */
+ if ((version=strrchr(pkg, '-')) == NULL) {
+ return 0;
+ }
+ if ((sep = strpbrk(pattern, "<>")) == NULL)
+ errx(EXIT_FAILURE, "dewey_match: '<' or '>' expected in `%s'", pattern);
+ /* compare name lengths */
+ if ((sep-pattern != version-pkg) ||
+ strncmp(pkg, pattern, (size_t)(version-pkg)) != 0)
+ return 0;
+ version++;
+
+ /* extract comparison operator */
+ if ((n = dewey_mktest(&op, sep)) < 0) {
+ return 0;
+ }
+ /* skip operator */
+ sep += n;
+
+ /* if greater than, look for less than */
+ sep2 = NULL;
+ if (op == DEWEY_GT || op == DEWEY_GE) {
+ if ((sep2 = strchr(sep, '<')) != NULL) {
+ if ((n = dewey_mktest(&op2, sep2)) < 0) {
+ return 0;
+ }
+ /* compare upper limit */
+ if (!dewey_cmp(version, op2, sep2+n))
+ return 0;
+ }
+ }
+
+ /* compare only pattern / lower limit */
+ if (sep2) {
+ char ver[PKG_PATTERN_MAX];
+
+ strlcpy(ver, sep, MIN(sizeof(ver), sep2-sep+1));
+ if (dewey_cmp(version, op, ver))
+ return 1;
+ }
+ else {
+ if (dewey_cmp(version, op, sep))
+ return 1;
+ }
+
+ return 0;
+}
+
diff --git a/pkgtools/pkg_install/files/lib/dewey.h b/pkgtools/pkg_install/files/lib/dewey.h
new file mode 100644
index 00000000000..14f2b413212
--- /dev/null
+++ b/pkgtools/pkg_install/files/lib/dewey.h
@@ -0,0 +1,19 @@
+/* $NetBSD: dewey.h,v 1.1 2005/11/05 13:20:09 wiz Exp $ */
+
+#ifndef _INST_LIB_DEWEY_H_
+#define _INST_LIB_DEWEY_H_
+
+int dewey_cmp(const char *, int, const char *);
+int dewey_match(const char *, const char *);
+int dewey_mktest(int *, const char *);
+
+enum {
+ DEWEY_LT,
+ DEWEY_LE,
+ DEWEY_EQ,
+ DEWEY_GE,
+ DEWEY_GT,
+ DEWEY_NE
+};
+
+#endif /* _INST_LIB_DEWEY_H_ */
diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h
index 5e52701c6b2..88bbb73d8ec 100644
--- a/pkgtools/pkg_install/files/lib/lib.h
+++ b/pkgtools/pkg_install/files/lib/lib.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.16 2005/02/04 09:10:13 jlam Exp $ */
+/* $NetBSD: lib.h,v 1.17 2005/11/05 13:20:09 wiz Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -152,12 +152,16 @@ enum {
#define MTREE_FNAME "+MTREE_DIRS"
#define BUILD_VERSION_FNAME "+BUILD_VERSION"
#define BUILD_INFO_FNAME "+BUILD_INFO"
+#define INSTALLED_INFO_FNAME "+INSTALLED_INFO"
#define SIZE_PKG_FNAME "+SIZE_PKG"
#define SIZE_ALL_FNAME "+SIZE_ALL"
#define PRESERVE_FNAME "+PRESERVE"
#define VIEWS_FNAME "+VIEWS"
#define DEPOT_FNAME "+DEPOT"
+/* The names of special variables */
+#define AUTOMATIC_VARNAME "automatic"
+
/*
* files which we expect to be in every package, passed to
* tar --fast-read.
@@ -284,9 +288,19 @@ int fexec(const char *, ...);
int fexec_skipempty(const char *, ...);
int fcexec(const char *, const char *, ...);
+/* variables file handling */
+
+char *var_get(const char *, const char *);
+int var_set(const char *, const char *, const char *);
+
+/* automatically installed as dependency */
+
+Boolean is_automatic_installed(const char *);
+int mark_as_automatic_installed(const char *, int);
+
/* String */
char *get_dash_string(char **);
-void str_lowercase(char *);
+void str_lowercase(unsigned char *);
const char *basename_of(const char *);
const char *dirname_of(const char *);
const char *suffix_of(const char *);
@@ -347,7 +361,7 @@ void add_plist_top(package_t *, pl_ent_t, const char *);
void delete_plist(package_t *, Boolean, pl_ent_t, char *);
void write_plist(package_t *, FILE *, char *);
void read_plist(package_t *, FILE *);
-int plist_cmd(char *, char **);
+int plist_cmd(unsigned char *, char **);
int delete_package(Boolean, Boolean, package_t *, Boolean);
/* Package Database */
diff --git a/pkgtools/pkg_install/files/lib/nbcompat.h b/pkgtools/pkg_install/files/lib/nbcompat.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/pkgtools/pkg_install/files/lib/nbcompat.h
diff --git a/pkgtools/pkg_install/files/lib/plist.c b/pkgtools/pkg_install/files/lib/plist.c
index 643f04060fb..38c58fd39ec 100644
--- a/pkgtools/pkg_install/files/lib/plist.c
+++ b/pkgtools/pkg_install/files/lib/plist.c
@@ -1,4 +1,4 @@
-/* $NetBSD: plist.c,v 1.13 2005/01/07 11:58:12 agc Exp $ */
+/* $NetBSD: plist.c,v 1.14 2005/11/05 13:20:09 wiz Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.13 2005/01/07 11:58:12 agc Exp $");
+__RCSID("$NetBSD: plist.c,v 1.14 2005/11/05 13:20:09 wiz Exp $");
#endif
#endif
@@ -240,18 +240,19 @@ free_plist(package_t *pkg)
* optionally its argument(s)
*/
int
-plist_cmd(char *s, char **arg)
+plist_cmd(unsigned char *s, char **arg)
{
const cmd_t *cmdp;
- char cmd[MaxPathSize + 20]; /* 20 == fudge for max cmd len */
- char *cp;
- char *sp;
+ /* 20 == fudge for max cmd len */
+ unsigned char cmd[MaxPathSize + 20];
+ unsigned char *cp;
+ unsigned char *sp;
(void) strlcpy(cmd, s, sizeof(cmd));
str_lowercase(cmd);
for (cp = cmd, sp = s; *cp; cp++, sp++) {
- if (isspace((unsigned char) *cp)) {
- for (*cp = '\0'; isspace((unsigned char) *sp); sp++) {
+ if (isspace(*cp)) {
+ for (*cp = '\0'; isspace(*sp); sp++) {
}
break;
}
diff --git a/pkgtools/pkg_install/files/lib/str.c b/pkgtools/pkg_install/files/lib/str.c
index 8995afae198..f2b77bb5b61 100644
--- a/pkgtools/pkg_install/files/lib/str.c
+++ b/pkgtools/pkg_install/files/lib/str.c
@@ -1,4 +1,4 @@
-/* $NetBSD: str.c,v 1.13 2005/05/30 19:45:02 wiz Exp $ */
+/* $NetBSD: str.c,v 1.14 2005/11/05 13:20:09 wiz Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.13 2005/05/30 19:45:02 wiz Exp $");
+__RCSID("$NetBSD: str.c,v 1.14 2005/11/05 13:20:09 wiz Exp $");
#endif
#endif
@@ -45,6 +45,10 @@ __RCSID("$NetBSD: str.c,v 1.13 2005/05/30 19:45:02 wiz Exp $");
#include <fnmatch.h>
#endif
#include "lib.h"
+#include "dewey.h"
+
+/* pull in definitions and macros for resizing arrays as we go */
+#include "defs.h"
/*
* Return the suffix portion of a path
@@ -106,214 +110,11 @@ get_dash_string(char **s)
* Lowercase a whole string
*/
void
-str_lowercase(char *s)
+str_lowercase(unsigned char *s)
{
for (; *s; s++) {
- *s = tolower((unsigned char)*s);
- }
-}
-
-/* pull in definitions and macros for resizing arrays as we go */
-#include "defs.h"
-
-/* do not modify these values, or things will NOT work */
-enum {
- Alpha = -3,
- Beta = -2,
- RC = -1,
- Dot = 0,
- Patch = 1
-};
-
-/* this struct defines a version number */
-typedef struct arr_t {
- unsigned c; /* # of version numbers */
- unsigned size; /* size of array */
- int64_t *v; /* array of decimal numbers */
- int64_t netbsd; /* any "nb" suffix */
-} arr_t;
-
-/* this struct describes a test */
-typedef struct test_t {
- const char *s; /* string representation */
- unsigned len; /* length of string */
- int t; /* enumerated type of test */
-} test_t;
-
-enum {
- LT,
- LE,
- EQ,
- GE,
- GT,
- NE
-};
-
-/* the tests that are recognised. */
-static const test_t tests[] = {
- { "<=", 2, LE },
- { "<", 1, LT },
- { ">=", 2, GE },
- { ">", 1, GT },
- { "==", 2, EQ },
- { "!=", 2, NE },
- { NULL, 0, 0 }
-};
-
-static const test_t modifiers[] = {
- { "alpha", 5, Alpha },
- { "beta", 4, Beta },
- { "pre", 3, RC },
- { "rc", 2, RC },
- { "pl", 2, Dot },
- { "_", 1, Dot },
- { ".", 1, Dot },
- { NULL, 0, 0 }
-};
-
-
-
-/* locate the test in the tests array */
-static int
-mktest(int *op, const char *test)
-{
- const test_t *tp;
-
- for (tp = tests ; tp->s ; tp++) {
- if (strncasecmp(test, tp->s, tp->len) == 0) {
- *op = tp->t;
- return tp->len;
- }
- }
- warnx("relational test not found `%.10s'", test);
- return -1;
-}
-
-/*
- * make a component of a version number.
- * '.' encodes as Dot which is '0'
- * '_' encodes as 'patch level', or 'Dot', which is 0.
- * 'pl' encodes as 'patch level', or 'Dot', which is 0.
- * 'alpha' encodes as 'alpha version', or Alpha, which is -3.
- * 'beta' encodes as 'beta version', or Beta, which is -2.
- * 'rc' encodes as 'release candidate', or RC, which is -1.
- * 'nb' encodes as 'netbsd version', which is used after all other tests
- */
-static int
-mkcomponent(arr_t *ap, const char *num)
-{
- static const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
- const test_t *modp;
- int64_t n;
- const char *cp;
-
- if (*num == 0) {
- return 0;
- }
- ALLOC(int64_t, ap->v, ap->size, ap->c, 62, "mkver", exit(EXIT_FAILURE));
- if (isdigit((unsigned char)*num)) {
- for (cp = num, n = 0 ; isdigit((unsigned char)*num) ; num++) {
- n = (n * 10) + (*num - '0');
- }
- ap->v[ap->c++] = n;
- return (int)(num - cp);
- }
- for (modp = modifiers ; modp->s ; modp++) {
- if (strncasecmp(num, modp->s, modp->len) == 0) {
- ap->v[ap->c++] = modp->t;
- return modp->len;
- }
- }
- if (strncasecmp(num, "nb", 2) == 0) {
- for (cp = num, num += 2, n = 0 ; isdigit((unsigned char)*num) ; num++) {
- n = (n * 10) + (*num - '0');
- }
- ap->netbsd = n;
- return (int)(num - cp);
- }
- if (isalpha((unsigned char)*num)) {
- ap->v[ap->c++] = Dot;
- cp = strchr(alphas, tolower((unsigned char)*num));
- ALLOC(int64_t, ap->v, ap->size, ap->c, 62, "mkver", exit(EXIT_FAILURE));
- ap->v[ap->c++] = (int64_t)(cp - alphas) + 1;
- return 1;
- }
- warnx("`%c' not recognised", *num);
- return 1;
-}
-
-/* make a version number string into an array of comparable 64bit ints */
-static int
-mkversion(arr_t *ap, const char *num)
-{
- (void) memset(ap, 0, sizeof(arr_t));
- while (*num) {
- num += mkcomponent(ap, num);
- }
- return 1;
-}
-
-#define DIGIT(v, c, n) (((n) < (c)) ? v[n] : 0)
-
-/* compare the result against the test we were expecting */
-static int
-result(int64_t cmp, int tst)
-{
- switch(tst) {
- case LT:
- return cmp < 0;
- case LE:
- return cmp <= 0;
- case GT:
- return cmp > 0;
- case GE:
- return cmp >= 0;
- case EQ:
- return cmp == 0;
- case NE:
- return cmp != 0;
- default:
- warnx("result: unknown test %d", tst);
- return 0;
- }
-}
-
-/* do the test on the 2 vectors */
-static int
-vtest(arr_t *lhs, int tst, arr_t *rhs)
-{
- int64_t cmp;
- int c;
- int i;
-
- for (i = 0, c = MAX(lhs->c, rhs->c) ; i < c ; i++) {
- if ((cmp = DIGIT(lhs->v, lhs->c, i) - DIGIT(rhs->v, rhs->c, i)) != 0) {
- return result(cmp, tst);
- }
+ *s = tolower(*s);
}
- return result(lhs->netbsd - rhs->netbsd, tst);
-}
-
-/*
- * Compare two dewey decimal numbers
- */
-static int
-deweycmp(const char *lhs, int op, const char *rhs)
-{
- arr_t right;
- arr_t left;
-
- (void) memset(&left, 0, sizeof(left));
- if (!mkversion(&left, lhs)) {
- warnx("Bad lhs version `%s'", lhs);
- return 0;
- }
- (void) memset(&right, 0, sizeof(right));
- if (!mkversion(&right, rhs)) {
- warnx("Bad rhs version `%s'", rhs);
- return 0;
- }
- return vtest(&left, op, &right);
}
/*
@@ -365,73 +166,6 @@ alternate_match(const char *pattern, const char *pkg)
}
/*
- * Perform dewey match on "pkg" against "pattern".
- * Return 1 on match, 0 otherwise
- */
-static int
-dewey_match(const char *pattern, const char *pkg)
-{
- const char *version;
- const char *sep, *sep2;
- int op, op2;
- int n;
-
- /* compare names */
- if ((version=strrchr(pkg, '-')) == NULL) {
-#if 0
- /* too noisy, warns about "pkgdb.byfile.db" on
- * every invocation */
- warnx("Invalid package name `%s'", pkg);
-#endif
- return 0;
- }
- if ((sep = strpbrk(pattern, "<>")) == NULL)
- errx(EXIT_FAILURE, "dewey_match: '<' or '>' expected in `%s'", pattern);
- /* compare name lengths */
- if ((sep-pattern != version-pkg) ||
- strncmp(pkg, pattern, (size_t)(version-pkg)) != 0)
- return 0;
- version++;
-
- /* extract comparison operator */
- if ((n = mktest(&op, sep)) < 0) {
- warnx("Bad comparison `%s'", sep);
- return 0;
- }
- /* skip operator */
- sep += n;
-
- /* if greater than, look for less than */
- sep2 = NULL;
- if (op == GT || op == GE) {
- if ((sep2 = strchr(sep, '<')) != NULL) {
- if ((n = mktest(&op2, sep2)) < 0) {
- warnx("Bad comparison `%s'", sep2);
- return 0;
- }
- /* compare upper limit */
- if (!deweycmp(version, op2, sep2+n))
- return 0;
- }
- }
-
- /* compare only pattern / lower limit */
- if (sep2) {
- char ver[PKG_PATTERN_MAX];
-
- strlcpy(ver, sep, MIN(sizeof(ver), sep2-sep+1));
- if (deweycmp(version, op, ver))
- return 1;
- }
- else {
- if (deweycmp(version, op, sep))
- return 1;
- }
-
- return 0;
-}
-
-/*
* Perform glob match on "pkg" against "pattern".
* Return 1 on match, 0 otherwise
*/
@@ -579,7 +313,8 @@ findbestmatchingname_fn(const char *found, void *vp)
} else {
/* if best_version==NULL only if best==NULL
* (or best[0]='\0') */
- if (best == NULL || best[0] == '\0' || deweycmp(found_version, GT, best_version)) {
+ if (best == NULL || best[0] == '\0' ||
+ dewey_cmp(found_version, DEWEY_GT, best_version)) {
/* found pkg(version) is bigger than current "best"
* version - remember! */
strcpy(best, found);
diff --git a/pkgtools/pkg_install/files/lib/var.c b/pkgtools/pkg_install/files/lib/var.c
new file mode 100644
index 00000000000..825dbbe5447
--- /dev/null
+++ b/pkgtools/pkg_install/files/lib/var.c
@@ -0,0 +1,239 @@
+/* $NetBSD: var.c,v 1.1 2005/11/05 13:20:09 wiz Exp $ */
+
+/*-
+ * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron, Thomas Klausner, and Johnny Lam.
+ *
+ * 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. 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: var.c,v 1.1 2005/11/05 13:20:09 wiz Exp $");
+#endif
+
+#include <sys/stat.h>
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "lib.h"
+
+static const char *var_cmp(const char *, size_t, const char *, size_t);
+static void var_print(FILE *, const char *, const char *);
+
+char *
+var_get(const char *fname, const char *variable)
+{
+ FILE *fp;
+ char *line;
+ size_t len;
+ size_t varlen;
+ char *value;
+ size_t valuelen;
+ size_t thislen;
+ const char *p;
+
+ varlen = strlen(variable);
+ if (varlen == 0)
+ return NULL;
+
+ fp = fopen(fname, "r");
+ if (!fp) {
+ if (errno != ENOENT)
+ warn("var_get: can't open '%s' for reading", fname);
+ return NULL;
+ }
+
+ value = NULL;
+ valuelen = 0;
+
+ while ((line = fgetln(fp, &len)) != (char *) NULL) {
+ if (line[len - 1] == '\n')
+ --len;
+ if ((p=var_cmp(line, len, variable, varlen)) == NULL)
+ continue;
+
+ thislen = line+len - p;
+ if (value) {
+ value = realloc(value, valuelen+thislen+2);
+ value[valuelen++] = '\n';
+ }
+ else {
+ value = malloc(thislen+1);
+ }
+ sprintf(value+valuelen, "%.*s", (int)thislen, p);
+ valuelen += thislen;
+ }
+ (void) fclose(fp);
+ return value;
+}
+
+int
+var_set(const char *fname, const char *variable, const char *value)
+{
+ FILE *fp;
+ FILE *fout;
+ char *tmpname;
+ int fd;
+ char *line;
+ size_t len;
+ size_t varlen;
+ Boolean done;
+ struct stat st;
+
+ varlen = strlen(variable);
+ if (varlen == 0)
+ return 0;
+
+ fp = fopen(fname, "r");
+ if (!fp && errno != ENOENT) {
+ warn("var_set: can't open '%s' for reading", fname);
+ return -1;
+ }
+
+ tmpname = malloc(strlen(fname)+8);
+ sprintf(tmpname, "%s.XXXXXX", fname);
+ if ((fd=mkstemp(tmpname)) < 0) {
+ free(tmpname);
+ warn("var_set: can't open temp file for '%s' for writing",
+ fname);
+ return -1;
+ }
+ if (chmod(tmpname, 0644) < 0) {
+ close(fd);
+ free(tmpname);
+ warn("var_set: can't set permissions for temp file for '%s'",
+ fname);
+ return -1;
+ }
+ if ((fout=fdopen(fd, "w")) == NULL) {
+ close(fd);
+ remove(tmpname);
+ free(tmpname);
+ warn("var_set: can't open temp file for '%s' for writing",
+ fname);
+ return -1;
+ }
+
+ done = FALSE;
+
+ if (fp) {
+ while ((line = fgetln(fp, &len)) != (char *) NULL) {
+ if (var_cmp(line, len, variable, varlen) == NULL)
+ fprintf(fout, "%.*s", (int)len, line);
+ else {
+ if (!done && value) {
+ var_print(fout, variable, value);
+ done = TRUE;
+ }
+ }
+ }
+ (void) fclose(fp);
+ }
+
+ if (!done && value)
+ var_print(fout, variable, value);
+
+ if (fclose(fout) < 0) {
+ free(tmpname);
+ warn("var_set: write error for '%s'", fname);
+ return -1;
+ }
+
+ if (stat(tmpname, &st) < 0) {
+ free(tmpname);
+ warn("var_set: cannot stat tempfile for '%s'", fname);
+ return -1;
+ }
+
+ if (st.st_size == 0) {
+ if (remove(tmpname) < 0) {
+ free(tmpname);
+ warn("var_set: cannot remove tempfile for '%s'",
+ fname);
+ return -1;
+ }
+ free(tmpname);
+ if (remove(fname) < 0) {
+ warn("var_set: cannot remove '%s'", fname);
+ return -1;
+ }
+ return 0;
+ }
+
+ if (rename(tmpname, fname) < 0) {
+ free(tmpname);
+ warn("var_set: cannot move tempfile to '%s'", fname);
+ return -1;
+ }
+ free(tmpname);
+ return 0;
+}
+
+static const char *
+var_cmp(const char *line, size_t linelen, const char *var, size_t varlen)
+{
+ /*
+ * We expect lines to look like one of the following
+ * forms:
+ * VAR=value
+ * VAR= value
+ * We print out the value of VAR, or nothing if it
+ * doesn't exist.
+ */
+ if (linelen < varlen+1)
+ return NULL;
+ if (strncmp(var, line, varlen) != 0)
+ return NULL;
+
+ line += varlen;
+ if (*line != '=')
+ return NULL;
+
+ ++line;
+ linelen -= varlen+1;
+ if (linelen > 0 && *line == ' ')
+ ++line;
+ return line;
+}
+
+static void
+var_print(FILE *f, const char *variable, const char *value)
+{
+ const char *p;
+
+ while ((p=strchr(value, '\n')) != NULL) {
+ if (p != value)
+ fprintf(f, "%s=%.*s\n", variable, (int)(p-value), value);
+ value = p+1;
+ }
+
+ if (*value)
+ fprintf(f, "%s=%s\n", variable, value);
+}
diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h
index 8642bc8f70e..1bb1557f425 100644
--- a/pkgtools/pkg_install/files/lib/version.h
+++ b/pkgtools/pkg_install/files/lib/version.h
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.48 2005/10/30 21:27:47 joerg Exp $ */
+/* $NetBSD: version.h,v 1.49 2005/11/05 13:20:09 wiz 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 "20051030"
+#define PKGTOOLS_VERSION "20051103"
#endif /* _INST_LIB_VERSION_H_ */
diff --git a/pkgtools/pkg_install/files/pi2nbcompat b/pkgtools/pkg_install/files/pi2nbcompat
new file mode 100755
index 00000000000..820ff5bcf69
--- /dev/null
+++ b/pkgtools/pkg_install/files/pi2nbcompat
@@ -0,0 +1,141 @@
+#!/bin/sh
+#
+# $NetBSD: pi2nbcompat,v 1.1 2005/11/05 13:20:08 wiz Exp $
+#
+# Copyright (c) 2003 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# 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.
+#
+
+if [ $# -lt 2 ]; then echo "src2nbcompat src dest"; exit 1; fi
+
+src=$1
+dest=$2
+
+case $src in
+/*) ;;
+*) src=`pwd`/$src ;;
+esac
+
+case $dest in
+/*) ;;
+*) dest=`pwd`/$dest ;;
+esac
+
+make_dir()
+{
+ _d="$1"
+ _destdir="$2"
+ _newd=${3-`echo $_d | sed 's,^\./,,'`}
+ case $_newd in
+ *CVS)
+ ;;
+ .)
+ ;;
+ *)
+ mkdir -p $_destdir/$_newd
+ ;;
+ esac
+}
+
+copy_file()
+{
+ _f="$1"
+ _destdir="$2"
+ _newf=${3-`echo $_f | sed 's,^\./,,'`}
+ case $_newf in
+ *CVS/*)
+ # Skip copying over any CVS information.
+ ;;
+ *Makefile|*Makefile.inc)
+ # Skip copying over the Makefiles since we'll be using
+ # a GNU autoconf-based build infrastructure.
+ ;;
+ *.sh)
+ # Assume shell scripts will require variable substitution
+ # by the GNU configure script.
+ #
+ cp $_f $_destdir/$_newf.in
+ ;;
+ *.[1-9])
+ # Copy the manpage over, and generate the catpage.
+ cp $_newf $_destdir/$_newf.tmp
+ if [ -f $_destdir/$_newf ] && \
+ diff -q -I "\$NetBSD.*\$" $_destdir/$_newf $_destdir/$_newf.tmp >/dev/null; then
+ rm -f $_destdir/$_newf.tmp
+ else
+ mv -f $_destdir/$_newf.tmp $_destdir/$_newf
+ _catf=`echo $_newf | sed 's,\.\([1-9]\),.cat\1,'`
+ nroff -mandoc $_newf > $_destdir/$_catf
+ fi
+ ;;
+ *)
+ # Everything else just gets copied verbatim.
+ cp $_newf $_destdir/$_newf.tmp
+ if [ -f $_destdir/$_newf ] && \
+ diff -q -I "\$NetBSD.*\$" $_destdir/$_newf $_destdir/$_newf.tmp >/dev/null; then
+ rm -f $_destdir/$_newf.tmp
+ else
+ mv -f $_destdir/$_newf.tmp $_destdir/$_newf
+ fi
+ ;;
+ esac
+}
+
+if [ -f "$src" ]; then
+ srcdir=`dirname $src`
+ destdir=`dirname $dest`
+else
+ srcdir="$src"
+ destdir="$dest"
+fi
+
+echo "Preparing directory $destdir"
+mkdir -p $destdir
+
+if [ -f "$src" ]; then
+ echo "Copying $src to $dest"
+ cd $srcdir
+ copy_file `basename $src` $destdir `basename $dest`
+else
+ echo "Copying files and directories to $destdir"
+ cd $srcdir
+ find . -type d -print |
+ while read d; do
+ make_dir $d $destdir
+ done
+ find . \! -type d -print |
+ while read f; do
+ copy_file $f $destdir
+ done
+fi
diff --git a/pkgtools/pkg_install/files/pkg_install2nbcompat b/pkgtools/pkg_install/files/pkg_install2nbcompat
index f3d2ada51f8..d3aa3b84f7e 100755
--- a/pkgtools/pkg_install/files/pkg_install2nbcompat
+++ b/pkgtools/pkg_install/files/pkg_install2nbcompat
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $NetBSD: pkg_install2nbcompat,v 1.2 2005/02/03 23:53:23 jlam Exp $
+# $NetBSD: pkg_install2nbcompat,v 1.3 2005/11/05 13:20:09 wiz Exp $
#
# Copyright (c) 2004 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -47,7 +47,7 @@ if [ ! -d "${BSDSRCDIR}" ]; then
exit 1
fi
-src2nbcompat="${PKGSRCDIR}/pkgtools/libnbcompat/files/src2nbcompat"
+src2nbcompat="${PKGSRCDIR}/pkgtools/pkg_install/files/pi2nbcompat"
dest=$1
$src2nbcompat ${BSDSRCDIR}/usr.sbin/pkg_install $dest