1 /*	$NetBSD: main.c,v 1.1.1.7 2010/01/30 21:33:31 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.1.1.7 2010/01/30 21:33:31 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 static const char Options[] = "B:C:D:EF:I:K:L:OP:S:T:UVb:c:d:f:g:i:k:ln:p:r:s:u:v";
30 
31 char   *Prefix = NULL;
32 char   *Comment = NULL;
33 char   *Desc = NULL;
34 char   *Display = NULL;
35 char   *Install = NULL;
36 char   *DeInstall = NULL;
37 char   *Contents = NULL;
38 char   *Pkgdeps = NULL;
39 char   *BuildPkgdeps = NULL;
40 char   *Pkgcfl = NULL;
41 char   *BuildVersion = NULL;
42 char   *BuildInfo = NULL;
43 char   *SizePkg = NULL;
44 char   *SizeAll = NULL;
45 char   *Preserve = NULL;
46 char   *DefaultOwner = NULL;
47 char   *DefaultGroup = NULL;
48 char   *realprefix = NULL;
49 const char *CompressionType = NULL;
50 int	update_pkgdb = 1;
51 int	create_views = 0;
52 int     PlistOnly = 0;
53 int     RelativeLinks = 0;
54 Boolean File2Pkg = FALSE;
55 
56 static void
usage(void)57 usage(void)
58 {
59 	fprintf(stderr,
60 	    "usage: pkg_create [-ElOUVv] [-B build-info-file] [-b build-version-file]\n"
61             "                  [-C cpkgs] [-D displayfile] [-F compression] \n"
62 	    "                  [-I realprefix] [-i iscript]\n"
63             "                  [-K pkg_dbdir] [-k dscript]\n"
64             "                  [-n preserve-file] [-P dpkgs] [-p prefix] [-r rscript]\n"
65             "                  [-S size-all-file] [-s size-pkg-file]\n"
66 	    "                  [-T buildpkgs] [-u owner] [-g group]\n"
67             "                  -c comment -d description -f packlist\n"
68             "                  pkg-name\n");
69 	exit(1);
70 }
71 
72 int
main(int argc,char ** argv)73 main(int argc, char **argv)
74 {
75 	int     ch;
76 
77 	setprogname(argv[0]);
78 	while ((ch = getopt(argc, argv, Options)) != -1)
79 		switch (ch) {
80 		case 'v':
81 			Verbose = TRUE;
82 			break;
83 
84 		case 'E':
85 			create_views = 1;
86 			break;
87 
88 		case 'F':
89 			CompressionType = optarg;
90 			break;
91 
92 		case 'I':
93 			realprefix = optarg;
94 			break;
95 
96 		case 'O':
97 			PlistOnly = 1;
98 			break;
99 
100 		case 'U':
101 			update_pkgdb = 0;
102 			break;
103 
104 		case 'p':
105 			Prefix = optarg;
106 			break;
107 
108 		case 's':
109 			SizePkg = optarg;
110 			break;
111 
112 		case 'S':
113 			SizeAll = optarg;
114 			break;
115 
116 		case 'f':
117 			Contents = optarg;
118 			break;
119 
120 		case 'c':
121 			Comment = optarg;
122 			break;
123 
124 		case 'd':
125 			Desc = optarg;
126 			break;
127 
128 		case 'g':
129 			DefaultGroup = optarg;
130 			break;
131 
132 		case 'i':
133 			Install = optarg;
134 			break;
135 
136 		case 'K':
137 			pkgdb_set_dir(optarg, 3);
138 			break;
139 
140 		case 'k':
141 			DeInstall = optarg;
142 			break;
143 
144 		case 'l':
145 			RelativeLinks = 1;
146 			break;
147 
148 		case 'L':
149 			warnx("Obsolete -L option ignored");
150 			break;
151 
152 		case 'u':
153 			DefaultOwner = optarg;
154 			break;
155 
156 		case 'D':
157 			Display = optarg;
158 			break;
159 
160 		case 'n':
161 			Preserve = optarg;
162 			break;
163 
164 		case 'P':
165 			Pkgdeps = optarg;
166 			break;
167 
168 		case 'T':
169 			BuildPkgdeps = optarg;
170 			break;
171 
172 		case 'C':
173 			Pkgcfl = optarg;
174 			break;
175 
176 		case 'b':
177 			BuildVersion = optarg;
178 			break;
179 
180 		case 'B':
181 			BuildInfo = optarg;
182 			break;
183 
184 		case 'V':
185 			show_version();
186 			/* NOTREACHED */
187 
188 		case '?':
189 		default:
190 			usage();
191 			break;
192 		}
193 
194 	argc -= optind;
195 	argv += optind;
196 
197 	pkg_install_config();
198 
199 	if (argc == 0) {
200 		warnx("missing package name");
201 		usage();
202 	}
203 	if (argc != 1) {
204 		warnx("only one package name allowed");
205 		usage();
206 	}
207 
208 	if (pkg_perform(*argv))
209 		return 0;
210 	if (Verbose) {
211 		if (PlistOnly)
212 			warnx("package registration failed");
213 		else
214 			warnx("package creation failed");
215 	}
216 	return 1;
217 }
218