main.c revision 1.2
1/*	$NetBSD: main.c,v 1.2 2017/04/20 13:18:23 joerg Exp $	*/
2
3#if HAVE_CONFIG_H
4#include "config.h"
5#endif
6#include <nbcompat.h>
7#if HAVE_SYS_CDEFS_H
8#include <sys/cdefs.h>
9#endif
10__RCSID("$NetBSD: main.c,v 1.2 2017/04/20 13:18:23 joerg Exp $");
11
12/*
13 * FreeBSD install - a package for the installation and maintainance
14 * of non-core utilities.
15 *
16 * Jordan K. Hubbard
17 * 18 July 1993
18 *
19 * This is the create module.
20 *
21 */
22
23#if HAVE_ERR_H
24#include <err.h>
25#endif
26#include "lib.h"
27#include "create.h"
28
29/* -U is silently ignored, it used to inhibit pkgdb changes. */
30static const char Options[] = "B:C:D:F:I:K:L:OP:S:T:UVb:c:d:f:g:i:k:ln:p:r:s:u:v";
31
32char   *Prefix = NULL;
33char   *Comment = NULL;
34char   *Desc = NULL;
35char   *Display = NULL;
36char   *Install = NULL;
37char   *DeInstall = NULL;
38char   *Contents = NULL;
39char   *Pkgdeps = NULL;
40char   *BuildPkgdeps = NULL;
41char   *Pkgcfl = NULL;
42char   *BuildVersion = NULL;
43char   *BuildInfo = NULL;
44char   *SizePkg = NULL;
45char   *SizeAll = NULL;
46char   *Preserve = NULL;
47char   *DefaultOwner = NULL;
48char   *DefaultGroup = NULL;
49char   *realprefix = NULL;
50const char *CompressionType = NULL;
51int     PlistOnly = 0;
52int     RelativeLinks = 0;
53Boolean File2Pkg = FALSE;
54
55static void
56usage(void)
57{
58	fprintf(stderr,
59	    "usage: pkg_create [-lOUVv] [-B build-info-file] [-b build-version-file]\n"
60            "                  [-C cpkgs] [-D displayfile] [-F compression] \n"
61	    "                  [-I realprefix] [-i iscript]\n"
62            "                  [-K pkg_dbdir] [-k dscript]\n"
63            "                  [-n preserve-file] [-P dpkgs] [-p prefix] [-r rscript]\n"
64            "                  [-S size-all-file] [-s size-pkg-file]\n"
65	    "                  [-T buildpkgs] [-u owner] [-g group]\n"
66            "                  -c comment -d description -f packlist\n"
67            "                  pkg-name\n");
68	exit(1);
69}
70
71int
72main(int argc, char **argv)
73{
74	int     ch;
75
76	setprogname(argv[0]);
77	while ((ch = getopt(argc, argv, Options)) != -1)
78		switch (ch) {
79		case 'v':
80			Verbose = TRUE;
81			break;
82
83		case 'F':
84			CompressionType = optarg;
85			break;
86
87		case 'I':
88			realprefix = optarg;
89			break;
90
91		case 'O':
92			PlistOnly = 1;
93			break;
94
95		case 'U':
96			break;
97
98		case 'p':
99			Prefix = optarg;
100			break;
101
102		case 's':
103			SizePkg = optarg;
104			break;
105
106		case 'S':
107			SizeAll = optarg;
108			break;
109
110		case 'f':
111			Contents = optarg;
112			break;
113
114		case 'c':
115			Comment = optarg;
116			break;
117
118		case 'd':
119			Desc = optarg;
120			break;
121
122		case 'g':
123			DefaultGroup = optarg;
124			break;
125
126		case 'i':
127			Install = optarg;
128			break;
129
130		case 'K':
131			pkgdb_set_dir(optarg, 3);
132			break;
133
134		case 'k':
135			DeInstall = optarg;
136			break;
137
138		case 'l':
139			RelativeLinks = 1;
140			break;
141
142		case 'L':
143			warnx("Obsolete -L option ignored");
144			break;
145
146		case 'u':
147			DefaultOwner = optarg;
148			break;
149
150		case 'D':
151			Display = optarg;
152			break;
153
154		case 'n':
155			Preserve = optarg;
156			break;
157
158		case 'P':
159			Pkgdeps = optarg;
160			break;
161
162		case 'T':
163			BuildPkgdeps = optarg;
164			break;
165
166		case 'C':
167			Pkgcfl = optarg;
168			break;
169
170		case 'b':
171			BuildVersion = optarg;
172			break;
173
174		case 'B':
175			BuildInfo = optarg;
176			break;
177
178		case 'V':
179			show_version();
180			/* NOTREACHED */
181
182		case '?':
183		default:
184			usage();
185			break;
186		}
187
188	argc -= optind;
189	argv += optind;
190
191	pkg_install_config();
192
193	if (argc == 0) {
194		warnx("missing package name");
195		usage();
196	}
197	if (argc != 1) {
198		warnx("only one package name allowed");
199		usage();
200	}
201
202	if (pkg_perform(*argv))
203		return 0;
204	if (Verbose) {
205		if (PlistOnly)
206			warnx("PLIST adjustment failed");
207		else
208			warnx("package creation failed");
209	}
210	return 1;
211}
212