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