main.c revision 152210
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 152210 2005-11-08 20:48:26Z krion $");
14
15#include <err.h>
16#include "lib.h"
17#include "create.h"
18
19static char Options[] = "EGYNORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
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;
44enum zipper	Zipper	= GZIP;
45
46static void usage __P((void));
47
48int
49main(int argc, char **argv)
50{
51    int ch;
52    char **pkgs, **start, *tmp;
53
54    pkgs = start = argv;
55    while ((ch = getopt(argc, argv, Options)) != -1)
56	switch(ch) {
57	case 'v':
58	    Verbose = TRUE;
59	    break;
60
61	case 'x':
62	    MatchType = MATCH_REGEX;
63	    break;
64
65	case 'E':
66	    MatchType = MATCH_EREGEX;
67	    break;
68
69	case 'G':
70	    MatchType = MATCH_EXACT;
71	    break;
72
73	case 'N':
74	    AutoAnswer = NO;
75	    break;
76
77	case 'Y':
78	    AutoAnswer = YES;
79	    break;
80
81	case 'O':
82	    PlistOnly = TRUE;
83	    break;
84
85	case 'p':
86	    Prefix = optarg;
87	    break;
88
89	case 's':
90	    SrcDir = optarg;
91	    break;
92
93	case 'S':
94	    BaseDir = optarg;
95	    break;
96
97	case 'f':
98	    Contents = optarg;
99	    break;
100
101	case 'C':
102	    Conflicts = optarg;
103	    break;
104
105	case 'c':
106	    Comment = optarg;
107	    break;
108
109	case 'd':
110	    Desc = optarg;
111	    break;
112
113	case 'i':
114	    Install = optarg;
115	    break;
116
117	case 'I':
118	    PostInstall = optarg;
119	    break;
120
121	case 'k':
122	    DeInstall = optarg;
123	    break;
124
125	case 'K':
126	    PostDeInstall = optarg;
127	    break;
128
129	case 'r':
130	    Require = optarg;
131	    break;
132
133	case 't':
134	    strlcpy(PlayPen, optarg, sizeof(PlayPen));
135	    break;
136
137	case 'X':
138	    ExcludeFrom = optarg;
139	    break;
140
141	case 'h':
142	    Dereference = TRUE;
143	    break;
144
145	case 'D':
146	    Display = optarg;
147	    break;
148
149	case 'm':
150	    Mtree = optarg;
151	    break;
152
153	case 'P':
154	    Pkgdeps = optarg;
155	    break;
156
157	case 'o':
158	    Origin = optarg;
159	    break;
160
161	case 'y':
162	case 'j':
163	    Zipper = BZIP2;
164	    break;
165
166	case 'z':
167	    Zipper = GZIP;
168	    break;
169
170	case 'b':
171	    InstalledPkg = optarg;
172	    while ((tmp = strrchr(optarg, (int)'/')) != NULL) {
173		*tmp++ = '\0';
174		/*
175		 * If character after the '/' is alphanumeric, then we've
176		 * found the package name.  Otherwise we've come across
177		 * a trailing '/' and need to continue our quest.
178		 */
179		if (isalpha(*tmp)) {
180		    InstalledPkg = tmp;
181		    break;
182		}
183	    }
184	    break;
185
186	case 'R':
187	    Recursive = TRUE;
188	    break;
189
190	case '?':
191	default:
192	    usage();
193	    break;
194	}
195
196    argc -= optind;
197    argv += optind;
198
199    /* Get all the remaining package names, if any */
200    while (*argv)
201	*pkgs++ = *argv++;
202
203    /* If no packages, yelp */
204    if ((pkgs == start) && (InstalledPkg == NULL))
205	warnx("missing package name"), usage();
206    *pkgs = NULL;
207    if ((start[0] != NULL) && (start[1] != NULL)) {
208	warnx("only one package name allowed ('%s' extraneous)", start[1]);
209	usage();
210    }
211    if (start[0] == NULL)
212	start[0] = InstalledPkg;
213    if (!pkg_perform(start)) {
214	if (Verbose)
215	    warnx("package creation failed");
216	return 1;
217    }
218    else
219	return 0;
220}
221
222static void
223usage()
224{
225    fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
226"usage: pkg_create [-YNOhvyz] [-P pkgs] [-C conflicts] [-p prefix] ",
227"                  [-i iscript] [-I piscript] [-k dscript] [-K pdscript] ",
228"                  [-r rscript] [-t template] [-X excludefile] ",
229"                  [-D displayfile] [-m mtreefile] [-o origin] ",
230"                  [-s srcdir] [-S basedir] ",
231"                  -c comment -d description -f packlist pkg-filename",
232"       pkg_create [-EGYNhvxyzR] -b pkg-name [pkg-filename]");
233    exit(1);
234}
235