Deleted Added
full compact
perform.c (41080) perform.c (41866)
1#ifndef lint
2static const char rcsid[] =
1#ifndef lint
2static const char rcsid[] =
3 "$Id: perform.c,v 1.16 1998/09/11 07:26:58 jkh Exp $";
3 "$Id: perform.c,v 1.17 1998/11/11 06:09:04 jkh Exp $";
4#endif
5
6/*
7 * FreeBSD install - a package for the installation and maintainance
8 * of non-core utilities.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions

--- 37 unchanged lines hidden (view full) ---

49static int
50pkg_do(char *pkg)
51{
52 FILE *cfile;
53 char home[FILENAME_MAX];
54 PackingList p;
55 char *tmp;
56 int len;
4#endif
5
6/*
7 * FreeBSD install - a package for the installation and maintainance
8 * of non-core utilities.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions

--- 37 unchanged lines hidden (view full) ---

49static int
50pkg_do(char *pkg)
51{
52 FILE *cfile;
53 char home[FILENAME_MAX];
54 PackingList p;
55 char *tmp;
56 int len;
57 /* support for separate pre/post install scripts */
58 int new_m = 0;
59 char pre_script[FILENAME_MAX] = DEINSTALL_FNAME;
60 char post_script[FILENAME_MAX];
61 char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX];
57
58 if (!pkg || !(len = strlen(pkg)))
59 return 1;
60 if (pkg[len - 1] == '/')
61 pkg[len - 1] = '\0';
62
63 /* Reset some state */
64 if (Plist.head)
65 free_plist(&Plist);
66
67 sprintf(LogDir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
68 pkg);
62
63 if (!pkg || !(len = strlen(pkg)))
64 return 1;
65 if (pkg[len - 1] == '/')
66 pkg[len - 1] = '\0';
67
68 /* Reset some state */
69 if (Plist.head)
70 free_plist(&Plist);
71
72 sprintf(LogDir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
73 pkg);
74
69 if (!fexists(LogDir)) {
70 warnx("no such package '%s' installed", pkg);
71 return 1;
72 }
75 if (!fexists(LogDir)) {
76 warnx("no such package '%s' installed", pkg);
77 return 1;
78 }
79
73 if (!getcwd(home, FILENAME_MAX)) {
74 cleanup(0);
75 errx(2, "unable to get current working directory!");
76 }
80 if (!getcwd(home, FILENAME_MAX)) {
81 cleanup(0);
82 errx(2, "unable to get current working directory!");
83 }
84
77 if (chdir(LogDir) == FAIL) {
78 warnx("unable to change directory to %s! deinstall failed", LogDir);
79 return 1;
80 }
85 if (chdir(LogDir) == FAIL) {
86 warnx("unable to change directory to %s! deinstall failed", LogDir);
87 return 1;
88 }
89
81 if (!isemptyfile(REQUIRED_BY_FNAME)) {
82 char buf[512];
83 warnx("package `%s' is required by these other packages\n"
84 "and may not be deinstalled%s:",
85 pkg, Force ? " (but I'll delete it anyway)" : "" );
86 cfile = fopen(REQUIRED_BY_FNAME, "r");
87 if (cfile) {
88 while (fgets(buf, sizeof(buf), cfile))
89 fprintf(stderr, "%s", buf);
90 fclose(cfile);
91 } else
92 warnx("cannot open requirements file `%s'", REQUIRED_BY_FNAME);
93 if (!Force)
94 return 1;
95 }
90 if (!isemptyfile(REQUIRED_BY_FNAME)) {
91 char buf[512];
92 warnx("package `%s' is required by these other packages\n"
93 "and may not be deinstalled%s:",
94 pkg, Force ? " (but I'll delete it anyway)" : "" );
95 cfile = fopen(REQUIRED_BY_FNAME, "r");
96 if (cfile) {
97 while (fgets(buf, sizeof(buf), cfile))
98 fprintf(stderr, "%s", buf);
99 fclose(cfile);
100 } else
101 warnx("cannot open requirements file `%s'", REQUIRED_BY_FNAME);
102 if (!Force)
103 return 1;
104 }
105
96 sanity_check(LogDir);
97 cfile = fopen(CONTENTS_FNAME, "r");
106 sanity_check(LogDir);
107 cfile = fopen(CONTENTS_FNAME, "r");
108
98 if (!cfile) {
99 warnx("unable to open '%s' file", CONTENTS_FNAME);
100 return 1;
101 }
109 if (!cfile) {
110 warnx("unable to open '%s' file", CONTENTS_FNAME);
111 return 1;
112 }
113
102 /* If we have a prefix, add it now */
103 if (Prefix)
104 add_plist(&Plist, PLIST_CWD, Prefix);
105 read_plist(&Plist, cfile);
106 fclose(cfile);
107 p = find_plist(&Plist, PLIST_CWD);
114 /* If we have a prefix, add it now */
115 if (Prefix)
116 add_plist(&Plist, PLIST_CWD, Prefix);
117 read_plist(&Plist, cfile);
118 fclose(cfile);
119 p = find_plist(&Plist, PLIST_CWD);
120
108 if (!p) {
109 warnx("package '%s' doesn't have a prefix", pkg);
110 return 1;
111 }
121 if (!p) {
122 warnx("package '%s' doesn't have a prefix", pkg);
123 return 1;
124 }
125
112 setenv(PKG_PREFIX_VNAME, p->name, 1);
126 setenv(PKG_PREFIX_VNAME, p->name, 1);
127
113 if (fexists(REQUIRE_FNAME)) {
114 if (Verbose)
115 printf("Executing 'require' script.\n");
116 vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */
117 if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) {
118 warnx("package %s fails requirements %s", pkg,
119 Force ? "" : "- not deleted");
120 if (!Force)
121 return 1;
122 }
123 }
128 if (fexists(REQUIRE_FNAME)) {
129 if (Verbose)
130 printf("Executing 'require' script.\n");
131 vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */
132 if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) {
133 warnx("package %s fails requirements %s", pkg,
134 Force ? "" : "- not deleted");
135 if (!Force)
136 return 1;
137 }
138 }
124 if (!NoDeInstall && fexists(DEINSTALL_FNAME)) {
139
140 /* Test whether to use the old method of passing tokens to deinstallation
141 * scripts, and set appropriate variables..
142 */
143
144 if (fexists(POST_DEINSTALL_FNAME)) {
145 new_m = 1;
146 sprintf(post_script, "%s", POST_DEINSTALL_FNAME);
147 sprintf(pre_arg, "");
148 sprintf(post_arg, "");
149 } else {
150 if (fexists(DEINSTALL_FNAME)) {
151 sprintf(post_script, "%s", DEINSTALL_FNAME);
152 sprintf(pre_arg, "DEINSTALL");
153 sprintf(post_arg, "POST-DEINSTALL");
154 }
155 }
156
157 if (!NoDeInstall && fexists(pre_script)) {
125 if (Fake)
126 printf("Would execute de-install script at this point.\n");
127 else {
158 if (Fake)
159 printf("Would execute de-install script at this point.\n");
160 else {
128 vsystem("chmod +x %s", DEINSTALL_FNAME); /* make sure */
129 if (vsystem("./%s %s DEINSTALL", DEINSTALL_FNAME, pkg)) {
161 vsystem("chmod +x %s", pre_script); /* make sure */
162 if (vsystem("./%s %s %s", pre_script, pkg, pre_arg)) {
130 warnx("deinstall script returned error status");
131 if (!Force)
132 return 1;
133 }
134 }
135 }
163 warnx("deinstall script returned error status");
164 if (!Force)
165 return 1;
166 }
167 }
168 }
169
136 if (chdir(home) == FAIL) {
137 cleanup(0);
138 errx(2, "Toto! This doesn't look like Kansas anymore!");
139 }
170 if (chdir(home) == FAIL) {
171 cleanup(0);
172 errx(2, "Toto! This doesn't look like Kansas anymore!");
173 }
174
140 if (!Fake) {
141 /* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */
142 if (delete_package(FALSE, CleanDirs, &Plist) == FAIL)
143 warnx(
144 "couldn't entirely delete package (perhaps the packing list is\n"
145 "incorrectly specified?)");
175 if (!Fake) {
176 /* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */
177 if (delete_package(FALSE, CleanDirs, &Plist) == FAIL)
178 warnx(
179 "couldn't entirely delete package (perhaps the packing list is\n"
180 "incorrectly specified?)");
181 }
182
183 if (chdir(LogDir) == FAIL) {
184 warnx("unable to change directory to %s! deinstall failed", LogDir);
185 return 1;
186 }
187
188 if (!NoDeInstall && fexists(post_script)) {
189 if (Fake)
190 printf("Would execute post-deinstall script at this point.\n");
191 else {
192 vsystem("chmod +x %s", post_script); /* make sure */
193 if (vsystem("./%s %s %s", post_script, pkg, post_arg)) {
194 warnx("post-deinstall script returned error status");
195 if (!Force)
196 return 1;
197 }
198 }
199 }
200
201 if (chdir(home) == FAIL) {
202 cleanup(0);
203 errx(2, "Toto! This doesn't look like Kansas anymore!");
204 }
205
206 if (!Fake) {
146 if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) {
147 warnx("couldn't remove log entry in %s, deinstall failed", LogDir);
148 if (!Force)
149 return 1;
150 }
151 }
207 if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) {
208 warnx("couldn't remove log entry in %s, deinstall failed", LogDir);
209 if (!Force)
210 return 1;
211 }
212 }
213
152 for (p = Plist.head; p ; p = p->next) {
153 if (p->type != PLIST_PKGDEP)
154 continue;
155 if (Verbose)
156 printf("Attempting to remove dependency on package `%s'\n", p->name);
157 if (!Fake)
158 undepend(p, pkg);
159 }

--- 74 unchanged lines hidden ---
214 for (p = Plist.head; p ; p = p->next) {
215 if (p->type != PLIST_PKGDEP)
216 continue;
217 if (Verbose)
218 printf("Attempting to remove dependency on package `%s'\n", p->name);
219 if (!Fake)
220 undepend(p, pkg);
221 }

--- 74 unchanged lines hidden ---