1 /* $NetBSD: main.c,v 1.28 2009/09/11 18:00:13 joerg Exp $ */
10 __RCSID("$NetBSD: main.c,v 1.28 2009/09/11 18:00:13 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
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.
29 * This is the add module.
34 #include <sys/ioctl.h>
44 static const char Options
[] = ".aBbcDde:E:fFhIiK:kLl:mNnpQ:qrRsSuvVX";
47 enum which Which
= WHICH_LIST
;
48 Boolean File2Pkg
= FALSE
;
49 Boolean Quiet
= FALSE
;
50 const char *InfoPrefix
= "";
51 const char *BuildInfoVariable
= "";
57 fprintf(stderr
, "%s\n%s\n%s\n%s\n",
58 "usage: pkg_info [-BbcDdFfhIikLmNnpqrRSsVvX] [-e package] [-E package]",
59 " [-K pkg_dbdir] [-l prefix] pkg-name ...",
60 " pkg_info [-a | -u] [flags]",
61 " pkg_info [-Q variable] pkg-name ...");
66 main(int argc
, char **argv
)
68 char *CheckPkg
= NULL
;
69 char *BestCheckPkg
= NULL
;
75 while ((ch
= getopt(argc
, argv
, Options
)) != -1)
77 case '.': /* for backward compatibility */
85 Flags
|= SHOW_BUILD_INFO
;
89 Flags
|= SHOW_BUILD_VERSION
;
93 Flags
|= SHOW_COMMENT
;
97 Flags
|= SHOW_DISPLAY
;
105 BestCheckPkg
= optarg
;
125 Flags
|= SHOW_INSTALL
;
129 _pkgdb_setPKGDB_DIR(optarg
);
133 Flags
|= SHOW_DEINSTALL
;
149 Flags
|= SHOW_BLD_DEPENDS
;
153 Flags
|= SHOW_DEPENDS
;
157 Flags
|= SHOW_PREFIX
;
161 Flags
|= SHOW_BI_VAR
;
162 BuildInfoVariable
= optarg
;
170 Flags
|= SHOW_FULL_REQBY
;
178 Flags
|= SHOW_PKG_SIZE
;
182 Flags
|= SHOW_ALL_SIZE
;
191 /* Reasonable definition of 'everything' */
192 Flags
= SHOW_COMMENT
| SHOW_DESC
| SHOW_PLIST
| SHOW_INSTALL
|
193 SHOW_DEINSTALL
| SHOW_DISPLAY
| SHOW_MTREE
|
194 SHOW_REQBY
| SHOW_BLD_DEPENDS
| SHOW_DEPENDS
| SHOW_PKG_SIZE
| SHOW_ALL_SIZE
;
202 Flags
|= SHOW_SUMMARY
;
215 if (argc
== 0 && !Flags
&& !CheckPkg
) {
216 /* No argument or relevant flags specified - assume -I */
218 /* assume -a if neither -u nor -a is given */
219 if (Which
== WHICH_LIST
)
223 if (CheckPkg
!= NULL
&& BestCheckPkg
!= NULL
) {
224 warnx("-E and -e are mutally exlusive");
228 if (argc
!= 0 && CheckPkg
!= NULL
) {
229 warnx("can't give any additional arguments to -e");
233 if (argc
!= 0 && BestCheckPkg
!= NULL
) {
234 warnx("can't give any additional arguments to -E");
238 if (argc
!= 0 && Which
!= WHICH_LIST
) {
239 warnx("can't use both -a/-u and package name");
243 /* Set some reasonable defaults */
245 Flags
= SHOW_COMMENT
| SHOW_DESC
| SHOW_REQBY
246 | SHOW_DEPENDS
| SHOW_DISPLAY
;
248 /* -Fe /filename -> change CheckPkg to real packagename */
253 if (!pkgdb_open(ReadOnly
))
254 err(EXIT_FAILURE
, "cannot open pkgdb");
256 s
= pkgdb_retrieve(CheckPkg
);
259 errx(EXIT_FAILURE
, "No matching pkg for %s.", CheckPkg
);
260 CheckPkg
= xstrdup(s
);
264 return CheckForPkg(CheckPkg
);
268 return CheckForBestPkg(BestCheckPkg
);
272 /* Get all the remaining package names, if any */
273 if (File2Pkg
&& Which
== WHICH_LIST
)
274 if (!pkgdb_open(ReadOnly
)) {
275 err(EXIT_FAILURE
, "cannot open pkgdb");
278 /* pkgdb: if -F flag given, don't add pkgnames to the "pkgs"
279 * queue but rather resolve the given filenames to pkgnames
280 * using pkgdb_retrieve, then add them. */
284 s
= pkgdb_retrieve(*argv
);
288 TAILQ_INSERT_TAIL(&pkgs
, lpp
, lp_link
);
290 errx(EXIT_FAILURE
, "No matching pkg for %s.", *argv
);
292 if (ispkgpattern(*argv
)) {
293 switch (add_installed_pkgs_by_pattern(*argv
, &pkgs
)) {
295 errx(EXIT_FAILURE
, "No matching pkg for %s.", *argv
);
297 errx(EXIT_FAILURE
, "Error during search in pkgdb for %s", *argv
);
302 dbdir
= _pkgdb_getPKGDB_DIR();
303 if (**argv
== '/' && strncmp(*argv
, dbdir
, strlen(dbdir
)) == 0) {
304 *argv
+= strlen(dbdir
) + 1;
305 if ((*argv
)[strlen(*argv
) - 1] == '/') {
306 (*argv
)[strlen(*argv
) - 1] = 0;
309 lpp
= alloc_lpkg(*argv
);
310 TAILQ_INSERT_TAIL(&pkgs
, lpp
, lp_link
);
319 /* If no packages, yelp */
320 if (TAILQ_FIRST(&pkgs
) == NULL
&& Which
== WHICH_LIST
&& !CheckPkg
)
321 warnx("missing package name(s)"), usage();
323 rc
= pkg_perform(&pkgs
);