Use err(3). Cosmetics in usage string and man page.

This commit is contained in:
Philippe Charnier 1997-10-08 07:48:21 +00:00
parent 4586e1abc5
commit 6fed414929
25 changed files with 310 additions and 377 deletions

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id: extract.c,v 1.15 1997/06/30 02:57:40 jkh Exp $";
static const char rcsid[] =
"$Id: extract.c,v 1.16 1997/07/01 06:13:35 jkh Exp $";
#endif
/*
@ -22,6 +23,7 @@ static const char *rcsid = "$Id: extract.c,v 1.15 1997/06/30 02:57:40 jkh Exp $"
*
*/
#include <err.h>
#include "lib.h"
#include "add.h"
@ -35,7 +37,8 @@ static const char *rcsid = "$Id: extract.c,v 1.15 1997/06/30 02:57:40 jkh Exp $"
strcat(where_args, "|tar xf - -C "); \
strcat(where_args, todir); \
if (system(where_args)) \
barf("can not invoke %d byte tar pipeline: %s", strlen(where_args), where_args); \
cleanup(0), errx(2, "can not invoke %d byte tar pipeline: %s", \
strlen(where_args), where_args); \
strcpy(where_args, STARTSTRING); \
where_count = sizeof(STARTSTRING)-1; \
} \
@ -59,7 +62,7 @@ rollback(char *name, char *home, PackingList start, PackingList stop)
(void)chflags(try, 0);
(void)unlink(try);
if (rename(bup, try))
whinge("rollback: unable to rename %s back to %s.", bup, try);
warnx("rollback: unable to rename %s back to %s", bup, try);
}
}
else if (q->type == PLIST_CWD) {
@ -83,10 +86,10 @@ extract_plist(char *home, Package *pkg)
maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */
where_args = alloca(maxargs);
if (!where_args)
barf("can't get argument list space");
cleanup(0), errx(2, "can't get argument list space");
perm_args = alloca(maxargs);
if (!perm_args)
barf("can't get argument list space");
cleanup(0), errx(2, "can't get argument list space");
strcpy(where_args, STARTSTRING);
where_count = sizeof(STARTSTRING)-1;
@ -129,7 +132,9 @@ extract_plist(char *home, Package *pkg)
if (make_preserve_name(pf, FILENAME_MAX, PkgName, try)) {
if (rename(try, pf)) {
whinge("Unable to back up %s to %s, aborting pkg_add", try, pf);
warnx(
"unable to back up %s to %s, aborting pkg_add",
try, pf);
rollback(PkgName, home, pkg->head, p);
return;
}
@ -143,7 +148,7 @@ extract_plist(char *home, Package *pkg)
}
add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "%s ", p->name);
if (add_count > maxargs - perm_count)
barf("oops, miscounted strings!");
cleanup(0), errx(2, "oops, miscounted strings!");
perm_count += add_count;
}
else {
@ -157,13 +162,13 @@ extract_plist(char *home, Package *pkg)
}
add_count = snprintf(&where_args[where_count], maxargs - where_count, " %s", p->name);
if (add_count > maxargs - where_count)
barf("oops, miscounted strings!");
cleanup(0), errx(2, "oops, miscounted strings!");
where_count += add_count;
add_count = snprintf(&perm_args[perm_count],
maxargs - perm_count,
"%s ", p->name);
if (add_count > maxargs - perm_count)
barf("oops, miscounted strings!");
cleanup(0), errx(2, "oops, miscounted strings!");
perm_count += add_count;
}
}
@ -175,7 +180,8 @@ extract_plist(char *home, Package *pkg)
PUSHOUT(Directory);
if (strcmp(p->name, ".")) {
if (!Fake && make_hierarchy(p->name) == FAIL)
barf("Unable make directory '%s'.", p->name);
cleanup(0), errx(2, "unable to make directory '%s'",
p->name);
Directory = p->name;
}
else
@ -184,13 +190,14 @@ extract_plist(char *home, Package *pkg)
case PLIST_CMD:
if (last_file == NULL)
barf("No last file specified for '%s' command.", p->name);
cleanup(0), errx(2, "no last file specified for '%s' command",
p->name);
format_cmd(cmd, p->name, Directory, last_file);
PUSHOUT(Directory);
if (Verbose)
printf("extract: execute '%s'\n", cmd);
if (!Fake && system(cmd))
whinge("Command '%s' failed.", cmd);
warnx("command '%s' failed", cmd);
break;
case PLIST_CHMOD:

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id$";
static const char rcsid[] =
"$Id: futil.c,v 1.6 1997/02/22 16:09:17 peter Exp $";
#endif
/*
@ -22,6 +23,7 @@ static const char *rcsid = "$Id$";
*
*/
#include <err.h>
#include "lib.h"
#include "add.h"
@ -73,22 +75,19 @@ apply_perms(char *dir, char *arg)
if (Mode)
if (vsystem("cd %s && chmod -R %s %s", cd_to, Mode, arg))
whinge("Couldn't change modes of '%s' to '%s'.",
arg, Mode);
warnx("couldn't change modes of '%s' to '%s'", arg, Mode);
if (Owner && Group) {
if (vsystem("cd %s && chown -R %s.%s %s", cd_to, Owner, Group, arg))
whinge("Couldn't change owner/group of '%s' to '%s.%s'.",
warnx("couldn't change owner/group of '%s' to '%s.%s'",
arg, Owner, Group);
return;
}
if (Owner) {
if (vsystem("cd %s && chown -R %s %s", cd_to, Owner, arg))
whinge("Couldn't change owner of '%s' to '%s'.",
arg, Owner);
warnx("couldn't change owner of '%s' to '%s'", arg, Owner);
return;
} else if (Group)
if (vsystem("cd %s && chgrp -R %s %s", cd_to, Group, arg))
whinge("Couldn't change group of '%s' to '%s'.",
arg, Group);
warnx("couldn't change group of '%s' to '%s'", arg, Group);
}

View File

@ -1,5 +1,6 @@
#ifndef lint
static char *rcsid = "$Id: main.c,v 1.14 1997/03/31 05:10:45 imp Exp $";
static const char rcsid[] =
"$Id: main.c,v 1.15 1997/09/18 14:08:27 phk Exp $";
#endif
/*
@ -23,6 +24,7 @@ static char *rcsid = "$Id: main.c,v 1.14 1997/03/31 05:10:45 imp Exp $";
*
*/
#include <err.h>
#include <sys/param.h>
#include "lib.h"
#include "add.h"
@ -45,12 +47,14 @@ add_mode_t AddMode = NORMAL;
char pkgnames[MAX_PKGS][MAXPATHLEN];
char *pkgs[MAX_PKGS];
static void usage __P((void));
int
main(int argc, char **argv)
{
int ch, err;
char **start;
char *prog_name = argv[0], *cp;
char *cp;
start = argv;
while ((ch = getopt(argc, argv, Options)) != -1) {
@ -95,7 +99,7 @@ main(int argc, char **argv)
case 'h':
case '?':
default:
usage(prog_name, NULL);
usage();
break;
}
}
@ -103,7 +107,7 @@ main(int argc, char **argv)
argv += optind;
if (argc > MAX_PKGS) {
whinge("Too many packages (max %d).", MAX_PKGS);
warnx("too many packages (max %d)", MAX_PKGS);
return(1);
}
@ -121,7 +125,7 @@ main(int argc, char **argv)
pkgs[ch] = realpath(*argv, pkgnames[ch]);
else { /* look for the file in the expected places */
if (!(cp = fileFindByPath(NULL, *argv)))
whinge("Can't find package '%s'.", *argv);
warnx("can't find package '%s'", *argv);
else
pkgs[ch] = strcpy(pkgnames[ch], cp);
}
@ -130,39 +134,24 @@ main(int argc, char **argv)
}
/* If no packages, yelp */
else if (!ch)
usage(prog_name, "Missing package name(s)");
warnx("missing package name(s)"), usage();
else if (ch > 1 && AddMode == MASTER)
usage(prog_name, "Only one package name may be specified with master mode");
warnx("only one package name may be specified with master mode"),
usage();
if ((err = pkg_perform(pkgs)) != 0) {
if (Verbose)
fprintf(stderr, "%d package addition(s) failed.\n", err);
warnx("%d package addition(s) failed", err);
return err;
}
else
return 0;
}
void
usage(const char *name, const char *fmt, ...)
static void
usage()
{
va_list args;
va_start(args, fmt);
if (fmt) {
fprintf(stderr, "%s: ", name);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n\n");
}
va_end(args);
fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name);
fprintf(stderr, "Where args are one or more of:\n\n");
fprintf(stderr, "-v verbose\n");
fprintf(stderr, "-p arg override prefix with arg\n");
fprintf(stderr, "-I don't execute pkg install script, if any\n");
fprintf(stderr, "-R don't record installation (can't delete!)\n");
fprintf(stderr, "-n don't actually install, just show steps\n");
fprintf(stderr, "-t temp use temp as template for mktemp()\n");
fprintf(stderr, "-S run in SLAVE mode\n");
fprintf(stderr, "-M run in MASTER mode\n");
fprintf(stderr, "%s\n%s\n",
"usage: pkg_add [-vInfRMS] [-t template] [-p prefix]",
" pkg-name [pkg-name ...]");
exit(1);
}

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id: perform.c,v 1.41 1997/02/22 16:09:20 peter Exp $";
static const char rcsid[] =
"$Id: perform.c,v 1.42 1997/06/29 10:41:44 jkh Exp $";
#endif
/*
@ -22,6 +23,7 @@ static const char *rcsid = "$Id: perform.c,v 1.41 1997/02/22 16:09:20 peter Exp
*
*/
#include <err.h>
#include "lib.h"
#include "add.h"
@ -80,7 +82,7 @@ pkg_do(char *pkg)
fgets(playpen, FILENAME_MAX, stdin);
playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */
if (chdir(playpen) == FAIL) {
whinge("pkg_add in SLAVE mode can't chdir to %s.", playpen);
warnx("pkg_add in SLAVE mode can't chdir to %s", playpen);
return 1;
}
read_plist(&Plist, stdin);
@ -91,14 +93,16 @@ pkg_do(char *pkg)
/* Is it an ftp://foo.bar.baz/file.tgz specification? */
if (isURL(pkg)) {
if (!(Home = fileGetURL(NULL, pkg))) {
whinge("Unable to fetch `%s' by URL.", pkg);
warnx("unable to fetch `%s' by URL", pkg);
return 1;
}
where_to = Home;
strcpy(pkg_fullname, pkg);
cfile = fopen(CONTENTS_FNAME, "r");
if (!cfile) {
whinge("Unable to open table of contents file `%s' - not a package?", CONTENTS_FNAME);
warnx(
"unable to open table of contents file `%s' - not a package?",
CONTENTS_FNAME);
goto bomb;
}
read_plist(&Plist, cfile);
@ -108,7 +112,7 @@ pkg_do(char *pkg)
strcpy(pkg_fullname, pkg); /* copy for sanity's sake, could remove pkg_fullname */
if (strcmp(pkg, "-")) {
if (stat(pkg_fullname, &sb) == FAIL) {
whinge("Can't stat package file '%s'.", pkg_fullname);
warnx("can't stat package file '%s'", pkg_fullname);
goto bomb;
}
sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME);
@ -120,15 +124,19 @@ pkg_do(char *pkg)
}
Home = make_playpen(playpen, sb.st_size * 4);
if (!Home)
whinge("Unable to make playpen for %d bytes.\n", sb.st_size * 4);
warnx("unable to make playpen for %d bytes", sb.st_size * 4);
where_to = Home;
if (unpack(pkg_fullname, extract)) {
whinge("Unable to extract table of contents file from `%s' - not a package?.", pkg_fullname);
warnx(
"unable to extract table of contents file from `%s' - not a package?",
pkg_fullname);
goto bomb;
}
cfile = fopen(CONTENTS_FNAME, "r");
if (!cfile) {
whinge("Unable to open table of contents file `%s' - not a package?", CONTENTS_FNAME);
warnx(
"unable to open table of contents file `%s' - not a package?",
CONTENTS_FNAME);
goto bomb;
}
read_plist(&Plist, cfile);
@ -145,8 +153,7 @@ pkg_do(char *pkg)
printf("Desired prefix of %s does not exist, creating..\n", p->name);
vsystem("mkdir -p %s", p->name);
if (chdir(p->name) == -1) {
whinge("Unable to change directory to `%s' - no permission?", p->name);
perror("chdir");
warn("unable to change directory to `%s'", p->name);
goto bomb;
}
}
@ -154,7 +161,9 @@ pkg_do(char *pkg)
inPlace = 1;
}
else {
whinge("No prefix specified in `%s' - this is a bad package!", pkg_fullname);
warnx(
"no prefix specified in `%s' - this is a bad package!",
pkg_fullname);
goto bomb;
}
}
@ -166,10 +175,11 @@ pkg_do(char *pkg)
*/
if (!inPlace && min_free(playpen) < sb.st_size * 4) {
whinge("Projected size of %d exceeds available free space.\n"
"Please set your PKG_TMPDIR variable to point to a location with more\n"
"free space and try again.", sb.st_size * 4);
whinge("Not extracting %s\ninto %s, sorry!", pkg_fullname, where_to);
warnx("projected size of %d exceeds available free space.\n"
"Please set your PKG_TMPDIR variable to point to a location with more\n"
"free space and try again", sb.st_size * 4);
warnx("not extracting %s\ninto %s, sorry!",
pkg_fullname, where_to);
goto bomb;
}
@ -179,7 +189,7 @@ pkg_do(char *pkg)
/* Finally unpack the whole mess */
if (unpack(pkg_fullname, NULL)) {
whinge("Unable to extract `%s'!", pkg_fullname);
warnx("unable to extract `%s'!", pkg_fullname);
goto bomb;
}
}
@ -212,7 +222,7 @@ pkg_do(char *pkg)
/* See if we're already registered */
sprintf(LogDir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, PkgName);
if (isdir(LogDir) && !Force) {
whinge("Package `%s' already recorded as installed.\n", PkgName);
warnx("package `%s' already recorded as installed", PkgName);
code = 1;
goto success; /* close enough for government work */
}
@ -237,7 +247,8 @@ pkg_do(char *pkg)
if (Verbose)
printf("Loading it from %s.\n", cp);
if (vsystem("pkg_add %s", cp)) {
whinge("Autoload of dependency `%s' failed%s", cp, Force ? " (proceeding anyway)" : "!");
warnx("autoload of dependency `%s' failed%s",
cp, Force ? " (proceeding anyway)" : "!");
if (!Force)
++code;
}
@ -247,12 +258,14 @@ pkg_do(char *pkg)
if (Verbose)
printf("Finished loading %s over FTP.\n", p->name);
if (!fexists("+CONTENTS")) {
whinge("Autoloaded package %s has no +CONTENTS file?", p->name);
warnx("autoloaded package %s has no +CONTENTS file?",
p->name);
if (!Force)
++code;
}
else if (vsystem("(pwd; cat +CONTENTS) | pkg_add %s-S", Verbose ? "-v " : "")) {
whinge("pkg_add of dependency `%s' failed%s", p->name, Force ? " (proceeding anyway)" : "!");
warnx("pkg_add of dependency `%s' failed%s",
p->name, Force ? " (proceeding anyway)" : "!");
if (!Force)
++code;
}
@ -285,8 +298,8 @@ pkg_do(char *pkg)
if (Verbose)
printf("Running requirements file first for %s..\n", PkgName);
if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, PkgName)) {
whinge("Package %s fails requirements %s", pkg_fullname,
Force ? "installing anyway" : "- not installed.");
warnx("package %s fails requirements %s", pkg_fullname,
Force ? "installing anyway" : "- not installed");
if (!Force) {
code = 1;
goto success; /* close enough for government work */
@ -300,7 +313,7 @@ pkg_do(char *pkg)
if (Verbose)
printf("Running install with PRE-INSTALL for %s..\n", PkgName);
if (!Fake && vsystem("./%s %s PRE-INSTALL", INSTALL_FNAME, PkgName)) {
whinge("Install script returned error status.");
warnx("install script returned error status");
unlink(INSTALL_FNAME);
code = 1;
goto success; /* nothing to uninstall yet */
@ -319,7 +332,7 @@ pkg_do(char *pkg)
printf("mtree -U -f %s -d -e -p %s\n", MTREE_FNAME, p ? p->name : "/");
if (!Fake) {
if (vsystem("/usr/sbin/mtree -U -f %s -d -e -p %s", MTREE_FNAME, p ? p->name : "/"))
whinge("mtree returned a non-zero status - continuing.");
warnx("mtree returned a non-zero status - continuing");
}
unlink(MTREE_FNAME);
}
@ -329,7 +342,7 @@ pkg_do(char *pkg)
if (Verbose)
printf("Running install with POST-INSTALL for %s..\n", PkgName);
if (!Fake && vsystem("./%s %s POST-INSTALL", INSTALL_FNAME, PkgName)) {
whinge("Install script returned error status.");
warnx("install script returned error status");
unlink(INSTALL_FNAME);
code = 1;
goto fail;
@ -344,9 +357,9 @@ pkg_do(char *pkg)
umask(022);
if (getuid() != 0)
whinge("Not running as root - trying to record install anyway.");
warnx("not running as root - trying to record install anyway");
if (!PkgName) {
whinge("No package name! Can't record package, sorry.");
warnx("no package name! can't record package, sorry");
code = 1;
goto success; /* well, partial anyway */
}
@ -354,7 +367,7 @@ pkg_do(char *pkg)
if (Verbose)
printf("Attempting to record package into %s..\n", LogDir);
if (make_hierarchy(LogDir)) {
whinge("Can't record package into '%s', you're on your own!",
warnx("can't record package into '%s', you're on your own!",
LogDir);
bzero(LogDir, FILENAME_MAX);
code = 1;
@ -369,7 +382,8 @@ pkg_do(char *pkg)
sprintf(contents, "%s/%s", LogDir, CONTENTS_FNAME);
cfile = fopen(contents, "w");
if (!cfile) {
whinge("Can't open new contents file '%s'! Can't register pkg.", contents);
warnx("can't open new contents file '%s'! can't register pkg",
contents);
goto success; /* can't log, but still keep pkg */
}
write_plist(&Plist, cfile);
@ -387,12 +401,12 @@ pkg_do(char *pkg)
basename_of(p->name), REQUIRED_BY_FNAME);
cfile = fopen(contents, "a");
if (!cfile)
whinge("Warning: Can't open dependency file '%s'!\n"
"\tDependency registration is incomplete.", contents);
warnx("can't open dependency file '%s'!\n"
"dependency registration is incomplete", contents);
else {
fprintf(cfile, "%s\n", PkgName);
if (fclose(cfile) == EOF)
whinge("Cannot properly close file %s", contents);
warnx("cannot properly close file %s", contents);
}
}
if (Verbose)
@ -412,7 +426,7 @@ pkg_do(char *pkg)
putc('\n', stdout);
(void) fclose(fp);
} else
whinge("Cannot open %s as display file.", buf);
warnx("cannot open %s as display file", buf);
}
goto success;
@ -439,15 +453,15 @@ sanity_check(char *pkg)
int code = 0;
if (!fexists(CONTENTS_FNAME)) {
whinge("Package %s has no CONTENTS file!", pkg);
warnx("package %s has no CONTENTS file!", pkg);
code = 1;
}
else if (!fexists(COMMENT_FNAME)) {
whinge("Package %s has no COMMENT file!", pkg);
warnx("package %s has no COMMENT file!", pkg);
code = 1;
}
else if (!fexists(DESC_FNAME)) {
whinge("Package %s has no DESC file!", pkg);
warnx("package %s has no DESC file!", pkg);
code = 1;
}
return code;

View File

@ -21,7 +21,7 @@
.Os FreeBSD
.Sh NAME
.Nm pkg_add
.Nd a utility for installing software package distributions.
.Nd a utility for installing software package distributions
.Sh SYNOPSIS
.Nm
.Op Fl vInfRMS
@ -64,36 +64,31 @@ command to examine the package file.
.Ef
.Sh OPTIONS
The following command line arguments are supported.
The following command line arguments are supported:
.Bl -tag -width indent
.It Ar pkg-name [... pkg-name]
The named packages are installed. A package name of - will cause
.Nm
to read from stdin.
.It Fl v
Turns on verbose output.
.Em "Optional."
Turn on verbose output.
.It Fl I
If an installation script exists for a given package, do not execute it.
.Em "Optional."
.It Fl n
Don't actually install a package, just report the steps that
would be taken if it was.
.Em "Optional."
.It Fl R
Do not record the installation of a package. This means
that you cannot deinstall it later, so only use this option if
you know what you are doing!
.Em "Optional."
.It Fl f
Forces installation to proceed even if prerequisite packages are not
Force installation to proceed even if prerequisite packages are not
installed or the requirements script fails. Although
.Nm
will still try to find and auto-install missing prerequisite packages,
a failure to find one will not be fatal.
.Em "Optional."
.It Fl p Ar prefix
Sets
Set
.Ar prefix
as the directory in which to extract files from a package.
If a package has set its default directory, it will be overridden
@ -114,7 +109,6 @@ modes (see the
and
.Fl S
options).
.Em "Optional."
.It Fl t Ar template
Use
.Ar template
@ -136,7 +130,6 @@ You can get a performance boost by setting the staging area
to reside on the same disk partition as target directories for package
file installation; often this is
.Pa /usr .
.Em "Optional."
.It Fl M
Run in
.Cm MASTER
@ -199,7 +192,7 @@ passive mode
.Ef
ftp.
.Sh TECHNICAL DETAILS
.Nm
.Nm Pkg_add
is fairly simple. It extracts each package's "packing list"
into a special staging directory in /tmp (or $PKG_TMPDIR if set), parses it,
and then runs through the following sequence to fully extract the contents:
@ -222,7 +215,8 @@ directives which control how the package is added to the system.
At the time of this writing, the only currently implemented option is
.Cm @option extract-in-place
which will cause the package to be extracted directly into its
prefix directory without moving through a staging area in /tmp.
prefix directory without moving through a staging area in
.Pa /tmp .
.It
If
.Cm @option extract-in-place

View File

@ -1,4 +1,4 @@
/* $Id: create.h,v 1.11 1997/02/22 16:09:24 peter Exp $ */
/* $Id: create.h,v 1.12 1997/06/06 12:19:11 jkh Exp $ */
/*
* FreeBSD install - a package for the installation and maintainance
@ -40,7 +40,6 @@ extern int Dereference;
extern int PlistOnly;
void check_list(char *, Package *);
void usage(const char *, const char *, ...);
int pkg_perform(char **);
void copy_plist(char *, Package *);

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id: main.c,v 1.15 1997/03/31 05:10:47 imp Exp $";
static const char rcsid[] =
"$Id: main.c,v 1.16 1997/06/06 12:19:11 jkh Exp $";
#endif
/*
@ -13,6 +14,7 @@ static const char *rcsid = "$Id: main.c,v 1.15 1997/03/31 05:10:47 imp Exp $";
*
*/
#include <err.h>
#include "lib.h"
#include "create.h"
@ -34,12 +36,13 @@ char PlayPen[FILENAME_MAX];
int Dereference = 0;
int PlistOnly = 0;
static void usage __P((void));
int
main(int argc, char **argv)
{
int ch;
char **pkgs, **start;
char *prog_name = argv[0];
pkgs = start = argv;
while ((ch = getopt(argc, argv, Options)) != -1)
@ -118,7 +121,7 @@ main(int argc, char **argv)
case '?':
default:
usage(prog_name, NULL);
usage();
break;
}
@ -131,51 +134,27 @@ main(int argc, char **argv)
/* If no packages, yelp */
if (pkgs == start)
usage(prog_name, "Missing package name");
warnx("missing package name"), usage();
*pkgs = NULL;
if (start[1])
usage(prog_name, "Only one package name allowed\n\t('%s' extraneous)",
start[1]);
warnx("only one package name allowed ('%s' extraneous)", start[1]),
usage();
if (!pkg_perform(start)) {
if (Verbose)
fprintf(stderr, "Package creation failed.\n");
warnx("package creation failed");
return 1;
}
else
return 0;
}
void
usage(const char *name, const char *fmt, ...)
static void
usage()
{
va_list args;
va_start(args, fmt);
if (fmt) {
fprintf(stderr, "%s: ", name);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n\n");
}
va_end(args);
fprintf(stderr, "Usage: %s [args] pkg\n\n", name);
fprintf(stderr, "Where args are one or more of:\n\n");
fprintf(stderr, "-c [-]file Get one-line comment from file (-or arg)\n");
fprintf(stderr, "-d [-]file Get description from file (-or arg)\n");
fprintf(stderr, "-f file get list of files from file (- for stdin)\n");
fprintf(stderr, "-h follow symbolic links\n");
fprintf(stderr, "-i script install script\n");
fprintf(stderr, "-k script de-install script\n");
fprintf(stderr, "-D file install notice\n");
fprintf(stderr, "-m file mtree spec for directories\n");
fprintf(stderr, "-P pkgs set package dependency list to pkgs\n");
fprintf(stderr, "-p prefix install prefix will be arg\n");
fprintf(stderr, "-r script pre/post requirements script\n");
fprintf(stderr, "-t temp use temp as template for mktemp()\n");
fprintf(stderr, "-X file exclude files listed in file\n");
fprintf(stderr, "-v verbose\n");
fprintf(stderr, "-Y assume `yes' answer to all questions\n");
fprintf(stderr, "-N assume `no' answer to all questions\n");
fprintf(stderr, "-O print a revised packing list and exit\n");
fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: pkg_create [-YNOhv] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
" [-k dscript] [-r rscript] [-t template] [-X excludefile]",
" [-D displayfile] [-m mtreefile] -c comment -d description",
" -f packlist pkg-name");
exit(1);
}

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id: perform.c,v 1.35 1997/06/06 12:19:11 jkh Exp $";
static const char rcsid[] =
"$Id: perform.c,v 1.36 1997/07/04 04:48:02 jkh Exp $";
#endif
/*
@ -25,7 +26,7 @@ static const char *rcsid = "$Id: perform.c,v 1.35 1997/06/06 12:19:11 jkh Exp $"
#include "lib.h"
#include "create.h"
#include <errno.h>
#include <err.h>
#include <signal.h>
#include <sys/syslimits.h>
#include <sys/wait.h>
@ -56,7 +57,8 @@ pkg_perform(char **pkgs)
else {
pkg_in = fopen(Contents, "r");
if (!pkg_in)
barf("Unable to open contents file '%s' for input.", Contents);
cleanup(0), errx(2, "unable to open contents file '%s' for input",
Contents);
}
plist.head = plist.tail = NULL;
@ -168,10 +170,10 @@ pkg_perform(char **pkgs)
/* Finally, write out the packing list */
fp = fopen(CONTENTS_FNAME, "w");
if (!fp)
barf("Can't open file %s for writing.", CONTENTS_FNAME);
cleanup(0), errx(2, "can't open file %s for writing", CONTENTS_FNAME);
write_plist(&plist, fp);
if (fclose(fp))
barf("Error while closing %s.", CONTENTS_FNAME);
cleanup(0), errx(2, "error while closing %s", CONTENTS_FNAME);
/* And stick it into a tar ball */
make_dist(home, pkg, suffix, &plist);
@ -223,21 +225,22 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
/* Set up a pipe for passing the filenames, and fork off a tar process. */
if (pipe(pipefds) == -1)
barf("Cannot create pipe: %s", strerror(errno));
cleanup(0), errx(2, "cannot create pipe");
if ((pid = fork()) == -1)
barf("Cannot fork process for tar: %s", strerror(errno));
cleanup(0), errx(2, "cannot fork process for tar");
if (pid == 0) { /* The child */
dup2(pipefds[0], 0);
close(pipefds[0]);
close(pipefds[1]);
execv("/usr/bin/tar", args);
barf("Failed to execute tar command: %s", strerror(errno));
cleanup(0);
errx(2, "failed to execute tar command");
}
/* Meanwhile, back in the parent process ... */
close(pipefds[0]);
if ((totar = fdopen(pipefds[1], "w")) == NULL)
barf("fdopen failed: %s", strerror(errno));
cleanup(0), errx(2, "fdopen failed");
fprintf(totar, "%s\n", CONTENTS_FNAME);
fprintf(totar, "%s\n", COMMENT_FNAME);
@ -267,18 +270,21 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
wait(&ret);
/* assume either signal or bad exit is enough for us */
if (ret)
barf("tar command failed with code %d", ret);
cleanup(0), errx(2, "tar command failed with code %d", ret);
}
static void
sanity_check()
{
if (!Comment)
barf("Required package comment string is missing (-c comment).");
cleanup(0), errx(2,
"required package comment string is missing (-c comment)");
if (!Desc)
barf("Required package description string is missing (-d desc).");
cleanup(0), errx(2,
"required package description string is missing (-d desc)");
if (!Contents)
barf("Required package contents list is missing (-f [-]file).");
cleanup(0), errx(2,
"required package contents list is missing (-f [-]file)");
}

View File

@ -15,7 +15,7 @@
.\"
.\"
.\" @(#)pkg_create.1
.\" $Id: pkg_create.1,v 1.21 1997/07/01 06:13:44 jkh Exp $
.\" $Id: pkg_create.1,v 1.22 1997/09/27 13:41:33 hoek Exp $
.\"
.\" hacked up by John Kohl for NetBSD--fixed a few bugs, extended keywords,
.\" added dependency tracking, etc.
@ -28,7 +28,7 @@
.Os FreeBSD
.Sh NAME
.Nm pkg_create
.Nd a utility for creating software package distributions.
.Nd a utility for creating software package distributions
.Sh SYNOPSIS
.Nm
.Op Fl YNOhv
@ -42,6 +42,7 @@
.Op Fl X Ar excludefile
.Op Fl D Ar displayfile
.Op Fl m Ar mtreefile
.Fl c Ar comment
.Fl d Ar description
.Fl f Ar packlist
.Ar pkg-name
@ -56,7 +57,7 @@ do so. It is more expected that you will use a front-end tool for
the job rather than muddling through it yourself. Nonetheless, a short
description of the input syntax is included in this document.
.Sh OPTIONS
The following command line options are supported.
The following command line options are supported:
.Bl -tag -width indent
.It Fl f Ar packinglist
Fetch ``packing list'' for package from the file
@ -68,7 +69,6 @@ if
is a
.Cm -
(dash).
.Em "Mandatory."
.It Fl c Ar [-]desc
Fetch package ``one line description'' from file
.Ar desc
@ -77,17 +77,14 @@ or, if preceded by
the argument itself. This string should also
give some idea of which version of the product (if any) the package
represents.
.Em "Mandatory."
.It Fl d Ar [-]desc
Fetch long description for package from file
.Ar desc
or, if preceded by
.Cm - ,
the argument itself.
.Em "Mandatory."
.It Fl Y
Assume a default answer of `Yes' for any questions asked.
.Em "Optional."
.It Fl N
Assume a default answer of `No' for any questions asked.
.It Fl O
@ -96,49 +93,42 @@ Go into a `packing list Only' mode. This is a custom hack for the
and is used to do `fake pkg_add' operations when a port is installed.
In such cases, it is necessary to know what the final, adjusted packing
list will look like.
.Em "Optional."
.It Fl v
Turns on verbose output.
.Em "Optional."
Turn on verbose output.
.It Fl h
Forces tar to follow symbolic links, so that the files they point to
Force tar to follow symbolic links, so that the files they point to
are dumped, rather than the links themselves.
.It Fl i Ar iscript
Sets
Set
.Ar iscript
to be the install procedure for the package. This can be any
executable program (or shell script). It will be invoked automatically
when the package is later installed.
.Em "Optional."
.It Fl P Ar pkgs
Sets the initial package dependency list to
Set the initial package dependency list to
.Ar pkgs .
This is assumed to be a whitespace separated list of package names
and is meant as a convenient shorthand for specifying multiple
.Cm @pkgdep
directives in the packing list (see PACKING LIST DETAILS section below).
.Em "Optional."
.It Fl p Ar prefix
Sets
Set
.Ar prefix
as the initial directory ``base'' to start from in selecting files for
the package.
.Em "Optional."
.It Fl k Ar dscript
Sets
Set
.Ar dscript
to be the de-install procedure for the package. This can be any
executable program (or shell script). It will be invoked automatically
when the package is later (if ever) de-installed.
.Em "Optional."
.It Fl r Ar rscript
Sets
Set
.Ar rscript
to be the ``requirements'' procedure for the package. This can be any
executable program (or shell script). It will be invoked automatically
at installation/deinstallation time to determine whether or not
installation/deinstallation should proceed.
.Em "Optional."
.It Fl t Ar template
Use
.Ar template
@ -153,7 +143,6 @@ directory is limited. Be sure to leave some number of `X' characters
for
.Xr mktemp 3
to fill in with a unique ID.
.Em "Optional."
.It Fl X Ar excludefile
Pass
.Ar excludefile
@ -206,14 +195,14 @@ installed with. This is done by imbeding specialized command sequences
in the packing list. Briefly described, these sequences are:
.Bl -tag -width indent -compact
.It Cm @cwd Ar directory
Sets the internal directory pointer to point to
Set the internal directory pointer to point to
.Ar directory .
All subsequent filenames will be assumed relative to this directory.
Note:
.Cm @cd
is also an alias for this command.
.It Cm @srcdir Ar directory
Sets the internal directory pointer for _creation only_ to
Set the internal directory pointer for _creation only_ to
.Ar directory .
That is to say that it overrides
.Cm @cwd
@ -235,17 +224,17 @@ and the last extracted file was
Expands to the last filename extracted (as specified), in the example case
.Pa bin/emacs
.It Cm "%D"
Expands to the current directory prefix, as set with
Expand to the current directory prefix, as set with
.Cm @cwd ,
in the example case
.Pa /usr/local .
.It Cm "%B"
Expands to the ``basename'' of the fully qualified filename, that
Expand to the ``basename'' of the fully qualified filename, that
is the current directory prefix, plus the last filespec, minus
the trailing filename. In the example case, that would be
.Pa /usr/local/bin .
.It Cm "%f"
Expands to the ``filename'' part of the fully qualified name, or
Expand to the ``filename'' part of the fully qualified name, or
the converse of
.Cm %B ,
being in the example case,
@ -271,7 +260,7 @@ sequence expansion'' to get at files regardless of where they've
been potentially redirected (see
.Fl p ) .
.It Cm @mode Ar mode
Sets default permission for all subsequently extracted files to
Set default permission for all subsequently extracted files to
.Ar mode .
Format is the same as that used by the
.Cm chmod
@ -279,7 +268,7 @@ command (well, considering that it's later handed off to it, that's
no surprise). Use without an arg to set back to default (extraction)
permissions.
.It Cm @option Ar option
Sets internal package options, the only two currently supported ones
Set internal package options, the only two currently supported ones
being
.Ar extract-in-place ,
which tells the pkg_add command not to extract the package's tarball
@ -291,12 +280,12 @@ which tells pkg_add to move any existing files out of the way,
preserving the previous contents (which are also resurrected on
pkg_delete, so caveat emptor).
.It Cm @owner Ar user
Sets default ownership for all subsequently extracted files to
Set default ownership for all subsequently extracted files to
.Ar user .
Use without an arg to set back to default (extraction)
ownership.
.It Cm @group Ar group
Sets default group ownership for all subsequently extracted files to
Set default group ownership for all subsequently extracted files to
.Ar group .
Use without an arg to set back to default (extraction)
group ownership.
@ -317,7 +306,7 @@ file, so you can pack a
specialized datafile in with a distribution for your install script (or
something) yet have the installer ignore it.
.It Cm @name Ar name
Sets the name of the package. This is mandatory and is usually
Set the name of the package. This is mandatory and is usually
put at the top. This name is potentially different than the name of
the file it came in, and is used when keeping track of the package
for later deinstallation. Note that
@ -353,7 +342,7 @@ as the file to be displayed at install time (see
.Fl D
above).
.It Cm @pkgdep Ar pkgname
Declares a dependency on the
Declare a dependency on the
.Ar pkgname
package. The
.Ar pkgname

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id$";
static const char rcsid[] =
"$Id: pl.c,v 1.10 1997/02/22 16:09:30 peter Exp $";
#endif
/*
@ -25,6 +26,7 @@ static const char *rcsid = "$Id$";
#include "lib.h"
#include "create.h"
#include <errno.h>
#include <err.h>
#include <md5.h>
/* Check a list for files that require preconversion */
@ -84,7 +86,7 @@ trylink(const char *from, const char *to)
if (where_count > sizeof(STARTSTRING)-1) { \
strcat(where_args, "|tar xpf -"); \
if (system(where_args)) \
barf("can't invoke tar pipeline"); \
cleanup(0), errx(2, "can't invoke tar pipeline"); \
memset(where_args, 0, maxargs); \
last_chdir = NULL; \
strcpy(where_args, STARTSTRING); \
@ -111,7 +113,7 @@ copy_plist(char *home, Package *plist)
and sh -c */
where_args = malloc(maxargs);
if (!where_args)
barf("can't get argument list space");
cleanup(0), errx(2, "can't get argument list space");
memset(where_args, 0, maxargs);
strcpy(where_args, STARTSTRING);
@ -172,7 +174,7 @@ copy_plist(char *home, Package *plist)
last_chdir = home;
}
if (add_count > maxargs - where_count)
barf("oops, miscounted strings!");
cleanup(0), errx(2, "oops, miscounted strings!");
where_count += add_count;
}
/*
@ -206,7 +208,7 @@ copy_plist(char *home, Package *plist)
mythere ? mythere : where,
p->name);
if (add_count > maxargs - where_count)
barf("oops, miscounted strings!");
cleanup(0), errx(2, "oops, miscounted strings!");
where_count += add_count;
last_chdir = (mythere ? mythere : where);
}

View File

@ -1,5 +1,6 @@
#ifndef lint
static char *rcsid = "$Id: main.c,v 1.9 1997/03/31 05:10:48 imp Exp $";
static const char rcsid[] =
"$Id: main.c,v 1.10 1997/09/18 14:08:40 phk Exp $";
#endif
/*
@ -23,9 +24,9 @@ static char *rcsid = "$Id: main.c,v 1.9 1997/03/31 05:10:48 imp Exp $";
*
*/
#include <err.h>
#include "lib.h"
#include "delete.h"
#include <err.h>
static char Options[] = "hvDdnfp:";
@ -33,12 +34,13 @@ char *Prefix = NULL;
Boolean NoDeInstall = FALSE;
Boolean CleanDirs = FALSE;
static void usage __P((void));
int
main(int argc, char **argv)
{
int ch, error;
char **pkgs, **start;
char *prog_name = argv[0];
pkgs = start = argv;
while ((ch = getopt(argc, argv, Options)) != -1)
@ -71,7 +73,7 @@ main(int argc, char **argv)
case 'h':
case '?':
default:
usage(prog_name, NULL);
usage();
break;
}
@ -85,39 +87,22 @@ main(int argc, char **argv)
/* If no packages, yelp */
if (pkgs == start)
usage(prog_name, "Missing package name(s)");
warnx("missing package name(s)"), usage();
*pkgs = NULL;
if (!Fake && getuid() != 0)
errx(1, "You must be root to delete packages.");
errx(1, "you must be root to delete packages");
if ((error = pkg_perform(start)) != 0) {
if (Verbose)
fprintf(stderr, "%d package deletion(s) failed.\n", error);
warnx("%d package deletion(s) failed", error);
return error;
}
else
return 0;
}
void
usage(const char *name, const char *fmt, ...)
static void
usage()
{
va_list args;
va_start(args, fmt);
if (fmt) {
fprintf(stderr, "%s: ", name);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n\n");
}
va_end(args);
fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name);
fprintf(stderr, "Where args are one or more of:\n\n");
fprintf(stderr, "-v verbose\n");
fprintf(stderr, "-p arg override prefix with arg\n");
fprintf(stderr, "-d delete empty directories when deinstalling\n");
fprintf(stderr, "-f force delete even if dependencies exist\n");
fprintf(stderr, " or deinstall/requirement checks fail\n");
fprintf(stderr, "-D don't execute pkg de-install script, if any\n");
fprintf(stderr, "-n don't actually de-install, just show steps\n");
fprintf(stderr, "usage: pkg_delete [-vDdnf] [-p prefix] pkg-name ...\n");
exit(1);
}

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id: perform.c,v 1.12 1997/02/22 16:09:37 peter Exp $";
static const char rcsid[] =
"$Id: perform.c,v 1.13 1997/03/06 10:21:57 jkh Exp $";
#endif
/*
@ -22,6 +23,7 @@ static const char *rcsid = "$Id: perform.c,v 1.12 1997/02/22 16:09:37 peter Exp
*
*/
#include <err.h>
#include "lib.h"
#include "delete.h"
@ -59,33 +61,34 @@ pkg_do(char *pkg)
sprintf(LogDir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
pkg);
if (!fexists(LogDir)) {
whinge("No such package '%s' installed.", pkg);
warnx("no such package '%s' installed", pkg);
return 1;
}
if (!getcwd(home, FILENAME_MAX))
barf("Unable to get current working directory!");
cleanup(0), errx(2, "unable to get current working directory!");
if (chdir(LogDir) == FAIL) {
whinge("Unable to change directory to %s! Deinstall failed.", LogDir);
warnx("unable to change directory to %s! deinstall failed", LogDir);
return 1;
}
if (!isemptyfile(REQUIRED_BY_FNAME)) {
char buf[512];
whinge("Package `%s' is required by these other packages", pkg);
whinge("and may not be deinstalled%s:", Force ? " (but I'll delete it anyway)" : "" );
warnx("package `%s' is required by these other packages\n"
"and may not be deinstalled%s:",
pkg, Force ? " (but I'll delete it anyway)" : "" );
cfile = fopen(REQUIRED_BY_FNAME, "r");
if (cfile) {
while (fgets(buf, sizeof(buf), cfile))
fprintf(stderr, "%s", buf);
fclose(cfile);
} else
whinge("cannot open requirements file `%s'", REQUIRED_BY_FNAME);
warnx("cannot open requirements file `%s'", REQUIRED_BY_FNAME);
if (!Force)
return 1;
}
sanity_check(LogDir);
cfile = fopen(CONTENTS_FNAME, "r");
if (!cfile) {
whinge("Unable to open '%s' file.", CONTENTS_FNAME);
warnx("unable to open '%s' file", CONTENTS_FNAME);
return 1;
}
/* If we have a prefix, add it now */
@ -95,7 +98,7 @@ pkg_do(char *pkg)
fclose(cfile);
p = find_plist(&Plist, PLIST_CWD);
if (!p) {
whinge("Package '%s' doesn't have a prefix.", pkg);
warnx("package '%s' doesn't have a prefix", pkg);
return 1;
}
setenv(PKG_PREFIX_VNAME, p->name, 1);
@ -104,8 +107,8 @@ pkg_do(char *pkg)
printf("Executing 'require' script.\n");
vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */
if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) {
whinge("Package %s fails requirements %s", pkg,
Force ? "." : "- not deleted.");
warnx("package %s fails requirements %s", pkg,
Force ? "" : "- not deleted");
if (!Force)
return 1;
}
@ -116,21 +119,22 @@ pkg_do(char *pkg)
else {
vsystem("chmod +x %s", DEINSTALL_FNAME); /* make sure */
if (vsystem("./%s %s DEINSTALL", DEINSTALL_FNAME, pkg)) {
whinge("De-Install script returned error status.");
warnx("deinstall script returned error status");
if (!Force)
return 1;
}
}
}
if (chdir(home) == FAIL)
barf("Toto! This doesn't look like Kansas anymore!");
cleanup(0), errx(2, "Toto! This doesn't look like Kansas anymore!");
if (!Fake) {
/* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */
if (delete_package(FALSE, CleanDirs, &Plist) == FAIL)
whinge("Couldn't entirely delete package (perhaps the packing list is\n"
"incorrectly specified?)\n");
warnx(
"couldn't entirely delete package (perhaps the packing list is\n"
"incorrectly specified?)");
if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) {
whinge("Couldn't remove log entry in %s, de-install failed.", LogDir);
warnx("couldn't remove log entry in %s, deinstall failed", LogDir);
if (!Force)
return 1;
}
@ -150,7 +154,8 @@ static void
sanity_check(char *pkg)
{
if (!fexists(CONTENTS_FNAME))
barf("Installed package %s has no %s file!", pkg, CONTENTS_FNAME);
cleanup(0), errx(2, "installed package %s has no %s file!",
pkg, CONTENTS_FNAME);
}
void
@ -173,21 +178,21 @@ undepend(PackingList p, char *pkgname)
p->name, REQUIRED_BY_FNAME);
fp = fopen(fname, "r");
if (fp == NULL) {
whinge("Couldn't open dependency file `%s'", fname);
warnx("couldn't open dependency file `%s'", fname);
return;
}
sprintf(ftmp, "%s.XXXXXX", fname);
s = mkstemp(ftmp);
if (s == -1) {
fclose(fp);
whinge("Couldn't open temp file `%s'", ftmp);
warnx("couldn't open temp file `%s'", ftmp);
return;
}
fpwr = fdopen(s, "w");
if (fpwr == NULL) {
close(s);
fclose(fp);
whinge("Couldn't fdopen temp file `%s'", ftmp);
warnx("couldn't fdopen temp file `%s'", ftmp);
remove(ftmp);
return;
}
@ -199,18 +204,18 @@ undepend(PackingList p, char *pkgname)
}
(void) fclose(fp);
if (fchmod(s, 0644) == FAIL) {
whinge("Error changing permission of temp file `%s'", ftmp);
warnx("error changing permission of temp file `%s'", ftmp);
fclose(fpwr);
remove(ftmp);
return;
}
if (fclose(fpwr) == EOF) {
whinge("Error closing temp file `%s'", ftmp);
warnx("error closing temp file `%s'", ftmp);
remove(ftmp);
return;
}
if (rename(ftmp, fname) == -1)
whinge("Error renaming `%s' to `%s'", ftmp, fname);
warnx("error renaming `%s' to `%s'", ftmp, fname);
remove(ftmp); /* just in case */
return;
}

View File

@ -21,7 +21,7 @@
.Os FreeBSD 2.0
.Sh NAME
.Nm pkg_delete
.Nd a utility for deleting previously installed software package distributions.
.Nd a utility for deleting previously installed software package distributions
.Sh SYNOPSIS
.Nm
.Op Fl vDdnf
@ -63,28 +63,24 @@ command to examine the installed package control files.
.Ef
.Sh OPTIONS
The following command line options are supported.
The following command line options are supported:
.Bl -tag -width indent
.It Ar pkg-name ...
The named packages are deinstalled.
.It Fl v
Turns on verbose output.
.Em "Optional."
Turn on verbose output.
.It Fl D
If a deinstallation script exists for a given package, do not execute it.
.Em "Optional."
.It Fl n
Don't actually deinstall a package, just report the steps that
would be taken if it were.
.Em "Optional."
.It Fl p Ar prefix
Sets
Set
.Ar prefix
as the directory in which to delete files from any installed packages
which do not explicitly set theirs. For most packages, the prefix will
be set automatically to the installed location by
.Xr pkg_add 1 .
.Em "Optional."
.It Fl d
Remove empty directories created by file cleanup. By default, only
files/directories explicitly listed in a package's contents (either as
@ -94,16 +90,14 @@ directive) will be removed at deinstallation time. This option tells
.Nm
to also remove any directories that were emptied as a result of removing
the package.
.Em "Optional."
.It Fl f
Force removal of the package, even if a dependency is recorded or the
deinstall or require script fails.
.Em "Optional."
.El
.Pp
.Sh TECHNICAL DETAILS
.Nm
.Nm Pkg_delete
does pretty much what it says. It examines installed package records in
.Pa /var/db/pkg/<pkg-name> ,
deletes the package contents, and finally removes the package records.

View File

@ -1,5 +1,6 @@
#ifndef lint
static char *rcsid = "$Id: main.c,v 1.12 1997/02/22 16:09:41 peter Exp $";
static const char rcsid[] =
"$Id: main.c,v 1.13 1997/03/31 05:10:50 imp Exp $";
#endif
/*
@ -23,6 +24,7 @@ static char *rcsid = "$Id: main.c,v 1.12 1997/02/22 16:09:41 peter Exp $";
*
*/
#include <err.h>
#include "lib.h"
#include "info.h"
@ -35,12 +37,13 @@ char *InfoPrefix = "";
char PlayPen[FILENAME_MAX];
char *CheckPkg = NULL;
static void usage __P((void));
int
main(int argc, char **argv)
{
int ch;
char **pkgs, **start;
char *prog_name = argv[0];
pkgs = start = argv;
while ((ch = getopt(argc, argv, Options)) != -1)
@ -123,7 +126,7 @@ main(int argc, char **argv)
case 'h':
case '?':
default:
usage(prog_name, NULL);
usage();
break;
}
@ -140,42 +143,17 @@ main(int argc, char **argv)
/* If no packages, yelp */
if (pkgs == start && !AllInstalled && !CheckPkg)
usage(prog_name, "Missing package name(s)");
warnx("missing package name(s)"), usage();
*pkgs = NULL;
return pkg_perform(start);
}
void
usage(const char *name, const char *fmt, ...)
static void
usage()
{
va_list args;
va_start(args, fmt);
if (fmt) {
fprintf(stderr, "%s: ", name);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n\n");
}
va_end(args);
fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name);
fprintf(stderr, "Where args are one or more of:\n\n");
fprintf(stderr, "-a show all installed packages (if any)\n");
fprintf(stderr, "-I print 'index' of packages\n");
fprintf(stderr, "-c print `one line comment'\n");
fprintf(stderr, "-d print description\n");
fprintf(stderr, "-D print install notice\n");
fprintf(stderr, "-f show packing list\n");
fprintf(stderr, "-i show install script\n");
fprintf(stderr, "-k show deinstall script\n");
fprintf(stderr, "-r show requirements script\n");
fprintf(stderr, "-R show packages depending on this package\n");
fprintf(stderr, "-p show prefix\n");
fprintf(stderr, "-l <str> Prefix each info catagory with <str>\n");
fprintf(stderr, "-L show intalled files\n");
fprintf(stderr, "-q minimal output (``quiet'' mode)\n");
fprintf(stderr, "-v show all information\n");
fprintf(stderr, "-t temp use temp as template for mktemp()\n");
fprintf(stderr, "-e pkg returns 0 if pkg is installed, 1 otherwise\n");
fprintf(stderr, "\n[no args = -c -d -R]\n");
fprintf(stderr, "%s\n%s\n%s\n",
"usage: pkg_info [-cdDikrRpLqImv] [-e package] [-l prefix]",
" pkg-name [pkg-name ...]",
" pkg_info -a [flags]");
exit(1);
}

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id$";
static const char rcsid[] =
"$Id: perform.c,v 1.21 1997/02/22 16:09:42 peter Exp $";
#endif
/*
@ -112,13 +113,13 @@ pkg_do(char *pkg)
* be very optimistic.
*/
if (stat(fname, &sb) == FAIL) {
whinge("Can't stat package file '%s'.", fname);
warnx("can't stat package file '%s'", fname);
code = 1;
goto bail;
}
Home = make_playpen(PlayPen, sb.st_size / 2);
if (unpack(fname, "+*")) {
whinge("Error during unpacking, no info for '%s' available.", pkg);
warnx("error during unpacking, no info for '%s' available", pkg);
code = 1;
goto bail;
}
@ -130,11 +131,11 @@ pkg_do(char *pkg)
sprintf(log_dir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
pkg);
if (!fexists(log_dir)) {
whinge("Can't find package `%s' installed or in a file!", pkg);
warnx("can't find package `%s' installed or in a file!", pkg);
return 1;
}
if (chdir(log_dir) == FAIL) {
whinge("Can't change directory to '%s'!", log_dir);
warnx("can't change directory to '%s'!", log_dir);
return 1;
}
installed = TRUE;
@ -144,7 +145,7 @@ pkg_do(char *pkg)
plist.head = plist.tail = NULL;
fp = fopen(CONTENTS_FNAME, "r");
if (!fp) {
whinge("Unable to open %s file.", CONTENTS_FNAME);
warnx("unable to open %s file", CONTENTS_FNAME);
code = 1;
goto bail;
}

View File

@ -21,7 +21,7 @@
.Os FreeBSD
.Sh NAME
.Nm pkg_info
.Nd a utility for displaying information on software packages.
.Nd a utility for displaying information on software packages
.Sh SYNOPSIS
.Nm pkg_info
.Op Fl cdDikrRpLqImv
@ -40,7 +40,7 @@ with the
.Xr pkg_create 1
command.
.Sh OPTIONS
The following command line options are supported.
The following command line options are supported:
.Bl -tag -width indent
.It Ar pkg-name ...
The named packages are described. A package name may either be the name of
@ -49,7 +49,7 @@ URL to an ftp available package.
.It Fl a
Show all currently installed packages.
.It Fl v
Turns on verbose output.
Turn on verbose output.
.It Fl p
Show the installation prefix for each package.
.It Fl q

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id$";
static const char rcsid[] =
"$Id: show.c,v 1.10 1997/02/22 16:09:43 peter Exp $";
#endif
/*
@ -55,7 +56,7 @@ show_index(char *title, char *fname)
printf("%s%s", InfoPrefix, title);
fp = fopen(fname, "r");
if (!fp) {
whinge("show_file: Can't open '%s' for reading.", fname);
warnx("show_file: can't open '%s' for reading", fname);
return;
}
if(fgets(line, MAXINDEXSIZE+1, fp)) {
@ -154,7 +155,8 @@ show_plist(char *title, Package *plist, plist_t type)
break;
default:
barf("Unknown command type %d (%s)\n", p->type, p->name);
cleanup(0);
errx(2, "unknown command type %d (%s)", p->type, p->name);
break;
}
p = p->next;

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id$";
static const char rcsid[] =
"$Id: exec.c,v 1.5 1997/02/22 16:09:46 peter Exp $";
#endif
/*
@ -22,6 +23,7 @@ static const char *rcsid = "$Id$";
*
*/
#include <err.h>
#include "lib.h"
/*
@ -40,13 +42,13 @@ vsystem(const char *fmt, ...)
maxargs -= 32; /* some slop for the sh -c */
cmd = malloc(maxargs);
if (!cmd) {
whinge("vsystem can't alloc arg space");
warnx("vsystem can't alloc arg space");
return 1;
}
va_start(args, fmt);
if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
whinge("vsystem args are too long");
warnx("vsystem args are too long");
return 1;
}
#ifdef DEBUG

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id: file.c,v 1.27 1997/02/22 16:09:47 peter Exp $";
static const char rcsid[] =
"$Id: file.c,v 1.28 1997/07/01 06:13:50 jkh Exp $";
#endif
/*
@ -23,6 +24,7 @@ static const char *rcsid = "$Id: file.c,v 1.27 1997/02/22 16:09:47 peter Exp $";
*/
#include "lib.h"
#include <err.h>
#include <ftpio.h>
#include <netdb.h>
#include <pwd.h>
@ -220,13 +222,13 @@ fileGetURL(char *base, char *spec)
strcpy(fname, spec);
cp = fileURLHost(fname, host, HOSTNAME_MAX);
if (!*cp) {
whinge("URL `%s' has bad host part!", fname);
warnx("URL `%s' has bad host part!", fname);
return NULL;
}
cp = fileURLFilename(fname, file, FILENAME_MAX);
if (!*cp) {
whinge("URL `%s' has bad filename part!", fname);
warnx("URL `%s' has bad filename part!", fname);
return NULL;
}
@ -236,7 +238,7 @@ fileGetURL(char *base, char *spec)
/* Make up a convincing "password" */
pw = getpwuid(getuid());
if (!pw) {
whinge("Can't get user name for ID %d\n.", getuid());
warnx("can't get user name for ID %d", getuid());
strcpy(pword, "joe@");
}
else {
@ -325,14 +327,15 @@ fileGetContents(char *fname)
int fd;
if (stat(fname, &sb) == FAIL)
barf("Can't stat '%s'.", fname);
cleanup(0), errx(2, "can't stat '%s'", fname);
contents = (char *)malloc(sb.st_size + 1);
fd = open(fname, O_RDONLY, 0);
if (fd == FAIL)
barf("Unable to open '%s' for reading.", fname);
cleanup(0), errx(2, "unable to open '%s' for reading", fname);
if (read(fd, contents, sb.st_size) != sb.st_size)
barf("Short read on '%s' - did not get %qd bytes.", fname, sb.st_size);
cleanup(0), errx(2, "short read on '%s' - did not get %qd bytes",
fname, sb.st_size);
close(fd);
contents[sb.st_size] = '\0';
return contents;
@ -381,12 +384,13 @@ write_file(char *name, char *str)
fp = fopen(name, "w");
if (!fp)
barf("Cannot fopen '%s' for writing.", name);
cleanup(0), errx(2, "cannot fopen '%s' for writing", name);
len = strlen(str);
if (fwrite(str, 1, len, fp) != len)
barf("Short fwrite on '%s', tried to write %d bytes.", name, len);
cleanup(0), errx(2, "short fwrite on '%s', tried to write %d bytes",
name, len);
if (fclose(fp))
barf("failure to fclose '%s'.", name);
cleanup(0), errx(2, "failure to fclose '%s'", name);
}
void
@ -399,7 +403,7 @@ copy_file(char *dir, char *fname, char *to)
else
snprintf(cmd, FILENAME_MAX, "cp -p -r %s/%s %s", dir, fname, to);
if (vsystem(cmd))
barf("Could not perform '%s'", cmd);
cleanup(0), errx(2, "could not perform '%s'", cmd);
}
void
@ -412,7 +416,7 @@ move_file(char *dir, char *fname, char *to)
else
snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to);
if (vsystem(cmd))
barf("Could not perform '%s'", cmd);
cleanup(0), errx(2, "could not perform '%s'", cmd);
}
/*
@ -442,7 +446,7 @@ copy_hierarchy(char *dir, char *fname, Boolean to)
printf("Using '%s' to copy trees.\n", cmd);
#endif
if (system(cmd))
barf("copy_file: Could not perform '%s'", cmd);
cleanup(0), errx(2, "copy_file: could not perform '%s'", cmd);
}
/* Unpack a tar file */
@ -468,7 +472,7 @@ unpack(char *pkg, char *flist)
strcpy(args, "z");
strcat(args, "xpf");
if (vsystem("tar %s %s %s", args, pkg, flist ? flist : "")) {
whinge("Tar extract of %s failed!", pkg);
warnx("tar extract of %s failed!", pkg);
return 1;
}
return 0;

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id$";
static const char rcsid[] =
"$Id: global.c,v 1.5 1997/02/22 16:09:48 peter Exp $";
#endif
/*

View File

@ -1,4 +1,4 @@
/* $Id$ */
/* $Id: lib.h,v 1.24 1997/02/22 16:09:49 peter Exp $ */
/*
* FreeBSD install - a package for the installation and maintainance
@ -165,7 +165,6 @@ int plist_cmd(char *, char **);
int delete_package(Boolean, Boolean, Package *);
/* For all */
void usage(const char *, const char *, ...);
int pkg_perform(char **);
/* Externs */

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id$";
static const char rcsid[] =
"$Id: msg.c,v 1.8 1997/02/22 16:09:50 peter Exp $";
#endif
/*
@ -23,44 +24,18 @@ static const char *rcsid = "$Id$";
*
*/
#include <err.h>
#include "lib.h"
/* Die a relatively simple death */
void
upchuck(const char *err)
{
fprintf(stderr, "Fatal error during execution: ");
perror(err);
warn("fatal error during execution: %s", err);
cleanup(0);
exit(1);
}
/* Die a more complex death */
void
barf(const char *err, ...)
{
va_list args;
va_start(args, err);
vfprintf(stderr, err, args);
fputc('\n', stderr);
va_end(args);
cleanup(0);
exit(2);
}
/* Get annoyed about something but don't go to pieces over it */
void
whinge(const char *err, ...)
{
va_list args;
va_start(args, err);
vfprintf(stderr, err, args);
fputc('\n', stderr);
va_end(args);
}
/*
* As a yes/no question, prompting from the varargs string and using
* default if user just hits return.
@ -79,7 +54,7 @@ y_or_n(Boolean def, const char *msg, ...)
*/
tty = fopen("/dev/tty", "r");
if (!tty)
barf("Can't open /dev/tty!\n");
cleanup(0), errx(2, "can't open /dev/tty!");
while (ch != 'Y' && ch != 'N') {
vfprintf(stderr, msg, args);
if (def)

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id$";
static const char rcsid[] =
"$Id: pen.c,v 1.24 1997/02/22 16:09:50 peter Exp $";
#endif
/*
@ -22,6 +23,7 @@ static const char *rcsid = "$Id$";
*
*/
#include <err.h>
#include "lib.h"
#include <sys/signal.h>
#include <sys/param.h>
@ -57,9 +59,11 @@ find_play_pen(char *pen, size_t sz)
else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
strcpy(pen, "/usr/tmp/instmp.XXXXXX");
else {
barf("Can't find enough temporary space to extract the files, please set\n"
"your PKG_TMPDIR environment variable to a location with at least %d bytes\n"
"free.", sz);
cleanup(0);
errx(2,
"can't find enough temporary space to extract the files, please set your\n"
"PKG_TMPDIR environment variable to a location with at least %d bytes\n"
"free", sz);
return NULL;
}
return pen;
@ -76,12 +80,12 @@ make_playpen(char *pen, size_t sz)
return NULL;
if (!mktemp(pen)) {
barf("Can't mktemp '%s'.", pen);
return NULL;
cleanup(0);
errx(2, "can't mktemp '%s'", pen);
}
if (mkdir(pen, 0755) == FAIL) {
barf("Can't mkdir '%s'.", pen);
return NULL;
cleanup(0);
errx(2, "can't mkdir '%s'", pen);
}
if (Verbose) {
if (sz)
@ -89,10 +93,10 @@ make_playpen(char *pen, size_t sz)
}
if (min_free(pen) < sz) {
rmdir(pen);
barf("Not enough free space to create: `%s'\n"
cleanup(0);
errx(2, "not enough free space to create '%s'.\n"
"Please set your PKG_TMPDIR environment variable to a location\n"
"with more space and\ntry the command again.", pen);
return NULL;
"with more space and\ntry the command again", pen);
}
if (Current[0])
strcpy(Previous, Current);
@ -101,7 +105,7 @@ make_playpen(char *pen, size_t sz)
return NULL;
}
if (chdir(pen) == FAIL)
barf("Can't chdir to '%s'.", pen);
cleanup(0), errx(2, "can't chdir to '%s'", pen);
strcpy(Current, pen);
return Previous;
}
@ -115,10 +119,10 @@ leave_playpen(char *save)
/* Don't interrupt while we're cleaning up */
oldsig = signal(SIGINT, SIG_IGN);
if (Previous[0] && chdir(Previous) == FAIL)
barf("Can't chdir back to '%s'.", Previous);
cleanup(0), errx(2, "can't chdir back to '%s'", Previous);
else if (Current[0] && strcmp(Current, Previous)) {
if (vsystem("rm -rf %s", Current))
whinge("Couldn't remove temporary dir '%s'", Current);
warnx("couldn't remove temporary dir '%s'", Current);
strcpy(Current, Previous);
}
if (save)
@ -134,7 +138,7 @@ min_free(char *tmpdir)
struct statfs buf;
if (statfs(tmpdir, &buf) != 0) {
perror("Error in statfs");
warn("statfs");
return -1;
}
return (off_t)buf.f_bavail * (off_t)buf.f_bsize;

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id: plist.c,v 1.22 1997/07/01 06:13:51 jkh Exp $";
static const char rcsid[] =
"$Id: plist.c,v 1.23 1997/09/02 08:48:47 jkh Exp $";
#endif
/*
@ -23,7 +24,7 @@ static const char *rcsid = "$Id: plist.c,v 1.22 1997/07/01 06:13:51 jkh Exp $";
*/
#include "lib.h"
#include <errno.h>
#include <err.h>
#include <md5.h>
/* Add an item to a packing list */
@ -250,7 +251,7 @@ read_plist(Package *pkg, FILE *fp)
if (pline[0] == CMD_CHAR) {
cmd = plist_cmd(pline + 1, &cp);
if (cmd == FAIL)
barf("Bad command '%s'", pline);
cleanup(0), errx(2, "bad command '%s'", pline);
if (*cp == '\0')
cp = NULL;
}
@ -334,7 +335,8 @@ write_plist(Package *pkg, FILE *fp)
break;
default:
barf("Unknown command type %d (%s)\n", plist->type, plist->name);
cleanup(0);
errx(2, "unknown command type %d (%s)", plist->type, plist->name);
break;
}
plist = plist->next;
@ -378,7 +380,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
if (Verbose)
printf("Execute `%s'\n", tmp);
if (!Fake && system(tmp)) {
whinge("unexec command for `%s' failed.", tmp);
warnx("unexec command for `%s' failed", tmp);
fail = FAIL;
}
break;
@ -387,8 +389,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
last_file = p->name;
sprintf(tmp, "%s/%s", Where, p->name);
if (isdir(tmp)) {
whinge("Attempting to delete directory `%s' as a file\n"
"This packing list is incorrect - ignoring delete request.\n", tmp);
warnx("attempting to delete directory `%s' as a file\n"
"this packing list is incorrect - ignoring delete request", tmp);
}
else {
if (p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) {
@ -418,7 +420,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
if (make_preserve_name(tmp2, FILENAME_MAX, name, tmp)) {
if (fexists(tmp2)) {
if (rename(tmp2, tmp))
whinge("preserve: Unable to restore %s as %s, errno = %d", tmp2, tmp, errno);
warn("preserve: unable to restore %s as %s",
tmp2, tmp);
}
}
}
@ -429,14 +432,14 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
case PLIST_DIR_RM:
sprintf(tmp, "%s/%s", Where, p->name);
if (!isdir(tmp)) {
whinge("Attempting to delete file `%s' as a directory\n"
"This packing list is incorrect - ignoring delete request.\n", tmp);
warnx("attempting to delete file `%s' as a directory\n"
"this packing list is incorrect - ignoring delete request", tmp);
}
else {
if (Verbose)
printf("Delete directory %s\n", tmp);
if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
whinge("Unable to completely remove directory '%s'", tmp);
warnx("unable to completely remove directory '%s'", tmp);
fail = FAIL;
}
}
@ -464,7 +467,8 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
cp1 = cp2 = dir;
if (!fexists(dir)) {
if (!ign_err)
whinge("%s `%s' doesn't really exist.", isdir(dir) ? "Directory" : "File", dir);
warnx("%s `%s' doesn't really exist",
isdir(dir) ? "directory" : "file", dir);
return !ign_err;
}
else if (nukedirs) {
@ -489,7 +493,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
return 0;
if (RMDIR(dir) && !ign_err)
if (!fexists(dir))
whinge("Directory `%s' doesn't really exist.", dir);
warnx("directory `%s' doesn't really exist", dir);
else
return 1;
/* back up the pathname one component */

View File

@ -1,5 +1,6 @@
#ifndef lint
static const char *rcsid = "$Id";
static const char rcsid[] =
"$Id$";
#endif
/*