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