1993-08-26 01:19:55 +00:00
|
|
|
#ifndef lint
|
1997-10-08 07:48:21 +00:00
|
|
|
static const char rcsid[] =
|
1997-10-13 15:03:55 +00:00
|
|
|
"$Id: perform.c,v 1.22 1997/10/08 07:47:29 charnier Exp $";
|
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
|
|
|
|
* 23 Aug 1993
|
|
|
|
*
|
|
|
|
* This is the main body of the info module.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lib.h"
|
|
|
|
#include "info.h"
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
static int pkg_do(char *);
|
|
|
|
|
|
|
|
int
|
|
|
|
pkg_perform(char **pkgs)
|
|
|
|
{
|
|
|
|
int i, err_cnt = 0;
|
1995-04-19 14:02:01 +00:00
|
|
|
char *tmp;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
signal(SIGINT, cleanup);
|
|
|
|
|
1995-04-19 14:02:01 +00:00
|
|
|
tmp = getenv(PKG_DBDIR);
|
|
|
|
if (!tmp)
|
|
|
|
tmp = DEF_LOG_DIR;
|
1993-08-26 01:19:55 +00:00
|
|
|
/* Overriding action? */
|
1996-06-16 16:33:34 +00:00
|
|
|
if (CheckPkg) {
|
|
|
|
char buf[FILENAME_MAX];
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1996-06-16 16:33:34 +00:00
|
|
|
snprintf(buf, FILENAME_MAX, "%s/%s", tmp, CheckPkg);
|
|
|
|
return abs(access(buf, R_OK));
|
|
|
|
}
|
|
|
|
else if (AllInstalled) {
|
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1996-06-16 16:33:34 +00:00
|
|
|
if (!isdir(tmp))
|
|
|
|
return 1;
|
|
|
|
dirp = opendir(tmp);
|
|
|
|
if (dirp) {
|
|
|
|
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
|
|
|
|
if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, ".."))
|
|
|
|
err_cnt += pkg_do(dp->d_name);
|
|
|
|
(void)closedir(dirp);
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
1996-06-16 16:33:34 +00:00
|
|
|
else
|
|
|
|
for (i = 0; pkgs[i]; i++)
|
|
|
|
err_cnt += pkg_do(pkgs[i]);
|
1993-08-26 01:19:55 +00:00
|
|
|
return err_cnt;
|
|
|
|
}
|
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
static char *Home;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
static int
|
|
|
|
pkg_do(char *pkg)
|
|
|
|
{
|
1995-04-26 15:08:02 +00:00
|
|
|
Boolean installed = FALSE, isTMP = FALSE;
|
1993-08-26 01:19:55 +00:00
|
|
|
char log_dir[FILENAME_MAX];
|
1995-04-26 15:08:02 +00:00
|
|
|
char fname[FILENAME_MAX];
|
1993-08-26 01:19:55 +00:00
|
|
|
Package plist;
|
|
|
|
FILE *fp;
|
1995-04-26 15:08:02 +00:00
|
|
|
struct stat sb;
|
1995-04-28 18:24:31 +00:00
|
|
|
char *cp = NULL;
|
1995-04-26 15:08:02 +00:00
|
|
|
int code = 0;
|
|
|
|
|
|
|
|
if (isURL(pkg)) {
|
1995-10-25 15:38:37 +00:00
|
|
|
if ((cp = fileGetURL(NULL, pkg)) != NULL) {
|
1995-04-26 15:08:02 +00:00
|
|
|
strcpy(fname, cp);
|
|
|
|
isTMP = TRUE;
|
|
|
|
}
|
|
|
|
}
|
1995-07-30 01:44:45 +00:00
|
|
|
else if (fexists(pkg) && isfile(pkg)) {
|
1995-04-26 15:08:02 +00:00
|
|
|
int len;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1995-05-10 23:00:07 +00:00
|
|
|
if (*pkg != '/') {
|
|
|
|
if (!getcwd(fname, FILENAME_MAX))
|
|
|
|
upchuck("getcwd");
|
|
|
|
len = strlen(fname);
|
|
|
|
snprintf(&fname[len], FILENAME_MAX - len, "/%s", pkg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcpy(fname, pkg);
|
1995-04-26 15:08:02 +00:00
|
|
|
cp = fname;
|
|
|
|
}
|
|
|
|
else {
|
1995-10-25 15:38:37 +00:00
|
|
|
if ((cp = fileFindByPath(NULL, pkg)) != NULL)
|
1995-04-26 15:08:02 +00:00
|
|
|
strncpy(fname, cp, FILENAME_MAX);
|
|
|
|
}
|
|
|
|
if (cp) {
|
1994-10-04 16:07:50 +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
|
1994-10-14 05:55:57 +00:00
|
|
|
* compress an average of 75%, but we're only unpacking the + files so
|
|
|
|
* be very optimistic.
|
1994-10-04 16:07:50 +00:00
|
|
|
*/
|
|
|
|
if (stat(fname, &sb) == FAIL) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("can't stat package file '%s'", fname);
|
1995-04-26 15:08:02 +00:00
|
|
|
code = 1;
|
|
|
|
goto bail;
|
1994-10-04 16:07:50 +00:00
|
|
|
}
|
1995-10-25 15:38:37 +00:00
|
|
|
Home = make_playpen(PlayPen, sb.st_size / 2);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (unpack(fname, "+*")) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("error during unpacking, no info for '%s' available", pkg);
|
1995-04-26 15:08:02 +00:00
|
|
|
code = 1;
|
|
|
|
goto bail;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
1995-04-26 15:08:02 +00:00
|
|
|
/* It's not an ininstalled package, try and find it among the installed */
|
1993-08-26 01:19:55 +00:00
|
|
|
else {
|
1995-04-19 14:02:01 +00:00
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
sprintf(log_dir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
|
|
|
|
pkg);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (!fexists(log_dir)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("can't find package `%s' installed or in a file!", pkg);
|
1993-08-26 01:19:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (chdir(log_dir) == FAIL) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("can't change directory to '%s'!", log_dir);
|
1993-08-26 01:19:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
installed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Suck in the contents list */
|
|
|
|
plist.head = plist.tail = NULL;
|
|
|
|
fp = fopen(CONTENTS_FNAME, "r");
|
|
|
|
if (!fp) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("unable to open %s file", CONTENTS_FNAME);
|
1995-04-26 15:08:02 +00:00
|
|
|
code = 1;
|
|
|
|
goto bail;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
/* If we have a prefix, add it now */
|
|
|
|
read_plist(&plist, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Index is special info type that has to override all others to make
|
|
|
|
* any sense.
|
|
|
|
*/
|
|
|
|
if (Flags & SHOW_INDEX) {
|
1995-04-26 15:08:02 +00:00
|
|
|
char tmp[FILENAME_MAX];
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1995-04-26 15:08:02 +00:00
|
|
|
snprintf(tmp, FILENAME_MAX, "%-19s ", pkg);
|
|
|
|
show_index(tmp, COMMENT_FNAME);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Start showing the package contents */
|
1993-09-08 01:46:59 +00:00
|
|
|
if (!Quiet)
|
|
|
|
printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Flags & SHOW_COMMENT)
|
1993-09-03 23:01:17 +00:00
|
|
|
show_file("Comment:\n", COMMENT_FNAME);
|
1994-12-06 00:51:50 +00:00
|
|
|
if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME))
|
|
|
|
show_file("Required by:\n", REQUIRED_BY_FNAME);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Flags & SHOW_DESC)
|
1993-09-03 23:01:17 +00:00
|
|
|
show_file("Description:\n", DESC_FNAME);
|
1994-12-06 00:51:50 +00:00
|
|
|
if ((Flags & SHOW_DISPLAY) && fexists(DISPLAY_FNAME))
|
|
|
|
show_file("Install notice:\n", DISPLAY_FNAME);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Flags & SHOW_PLIST)
|
1993-09-03 23:01:17 +00:00
|
|
|
show_plist("Packing list:\n", &plist, (plist_t)-1);
|
1993-08-26 01:19:55 +00:00
|
|
|
if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME))
|
1993-09-03 23:01:17 +00:00
|
|
|
show_file("Install script:\n", INSTALL_FNAME);
|
1993-08-26 01:19:55 +00:00
|
|
|
if ((Flags & SHOW_DEINSTALL) && fexists(DEINSTALL_FNAME))
|
1993-09-03 23:01:17 +00:00
|
|
|
show_file("De-Install script:\n", DEINSTALL_FNAME);
|
1994-12-06 00:51:50 +00:00
|
|
|
if ((Flags & SHOW_MTREE) && fexists(MTREE_FNAME))
|
|
|
|
show_file("mtree file:\n", MTREE_FNAME);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Flags & SHOW_PREFIX)
|
1993-09-03 23:01:17 +00:00
|
|
|
show_plist("Prefix(s):\n", &plist, PLIST_CWD);
|
1993-09-08 01:46:59 +00:00
|
|
|
if (Flags & SHOW_FILES)
|
|
|
|
show_files("Files:\n", &plist);
|
|
|
|
if (!Quiet)
|
|
|
|
puts(InfoPrefix);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
free_plist(&plist);
|
1995-04-26 15:08:02 +00:00
|
|
|
bail:
|
1995-10-25 15:38:37 +00:00
|
|
|
leave_playpen(Home);
|
1995-04-26 15:08:02 +00:00
|
|
|
if (isTMP)
|
|
|
|
unlink(fname);
|
|
|
|
return code;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cleanup(int sig)
|
|
|
|
{
|
1995-10-25 15:38:37 +00:00
|
|
|
leave_playpen(Home);
|
1997-10-13 15:03:55 +00:00
|
|
|
exit(1);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|