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