turns printfs back on
[freebsd-src/fkvm-freebsd.git] / usr.sbin / pkg_install / create / main.c
blobb98b21ee9db14ffcd511c3c7cc463eee10ea0161
1 /*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
5 * Jordan K. Hubbard
6 * 18 July 1993
8 * This is the create module.
12 #include <sys/cdefs.h>
13 __FBSDID("$FreeBSD$");
15 #include <getopt.h>
16 #include <err.h>
18 #include "lib.h"
19 #include "create.h"
21 match_t MatchType = MATCH_GLOB;
22 char *Prefix = NULL;
23 char *Comment = NULL;
24 char *Desc = NULL;
25 char *SrcDir = NULL;
26 char *BaseDir = NULL;
27 char *Display = NULL;
28 char *Install = NULL;
29 char *PostInstall = NULL;
30 char *DeInstall = NULL;
31 char *PostDeInstall = NULL;
32 char *Contents = NULL;
33 char *Require = NULL;
34 char *ExcludeFrom = NULL;
35 char *Mtree = NULL;
36 char *Pkgdeps = NULL;
37 char *Conflicts = NULL;
38 char *Origin = NULL;
39 char *InstalledPkg = NULL;
40 char PlayPen[FILENAME_MAX];
41 int Dereference = FALSE;
42 int PlistOnly = FALSE;
43 int Recursive = FALSE;
44 int Regenerate = TRUE;
45 int Help = FALSE;
46 enum zipper Zipper = BZIP2;
49 static void usage(void);
51 static char opts[] = "EGYNnORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
52 static struct option longopts[] = {
53 { "backup", required_argument, NULL, 'b' },
54 { "extended", no_argument, NULL, 'E' },
55 { "help", no_argument, &Help, TRUE },
56 { "no", no_argument, NULL, 'N' },
57 { "no-glob", no_argument, NULL, 'G' },
58 { "origin", required_argument, NULL, 'o' },
59 { "plist-only", no_argument, NULL, 'O' },
60 { "prefix", required_argument, NULL, 'p' },
61 { "recursive", no_argument, NULL, 'R' },
62 { "regex", no_argument, NULL, 'x' },
63 { "template", required_argument, NULL, 't' },
64 { "verbose", no_argument, NULL, 'v' },
65 { "yes", no_argument, NULL, 'Y' },
66 { NULL, 0, NULL, 0 },
69 int
70 main(int argc, char **argv)
72 int ch;
73 char **pkgs, **start, *tmp;
75 pkgs = start = argv;
76 while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1)
77 switch(ch) {
78 case 'v':
79 Verbose++;
80 break;
82 case 'x':
83 MatchType = MATCH_REGEX;
84 break;
86 case 'E':
87 MatchType = MATCH_EREGEX;
88 break;
90 case 'G':
91 MatchType = MATCH_EXACT;
92 break;
94 case 'N':
95 AutoAnswer = NO;
96 break;
98 case 'Y':
99 AutoAnswer = YES;
100 break;
102 case 'O':
103 PlistOnly = TRUE;
104 break;
106 case 'p':
107 Prefix = optarg;
108 break;
110 case 's':
111 SrcDir = optarg;
112 break;
114 case 'S':
115 BaseDir = optarg;
116 break;
118 case 'f':
119 Contents = optarg;
120 break;
122 case 'C':
123 Conflicts = optarg;
124 break;
126 case 'c':
127 Comment = optarg;
128 break;
130 case 'd':
131 Desc = optarg;
132 break;
134 case 'i':
135 Install = optarg;
136 break;
138 case 'I':
139 PostInstall = optarg;
140 break;
142 case 'k':
143 DeInstall = optarg;
144 break;
146 case 'K':
147 PostDeInstall = optarg;
148 break;
150 case 'r':
151 Require = optarg;
152 break;
154 case 't':
155 strlcpy(PlayPen, optarg, sizeof(PlayPen));
156 break;
158 case 'X':
159 ExcludeFrom = optarg;
160 break;
162 case 'h':
163 Dereference = TRUE;
164 break;
166 case 'D':
167 Display = optarg;
168 break;
170 case 'm':
171 Mtree = optarg;
172 break;
174 case 'P':
175 Pkgdeps = optarg;
176 break;
178 case 'o':
179 Origin = optarg;
180 break;
182 case 'y':
183 case 'j':
184 Zipper = BZIP2;
185 break;
187 case 'z':
188 Zipper = GZIP;
189 break;
191 case 'b':
192 InstalledPkg = optarg;
193 while ((tmp = strrchr(optarg, (int)'/')) != NULL) {
194 *tmp++ = '\0';
196 * If character after the '/' is alphanumeric, then we've
197 * found the package name. Otherwise we've come across
198 * a trailing '/' and need to continue our quest.
200 if (isalpha(*tmp)) {
201 InstalledPkg = tmp;
202 break;
205 break;
207 case 'R':
208 Recursive = TRUE;
209 break;
211 case 'n':
212 Regenerate = FALSE;
213 break;
215 case 0:
216 if (Help)
217 usage();
218 break;
220 default:
221 usage();
222 break;
225 argc -= optind;
226 argv += optind;
228 /* Get all the remaining package names, if any */
229 while (*argv)
230 *pkgs++ = *argv++;
232 /* If no packages, yelp */
233 if ((pkgs == start) && (InstalledPkg == NULL))
234 warnx("missing package name"), usage();
235 *pkgs = NULL;
236 if ((start[0] != NULL) && (start[1] != NULL)) {
237 warnx("only one package name allowed ('%s' extraneous)", start[1]);
238 usage();
240 if (start[0] == NULL)
241 start[0] = InstalledPkg;
242 if (!pkg_perform(start)) {
243 if (Verbose)
244 warnx("package creation failed");
245 return 1;
247 else
248 return 0;
251 static void
252 usage()
254 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
255 "usage: pkg_create [-YNOhjnvyz] [-C conflicts] [-P pkgs] [-p prefix]",
256 " [-i iscript] [-I piscript] [-k dscript] [-K pdscript]",
257 " [-r rscript] [-s srcdir] [-S basedir]",
258 " [-t template] [-X excludefile]",
259 " [-D displayfile] [-m mtreefile] [-o originpath]",
260 " -c comment -d description -f packlist pkg-filename",
261 " pkg_create [-EGYNRhnvxy] -b pkg-name [pkg-filename]");
262 exit(1);