Deleted Added
full compact
1#ifndef lint
2static const char rcsid[] =
3 "$FreeBSD: head/usr.sbin/pkg_install/create/main.c 85470 2001-10-25 07:56:20Z sobomax $";
4#endif
5
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 93520 2002-04-01 09:39:07Z obrien $");
14
15#include <err.h>
16#include "lib.h"
17#include "create.h"
18
19static char Options[] = "YNOhvyf: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;
40int UseBzip2 = FALSE;
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 UseBzip2 = TRUE;
139 break;
140
141 case 'b':
142 InstalledPkg = optarg;
143 while ((tmp = strrchr(optarg, (int)'/')) != NULL) {
144 *tmp++ = '\0';
145 /*
146 * If character after the '/' is alphanumeric, then we've
147 * found the package name. Otherwise we've come across
148 * a trailing '/' and need to continue our quest.
149 */
150 if (isalpha(*tmp)) {
151 InstalledPkg = tmp;
152 break;
153 }
154 }
155 break;
156
157 case '?':
158 default:
159 usage();
160 break;
161 }
162
163 argc -= optind;
164 argv += optind;
165
166 /* Get all the remaining package names, if any */
167 while (*argv)
168 *pkgs++ = *argv++;
169
170 /* If no packages, yelp */
171 if ((pkgs == start) && (InstalledPkg == NULL))
172 warnx("missing package name"), usage();
173 *pkgs = NULL;
174 if ((start[0] != NULL) && (start[1] != NULL)) {
175 warnx("only one package name allowed ('%s' extraneous)", start[1]);
176 usage();
177 }
178 if (start[0] == NULL)
179 start[0] = InstalledPkg;
180 if (!pkg_perform(start)) {
181 if (Verbose)
182 warnx("package creation failed");
183 return 1;
184 }
185 else
186 return 0;
187}
188
189static void
190usage()
191{
192 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
193"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
194" [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ",
195" [-t template] [-X excludefile] [-D displayfile] ",
196" [-m mtreefile] [-o origin] -c comment -d description ",
197" -f packlist pkg-filename",
198" pkg_create [-YNhvy] -b pkg-name [pkg-filename]");
199 exit(1);
200}