3 * FreeBSD install - a package for the installation and maintainance
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
)
71 while ((ch
= getopt_long(argc
, argv
, opts
, longopts
, NULL
)) != -1)
99 MatchType
= MATCH_ALL
;
103 MatchType
= MATCH_EXACT
;
107 MatchType
= MATCH_REGEX
;
111 MatchType
= MATCH_EREGEX
;
131 /* Get all the remaining package names, if any */
133 /* Don't try to apply heuristics if arguments are regexs */
134 if (MatchType
!= MATCH_REGEX
)
135 while ((pkgs_split
= strrchr(*argv
, (int)'/')) != NULL
) {
136 *pkgs_split
++ = '\0';
138 * If character after the '/' is alphanumeric, then we've found the
139 * package name. Otherwise we've come across a trailing '/' and
140 * need to continue our quest.
142 if (isalnum(*pkgs_split
) || ((MatchType
== MATCH_GLOB
) && \
143 strpbrk(pkgs_split
, "*?[]") != NULL
)) {
151 /* If no packages, yelp */
152 if (pkgs
== start
&& MatchType
!= MATCH_ALL
)
153 warnx("missing package name(s)"), usage();
156 (void) stat(tmp
, &stat_s
);
157 if (!Fake
&& getuid() && geteuid() != stat_s
.st_uid
) {
159 errx(1, "you do not own %s, use -f to force", tmp
);
161 warnx("you do not own %s (proceeding anyways)", tmp
);
163 if ((error
= pkg_perform(start
)) != 0) {
165 warnx("%d package deletion(s) failed", error
);
175 fprintf(stderr
, "%s\n%s\n",
176 "usage: pkg_delete [-dDfGinrvxX] [-p prefix] pkg-name ...",
177 " pkg_delete -a [flags]");