3 * FreeBSD install - a package for the installation and maintenance
4 * of non-core utilities.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
18 * This is the delete module.
22 #include <sys/cdefs.h>
23 __FBSDID("$FreeBSD$");
25 #include <sys/types.h>
34 Boolean CleanDirs = FALSE;
35 Boolean Interactive = FALSE;
36 Boolean NoDeInstall = FALSE;
37 Boolean Recursive = FALSE;
38 match_t MatchType = MATCH_GLOB;
40 static void usage(void);
42 static char opts[] = "adDfGhinp:rvxX";
43 static struct option longopts[] = {
44 { "all", no_argument, NULL, 'a' },
45 { "clean-dirs", no_argument, NULL, 'd' },
46 { "dry-run", no_argument, NULL, 'n' },
47 { "extended", no_argument, NULL, 'X' },
48 { "force", no_argument, NULL, 'f' },
49 { "help", no_argument, NULL, 'h' },
50 { "interactive",no_argument, NULL, 'i' },
51 { "prefix", required_argument, NULL, 'p' },
52 { "recursive", no_argument, NULL, 'r' },
53 { "regex", no_argument, NULL, 'x' },
54 { "no-glob", no_argument, NULL, 'G' },
55 { "no-script", no_argument, NULL, 'D' },
56 { "no-scripts", no_argument, NULL, 'D' },
57 { "verbose", no_argument, NULL, 'v' },
62 main(int argc, char **argv)
72 while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1)
100 MatchType = MATCH_ALL;
104 MatchType = MATCH_EXACT;
108 MatchType = MATCH_REGEX;
112 MatchType = MATCH_EREGEX;
132 /* Get all the remaining package names, if any */
134 /* Don't try to apply heuristics if arguments are regexs */
135 if (MatchType != MATCH_REGEX)
136 while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
137 *pkgs_split++ = '\0';
139 * If character after the '/' is alphanumeric, then we've found the
140 * package name. Otherwise we've come across a trailing '/' and
141 * need to continue our quest.
143 if (isalnum(*pkgs_split) || ((MatchType == MATCH_GLOB) && \
144 strpbrk(pkgs_split, "*?[]") != NULL)) {
152 /* If no packages, yelp */
153 if (pkgs == start && MatchType != MATCH_ALL)
154 warnx("missing package name(s)"), usage();
157 (void) stat(tmp, &stat_s);
158 if (!Fake && getuid() && geteuid() != stat_s.st_uid) {
160 errx(1, "you do not own %s, use -f to force", tmp);
162 warnx("you do not own %s (proceeding anyways)", tmp);
164 if ((error = pkg_perform(start)) != 0) {
166 warnx("%d package deletion(s) failed", error);
176 fprintf(stderr, "%s\n%s\n",
177 "usage: pkg_delete [-dDfGinrvxX] [-p prefix] pkg-name ...",
178 " pkg_delete -a [flags]");