main.c revision 85019
1#ifndef lint
2static const char rcsid[] =
3  "$FreeBSD: head/usr.sbin/pkg_install/create/main.c 85019 2001-10-16 03:04:15Z sobomax $";
4#endif
5
6/*
7 * FreeBSD install - a package for the installation and maintainance
8 * of non-core utilities.
9 *
10 * Jordan K. Hubbard
11 * 18 July 1993
12 *
13 * This is the create module.
14 *
15 */
16
17#include <err.h>
18#include "lib.h"
19#include "create.h"
20
21static char Options[] = "YNOhvyf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:b:";
22
23char	*Prefix		= NULL;
24char	*Comment        = NULL;
25char	*Desc		= NULL;
26char	*SrcDir		= 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	*Origin		= NULL;
38char	*InstalledPkg	= NULL;
39char	PlayPen[FILENAME_MAX];
40int	Dereference	= FALSE;
41int	PlistOnly	= FALSE;
42int	UseBzip2	= FALSE;
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 'f':
80	    Contents = optarg;
81	    break;
82
83	case 'c':
84	    Comment = optarg;
85	    break;
86
87	case 'd':
88	    Desc = optarg;
89	    break;
90
91	case 'i':
92	    Install = optarg;
93	    break;
94
95	case 'I':
96	    PostInstall = optarg;
97	    break;
98
99	case 'k':
100	    DeInstall = optarg;
101	    break;
102
103	case 'K':
104	    PostDeInstall = optarg;
105	    break;
106
107	case 'r':
108	    Require = optarg;
109	    break;
110
111	case 't':
112	    strlcpy(PlayPen, optarg, sizeof(PlayPen));
113	    break;
114
115	case 'X':
116	    ExcludeFrom = optarg;
117	    break;
118
119	case 'h':
120	    Dereference = TRUE;
121	    break;
122
123	case 'D':
124	    Display = optarg;
125	    break;
126
127	case 'm':
128	    Mtree = optarg;
129	    break;
130
131	case 'P':
132	    Pkgdeps = optarg;
133	    break;
134
135	case 'o':
136	    Origin = optarg;
137	    break;
138
139	case 'y':
140	    UseBzip2 = TRUE;
141	    break;
142
143	case 'b':
144	    while ((tmp = strrchr(optarg, (int)'/')) != NULL) {
145		*tmp++ = '\0';
146		/*
147		 * If character after the '/' is alphanumeric, then we've
148		 * found the package name.  Otherwise we've come across
149		 * a trailing '/' and need to continue our quest.
150		 */
151		if (isalpha(*tmp)) {
152		    InstalledPkg = tmp;
153		    break;
154		}
155	    }
156	    break;
157
158	case '?':
159	default:
160	    usage();
161	    break;
162	}
163
164    argc -= optind;
165    argv += optind;
166
167    /* Get all the remaining package names, if any */
168    while (*argv)
169	*pkgs++ = *argv++;
170
171    /* If no packages, yelp */
172    if ((pkgs == start) && (InstalledPkg == NULL))
173	warnx("missing package name"), usage();
174    *pkgs = NULL;
175    if ((start[0] != NULL) && (start[1] != NULL)) {
176	warnx("only one package name allowed ('%s' extraneous)", start[1]);
177	usage();
178    }
179    if (start[0] == NULL)
180	start[0] = InstalledPkg;
181    if (!pkg_perform(start)) {
182	if (Verbose)
183	    warnx("package creation failed");
184	return 1;
185    }
186    else
187	return 0;
188}
189
190static void
191usage()
192{
193    fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
194"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
195"                  [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ",
196"                  [-t template] [-X excludefile] [-D displayfile] ",
197"                  [-m mtreefile] [-o origin] -c comment -d description ",
198"                  -f packlist pkg-filename",
199"       pkg_create [-YNhvy] -b pkg-name [pkg-filename]");
200    exit(1);
201}
202