1993-08-26 01:19:55 +00:00
|
|
|
#ifndef lint
|
1997-10-08 07:48:21 +00:00
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1993-08-26 01:19:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
|
|
|
* This is the main body of the add module.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-10-08 07:48:21 +00:00
|
|
|
#include <err.h>
|
2000-12-09 09:35:55 +00:00
|
|
|
#include <paths.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
#include "lib.h"
|
|
|
|
#include "add.h"
|
|
|
|
|
2001-10-08 17:01:35 +00:00
|
|
|
#include <libgen.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
#include <signal.h>
|
1994-12-06 00:51:50 +00:00
|
|
|
#include <sys/wait.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
static int pkg_do(char *);
|
|
|
|
static int sanity_check(char *);
|
|
|
|
static char LogDir[FILENAME_MAX];
|
1998-07-17 14:56:31 +00:00
|
|
|
static int zapLogDir; /* Should we delete LogDir? */
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
pkg_perform(char **pkgs)
|
|
|
|
{
|
|
|
|
int i, err_cnt = 0;
|
|
|
|
|
|
|
|
signal(SIGINT, cleanup);
|
|
|
|
signal(SIGHUP, cleanup);
|
|
|
|
|
1993-09-05 04:53:51 +00:00
|
|
|
if (AddMode == SLAVE)
|
|
|
|
err_cnt = pkg_do(NULL);
|
|
|
|
else {
|
|
|
|
for (i = 0; pkgs[i]; i++)
|
|
|
|
err_cnt += pkg_do(pkgs[i]);
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
return err_cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Package Plist;
|
1995-10-25 15:38:37 +00:00
|
|
|
static char *Home;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1995-04-26 15:06:26 +00:00
|
|
|
/*
|
|
|
|
* This is seriously ugly code following. Written very fast!
|
|
|
|
* [And subsequently made even worse.. Sigh! This code was just born
|
|
|
|
* to be hacked, I guess.. :) -jkh]
|
|
|
|
*/
|
1993-08-26 01:19:55 +00:00
|
|
|
static int
|
|
|
|
pkg_do(char *pkg)
|
|
|
|
{
|
|
|
|
char pkg_fullname[FILENAME_MAX];
|
1995-10-25 15:38:37 +00:00
|
|
|
char playpen[FILENAME_MAX];
|
1995-04-22 13:58:24 +00:00
|
|
|
char extract_contents[FILENAME_MAX];
|
2001-10-08 17:01:35 +00:00
|
|
|
char *where_to, *extract;
|
1993-08-26 01:19:55 +00:00
|
|
|
FILE *cfile;
|
1995-10-25 15:38:37 +00:00
|
|
|
int code;
|
1994-05-25 06:24:18 +00:00
|
|
|
PackingList p;
|
1994-10-04 16:07:50 +00:00
|
|
|
struct stat sb;
|
1995-10-25 15:38:37 +00:00
|
|
|
int inPlace;
|
1998-12-16 13:59:31 +00:00
|
|
|
/* support for separate pre/post install scripts */
|
|
|
|
int new_m = 0;
|
|
|
|
char pre_script[FILENAME_MAX] = INSTALL_FNAME;
|
|
|
|
char post_script[FILENAME_MAX];
|
|
|
|
char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX];
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
code = 0;
|
1998-07-17 14:56:31 +00:00
|
|
|
zapLogDir = 0;
|
1993-08-26 01:19:55 +00:00
|
|
|
LogDir[0] = '\0';
|
1995-10-25 15:38:37 +00:00
|
|
|
strcpy(playpen, FirstPen);
|
|
|
|
inPlace = 0;
|
1995-04-26 07:43:35 +00:00
|
|
|
|
1995-04-26 15:06:26 +00:00
|
|
|
/* Are we coming in for a second pass, everything already extracted? */
|
1995-10-25 15:38:37 +00:00
|
|
|
if (!pkg) {
|
|
|
|
fgets(playpen, FILENAME_MAX, stdin);
|
|
|
|
playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */
|
|
|
|
if (chdir(playpen) == FAIL) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("pkg_add in SLAVE mode can't chdir to %s", playpen);
|
1993-09-05 04:53:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
read_plist(&Plist, stdin);
|
1995-10-25 15:38:37 +00:00
|
|
|
where_to = playpen;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
1995-04-26 15:06:26 +00:00
|
|
|
/* Nope - do it now */
|
1993-09-05 04:53:51 +00:00
|
|
|
else {
|
1995-10-25 15:38:37 +00:00
|
|
|
/* Is it an ftp://foo.bar.baz/file.tgz specification? */
|
1995-04-26 15:06:26 +00:00
|
|
|
if (isURL(pkg)) {
|
1995-10-25 15:38:37 +00:00
|
|
|
if (!(Home = fileGetURL(NULL, pkg))) {
|
2001-08-02 12:38:29 +00:00
|
|
|
warnx("unable to fetch '%s' by URL", pkg);
|
1995-04-26 15:06:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1995-10-25 15:38:37 +00:00
|
|
|
where_to = Home;
|
|
|
|
strcpy(pkg_fullname, pkg);
|
|
|
|
cfile = fopen(CONTENTS_FNAME, "r");
|
|
|
|
if (!cfile) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx(
|
2001-08-02 12:38:29 +00:00
|
|
|
"unable to open table of contents file '%s' - not a package?",
|
1997-10-08 07:48:21 +00:00
|
|
|
CONTENTS_FNAME);
|
1995-10-25 15:38:37 +00:00
|
|
|
goto bomb;
|
|
|
|
}
|
|
|
|
read_plist(&Plist, cfile);
|
|
|
|
fclose(cfile);
|
1995-04-26 15:06:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-05-17 10:12:45 +00:00
|
|
|
strcpy(pkg_fullname, pkg); /*
|
|
|
|
* Copy for sanity's sake,
|
|
|
|
* could remove pkg_fullname
|
|
|
|
*/
|
1996-03-12 06:12:43 +00:00
|
|
|
if (strcmp(pkg, "-")) {
|
|
|
|
if (stat(pkg_fullname, &sb) == FAIL) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("can't stat package file '%s'", pkg_fullname);
|
1996-03-12 06:12:43 +00:00
|
|
|
goto bomb;
|
|
|
|
}
|
|
|
|
sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME);
|
|
|
|
extract = extract_contents;
|
1995-10-25 15:38:37 +00:00
|
|
|
}
|
1997-02-15 14:17:28 +00:00
|
|
|
else {
|
1996-03-12 06:12:43 +00:00
|
|
|
extract = NULL;
|
1997-02-15 14:17:28 +00:00
|
|
|
sb.st_size = 100000; /* Make up a plausible average size */
|
|
|
|
}
|
1995-10-25 15:38:37 +00:00
|
|
|
Home = make_playpen(playpen, sb.st_size * 4);
|
|
|
|
if (!Home)
|
1999-08-11 20:55:42 +00:00
|
|
|
errx(1, "unable to make playpen for %qd bytes", sb.st_size * 4);
|
1995-10-25 15:38:37 +00:00
|
|
|
where_to = Home;
|
1998-08-27 14:59:55 +00:00
|
|
|
/* Since we can call ourselves recursively, keep notes on where we came from */
|
|
|
|
if (!getenv("_TOP"))
|
|
|
|
setenv("_TOP", Home, 1);
|
1996-03-12 06:12:43 +00:00
|
|
|
if (unpack(pkg_fullname, extract)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx(
|
2001-08-02 12:38:29 +00:00
|
|
|
"unable to extract table of contents file from '%s' - not a package?",
|
1997-10-08 07:48:21 +00:00
|
|
|
pkg_fullname);
|
1995-10-25 15:38:37 +00:00
|
|
|
goto bomb;
|
|
|
|
}
|
|
|
|
cfile = fopen(CONTENTS_FNAME, "r");
|
|
|
|
if (!cfile) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx(
|
2001-08-02 12:38:29 +00:00
|
|
|
"unable to open table of contents file '%s' - not a package?",
|
1997-10-08 07:48:21 +00:00
|
|
|
CONTENTS_FNAME);
|
1995-10-25 15:38:37 +00:00
|
|
|
goto bomb;
|
|
|
|
}
|
|
|
|
read_plist(&Plist, cfile);
|
|
|
|
fclose(cfile);
|
1995-04-22 13:58:24 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
/* Extract directly rather than moving? Oh goodie! */
|
|
|
|
if (find_plist_option(&Plist, "extract-in-place")) {
|
|
|
|
if (Verbose)
|
|
|
|
printf("Doing in-place extraction for %s\n", pkg_fullname);
|
|
|
|
p = find_plist(&Plist, PLIST_CWD);
|
|
|
|
if (p) {
|
|
|
|
if (!isdir(p->name) && !Fake) {
|
|
|
|
if (Verbose)
|
|
|
|
printf("Desired prefix of %s does not exist, creating..\n", p->name);
|
|
|
|
vsystem("mkdir -p %s", p->name);
|
|
|
|
if (chdir(p->name) == -1) {
|
2001-08-02 12:38:29 +00:00
|
|
|
warn("unable to change directory to '%s'", p->name);
|
1995-10-25 15:38:37 +00:00
|
|
|
goto bomb;
|
|
|
|
}
|
1995-04-22 13:58:24 +00:00
|
|
|
}
|
1995-10-25 15:38:37 +00:00
|
|
|
where_to = p->name;
|
|
|
|
inPlace = 1;
|
|
|
|
}
|
|
|
|
else {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx(
|
2001-08-02 12:38:29 +00:00
|
|
|
"no prefix specified in '%s' - this is a bad package!",
|
1997-10-08 07:48:21 +00:00
|
|
|
pkg_fullname);
|
1995-10-25 15:38:37 +00:00
|
|
|
goto bomb;
|
1995-04-22 13:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
1995-10-25 15:38:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply a crude heuristic to see how much space the package will
|
|
|
|
* take up once it's unpacked. I've noticed that most packages
|
|
|
|
* compress an average of 75%, so multiply by 4 for good measure.
|
|
|
|
*/
|
|
|
|
|
1996-03-12 06:12:43 +00:00
|
|
|
if (!inPlace && min_free(playpen) < sb.st_size * 4) {
|
1999-08-11 20:55:42 +00:00
|
|
|
warnx("projected size of %qd exceeds available free space.\n"
|
1997-10-08 07:48:21 +00:00
|
|
|
"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);
|
1995-04-26 15:06:26 +00:00
|
|
|
goto bomb;
|
1995-04-22 13:58:24 +00:00
|
|
|
}
|
1995-07-30 09:11:20 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
/* If this is a direct extract and we didn't want it, stop now */
|
|
|
|
if (inPlace && Fake)
|
|
|
|
goto success;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
/* Finally unpack the whole mess */
|
|
|
|
if (unpack(pkg_fullname, NULL)) {
|
2001-08-02 12:38:29 +00:00
|
|
|
warnx("unable to extract '%s'!", pkg_fullname);
|
1995-10-25 15:38:37 +00:00
|
|
|
goto bomb;
|
|
|
|
}
|
1995-04-22 07:41:02 +00:00
|
|
|
}
|
1996-03-12 06:12:43 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
/* Check for sanity and dependencies */
|
|
|
|
if (sanity_check(pkg))
|
|
|
|
goto bomb;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
/* If we're running in MASTER mode, just output the plist and return */
|
|
|
|
if (AddMode == MASTER) {
|
|
|
|
printf("%s\n", where_playpen());
|
|
|
|
write_plist(&Plist, stdout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
1995-04-22 13:58:24 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
/*
|
|
|
|
* If we have a prefix, delete the first one we see and add this
|
|
|
|
* one in place of it.
|
|
|
|
*/
|
|
|
|
if (Prefix) {
|
|
|
|
delete_plist(&Plist, FALSE, PLIST_CWD, NULL);
|
|
|
|
add_plist_top(&Plist, PLIST_CWD, Prefix);
|
|
|
|
}
|
1995-04-22 13:58:24 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1);
|
|
|
|
/* Protect against old packages with bogus @name fields */
|
|
|
|
PkgName = (p = find_plist(&Plist, PLIST_NAME)) ? p->name : "anonymous";
|
1995-04-26 15:06:26 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
/* See if we're already registered */
|
2001-08-02 13:13:06 +00:00
|
|
|
sprintf(LogDir, "%s/%s", LOG_DIR, PkgName);
|
1996-07-31 21:52:33 +00:00
|
|
|
if (isdir(LogDir) && !Force) {
|
2001-08-02 12:38:29 +00:00
|
|
|
warnx("package '%s' already recorded as installed", PkgName);
|
1995-10-25 15:38:37 +00:00
|
|
|
code = 1;
|
|
|
|
goto success; /* close enough for government work */
|
|
|
|
}
|
1995-04-26 07:43:35 +00:00
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
/* Now check the packing list for dependencies */
|
|
|
|
for (p = Plist.head; p ; p = p->next) {
|
|
|
|
if (p->type != PLIST_PKGDEP)
|
|
|
|
continue;
|
|
|
|
if (Verbose)
|
2001-08-02 12:38:29 +00:00
|
|
|
printf("Package '%s' depends on '%s'.\n", PkgName, p->name);
|
1996-10-14 19:41:44 +00:00
|
|
|
if (vsystem("pkg_info -e %s", p->name)) {
|
1995-10-25 15:38:37 +00:00
|
|
|
char path[FILENAME_MAX], *cp = NULL;
|
|
|
|
|
1996-10-14 19:41:44 +00:00
|
|
|
if (!Fake) {
|
|
|
|
if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) {
|
1998-08-27 14:59:55 +00:00
|
|
|
snprintf(path, FILENAME_MAX, "%s/%s.tgz", getenv("_TOP"), p->name);
|
1996-10-14 19:41:44 +00:00
|
|
|
if (fexists(path))
|
|
|
|
cp = path;
|
1995-11-12 04:55:40 +00:00
|
|
|
else
|
1996-10-14 19:41:44 +00:00
|
|
|
cp = fileFindByPath(pkg, p->name);
|
|
|
|
if (cp) {
|
|
|
|
if (Verbose)
|
|
|
|
printf("Loading it from %s.\n", cp);
|
2001-06-11 23:27:42 +00:00
|
|
|
if (vsystem("pkg_add %s'%s'", Verbose ? "-v " : "", cp)) {
|
2001-08-02 12:38:29 +00:00
|
|
|
warnx("autoload of dependency '%s' failed%s",
|
1997-10-08 07:48:21 +00:00
|
|
|
cp, Force ? " (proceeding anyway)" : "!");
|
1995-11-12 04:55:40 +00:00
|
|
|
if (!Force)
|
|
|
|
++code;
|
|
|
|
}
|
1996-10-14 19:41:44 +00:00
|
|
|
}
|
1998-09-08 03:02:45 +00:00
|
|
|
else {
|
|
|
|
warnx("could not find package %s %s",
|
|
|
|
p->name, Force ? " (proceeding anyway)" : "!");
|
|
|
|
if (!Force)
|
|
|
|
++code;
|
|
|
|
}
|
1996-10-14 19:41:44 +00:00
|
|
|
}
|
|
|
|
else if ((cp = fileGetURL(pkg, p->name)) != NULL) {
|
|
|
|
if (Verbose)
|
|
|
|
printf("Finished loading %s over FTP.\n", p->name);
|
|
|
|
if (!fexists("+CONTENTS")) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("autoloaded package %s has no +CONTENTS file?",
|
|
|
|
p->name);
|
1996-10-14 19:41:44 +00:00
|
|
|
if (!Force)
|
|
|
|
++code;
|
|
|
|
}
|
|
|
|
else if (vsystem("(pwd; cat +CONTENTS) | pkg_add %s-S", Verbose ? "-v " : "")) {
|
2001-08-02 12:38:29 +00:00
|
|
|
warnx("pkg_add of dependency '%s' failed%s",
|
1997-10-08 07:48:21 +00:00
|
|
|
p->name, Force ? " (proceeding anyway)" : "!");
|
1996-10-14 19:41:44 +00:00
|
|
|
if (!Force)
|
|
|
|
++code;
|
|
|
|
}
|
|
|
|
else if (Verbose)
|
2001-08-02 12:38:29 +00:00
|
|
|
printf("\t'%s' loaded successfully.\n", p->name);
|
1996-10-14 19:41:44 +00:00
|
|
|
/* Nuke the temporary playpen */
|
1998-02-16 17:16:51 +00:00
|
|
|
leave_playpen();
|
1995-04-26 07:43:35 +00:00
|
|
|
}
|
1995-10-25 15:38:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (Verbose)
|
|
|
|
printf("and was not found%s.\n", Force ? " (proceeding anyway)" : "");
|
|
|
|
else
|
|
|
|
printf("Package dependency %s for %s not found%s\n", p->name, pkg,
|
|
|
|
Force ? " (proceeding anyway)" : "!");
|
|
|
|
if (!Force)
|
|
|
|
++code;
|
1995-04-26 07:43:35 +00:00
|
|
|
}
|
1993-09-05 04:53:51 +00:00
|
|
|
}
|
1995-10-25 15:38:37 +00:00
|
|
|
else if (Verbose)
|
|
|
|
printf(" - already installed.\n");
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
|
1996-06-03 04:40:43 +00:00
|
|
|
if (code != 0)
|
|
|
|
goto bomb;
|
|
|
|
|
1995-04-26 07:43:35 +00:00
|
|
|
/* Look for the requirements file */
|
1993-08-26 01:19:55 +00:00
|
|
|
if (fexists(REQUIRE_FNAME)) {
|
|
|
|
vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */
|
|
|
|
if (Verbose)
|
|
|
|
printf("Running requirements file first for %s..\n", PkgName);
|
1998-01-21 06:08:35 +00:00
|
|
|
if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, PkgName)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("package %s fails requirements %s", pkg_fullname,
|
|
|
|
Force ? "installing anyway" : "- not installed");
|
1994-12-06 00:51:50 +00:00
|
|
|
if (!Force) {
|
|
|
|
code = 1;
|
|
|
|
goto success; /* close enough for government work */
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
1995-04-26 07:43:35 +00:00
|
|
|
|
2001-05-17 10:12:45 +00:00
|
|
|
/*
|
|
|
|
* Test whether to use the old method of passing tokens to installation
|
1998-12-16 13:59:31 +00:00
|
|
|
* scripts, and set appropriate variables..
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (fexists(POST_INSTALL_FNAME)) {
|
|
|
|
new_m = 1;
|
|
|
|
sprintf(post_script, "%s", POST_INSTALL_FNAME);
|
1999-08-11 20:55:42 +00:00
|
|
|
pre_arg[0] = '\0';
|
|
|
|
post_arg[0] = '\0';
|
1998-12-16 13:59:31 +00:00
|
|
|
} else {
|
|
|
|
if (fexists(INSTALL_FNAME)) {
|
|
|
|
sprintf(post_script, "%s", INSTALL_FNAME);
|
|
|
|
sprintf(pre_arg, "PRE-INSTALL");
|
|
|
|
sprintf(post_arg, "POST-INSTALL");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-26 07:43:35 +00:00
|
|
|
/* If we're really installing, and have an installation file, run it */
|
1998-12-16 13:59:31 +00:00
|
|
|
if (!NoInstall && fexists(pre_script)) {
|
|
|
|
vsystem("chmod +x %s", pre_script); /* make sure */
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Verbose)
|
1998-12-16 13:59:31 +00:00
|
|
|
printf("Running pre-install for %s..\n", PkgName);
|
|
|
|
if (!Fake && vsystem("./%s %s %s", pre_script, PkgName, pre_arg)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("install script returned error status");
|
1998-12-16 13:59:31 +00:00
|
|
|
unlink(pre_script);
|
1994-12-06 00:51:50 +00:00
|
|
|
code = 1;
|
|
|
|
goto success; /* nothing to uninstall yet */
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
1995-04-26 07:43:35 +00:00
|
|
|
|
|
|
|
/* Now finally extract the entire show if we're not going direct */
|
1995-10-25 15:38:37 +00:00
|
|
|
if (!inPlace && !Fake)
|
|
|
|
extract_plist(".", &Plist);
|
1995-04-26 07:43:35 +00:00
|
|
|
|
|
|
|
if (!Fake && fexists(MTREE_FNAME)) {
|
1994-12-06 00:51:50 +00:00
|
|
|
if (Verbose)
|
|
|
|
printf("Running mtree for %s..\n", PkgName);
|
|
|
|
p = find_plist(&Plist, PLIST_CWD);
|
|
|
|
if (Verbose)
|
2000-12-09 09:35:55 +00:00
|
|
|
printf("mtree -U -f %s -d -e -p %s >%s\n", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL);
|
1995-04-28 04:16:30 +00:00
|
|
|
if (!Fake) {
|
2001-01-15 09:45:16 +00:00
|
|
|
if (vsystem("/usr/sbin/mtree -U -f %s -d -e -p %s >%s", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL))
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("mtree returned a non-zero status - continuing");
|
1995-04-28 04:16:30 +00:00
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
}
|
1995-04-26 07:43:35 +00:00
|
|
|
|
1995-04-26 15:06:26 +00:00
|
|
|
/* Run the installation script one last time? */
|
1998-12-16 13:59:31 +00:00
|
|
|
if (!NoInstall && fexists(post_script)) {
|
|
|
|
vsystem("chmod +x %s", post_script); /* make sure */
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Verbose)
|
1998-12-16 13:59:31 +00:00
|
|
|
printf("Running post-install for %s..\n", PkgName);
|
|
|
|
if (!Fake && vsystem("./%s %s %s", post_script, PkgName, post_arg)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("install script returned error status");
|
1998-12-16 13:59:31 +00:00
|
|
|
unlink(post_script);
|
1994-12-06 00:51:50 +00:00
|
|
|
code = 1;
|
1993-08-26 01:19:55 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
1995-04-26 07:43:35 +00:00
|
|
|
|
1995-04-26 15:06:26 +00:00
|
|
|
/* Time to record the deed? */
|
1993-08-26 01:19:55 +00:00
|
|
|
if (!NoRecord && !Fake) {
|
1993-09-05 04:53:51 +00:00
|
|
|
char contents[FILENAME_MAX];
|
|
|
|
FILE *cfile;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
if (getuid() != 0)
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("not running as root - trying to record install anyway");
|
1993-08-26 01:19:55 +00:00
|
|
|
if (!PkgName) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("no package name! can't record package, sorry");
|
1993-08-26 01:19:55 +00:00
|
|
|
code = 1;
|
|
|
|
goto success; /* well, partial anyway */
|
|
|
|
}
|
2001-08-02 13:13:06 +00:00
|
|
|
sprintf(LogDir, "%s/%s", LOG_DIR, PkgName);
|
1998-07-17 14:56:31 +00:00
|
|
|
zapLogDir = 1;
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Verbose)
|
|
|
|
printf("Attempting to record package into %s..\n", LogDir);
|
|
|
|
if (make_hierarchy(LogDir)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("can't record package into '%s', you're on your own!",
|
1993-08-26 01:19:55 +00:00
|
|
|
LogDir);
|
|
|
|
bzero(LogDir, FILENAME_MAX);
|
|
|
|
code = 1;
|
|
|
|
goto success; /* close enough for government work */
|
|
|
|
}
|
1993-09-18 03:38:48 +00:00
|
|
|
/* Make sure pkg_info can read the entry */
|
|
|
|
vsystem("chmod a+rx %s", LogDir);
|
2001-10-08 17:01:35 +00:00
|
|
|
move_file(".", DESC_FNAME, LogDir);
|
|
|
|
move_file(".", COMMENT_FNAME, LogDir);
|
|
|
|
if (fexists(INSTALL_FNAME))
|
|
|
|
move_file(".", INSTALL_FNAME, LogDir);
|
|
|
|
if (fexists(POST_INSTALL_FNAME))
|
|
|
|
move_file(".", POST_INSTALL_FNAME, LogDir);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (fexists(DEINSTALL_FNAME))
|
1995-04-22 13:58:24 +00:00
|
|
|
move_file(".", DEINSTALL_FNAME, LogDir);
|
1998-12-16 13:59:31 +00:00
|
|
|
if (fexists(POST_DEINSTALL_FNAME))
|
|
|
|
move_file(".", POST_DEINSTALL_FNAME, LogDir);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (fexists(REQUIRE_FNAME))
|
1995-04-22 13:58:24 +00:00
|
|
|
move_file(".", REQUIRE_FNAME, LogDir);
|
2001-10-08 17:01:35 +00:00
|
|
|
if (fexists(DISPLAY_FNAME))
|
|
|
|
move_file(".", DISPLAY_FNAME, LogDir);
|
|
|
|
if (fexists(MTREE_FNAME))
|
|
|
|
move_file(".", MTREE_FNAME, LogDir);
|
1993-09-05 04:53:51 +00:00
|
|
|
sprintf(contents, "%s/%s", LogDir, CONTENTS_FNAME);
|
|
|
|
cfile = fopen(contents, "w");
|
|
|
|
if (!cfile) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("can't open new contents file '%s'! can't register pkg",
|
|
|
|
contents);
|
1993-09-05 04:53:51 +00:00
|
|
|
goto success; /* can't log, but still keep pkg */
|
|
|
|
}
|
|
|
|
write_plist(&Plist, cfile);
|
|
|
|
fclose(cfile);
|
1994-12-06 00:51:50 +00:00
|
|
|
for (p = Plist.head; p ; p = p->next) {
|
|
|
|
if (p->type != PLIST_PKGDEP)
|
|
|
|
continue;
|
|
|
|
if (Verbose)
|
2001-08-02 12:38:29 +00:00
|
|
|
printf("Attempting to record dependency on package '%s'\n", p->name);
|
2001-08-13 04:18:30 +00:00
|
|
|
sprintf(contents, "%s/%s/%s", LOG_DIR, basename(p->name),
|
2001-08-02 13:13:06 +00:00
|
|
|
REQUIRED_BY_FNAME);
|
1994-12-06 00:51:50 +00:00
|
|
|
cfile = fopen(contents, "a");
|
1995-06-11 19:33:05 +00:00
|
|
|
if (!cfile)
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("can't open dependency file '%s'!\n"
|
|
|
|
"dependency registration is incomplete", contents);
|
1995-06-11 19:33:05 +00:00
|
|
|
else {
|
1995-10-25 15:38:37 +00:00
|
|
|
fprintf(cfile, "%s\n", PkgName);
|
1995-06-11 19:33:05 +00:00
|
|
|
if (fclose(cfile) == EOF)
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("cannot properly close file %s", contents);
|
1994-12-06 00:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Verbose)
|
|
|
|
printf("Package %s registered in %s\n", PkgName, LogDir);
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1996-06-20 18:33:55 +00:00
|
|
|
if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) {
|
1994-12-06 00:51:50 +00:00
|
|
|
FILE *fp;
|
|
|
|
char buf[BUFSIZ];
|
1996-06-20 18:33:55 +00:00
|
|
|
|
1997-01-13 10:14:26 +00:00
|
|
|
snprintf(buf, sizeof buf, "%s/%s", LogDir, p->name);
|
|
|
|
fp = fopen(buf, "r");
|
1994-12-06 00:51:50 +00:00
|
|
|
if (fp) {
|
|
|
|
putc('\n', stdout);
|
|
|
|
while (fgets(buf, sizeof(buf), fp))
|
|
|
|
fputs(buf, stdout);
|
|
|
|
putc('\n', stdout);
|
|
|
|
(void) fclose(fp);
|
|
|
|
} else
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("cannot open %s as display file", buf);
|
1994-12-06 00:51:50 +00:00
|
|
|
}
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
goto success;
|
|
|
|
|
1995-04-22 13:58:24 +00:00
|
|
|
bomb:
|
|
|
|
code = 1;
|
|
|
|
goto success;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
fail:
|
1994-12-06 00:51:50 +00:00
|
|
|
/* Nuke the whole (installed) show, XXX but don't clean directories */
|
1993-08-26 01:19:55 +00:00
|
|
|
if (!Fake)
|
1994-12-06 00:51:50 +00:00
|
|
|
delete_package(FALSE, FALSE, &Plist);
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
success:
|
|
|
|
/* delete the packing list contents */
|
1995-10-25 15:38:37 +00:00
|
|
|
free_plist(&Plist);
|
1998-02-16 17:16:51 +00:00
|
|
|
leave_playpen();
|
1993-08-26 01:19:55 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sanity_check(char *pkg)
|
|
|
|
{
|
1995-04-26 07:43:35 +00:00
|
|
|
int code = 0;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
if (!fexists(CONTENTS_FNAME)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("package %s has no CONTENTS file!", pkg);
|
1995-04-26 07:43:35 +00:00
|
|
|
code = 1;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
1995-04-26 07:43:35 +00:00
|
|
|
else if (!fexists(COMMENT_FNAME)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("package %s has no COMMENT file!", pkg);
|
1995-04-26 07:43:35 +00:00
|
|
|
code = 1;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
1995-04-26 07:43:35 +00:00
|
|
|
else if (!fexists(DESC_FNAME)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("package %s has no DESC file!", pkg);
|
1995-04-26 07:43:35 +00:00
|
|
|
code = 1;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
1995-04-26 07:43:35 +00:00
|
|
|
return code;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-09-11 07:26:58 +00:00
|
|
|
cleanup(int sig)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
1998-02-16 17:16:51 +00:00
|
|
|
static int in_cleanup = 0;
|
|
|
|
|
|
|
|
if (!in_cleanup) {
|
|
|
|
in_cleanup = 1;
|
1998-09-11 07:26:58 +00:00
|
|
|
if (sig)
|
|
|
|
printf("Signal %d received, cleaning up..\n", sig);
|
1998-07-17 14:56:31 +00:00
|
|
|
if (!Fake && zapLogDir && LogDir[0])
|
1998-09-11 07:26:58 +00:00
|
|
|
vsystem("%s -rf %s", REMOVE_CMD, LogDir);
|
1998-02-16 17:16:51 +00:00
|
|
|
leave_playpen();
|
|
|
|
}
|
1998-09-11 07:26:58 +00:00
|
|
|
if (sig)
|
|
|
|
exit(1);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|