Implement framework to store variable=value pairs about an installed package.

Use this in pkg_add to mark installed dependencies as automatically installed.

pkg_add: new flag -A: marks package as automatically installed.
pkg_admin: new commands set and unset to modify variable pairs for
	   installed packages.
pkg_info: report these variable pairs with -Q/-B.
	  new flag -u: report only manually installed packages (not
	  installed with pkg_add -A).
	  Error out if -a/-u and a package name is specified.

Joint work with Thomas Klausner.

As discussed on tech-pkg.
This commit is contained in:
dillo 2005-11-03 21:16:41 +00:00
parent 58ce78eeda
commit 75b9797969
16 changed files with 621 additions and 139 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: add.h,v 1.7 2004/12/10 21:49:31 erh Exp $ */
/* $NetBSD: add.h,v 1.8 2005/11/03 21:16:41 dillo 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;

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.34 2004/12/29 11:34:59 agc Exp $ */
/* $NetBSD: main.c,v 1.35 2005/11/03 21:16:41 dillo 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.34 2004/12/29 11:34:59 agc Exp $");
__RCSID("$NetBSD: main.c,v 1.35 2005/11/03 21:16:41 dillo Exp $");
#endif
#endif
@ -37,7 +37,7 @@ __RCSID("$NetBSD: main.c,v 1.34 2004/12/29 11:34:59 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;
@ -45,6 +45,7 @@ char *Viewbase = NULL;
Boolean NoView = FALSE;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
Boolean Automatic = FALSE;
char *Mode = NULL;
char *Owner = NULL;
@ -59,7 +60,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);
@ -76,6 +77,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;

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.111 2005/07/18 09:06:48 hubertf Exp $ */
/* $NetBSD: perform.c,v 1.112 2005/11/03 21:16:41 dillo 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.111 2005/07/18 09:06:48 hubertf Exp $");
__RCSID("$NetBSD: perform.c,v 1.112 2005/11/03 21:16:41 dillo Exp $");
#endif
#endif
@ -149,7 +149,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)
@ -456,7 +457,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 */
}
@ -900,6 +909,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);
}
@ -1023,4 +1034,3 @@ pkg_perform(lpkg_head_t *pkgs)
return err_cnt;
}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_add.1,v 1.60 2005/07/18 09:06:49 hubertf Exp $
.\" $NetBSD: pkg_add.1,v 1.61 2005/11/03 21:16:41 dillo 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.

View File

@ -1,8 +1,8 @@
/* $NetBSD: main.c,v 1.48 2005/03/11 22:52:04 rillig Exp $ */
/* $NetBSD: main.c,v 1.49 2005/11/03 21:16:41 dillo Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: main.c,v 1.48 2005/03/11 22:52:04 rillig Exp $");
__RCSID("$NetBSD: main.c,v 1.49 2005/11/03 21:16:41 dillo Exp $");
#endif
/*
@ -44,6 +44,7 @@ __RCSID("$NetBSD: main.c,v 1.48 2005/03/11 22:52:04 rillig Exp $");
#include <md5.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "lib.h"
@ -57,10 +58,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"
@ -68,6 +70,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"
@ -76,7 +80,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);
}
@ -420,7 +424,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];
@ -428,10 +431,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) {
@ -467,7 +470,7 @@ main(int argc, char *argv[])
break;
default:
usage(prog);
usage();
/* NOTREACHED */
}
@ -475,7 +478,7 @@ main(int argc, char *argv[])
argv += optind;
if (argc <= 0) {
usage(prog);
usage();
}
if (use_default_sfx)
@ -488,7 +491,7 @@ main(int argc, char *argv[])
argv++; /* "pmatch" */
if (argv[0] == NULL || argv[1] == NULL) {
usage(prog);
usage();
}
pattern = argv[0];
@ -666,6 +669,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) {
@ -710,12 +719,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)
{

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_admin.1,v 1.35 2005/02/26 14:09:58 grant Exp $
.\" $NetBSD: pkg_admin.1,v 1.36 2005/11/03 21:16:41 dillo 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

View File

@ -1,4 +1,4 @@
/* $NetBSD: info.h,v 1.20 2005/02/16 08:35:26 agc Exp $ */
/* $NetBSD: info.h,v 1.21 2005/11/03 21:16:41 dillo 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 *);

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.45 2005/02/10 22:52:31 grant Exp $ */
/* $NetBSD: main.c,v 1.46 2005/11/03 21:16:41 dillo Exp $ */
#include <sys/cdefs.h>
#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.45 2005/02/10 22:52:31 grant Exp $");
__RCSID("$NetBSD: main.c,v 1.46 2005/11/03 21:16:41 dillo Exp $");
#endif
#endif
@ -38,10 +38,10 @@ __RCSID("$NetBSD: main.c,v 1.45 2005/02/10 22:52:31 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 = "";
@ -57,8 +57,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);
}
@ -77,7 +77,7 @@ main(int argc, char **argv)
break;
case 'a':
AllInstalled = TRUE;
Which = WHICH_ALL;
break;
case 'B':
@ -177,6 +177,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' */
@ -200,13 +204,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");
}
@ -239,7 +250,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");
}
@ -282,7 +293,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)) {

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.62 2005/02/20 14:41:05 grant Exp $ */
/* $NetBSD: perform.c,v 1.63 2005/11/03 21:16:41 dillo Exp $ */
#include <sys/cdefs.h>
#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.62 2005/02/20 14:41:05 grant Exp $");
__RCSID("$NetBSD: perform.c,v 1.63 2005/11/03 21:16:41 dillo Exp $");
#endif
#endif
@ -104,7 +104,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
@ -170,7 +175,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;
@ -195,7 +204,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);
@ -204,28 +213,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);
@ -234,16 +248,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)) {
@ -342,17 +367,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];
@ -366,7 +389,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);
}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_info.1,v 1.49 2005/05/30 13:10:14 wiz Exp $
.\" $NetBSD: pkg_info.1,v 1.50 2005/11/03 21:16:41 dillo 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

View File

@ -1,11 +1,11 @@
/* $NetBSD: show.c,v 1.31 2005/02/16 08:35:26 agc Exp $ */
/* $NetBSD: show.c,v 1.32 2005/11/03 21:16:41 dillo Exp $ */
#include <sys/cdefs.h>
#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.31 2005/02/16 08:35:26 agc Exp $");
__RCSID("$NetBSD: show.c,v 1.32 2005/11/03 21:16:41 dillo Exp $");
#endif
#endif
@ -99,7 +99,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];
@ -120,49 +120,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

View File

@ -1,11 +1,11 @@
# $NetBSD: Makefile,v 1.23 2004/05/23 02:24:52 lukem Exp $
# $NetBSD: Makefile,v 1.24 2005/11/03 21:16:41 dillo Exp $
# Original from FreeBSD, no rcs id.
MKPRIVATELIB= yes
LIB= install
SRCS= file.c ftpio.c global.c lpkg.c pen.c pkgdb.c \
plist.c str.c version.c path.c fexec.c
SRCS= automatic.c file.c ftpio.c global.c lpkg.c pen.c \
pkgdb.c plist.c str.c version.c path.c fexec.c var.c
version.o: version.h version.c

View File

@ -0,0 +1,80 @@
/* $NetBSD: automatic.c,v 1.1 2005/11/03 21:16:41 dillo 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/03 21:16:41 dillo 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);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lib.h,v 1.76 2005/05/31 22:29:41 wiz Exp $ */
/* $NetBSD: lib.h,v 1.77 2005/11/03 21:16:41 dillo Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@ -126,12 +126,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.
@ -258,6 +262,16 @@ 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(unsigned char *);

View File

@ -0,0 +1,239 @@
/* $NetBSD: var.c,v 1.1 2005/11/03 21:16:41 dillo 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/03 21:16:41 dillo 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", 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", 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, p-value, value);
value = p+1;
}
if (*value)
fprintf(f, "%s=%s\n", variable, value);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.69 2005/10/30 21:52:02 joerg Exp $ */
/* $NetBSD: version.h,v 1.70 2005/11/03 21:16:41 dillo 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_ */