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);
68 fp = fopen(fname, "r");
69 if (fp == (FILE *) NULL) {
70 warnx("show_file: can't open '%s' for reading", fname);
72 if(fgets(line, MAXINDEXSIZE + 1, fp)) {
73 size_t line_length = strlen(line);
75 if (line[line_length - 1] != '\n') { /* Do we have a trailing \n ? */
76 line[line_length] = '\n'; /* Add a trailing \n */
77 line[line_length + 1] = '\0'; /* Terminate string */
85 /* Show a packing list item type. If showall is TRUE, show all */
87 show_plist(const char *title, Package *plist, plist_t type, Boolean showall)
94 printf("%s%s", InfoPrefix, title);
99 if (p->type != type && showall != TRUE) {
106 printf(Quiet ? "%s\n" : "File: %s (ignored)\n", p->name);
110 printf(Quiet ? "%s\n" : "File: %s\n", p->name);
116 printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", (p->name == NULL) ? prefix : p->name);
120 printf(Quiet ? "@srcdir %s\n" : "\tSRCDIR to %s\n", p->name);
124 printf(Quiet ? "@exec %s\n" : "\tEXEC '%s'\n", p->name);
128 printf(Quiet ? "@unexec %s\n" : "\tUNEXEC '%s'\n", p->name);
132 printf(Quiet ? "@chmod %s\n" : "\tCHMOD to %s\n",
133 p->name ? p->name : "(clear default)");
137 printf(Quiet ? "@chown %s\n" : "\tCHOWN to %s\n",
138 p->name ? p->name : "(clear default)");
142 printf(Quiet ? "@chgrp %s\n" : "\tCHGRP to %s\n",
143 p->name ? p->name : "(clear default)");
147 printf(Quiet ? "@comment %s\n" : "\tComment: %s\n", p->name);
151 printf(Quiet ? "@noinst %s\n" : "\tNot installed: %s\n", p->name);
158 case PLIST_IGNORE_INST:
159 printf(Quiet ? "@ignore_inst ??? doesn't belong here.\n" :
160 "\tIgnore next file installation directive (doesn't belong)\n");
165 printf(Quiet ? "@name %s\n" : "\tPackage name: %s\n", p->name);
169 printf(Quiet ? "@display %s\n" : "\tInstall message file: %s\n", p->name);
173 printf(Quiet ? "@pkgdep %s\n" : "Dependency: %s\n", p->name);
176 case PLIST_DEPORIGIN:
177 printf(Quiet ? "@comment DEPORIGIN:%s\n" :
178 "\tdependency origin: %s\n", p->name);
181 case PLIST_CONFLICTS:
182 printf(Quiet ? "@conflicts %s\n" : "Conflicts: %s\n", p->name);
186 printf(Quiet ? "@mtree %s\n" : "\tPackage mtree file: %s\n", p->name);
190 printf(Quiet ? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p->name);
194 printf(Quiet ? "@option %s\n" :
195 "\tOption \"%s\" controlling package installation behaviour\n",
200 printf(Quiet ? "@comment ORIGIN:%s\n" :
201 "\tPackage origin: %s\n", p->name);
206 errx(2, "%s: unknown command type %d (%s)",
207 __func__, p->type, p->name);
215 elide_root(const char *dir)
217 if (strcmp(dir, "/") == 0)
222 /* Show all files in the packing list (except ignored ones) */
224 show_files(const char *title, Package *plist)
229 const char *dir = ".";
232 printf("%s%s", InfoPrefix, title);
238 printf("%s/%s\n", elide_root(dir), p->name);
255 /* Silence GCC in the -Wall mode */
263 /* Calculate and show size of all installed package files (except ignored ones) */
265 show_size(const char *title, Package *plist)
269 const char *dir = ".";
271 char tmp[FILENAME_MAX];
272 unsigned long size = 0;
278 descr = getbsize(&headerlen, &blksize);
280 printf("%s%s", InfoPrefix, title);
283 for (p = plist->head; p != NULL; p = p->next) {
287 snprintf(tmp, FILENAME_MAX, "%s/%s", elide_root(dir), p->name);
288 if (!lstat(tmp, &sb)) {
291 printf("%lu\t%s\n", (unsigned long) howmany(sb.st_size, blksize), tmp);
310 /* Silence GCC in the -Wall mode */
316 printf("%lu\t(%s)\n", howmany(size, blksize), descr);
319 printf("%lu\n", howmany(size, blksize));
321 printf("%lu\n", size);
324 /* Show files that don't match the recorded checksum */
326 show_cksum(const char *title, Package *plist)
329 const char *dir = ".";
331 char tmp[FILENAME_MAX];
335 printf("%s%s", InfoPrefix, title);
339 for (p = plist->head; p != NULL; p = p->next)
340 if (p->type == PLIST_CWD) {
347 } else if (p->type == PLIST_FILE) {
348 snprintf(tmp, FILENAME_MAX, "%s/%s", elide_root(dir), p->name);
350 warnx("%s doesn't exist", tmp);
352 } else if (p->next && p->next->type == PLIST_COMMENT &&
353 (strncmp(p->next->name, "MD5:", 4) == 0)) {
354 char *cp = NULL, buf[33];
357 * For packing lists whose version is 1.1 or greater, the md5
358 * hash for a symlink is calculated on the string returned
361 if (issymlink(tmp) && verscmp(plist, 1, 0) > 0) {
363 char linkbuf[FILENAME_MAX];
365 if ((len = readlink(tmp, linkbuf, FILENAME_MAX)) > 0)
366 cp = MD5Data((unsigned char *)linkbuf, len, buf);
367 } else if (isfile(tmp) || verscmp(plist, 1, 1) < 0)
368 cp = MD5File(tmp, buf);
372 if (strcmp(cp, p->next->name + 4))
373 printf("%s fails the original MD5 checksum\n", tmp);
375 printf("%s matched the original MD5 checksum\n", tmp);
382 /* Show an "origin" path (usually category/portname) */
384 show_origin(const char *title, Package *plist)
388 printf("%s%s", InfoPrefix, title);
391 printf("%s\n", plist->origin != NULL ? plist->origin : "");
394 /* Show revision number of the packing list */
396 show_fmtrev(const char *title, Package *plist)
400 printf("%s%s", InfoPrefix, title);
403 printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr);