perform.c revision 411
1#ifndef lint
2static const char *rcsid = "$Id: perform.c,v 1.4 1993/09/04 05:06:43 jkh Exp $";
3#endif
4
5/*
6 * FreeBSD install - a package for the installation and maintainance
7 * of non-core utilities.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * Jordan K. Hubbard
19 * 23 Aug 1993
20 *
21 * This is the main body of the info module.
22 *
23 */
24
25#include "lib.h"
26#include "info.h"
27
28#include <signal.h>
29
30static int pkg_do(char *);
31
32int
33pkg_perform(char **pkgs)
34{
35    int i, err_cnt = 0;
36
37    signal(SIGINT, cleanup);
38
39    /* Overriding action? */
40    if (AllInstalled || CheckPkg) {
41	if (isdir(LOG_DIR)) {
42	    DIR *dirp;
43	    struct dirent *dp;
44
45	    dirp = opendir(LOG_DIR);
46	    if (dirp) {
47		for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
48		    if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
49			if (CheckPkg) {
50			    if (!strcmp(dp->d_name, CheckPkg))
51				return 0;
52			}
53			else
54			    err_cnt += pkg_do(dp->d_name);
55		    }
56		}
57		(void)closedir(dirp);
58		if (CheckPkg)
59		    return 1;
60	    }
61	    else
62		++err_cnt;
63	}
64    }
65    for (i = 0; pkgs[i]; i++)
66	err_cnt += pkg_do(pkgs[i]);
67    return err_cnt;
68}
69
70static int
71pkg_do(char *pkg)
72{
73    Boolean installed = FALSE;
74    char log_dir[FILENAME_MAX];
75    char *home;
76    Package plist;
77    FILE *fp;
78
79    if (fexists(pkg)) {
80	char fname[FILENAME_MAX];
81
82	home = make_playpen(PlayPen);
83	if (pkg[0] == '/')
84	    strcpy(fname, pkg);
85	else
86	    sprintf(fname, "%s/%s", home, pkg);
87	if (unpack(fname, "+*")) {
88	    whinge("Error during unpacking, no info for '%s' available.", pkg);
89	    return 1;
90	}
91    }
92    else {
93	sprintf(log_dir, "%s/%s", LOG_DIR, pkg);
94	if (!fexists(log_dir)) {
95	    whinge("Can't find package '%s' installed or in a file!", pkg);
96	    return 1;
97	}
98	if (chdir(log_dir) == FAIL) {
99	    whinge("Can't change directory to '%s'!", log_dir);
100	    return 1;
101	}
102	installed = TRUE;
103    }
104
105    /* Suck in the contents list */
106    plist.head = plist.tail = NULL;
107    fp = fopen(CONTENTS_FNAME, "r");
108    if (!fp) {
109	whinge("Unable to open %s file.", CONTENTS_FNAME);
110	return 1;
111    }
112    /* If we have a prefix, add it now */
113    read_plist(&plist, fp);
114    fclose(fp);
115
116    /*
117     * Index is special info type that has to override all others to make
118     * any sense.
119     */
120    if (Flags & SHOW_INDEX) {
121	char fname[FILENAME_MAX];
122
123	sprintf(fname, "%s\t", pkg);
124	show_file(fname, COMMENT_FNAME);
125    }
126    else {
127	/* Start showing the package contents */
128	if (!Quiet)
129	    printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
130	if (Flags & SHOW_COMMENT)
131	    show_file("Comment:\n", COMMENT_FNAME);
132	if (Flags & SHOW_DESC)
133	    show_file("Description:\n", DESC_FNAME);
134	if (Flags & SHOW_PLIST)
135	    show_plist("Packing list:\n", &plist, (plist_t)-1);
136	if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME))
137	    show_file("Install script:\n", INSTALL_FNAME);
138	if ((Flags & SHOW_DEINSTALL) && fexists(DEINSTALL_FNAME))
139	    show_file("De-Install script:\n", DEINSTALL_FNAME);
140	if (Flags & SHOW_PREFIX)
141	    show_plist("Prefix(s):\n", &plist, PLIST_CWD);
142	if (Flags & SHOW_FILES)
143	    show_files("Files:\n", &plist);
144	if (!Quiet)
145	    puts(InfoPrefix);
146    }
147    free_plist(&plist);
148    leave_playpen();
149    return 0;
150}
151
152void
153cleanup(int sig)
154{
155    leave_playpen();
156}
157