2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
17 * Various display routines for the info module.
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
28 #include <sys/types.h>
33 show_file(const char *title, const char *fname)
40 printf("%s%s", InfoPrefix, title);
41 fp = fopen(fname, "r");
43 printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
45 while ((n = fread(line, 1, 1024, fp)) != 0)
46 fwrite(line, 1, n, stdout);
49 printf("\n"); /* just in case */
53 show_index(const char *title, const char *fname)
56 char line[MAXINDEXSIZE+2];
59 printf("%s%s", InfoPrefix, title);
60 fp = fopen(fname, "r");
62 warnx("show_file: can't open '%s' for reading", fname);
65 if(fgets(line, MAXINDEXSIZE+1, fp)) {
66 if(line[MAXINDEXSIZE-1] != '\n')
67 line[MAXINDEXSIZE] = '\n';
68 line[MAXINDEXSIZE+1] = 0;
74 /* Show a packing list item type. If showall is TRUE, show all */
76 show_plist(const char *title, Package *plist, plist_t type, Boolean showall)
82 printf("%s%s", InfoPrefix, title);
85 if (p->type != type && showall != TRUE) {
92 printf(Quiet ? "%s\n" : "File: %s (ignored)\n", p->name);
96 printf(Quiet ? "%s\n" : "File: %s\n", p->name);
100 printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", p->name);
104 printf(Quiet ? "@srcdir %s\n" : "\tSRCDIR to %s\n", p->name);
108 printf(Quiet ? "@exec %s\n" : "\tEXEC '%s'\n", p->name);
112 printf(Quiet ? "@unexec %s\n" : "\tUNEXEC '%s'\n", p->name);
116 printf(Quiet ? "@chmod %s\n" : "\tCHMOD to %s\n",
117 p->name ? p->name : "(clear default)");
121 printf(Quiet ? "@chown %s\n" : "\tCHOWN to %s\n",
122 p->name ? p->name : "(clear default)");
126 printf(Quiet ? "@chgrp %s\n" : "\tCHGRP to %s\n",
127 p->name ? p->name : "(clear default)");
131 printf(Quiet ? "@comment %s\n" : "\tComment: %s\n", p->name);
138 case PLIST_IGNORE_INST:
139 printf(Quiet ? "@ignore_inst ??? doesn't belong here.\n" :
140 "\tIgnore next file installation directive (doesn't belong)\n");
145 printf(Quiet ? "@name %s\n" : "\tPackage name: %s\n", p->name);
149 printf(Quiet ? "@display %s\n" : "\tInstall message file: %s\n", p->name);
153 printf(Quiet ? "@pkgdep %s\n" : "Dependency: %s\n", p->name);
156 case PLIST_DEPORIGIN:
157 printf(Quiet ? "@comment DEPORIGIN:%s\n" :
158 "\tdependency origin: %s\n", p->name);
162 printf(Quiet ? "@mtree %s\n" : "\tPackage mtree file: %s\n", p->name);
166 printf(Quiet ? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p->name);
170 printf(Quiet ? "@option %s\n" :
171 "\tOption \"%s\" controlling package installation behaviour\n",
176 printf(Quiet ? "@comment ORIGIN:%s\n" :
177 "\tPackage origin: %s\n", p->name);
182 errx(2, "%s: unknown command type %d (%s)",
183 __func__, p->type, p->name);
190 /* Show all files in the packing list (except ignored ones) */
192 show_files(const char *title, Package *plist)
196 const char *dir = ".";
199 printf("%s%s", InfoPrefix, title);
205 printf("%s/%s\n", dir, p->name);
217 /* Silence GCC in the -Wall mode */
225 /* Calculate and show size of all installed package files (except ignored ones) */
227 show_size(const char *title, Package *plist)
231 const char *dir = ".";
233 char tmp[FILENAME_MAX];
234 unsigned long size = 0;
239 descr = getbsize(&headerlen, &blksize);
241 printf("%s%s", InfoPrefix, title);
242 for (p = plist->head; p != NULL; p = p->next) {
246 snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
247 if (!lstat(tmp, &sb)) {
250 printf("%lu\t%s\n", (unsigned long) howmany(sb.st_size, blksize), tmp);
264 /* Silence GCC in the -Wall mode */
270 printf("%lu\t(%s)\n", howmany(size, blksize), descr);
272 printf("%lu\n", size);
275 /* Show files that don't match the recorded checksum */
277 show_cksum(const char *title, Package *plist)
280 const char *dir = ".";
281 char tmp[FILENAME_MAX];
284 printf("%s%s", InfoPrefix, title);
286 for (p = plist->head; p != NULL; p = p->next)
287 if (p->type == PLIST_CWD)
289 else if (p->type == PLIST_FILE) {
290 snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
292 warnx("%s doesn't exist\n", tmp);
293 else if (p->next && p->next->type == PLIST_COMMENT &&
294 (strncmp(p->next->name, "MD5:", 4) == 0)) {
295 char *cp = NULL, buf[33];
298 * For packing lists whose version is 1.1 or greater, the md5
299 * hash for a symlink is calculated on the string returned
302 if (issymlink(tmp) && verscmp(plist, 1, 0) > 0) {
304 char linkbuf[FILENAME_MAX];
306 if ((len = readlink(tmp, linkbuf, FILENAME_MAX)) > 0)
307 cp = MD5Data((unsigned char *)linkbuf, len, buf);
308 } else if (isfile(tmp) || verscmp(plist, 1, 1) < 0)
309 cp = MD5File(tmp, buf);
313 if (strcmp(cp, p->next->name + 4))
314 printf("%s fails the original MD5 checksum\n", tmp);
316 printf("%s matched the original MD5 checksum\n", tmp);
322 /* Show an "origin" path (usually category/portname) */
324 show_origin(const char *title, Package *plist)
328 printf("%s%s", InfoPrefix, title);
329 printf("%s\n", plist->origin != NULL ? plist->origin : "");
332 /* Show revision number of the packing list */
334 show_fmtrev(const char *title, Package *plist)
338 printf("%s%s", InfoPrefix, title);
339 printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr);