Create defaults/uuids and adjust the build to copy the file to /etc/defaults
[dragonfly/vkernel-mp.git] / usr.sbin / pkg_install / delete / main.c
blob12eaef56d60d093a4c4cf575a1b2773879ad5426
1 /*
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
8 * are met:
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.
15 * Jordan K. Hubbard
16 * 18 July 1993
18 * This is the delete module.
20 * $FreeBSD: src/usr.sbin/pkg_install/delete/main.c,v 1.26 2004/06/29 18:54:47 eik Exp $
21 * $DragonFly: src/usr.sbin/pkg_install/delete/main.c,v 1.5 2004/12/18 23:48:04 swildner Exp $
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <err.h>
27 #include "lib.h"
28 #include "delete.h"
30 static char Options[] = "adDfGhinp:rvxX";
32 char *Prefix = NULL;
33 Boolean CleanDirs = FALSE;
34 Boolean Interactive = FALSE;
35 Boolean NoDeInstall = FALSE;
36 Boolean Recursive = FALSE;
37 match_t MatchType = MATCH_GLOB;
39 static void usage(void);
41 int
42 main(int argc, char **argv)
44 int ch, error;
45 char **pkgs, **start;
46 char *pkgs_split;
47 const char *tmp;
48 struct stat stat_s;
50 pkgs = start = argv;
51 while ((ch = getopt(argc, argv, Options)) != -1)
52 switch(ch) {
53 case 'v':
54 Verbose = TRUE;
55 break;
57 case 'f':
58 Force = TRUE;
59 break;
61 case 'p':
62 Prefix = optarg;
63 break;
65 case 'D':
66 NoDeInstall = TRUE;
67 break;
69 case 'd':
70 CleanDirs = TRUE;
71 break;
73 case 'n':
74 Fake = TRUE;
75 Verbose = TRUE;
76 break;
78 case 'a':
79 MatchType = MATCH_ALL;
80 break;
82 case 'G':
83 MatchType = MATCH_EXACT;
84 break;
86 case 'x':
87 MatchType = MATCH_REGEX;
88 break;
90 case 'X':
91 MatchType = MATCH_EREGEX;
92 break;
94 case 'i':
95 Interactive = TRUE;
96 break;
98 case 'r':
99 Recursive = TRUE;
100 break;
102 case 'h':
103 case '?':
104 default:
105 usage();
106 break;
109 argc -= optind;
110 argv += optind;
112 /* Get all the remaining package names, if any */
113 while (*argv) {
114 /* Don't try to apply heuristics if arguments are regexs */
115 if (MatchType != MATCH_REGEX)
116 while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
117 *pkgs_split++ = '\0';
119 * If character after the '/' is alphanumeric, then we've found the
120 * package name. Otherwise we've come across a trailing '/' and
121 * need to continue our quest.
123 if (isalpha(*pkgs_split) || ((MatchType == MATCH_GLOB) && \
124 strpbrk(pkgs_split, "*?[]") != NULL)) {
125 *argv = pkgs_split;
126 break;
129 *pkgs++ = *argv++;
132 /* If no packages, yelp */
133 if (pkgs == start && MatchType != MATCH_ALL)
134 warnx("missing package name(s)"), usage();
135 *pkgs = NULL;
136 tmp = LOG_DIR;
137 stat(tmp, &stat_s);
138 if (!Fake && getuid() && geteuid() != stat_s.st_uid) {
139 if (!Force)
140 errx(1, "you do not own %s, use -f to force", tmp);
141 else
142 warnx("you do not own %s (proceeding anyways)", tmp);
144 if ((error = pkg_perform(start)) != 0) {
145 if (Verbose)
146 warnx("%d package deletion(s) failed", error);
147 return error;
149 else
150 return 0;
153 static void
154 usage()
156 fprintf(stderr, "%s\n%s\n",
157 "usage: pkg_delete [-dDfGinrvxX] [-p prefix] pkg-name ...",
158 " pkg_delete -a [flags]");
159 exit(1);