1999-03-22 09:04:16 +03:00
|
|
|
/* $NetBSD: perform.c,v 1.23 1999/03/22 06:04:17 abs Exp $ */
|
1997-06-05 16:59:18 +04:00
|
|
|
|
1997-10-17 18:53:18 +04:00
|
|
|
#include <sys/cdefs.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#ifndef lint
|
1997-06-05 16:59:18 +04:00
|
|
|
#if 0
|
1997-10-16 04:31:32 +04:00
|
|
|
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
|
1997-06-05 16:59:18 +04:00
|
|
|
#else
|
1999-03-22 09:04:16 +03:00
|
|
|
__RCSID("$NetBSD: perform.c,v 1.23 1999/03/22 06:04:17 abs Exp $");
|
1997-06-05 16:59:18 +04:00
|
|
|
#endif
|
1997-06-05 12:54:23 +04: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"
|
|
|
|
|
1998-08-27 16:54:03 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
1997-10-17 18:53:18 +04:00
|
|
|
#include <err.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#include <signal.h>
|
1998-07-09 21:49:51 +04:00
|
|
|
#include <dirent.h>
|
1998-08-27 16:54:03 +04:00
|
|
|
#include <ctype.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-08-27 16:54:03 +04:00
|
|
|
static char *Home;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-08-27 16:54:03 +04:00
|
|
|
static int
|
|
|
|
pkg_do(char *pkg)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-08-27 16:54:03 +04:00
|
|
|
Boolean installed = FALSE, isTMP = FALSE;
|
|
|
|
char log_dir[FILENAME_MAX];
|
|
|
|
char fname[FILENAME_MAX];
|
1998-10-09 22:27:31 +04:00
|
|
|
package_t plist;
|
1998-08-27 16:54:03 +04:00
|
|
|
FILE *fp;
|
|
|
|
struct stat sb;
|
|
|
|
char *cp = NULL;
|
|
|
|
int code = 0;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-08-27 16:54:03 +04:00
|
|
|
if (isURL(pkg)) {
|
|
|
|
if ((cp = fileGetURL(NULL, pkg)) != NULL) {
|
|
|
|
strcpy(fname, cp);
|
|
|
|
isTMP = TRUE;
|
|
|
|
}
|
|
|
|
} else if (fexists(pkg) && isfile(pkg)) {
|
|
|
|
int len;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-08-27 16:54:03 +04:00
|
|
|
if (*pkg != '/') {
|
1998-10-08 16:15:24 +04:00
|
|
|
if (!getcwd(fname, FILENAME_MAX)) {
|
|
|
|
cleanup(0);
|
|
|
|
err(1, "fatal error during execution: getcwd");
|
|
|
|
}
|
1998-08-27 16:54:03 +04:00
|
|
|
len = strlen(fname);
|
|
|
|
snprintf(&fname[len], FILENAME_MAX - len, "/%s", pkg);
|
|
|
|
} else
|
|
|
|
strcpy(fname, pkg);
|
|
|
|
cp = fname;
|
|
|
|
} else {
|
|
|
|
if ((cp = fileFindByPath(NULL, pkg)) != NULL)
|
|
|
|
strncpy(fname, cp, FILENAME_MAX);
|
|
|
|
}
|
|
|
|
if (cp) {
|
|
|
|
if (isURL(pkg)) {
|
|
|
|
/* file is already unpacked by fileGetURL() */
|
|
|
|
strcpy(PlayPen, cp);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* 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%, but we're only unpacking the + files so
|
|
|
|
* be very optimistic.
|
|
|
|
*/
|
|
|
|
if (stat(fname, &sb) == FAIL) {
|
|
|
|
warnx("can't stat package file '%s'", fname);
|
|
|
|
code = 1;
|
|
|
|
goto bail;
|
|
|
|
}
|
1998-10-08 16:57:58 +04:00
|
|
|
Home = make_playpen(PlayPen, PlayPenSize, sb.st_size / 2);
|
1998-08-27 16:54:03 +04:00
|
|
|
if (unpack(fname, "+*")) {
|
|
|
|
warnx("error during unpacking, no info for '%s' available", pkg);
|
|
|
|
code = 1;
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
1998-10-03 20:24:07 +04:00
|
|
|
* It's not an uninstalled package, try and find it among the
|
1998-08-27 16:54:03 +04:00
|
|
|
* installed
|
|
|
|
*/
|
|
|
|
else {
|
|
|
|
char *tmp;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-08 16:57:58 +04:00
|
|
|
(void) snprintf(log_dir, sizeof(log_dir), "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
|
1998-08-27 16:54:03 +04:00
|
|
|
pkg);
|
1999-03-22 09:04:16 +03:00
|
|
|
if (!fexists(log_dir) || !isdir(log_dir)) {
|
1998-08-27 16:54:03 +04:00
|
|
|
warnx("can't find package `%s' installed or in a file!", pkg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (chdir(log_dir) == FAIL) {
|
|
|
|
warnx("can't change directory to '%s'!", log_dir);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
installed = TRUE;
|
|
|
|
}
|
1998-07-09 21:49:51 +04:00
|
|
|
|
1998-08-27 16:54:03 +04:00
|
|
|
/* Suck in the contents list */
|
|
|
|
plist.head = plist.tail = NULL;
|
|
|
|
fp = fopen(CONTENTS_FNAME, "r");
|
|
|
|
if (!fp) {
|
|
|
|
warnx("unable to open %s file", CONTENTS_FNAME);
|
|
|
|
code = 1;
|
|
|
|
goto bail;
|
1998-07-09 21:49:51 +04:00
|
|
|
}
|
1998-08-27 16:54:03 +04: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) {
|
|
|
|
char tmp[FILENAME_MAX];
|
|
|
|
|
|
|
|
snprintf(tmp, FILENAME_MAX, "%-19s ", pkg);
|
|
|
|
show_index(tmp, COMMENT_FNAME);
|
|
|
|
} else {
|
|
|
|
/* Start showing the package contents */
|
1998-10-13 21:08:28 +04:00
|
|
|
if (!Quiet) {
|
1998-08-27 16:54:03 +04:00
|
|
|
printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if (Flags & SHOW_COMMENT) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_file("Comment:\n", COMMENT_FNAME);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
1999-03-04 03:35:05 +03:00
|
|
|
if (Flags & SHOW_DEPENDS) {
|
|
|
|
show_depends("Requires:\n", &plist);
|
|
|
|
}
|
1998-10-13 21:08:28 +04:00
|
|
|
if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME)) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_file("Required by:\n", REQUIRED_BY_FNAME);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if (Flags & SHOW_DESC) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_file("Description:\n", DESC_FNAME);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if ((Flags & SHOW_DISPLAY) && fexists(DISPLAY_FNAME)) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_file("Install notice:\n", DISPLAY_FNAME);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if (Flags & SHOW_PLIST) {
|
1998-10-09 13:35:39 +04:00
|
|
|
show_plist("Packing list:\n", &plist, PLIST_SHOW_ALL);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME)) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_file("Install script:\n", INSTALL_FNAME);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if ((Flags & SHOW_DEINSTALL) && fexists(DEINSTALL_FNAME)) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_file("De-Install script:\n", DEINSTALL_FNAME);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if ((Flags & SHOW_MTREE) && fexists(MTREE_FNAME)) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_file("mtree file:\n", MTREE_FNAME);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if (Flags & SHOW_PREFIX) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_plist("Prefix(s):\n", &plist, PLIST_CWD);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if (Flags & SHOW_FILES) {
|
1998-08-27 16:54:03 +04:00
|
|
|
show_files("Files:\n", &plist);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
|
|
|
if ((Flags & SHOW_BUILD_VERSION) && fexists(BUILD_VERSION_FNAME)) {
|
|
|
|
show_file("Build version:\n", BUILD_VERSION_FNAME);
|
|
|
|
}
|
1998-10-21 13:54:09 +04:00
|
|
|
if ((Flags & SHOW_BUILD_INFO) && fexists(BUILD_INFO_FNAME)) {
|
|
|
|
show_file("Build information:\n", BUILD_INFO_FNAME);
|
|
|
|
}
|
1998-10-13 21:08:28 +04:00
|
|
|
if (!Quiet) {
|
1998-08-27 16:54:03 +04:00
|
|
|
puts(InfoPrefix);
|
1998-10-13 21:08:28 +04:00
|
|
|
}
|
1998-07-09 21:49:51 +04:00
|
|
|
}
|
1998-08-27 16:54:03 +04:00
|
|
|
free_plist(&plist);
|
|
|
|
bail:
|
|
|
|
leave_playpen(Home);
|
|
|
|
if (isTMP)
|
|
|
|
unlink(fname);
|
|
|
|
return code;
|
|
|
|
}
|
1998-07-09 21:49:51 +04:00
|
|
|
|
1998-10-03 20:24:07 +04:00
|
|
|
/* fn to be called for pkgs found */
|
1998-10-04 05:48:15 +04:00
|
|
|
static int
|
|
|
|
foundpkg(const char *found, char *data)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-21 13:54:09 +04:00
|
|
|
if (!Quiet) {
|
|
|
|
printf("%s\n", found);
|
|
|
|
}
|
|
|
|
return 0;
|
1998-08-27 16:54:03 +04:00
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-03 20:24:07 +04:00
|
|
|
/* check if a package "pkgspec" (which can be a pattern) is installed */
|
|
|
|
/* return 0 if found, 1 otherwise (indicating an error). */
|
1998-08-27 16:54:03 +04:00
|
|
|
static int
|
1998-10-21 13:54:09 +04:00
|
|
|
CheckForPkg(char *pkgspec, char *dbdir)
|
1998-08-27 16:54:03 +04:00
|
|
|
{
|
1998-10-21 13:54:09 +04:00
|
|
|
struct stat st;
|
1998-08-27 16:54:03 +04:00
|
|
|
char buf[FILENAME_MAX];
|
|
|
|
int error;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-21 13:54:09 +04:00
|
|
|
if (strpbrk(pkgspec, "<>[]?*{")) {
|
|
|
|
/* expensive (pattern) match */
|
|
|
|
return !findmatchingname(dbdir, pkgspec, foundpkg, NULL);
|
|
|
|
}
|
|
|
|
/* simple match */
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", dbdir, pkgspec);
|
|
|
|
error = (stat(buf, &st) < 0);
|
|
|
|
if (!error && !Quiet) {
|
1998-08-27 16:54:03 +04:00
|
|
|
printf("%s\n", pkgspec);
|
1998-10-03 20:24:07 +04:00
|
|
|
}
|
1998-10-21 13:54:09 +04:00
|
|
|
return error;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cleanup(int sig)
|
|
|
|
{
|
1998-08-25 04:12:16 +04:00
|
|
|
leave_playpen(Home);
|
1998-08-27 16:54:03 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-03-22 08:02:39 +03:00
|
|
|
pkg_perform(lpkg_head_t *pkgs)
|
1998-08-27 16:54:03 +04:00
|
|
|
{
|
1998-10-21 13:54:09 +04:00
|
|
|
struct dirent *dp;
|
1998-08-27 16:54:03 +04:00
|
|
|
char *tmp;
|
1998-10-21 13:54:09 +04:00
|
|
|
DIR *dirp;
|
|
|
|
int err_cnt = 0;
|
1998-08-27 16:54:03 +04:00
|
|
|
|
|
|
|
signal(SIGINT, cleanup);
|
|
|
|
|
1998-10-21 13:54:09 +04:00
|
|
|
if ((tmp = getenv(PKG_DBDIR)) == (char *) NULL) {
|
1998-08-27 16:54:03 +04:00
|
|
|
tmp = DEF_LOG_DIR;
|
1998-10-21 13:54:09 +04:00
|
|
|
}
|
1998-08-27 16:54:03 +04:00
|
|
|
/* Overriding action? */
|
|
|
|
if (CheckPkg) {
|
1998-10-21 13:54:09 +04:00
|
|
|
err_cnt += CheckForPkg(CheckPkg, tmp);
|
1998-08-27 16:54:03 +04:00
|
|
|
} else if (AllInstalled) {
|
1999-01-19 20:01:56 +03:00
|
|
|
if (!(isdir(tmp) || islinktodir(tmp)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (File2Pkg) {
|
|
|
|
/* Show all files with the package they belong to */
|
|
|
|
char *file, *pkg;
|
|
|
|
|
|
|
|
/* pkg_info -Fa => Dump pkgdb */
|
|
|
|
if (pkgdb_open(1)==-1) {
|
|
|
|
err(1, "cannot open pkgdb");
|
|
|
|
}
|
|
|
|
while ((file = pkgdb_iter())) {
|
|
|
|
pkg = pkgdb_retrieve(file);
|
|
|
|
printf("%-50s %s\n", file, pkg);
|
1998-10-21 13:54:09 +04:00
|
|
|
}
|
1999-01-19 20:01:56 +03:00
|
|
|
pkgdb_close();
|
|
|
|
} else {
|
|
|
|
/* Show all packges with description */
|
1998-08-27 16:54:03 +04:00
|
|
|
if ((dirp = opendir(tmp)) != (DIR *) NULL) {
|
|
|
|
while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
|
1999-01-19 20:01:56 +03:00
|
|
|
char tmp2[FILENAME_MAX];
|
|
|
|
|
|
|
|
if (strcmp(dp->d_name, ".")==0 ||
|
|
|
|
strcmp(dp->d_name, "..")==0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
snprintf(tmp2, FILENAME_MAX, "%s/%s",
|
|
|
|
tmp, dp->d_name);
|
|
|
|
if (isfile(tmp2))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err_cnt += pkg_do(dp->d_name);
|
1998-08-27 16:54:03 +04:00
|
|
|
}
|
|
|
|
(void) closedir(dirp);
|
|
|
|
}
|
1999-01-19 20:01:56 +03:00
|
|
|
}
|
1998-08-27 16:54:03 +04:00
|
|
|
} else {
|
1999-03-22 08:02:39 +03:00
|
|
|
lpkg_t *lpp;
|
|
|
|
|
|
|
|
while ((lpp = TAILQ_FIRST(pkgs))) {
|
|
|
|
TAILQ_REMOVE(pkgs, lpp, lp_link);
|
|
|
|
err_cnt += pkg_do(lpp->lp_name);
|
|
|
|
free_lpkg(lpp);
|
|
|
|
}
|
1998-08-27 16:54:03 +04:00
|
|
|
}
|
|
|
|
return err_cnt;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|