main.c revision 213718
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Jordan K. Hubbard
6 * 18 July 1993
7 *
8 * This is the create module.
9 *
10 */
11
12#include <sys/cdefs.h>
13__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/create/main.c 213718 2010-10-12 10:04:44Z flz $");
14
15#include <getopt.h>
16#include <err.h>
17
18#include <pkg.h>
19#include "create.h"
20
21match_t	MatchType	= MATCH_GLOB;
22char	*Prefix		= NULL;
23char	*Comment        = NULL;
24char	*Desc		= NULL;
25char	*SrcDir		= NULL;
26char	*BaseDir	= NULL;
27char	*Display	= NULL;
28char	*Install	= NULL;
29char	*PostInstall	= NULL;
30char	*DeInstall	= NULL;
31char	*PostDeInstall	= NULL;
32char	*Contents	= NULL;
33char	*Require	= NULL;
34char	*ExcludeFrom	= NULL;
35char	*Mtree		= NULL;
36char	*Pkgdeps	= NULL;
37char	*Conflicts	= NULL;
38char	*Origin		= NULL;
39char	*InstalledPkg	= NULL;
40char	PlayPen[FILENAME_MAX];
41int	Dereference	= FALSE;
42int	PlistOnly	= FALSE;
43int	Recursive	= FALSE;
44int	Regenerate	= TRUE;
45int	Help		= FALSE;
46enum zipper	Zipper  = BZIP2;
47
48
49static void usage(void);
50
51static char opts[] = "EGYNnORhjJvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
52static 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 },
67};
68
69int
70main(int argc, char **argv)
71{
72    int ch;
73    char **pkgs, **start, *tmp;
74
75    pkg_wrap(PKG_INSTALL_VERSION, argv);
76
77    pkgs = start = argv;
78    while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1)
79	switch(ch) {
80	case 'v':
81	    Verbose++;
82	    break;
83
84	case 'x':
85	    MatchType = MATCH_REGEX;
86	    break;
87
88	case 'E':
89	    MatchType = MATCH_EREGEX;
90	    break;
91
92	case 'G':
93	    MatchType = MATCH_EXACT;
94	    break;
95
96	case 'N':
97	    AutoAnswer = NO;
98	    break;
99
100	case 'Y':
101	    AutoAnswer = YES;
102	    break;
103
104	case 'O':
105	    PlistOnly = TRUE;
106	    break;
107
108	case 'p':
109	    Prefix = optarg;
110	    break;
111
112	case 's':
113	    SrcDir = optarg;
114	    break;
115
116	case 'S':
117	    BaseDir = optarg;
118	    break;
119
120	case 'f':
121	    Contents = optarg;
122	    break;
123
124	case 'C':
125	    Conflicts = optarg;
126	    break;
127
128	case 'c':
129	    Comment = optarg;
130	    break;
131
132	case 'd':
133	    Desc = optarg;
134	    break;
135
136	case 'i':
137	    Install = optarg;
138	    break;
139
140	case 'I':
141	    PostInstall = optarg;
142	    break;
143
144	case 'k':
145	    DeInstall = optarg;
146	    break;
147
148	case 'K':
149	    PostDeInstall = optarg;
150	    break;
151
152	case 'r':
153	    Require = optarg;
154	    break;
155
156	case 't':
157	    strlcpy(PlayPen, optarg, sizeof(PlayPen));
158	    break;
159
160	case 'X':
161	    ExcludeFrom = optarg;
162	    break;
163
164	case 'h':
165	    Dereference = TRUE;
166	    break;
167
168	case 'D':
169	    Display = optarg;
170	    break;
171
172	case 'm':
173	    Mtree = optarg;
174	    break;
175
176	case 'P':
177	    Pkgdeps = optarg;
178	    break;
179
180	case 'o':
181	    Origin = optarg;
182	    break;
183
184	case 'y':
185	case 'j':
186	    Zipper = BZIP2;
187	    break;
188
189	case 'z':
190	    Zipper = GZIP;
191	    break;
192
193	case 'J':
194	    Zipper = XZ;
195	    break;
196
197	case 'b':
198	    InstalledPkg = optarg;
199	    while ((tmp = strrchr(optarg, (int)'/')) != NULL) {
200		*tmp++ = '\0';
201		/*
202		 * If character after the '/' is alphanumeric, then we've
203		 * found the package name.  Otherwise we've come across
204		 * a trailing '/' and need to continue our quest.
205		 */
206		if (isalpha(*tmp)) {
207		    InstalledPkg = tmp;
208		    break;
209		}
210	    }
211	    break;
212
213	case 'R':
214	    Recursive = TRUE;
215	    break;
216
217	case 'n':
218	    Regenerate = FALSE;
219	    break;
220
221	case 0:
222	    if (Help)
223		usage();
224	    break;
225
226	default:
227	    usage();
228	    break;
229	}
230
231    argc -= optind;
232    argv += optind;
233
234    /* Get all the remaining package names, if any */
235    while (*argv)
236	*pkgs++ = *argv++;
237
238    /* If no packages, yelp */
239    if ((pkgs == start) && (InstalledPkg == NULL))
240	warnx("missing package name"), usage();
241    *pkgs = NULL;
242    if ((start[0] != NULL) && (start[1] != NULL)) {
243	warnx("only one package name allowed ('%s' extraneous)", start[1]);
244	usage();
245    }
246    if (start[0] == NULL)
247	start[0] = InstalledPkg;
248    if (!pkg_perform(start)) {
249	if (Verbose)
250	    warnx("package creation failed");
251	return 1;
252    }
253    else
254	return 0;
255}
256
257static void
258usage(void)
259{
260    fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
261"usage: pkg_create [-YNOhjnvyz] [-C conflicts] [-P pkgs] [-p prefix]",
262"                  [-i iscript] [-I piscript] [-k dscript] [-K pdscript]",
263"                  [-r rscript] [-s srcdir] [-S basedir]",
264"                  [-t template] [-X excludefile]",
265"                  [-D displayfile] [-m mtreefile] [-o originpath]",
266"                  -c comment -d description -f packlist pkg-filename",
267"       pkg_create [-EGYNRhnvxy] -b pkg-name [pkg-filename]");
268    exit(1);
269}
270