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