perform.c revision 379
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) { 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 err_cnt += pkg_do(dp->d_name); 50 } 51 (void)closedir(dirp); 52 } 53 else 54 ++err_cnt; 55 } 56 } 57 for (i = 0; pkgs[i]; i++) 58 err_cnt += pkg_do(pkgs[i]); 59 return err_cnt; 60} 61 62static int 63pkg_do(char *pkg) 64{ 65 Boolean installed = FALSE; 66 char log_dir[FILENAME_MAX]; 67 char *home; 68 Package plist; 69 FILE *fp; 70 71 if (fexists(pkg)) { 72 char fname[FILENAME_MAX]; 73 74 home = make_playpen(); 75 if (pkg[0] == '/') 76 strcpy(fname, pkg); 77 else 78 sprintf(fname, "%s/%s", home, pkg); 79 if (unpack(fname, "+*")) { 80 whinge("Error during unpacking, no info for '%s' available.", pkg); 81 return 1; 82 } 83 } 84 else { 85 sprintf(log_dir, "%s/%s", LOG_DIR, pkg); 86 if (!fexists(log_dir)) { 87 whinge("Can't find package '%s' installed or in a file!", pkg); 88 return 1; 89 } 90 if (chdir(log_dir) == FAIL) { 91 whinge("Can't change directory to '%s'!", log_dir); 92 return 1; 93 } 94 installed = TRUE; 95 } 96 97 /* Suck in the contents list */ 98 plist.head = plist.tail = NULL; 99 fp = fopen(CONTENTS_FNAME, "r"); 100 if (!fp) { 101 whinge("Unable to open %s file.", CONTENTS_FNAME); 102 return 1; 103 } 104 /* If we have a prefix, add it now */ 105 read_plist(&plist, fp); 106 fclose(fp); 107 108 /* 109 * Index is special info type that has to override all others to make 110 * any sense. 111 */ 112 if (Flags & SHOW_INDEX) { 113 char fname[FILENAME_MAX]; 114 115 sprintf(fname, "%s\t", pkg); 116 show_file(fname, COMMENT_FNAME); 117 } 118 else { 119 /* Start showing the package contents */ 120 printf("%sInformation for %s:\n\n", InfoPrefix, pkg); 121 if (Flags & SHOW_COMMENT) 122 show_file("Comment:\n", COMMENT_FNAME); 123 if (Flags & SHOW_DESC) 124 show_file("Description:\n", DESC_FNAME); 125 if (Flags & SHOW_PLIST) 126 show_plist("Packing list:\n", &plist, (plist_t)-1); 127 if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME)) 128 show_file("Install script:\n", INSTALL_FNAME); 129 if ((Flags & SHOW_DEINSTALL) && fexists(DEINSTALL_FNAME)) 130 show_file("De-Install script:\n", DEINSTALL_FNAME); 131 if (Flags & SHOW_PREFIX) 132 show_plist("Prefix(s):\n", &plist, PLIST_CWD); 133 putchar('\014'); 134 } 135 free_plist(&plist); 136 leave_playpen(); 137 return 0; 138} 139 140void 141cleanup(int sig) 142{ 143 leave_playpen(); 144} 145