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