2 * FreeBSD install - a package for the installation and maintenance
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");
42 if (fp == (FILE *) NULL)
43 printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
46 while ((n = fread(line, 1, 1024, fp)) != 0)
47 fwrite(line, 1, n, stdout);
49 append_nl = (line[n - 1] != '\n'); /* Do we have a trailing \n ? */
53 printf("\n"); /* just in case */
57 show_index(const char *title, const char *fname)
60 char line[MAXINDEXSIZE+2];
62 strlcpy(line, "???\n", sizeof(line));
65 printf("%s%s", InfoPrefix, title);
66 fp = fopen(fname, "r");
67 if (fp == (FILE *) NULL) {
68 warnx("show_file: can't open '%s' for reading", fname);
70 if(fgets(line, MAXINDEXSIZE + 1, fp)) {
71 size_t line_length = strlen(line);
73 if (line[line_length - 1] != '\n') { /* Do we have a trailing \n ? */
74 line[line_length] = '\n'; /* Add a trailing \n */
75 line[line_length + 1] = '\0'; /* Terminate string */
83 /* Show a packing list item type. If showall is TRUE, show all */
85 show_plist(const char *title, Package *plist, plist_t type, Boolean showall)
92 printf("%s%s", InfoPrefix, title);
95 if (p->type != type && showall != TRUE) {
102 printf(Quiet ? "%s\n" : "File: %s (ignored)\n", p->name);
106 printf(Quiet ? "%s\n" : "File: %s\n", p->name);
112 printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", (p->name == NULL) ? prefix : p->name);
116 printf(Quiet ? "@srcdir %s\n" : "\tSRCDIR to %s\n", p->name);
120 printf(Quiet ? "@exec %s\n" : "\tEXEC '%s'\n", p->name);
124 printf(Quiet ? "@unexec %s\n" : "\tUNEXEC '%s'\n", p->name);
128 printf(Quiet ? "@chmod %s\n" : "\tCHMOD to %s\n",
129 p->name ? p->name : "(clear default)");
133 printf(Quiet ? "@chown %s\n" : "\tCHOWN to %s\n",
134 p->name ? p->name : "(clear default)");
138 printf(Quiet ? "@chgrp %s\n" : "\tCHGRP to %s\n",
139 p->name ? p->name : "(clear default)");
143 printf(Quiet ? "@comment %s\n" : "\tComment: %s\n", p->name);
147 printf(Quiet ? "@noinst %s\n" : "\tNot installed: %s\n", p->name);
154 case PLIST_IGNORE_INST:
155 printf(Quiet ? "@ignore_inst ??? doesn't belong here.\n" :
156 "\tIgnore next file installation directive (doesn't belong)\n");
161 printf(Quiet ? "@name %s\n" : "\tPackage name: %s\n", p->name);
165 printf(Quiet ? "@display %s\n" : "\tInstall message file: %s\n", p->name);
169 printf(Quiet ? "@pkgdep %s\n" : "Dependency: %s\n", p->name);
172 case PLIST_DEPORIGIN:
173 printf(Quiet ? "@comment DEPORIGIN:%s\n" :
174 "\tdependency origin: %s\n", p->name);
177 case PLIST_CONFLICTS:
178 printf(Quiet ? "@conflicts %s\n" : "Conflicts: %s\n", p->name);
182 printf(Quiet ? "@mtree %s\n" : "\tPackage mtree file: %s\n", p->name);
186 printf(Quiet ? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p->name);
190 printf(Quiet ? "@option %s\n" :
191 "\tOption \"%s\" controlling package installation behaviour\n",
196 printf(Quiet ? "@comment ORIGIN:%s\n" :
197 "\tPackage origin: %s\n", p->name);
202 errx(2, "%s: unknown command type %d (%s)",
203 __func__, p->type, p->name);
211 elide_root(const char *dir)
213 if (strcmp(dir, "/") == 0)
218 /* Show all files in the packing list (except ignored ones) */
220 show_files(const char *title, Package *plist)
225 const char *dir = ".";
228 printf("%s%s", InfoPrefix, title);
234 printf("%s/%s\n", elide_root(dir), p->name);
251 /* Silence GCC in the -Wall mode */
259 /* Calculate and show size of all installed package files (except ignored ones) */
261 show_size(const char *title, Package *plist)
265 const char *dir = ".";
267 char tmp[FILENAME_MAX];
268 unsigned long size = 0;
274 descr = getbsize(&headerlen, &blksize);
276 printf("%s%s", InfoPrefix, title);
277 for (p = plist->head; p != NULL; p = p->next) {
281 snprintf(tmp, FILENAME_MAX, "%s/%s", elide_root(dir), p->name);
282 if (!lstat(tmp, &sb)) {
285 printf("%lu\t%s\n", (unsigned long) howmany(sb.st_size, blksize), tmp);
304 /* Silence GCC in the -Wall mode */
310 printf("%lu\t(%s)\n", howmany(size, blksize), descr);
313 printf("%lu\n", howmany(size, blksize));
315 printf("%lu\n", size);
318 /* Show files that don't match the recorded checksum */
320 show_cksum(const char *title, Package *plist)
323 const char *dir = ".";
325 char tmp[FILENAME_MAX];
328 printf("%s%s", InfoPrefix, title);
330 for (p = plist->head; p != NULL; p = p->next)
331 if (p->type == PLIST_CWD) {
338 } else if (p->type == PLIST_FILE) {
339 snprintf(tmp, FILENAME_MAX, "%s/%s", elide_root(dir), p->name);
341 warnx("%s doesn't exist", tmp);
342 else if (p->next && p->next->type == PLIST_COMMENT &&
343 (strncmp(p->next->name, "MD5:", 4) == 0)) {
344 char *cp = NULL, buf[33];
347 * For packing lists whose version is 1.1 or greater, the md5
348 * hash for a symlink is calculated on the string returned
351 if (issymlink(tmp) && verscmp(plist, 1, 0) > 0) {
353 char linkbuf[FILENAME_MAX];
355 if ((len = readlink(tmp, linkbuf, FILENAME_MAX)) > 0)
356 cp = MD5Data((unsigned char *)linkbuf, len, buf);
357 } else if (isfile(tmp) || verscmp(plist, 1, 1) < 0)
358 cp = MD5File(tmp, buf);
362 if (strcmp(cp, p->next->name + 4))
363 printf("%s fails the original MD5 checksum\n", tmp);
365 printf("%s matched the original MD5 checksum\n", tmp);
371 /* Show an "origin" path (usually category/portname) */
373 show_origin(const char *title, Package *plist)
377 printf("%s%s", InfoPrefix, title);
378 printf("%s\n", plist->origin != NULL ? plist->origin : "");
381 /* Show revision number of the packing list */
383 show_fmtrev(const char *title, Package *plist)
387 printf("%s%s", InfoPrefix, title);
388 printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr);