Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / pkg_install / dist / add / main.c
blob3392bf691355aff72c3d104e404f7187ae0833ba
1 /* $NetBSD: main.c,v 1.22 2009/10/07 12:53:26 joerg Exp $ */
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.22 2009/10/07 12:53:26 joerg Exp $");
14 * FreeBSD install - a package for the installation and maintainance
15 * of non-core utilities.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
26 * Jordan K. Hubbard
27 * 18 July 1993
29 * This is the add module.
33 #if HAVE_ERR_H
34 #include <err.h>
35 #endif
36 #if HAVE_SYS_PARAM_H
37 #include <sys/param.h>
38 #endif
39 #include "lib.h"
40 #include "add.h"
42 static char Options[] = "AIK:LP:RVW:fhm:np:t:uvw:";
44 const char *PlainPkgdb = NULL;
45 char *Destdir = NULL;
46 char *OverrideMachine = NULL;
47 char *Prefix = NULL;
48 char *View = NULL;
49 char *Viewbase = NULL;
50 Boolean NoView = FALSE;
51 Boolean NoInstall = FALSE;
52 Boolean NoRecord = FALSE;
53 Boolean Automatic = FALSE;
54 Boolean ForceDepends = FALSE;
56 int LicenseCheck = 0;
57 int Replace = 0;
59 static void
60 usage(void)
62 (void) fprintf(stderr, "%s\n%s\n%s\n%s\n",
63 "usage: pkg_add [-AfhILnRuVv] [-C config] [-P destdir] [-K pkg_dbdir]",
64 " [-m machine] [-p prefix] [-s verification-type",
65 " [-W viewbase] [-w view]\n",
66 " [[ftp|http]://[user[:password]@]host[:port]][/path/]pkg-name ...");
67 exit(1);
70 int
71 main(int argc, char **argv)
73 int ch, error=0;
74 lpkg_head_t pkgs;
75 const char *pkgdb = NULL;
77 setprogname(argv[0]);
78 while ((ch = getopt(argc, argv, Options)) != -1) {
79 switch (ch) {
80 case 'A':
81 Automatic = TRUE;
82 break;
84 case 'C':
85 config_file = optarg;
87 case 'P':
88 Destdir = optarg;
89 break;
91 case 'f':
92 Force = TRUE;
93 ForceDepends = TRUE;
94 break;
96 case 'I':
97 NoInstall = TRUE;
98 break;
100 case 'K':
101 pkgdb = optarg;
102 break;
104 case 'L':
105 NoView = TRUE;
106 break;
108 case 'R':
109 NoRecord = TRUE;
110 break;
112 case 'm':
113 OverrideMachine = optarg;
114 break;
116 case 'n':
117 Fake = TRUE;
118 Verbose = TRUE;
119 break;
121 case 'p':
122 Prefix = optarg;
123 break;
125 case 'u':
126 Replace++;
127 break;
129 case 'V':
130 show_version();
131 /* NOTREACHED */
133 case 'v':
134 Verbose = TRUE;
135 break;
137 case 'W':
138 Viewbase = optarg;
139 break;
141 case 'w':
142 View = optarg;
143 break;
145 case 'h':
146 case '?':
147 default:
148 usage();
149 break;
152 argc -= optind;
153 argv += optind;
155 pkg_install_config();
157 if (pkgdb == NULL)
158 pkgdb = _pkgdb_getPKGDB_DIR();
159 PlainPkgdb = xstrdup(pkgdb);
161 if (Destdir != NULL) {
162 char *pkgdbdir;
164 pkgdbdir = xasprintf("%s/%s", Destdir, pkgdb);
165 _pkgdb_setPKGDB_DIR(pkgdbdir);
166 free(pkgdbdir);
167 } else
168 _pkgdb_setPKGDB_DIR(pkgdb);
170 process_pkg_path();
171 TAILQ_INIT(&pkgs);
173 if (argc == 0) {
174 /* If no packages, yelp */
175 warnx("missing package name(s)");
176 usage();
179 if (strcasecmp(do_license_check, "no") == 0)
180 LicenseCheck = 0;
181 else if (strcasecmp(do_license_check, "yes") == 0)
182 LicenseCheck = 1;
183 else if (strcasecmp(do_license_check, "always") == 0)
184 LicenseCheck = 2;
185 else
186 errx(1, "Unknown value of the configuration variable"
187 "CHECK_LICENSE");
189 if (LicenseCheck)
190 load_license_lists();
192 /* Get all the remaining package names, if any */
193 for (; argc > 0; --argc, ++argv) {
194 lpkg_t *lpp;
196 if (IS_STDIN(*argv))
197 lpp = alloc_lpkg("-");
198 else
199 lpp = alloc_lpkg(*argv);
201 TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
204 error += pkg_perform(&pkgs);
205 if (error != 0) {
206 warnx("%d package addition%s failed", error, error == 1 ? "" : "s");
207 exit(1);
209 exit(0);