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