1993-08-26 01:19:55 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* Various display routines for the info module.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-04-01 09:39:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
#include "lib.h"
|
|
|
|
#include "info.h"
|
1999-08-11 20:55:42 +00:00
|
|
|
#include <err.h>
|
2000-07-07 13:06:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2001-02-03 20:56:32 +00:00
|
|
|
#include <md5.h>
|
1999-08-11 20:55:42 +00:00
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
show_file(const char *title, const char *fname)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char line[1024];
|
|
|
|
int n;
|
|
|
|
|
1993-09-08 01:46:59 +00:00
|
|
|
if (!Quiet)
|
|
|
|
printf("%s%s", InfoPrefix, title);
|
1993-08-26 01:19:55 +00:00
|
|
|
fp = fopen(fname, "r");
|
1995-07-30 01:08:34 +00:00
|
|
|
if (!fp)
|
|
|
|
printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
|
|
|
|
else {
|
1996-06-20 18:33:55 +00:00
|
|
|
while ((n = fread(line, 1, 1024, fp)) != 0)
|
1995-07-30 01:08:34 +00:00
|
|
|
fwrite(line, 1, n, stdout);
|
|
|
|
fclose(fp);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
printf("\n"); /* just in case */
|
|
|
|
}
|
|
|
|
|
1995-01-05 01:10:13 +00:00
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
show_index(const char *title, const char *fname)
|
1995-01-05 01:10:13 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char line[MAXINDEXSIZE+2];
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-01-05 01:10:13 +00:00
|
|
|
if (!Quiet)
|
|
|
|
printf("%s%s", InfoPrefix, title);
|
|
|
|
fp = fopen(fname, "r");
|
|
|
|
if (!fp) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("show_file: can't open '%s' for reading", fname);
|
1995-01-05 01:10:13 +00:00
|
|
|
return;
|
1995-05-30 03:57:47 +00:00
|
|
|
}
|
1995-01-05 01:10:13 +00:00
|
|
|
if(fgets(line, MAXINDEXSIZE+1, fp)) {
|
|
|
|
if(line[MAXINDEXSIZE-1] != '\n')
|
|
|
|
line[MAXINDEXSIZE] = '\n';
|
|
|
|
line[MAXINDEXSIZE+1] = 0;
|
|
|
|
fputs(line, stdout);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
1995-05-30 03:57:47 +00:00
|
|
|
}
|
1995-01-05 01:10:13 +00:00
|
|
|
|
2001-10-10 06:58:42 +00:00
|
|
|
/* Show a packing list item type. If showall is TRUE, show all */
|
1993-08-26 01:19:55 +00:00
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
show_plist(const char *title, Package *plist, plist_t type, Boolean showall)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
|
|
|
PackingList p;
|
|
|
|
Boolean ign = FALSE;
|
|
|
|
|
1993-09-08 01:46:59 +00:00
|
|
|
if (!Quiet)
|
|
|
|
printf("%s%s", InfoPrefix, title);
|
1993-08-26 01:19:55 +00:00
|
|
|
p = plist->head;
|
|
|
|
while (p) {
|
2001-10-10 06:58:42 +00:00
|
|
|
if (p->type != type && showall != TRUE) {
|
1993-08-26 01:19:55 +00:00
|
|
|
p = p->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch(p->type) {
|
|
|
|
case PLIST_FILE:
|
|
|
|
if (ign) {
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "%s\n" : "File: %s (ignored)\n", p->name);
|
1993-08-26 01:19:55 +00:00
|
|
|
ign = FALSE;
|
|
|
|
}
|
|
|
|
else
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "%s\n" : "File: %s\n", p->name);
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case PLIST_CWD:
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", p->name);
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
case PLIST_SRC:
|
|
|
|
printf(Quiet ? "@srcdir %s\n" : "\tSRCDIR to %s\n", p->name);
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case PLIST_CMD:
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "@exec %s\n" : "\tEXEC '%s'\n", p->name);
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
1997-10-18 05:42:05 +00:00
|
|
|
case PLIST_UNEXEC:
|
|
|
|
printf(Quiet ? "@unexec %s\n" : "\tUNEXEC '%s'\n", p->name);
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case PLIST_CHMOD:
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "@chmod %s\n" : "\tCHMOD to %s\n",
|
|
|
|
p->name ? p->name : "(clear default)");
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CHOWN:
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "@chown %s\n" : "\tCHOWN to %s\n",
|
|
|
|
p->name ? p->name : "(clear default)");
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CHGRP:
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "@chgrp %s\n" : "\tCHGRP to %s\n",
|
|
|
|
p->name ? p->name : "(clear default)");
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_COMMENT:
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "@comment %s\n" : "\tComment: %s\n", p->name);
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_IGNORE:
|
|
|
|
ign = TRUE;
|
|
|
|
break;
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
case PLIST_IGNORE_INST:
|
|
|
|
printf(Quiet ? "@ignore_inst ??? doesn't belong here.\n" :
|
|
|
|
"\tIgnore next file installation directive (doesn't belong)\n");
|
|
|
|
ign = TRUE;
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case PLIST_NAME:
|
1993-09-08 01:46:59 +00:00
|
|
|
printf(Quiet ? "@name %s\n" : "\tPackage name: %s\n", p->name);
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
case PLIST_DISPLAY:
|
|
|
|
printf(Quiet ? "@display %s\n" : "\tInstall message file: %s\n", p->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_PKGDEP:
|
2002-05-05 21:03:25 +00:00
|
|
|
printf(Quiet ? "@pkgdep %s\n" : "Dependency: %s\n", p->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_DEPORIGIN:
|
|
|
|
printf(Quiet ? "@comment DEPORIGIN:%s\n" :
|
|
|
|
"\tdependency origin: %s\n", p->name);
|
1994-12-06 00:51:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_MTREE:
|
|
|
|
printf(Quiet ? "@mtree %s\n" : "\tPackage mtree file: %s\n", p->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_DIR_RM:
|
|
|
|
printf(Quiet ? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p->name);
|
|
|
|
break;
|
|
|
|
|
2001-08-06 20:09:26 +00:00
|
|
|
case PLIST_OPTION:
|
|
|
|
printf(Quiet ? "@option %s\n" :
|
|
|
|
"\tOption \"%s\" controlling package installation behaviour\n",
|
|
|
|
p->name);
|
|
|
|
break;
|
|
|
|
|
2002-05-05 12:54:11 +00:00
|
|
|
case PLIST_ORIGIN:
|
|
|
|
printf(Quiet ? "@comment ORIGIN:%s\n" :
|
|
|
|
"\tPackage origin: %s\n", p->name);
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
default:
|
1997-10-08 07:48:21 +00:00
|
|
|
cleanup(0);
|
2002-05-11 03:48:49 +00:00
|
|
|
errx(2, "%s: unknown command type %d (%s)",
|
2002-05-11 04:17:55 +00:00
|
|
|
__func__, p->type, p->name);
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-09-08 01:46:59 +00:00
|
|
|
/* Show all files in the packing list (except ignored ones) */
|
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
show_files(const char *title, Package *plist)
|
1993-09-08 01:46:59 +00:00
|
|
|
{
|
|
|
|
PackingList p;
|
|
|
|
Boolean ign = FALSE;
|
2001-10-10 06:58:42 +00:00
|
|
|
const char *dir = ".";
|
1993-09-08 01:46:59 +00:00
|
|
|
|
|
|
|
if (!Quiet)
|
|
|
|
printf("%s%s", InfoPrefix, title);
|
|
|
|
p = plist->head;
|
|
|
|
while (p) {
|
|
|
|
switch(p->type) {
|
|
|
|
case PLIST_FILE:
|
|
|
|
if (!ign)
|
|
|
|
printf("%s/%s\n", dir, p->name);
|
|
|
|
ign = FALSE;
|
|
|
|
break;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1993-09-08 01:46:59 +00:00
|
|
|
case PLIST_CWD:
|
|
|
|
dir = p->name;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_IGNORE:
|
|
|
|
ign = TRUE;
|
|
|
|
break;
|
2000-07-07 13:06:32 +00:00
|
|
|
|
|
|
|
/* Silence GCC in the -Wall mode */
|
|
|
|
default:
|
|
|
|
break;
|
1993-09-08 01:46:59 +00:00
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
2000-07-07 13:06:32 +00:00
|
|
|
|
|
|
|
/* Calculate and show size of all installed package files (except ignored ones) */
|
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
show_size(const char *title, Package *plist)
|
2000-07-07 13:06:32 +00:00
|
|
|
{
|
|
|
|
PackingList p;
|
|
|
|
Boolean ign = FALSE;
|
2001-10-10 06:58:42 +00:00
|
|
|
const char *dir = ".";
|
2000-07-07 13:06:32 +00:00
|
|
|
struct stat sb;
|
|
|
|
char tmp[FILENAME_MAX];
|
|
|
|
unsigned long size = 0;
|
|
|
|
long blksize;
|
2002-12-30 18:16:26 +00:00
|
|
|
int headerlen;
|
2000-07-07 13:06:32 +00:00
|
|
|
char *descr;
|
|
|
|
|
|
|
|
descr = getbsize(&headerlen, &blksize);
|
|
|
|
if (!Quiet)
|
|
|
|
printf("%s%s", InfoPrefix, title);
|
|
|
|
for (p = plist->head; p != NULL; p = p->next) {
|
|
|
|
switch (p->type) {
|
|
|
|
case PLIST_FILE:
|
|
|
|
if (!ign) {
|
|
|
|
snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
|
|
|
|
if (!lstat(tmp, &sb)) {
|
|
|
|
size += sb.st_size;
|
|
|
|
if (Verbose)
|
|
|
|
printf("%lu\t%s\n", (unsigned long) howmany(sb.st_size, blksize), tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ign = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CWD:
|
|
|
|
dir = p->name;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_IGNORE:
|
|
|
|
ign = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Silence GCC in the -Wall mode */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!Quiet)
|
|
|
|
printf("%lu\t(%s)\n", howmany(size, blksize), descr);
|
|
|
|
else
|
|
|
|
printf("%lu\n", size);
|
|
|
|
}
|
2000-10-23 07:01:31 +00:00
|
|
|
|
2001-02-03 20:56:32 +00:00
|
|
|
/* Show files that don't match the recorded checksum */
|
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
show_cksum(const char *title, Package *plist)
|
2001-02-03 20:56:32 +00:00
|
|
|
{
|
|
|
|
PackingList p;
|
2001-10-10 06:58:42 +00:00
|
|
|
const char *dir = ".";
|
2001-02-03 20:56:32 +00:00
|
|
|
char tmp[FILENAME_MAX];
|
|
|
|
|
|
|
|
if (!Quiet)
|
|
|
|
printf("%s%s", InfoPrefix, title);
|
|
|
|
|
|
|
|
for (p = plist->head; p != NULL; p = p->next)
|
|
|
|
if (p->type == PLIST_CWD)
|
|
|
|
dir = p->name;
|
|
|
|
else if (p->type == PLIST_FILE) {
|
|
|
|
snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
|
|
|
|
if (!fexists(tmp))
|
|
|
|
warnx("%s doesn't exist\n", tmp);
|
2002-05-02 12:52:42 +00:00
|
|
|
else if (p->next && p->next->type == PLIST_COMMENT &&
|
|
|
|
(strncmp(p->next->name, "MD5:", 4) == 0)) {
|
|
|
|
char *cp = NULL, buf[33];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For packing lists whose version is 1.1 or greater, the md5
|
|
|
|
* hash for a symlink is calculated on the string returned
|
|
|
|
* by readlink().
|
|
|
|
*/
|
|
|
|
if (issymlink(tmp) && verscmp(plist, 1, 0) > 0) {
|
|
|
|
int len;
|
|
|
|
char linkbuf[FILENAME_MAX];
|
|
|
|
|
|
|
|
if ((len = readlink(tmp, linkbuf, FILENAME_MAX)) > 0)
|
|
|
|
cp = MD5Data((unsigned char *)linkbuf, len, buf);
|
|
|
|
} else if (isfile(tmp) || verscmp(plist, 1, 1) < 0)
|
|
|
|
cp = MD5File(tmp, buf);
|
|
|
|
|
|
|
|
if (cp != NULL) {
|
|
|
|
/* Mismatch? */
|
2001-02-03 20:56:32 +00:00
|
|
|
if (strcmp(cp, p->next->name + 4))
|
|
|
|
printf("%s fails the original MD5 checksum\n", tmp);
|
|
|
|
else if (Verbose)
|
|
|
|
printf("%s matched the original MD5 checksum\n", tmp);
|
2001-02-05 09:56:52 +00:00
|
|
|
}
|
2001-02-03 20:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-23 07:01:31 +00:00
|
|
|
/* Show an "origin" path (usually category/portname) */
|
|
|
|
void
|
2001-10-10 06:58:42 +00:00
|
|
|
show_origin(const char *title, Package *plist)
|
2000-10-23 07:01:31 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (!Quiet)
|
|
|
|
printf("%s%s", InfoPrefix, title);
|
2002-05-04 14:49:49 +00:00
|
|
|
printf("%s\n", plist->origin != NULL ? plist->origin : "");
|
2000-10-23 07:01:31 +00:00
|
|
|
}
|
2001-10-10 08:21:41 +00:00
|
|
|
|
|
|
|
/* Show revision number of the packing list */
|
|
|
|
void
|
|
|
|
show_fmtrev(const char *title, Package *plist)
|
|
|
|
{
|
2002-05-04 14:49:49 +00:00
|
|
|
|
2001-10-10 08:21:41 +00:00
|
|
|
if (!Quiet)
|
|
|
|
printf("%s%s", InfoPrefix, title);
|
|
|
|
printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr);
|
|
|
|
}
|