1 /* $NetBSD: main.c,v 1.1.1.9 2013/04/20 15:26:53 wiz Exp $ */
10 __RCSID("$NetBSD: main.c,v 1.1.1.9 2013/04/20 15:26:53 wiz 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 pkg-name] [-e pkg-name]",
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_set_dir(optarg
, 3);
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 pkg_install_config();
217 if (argc
== 0 && !Flags
&& !CheckPkg
) {
218 /* No argument or relevant flags specified - assume -I */
220 /* assume -a if neither -u nor -a is given */
221 if (Which
== WHICH_LIST
)
225 if (CheckPkg
!= NULL
&& BestCheckPkg
!= NULL
) {
226 warnx("-E and -e are mutally exlusive");
230 if (argc
!= 0 && CheckPkg
!= NULL
) {
231 warnx("can't give any additional arguments to -e");
235 if (argc
!= 0 && BestCheckPkg
!= NULL
) {
236 warnx("can't give any additional arguments to -E");
240 if (argc
!= 0 && Which
!= WHICH_LIST
) {
241 warnx("can't use both -a/-u and package name");
245 /* Set some reasonable defaults */
247 Flags
= SHOW_COMMENT
| SHOW_DESC
| SHOW_REQBY
248 | SHOW_DEPENDS
| SHOW_DISPLAY
;
250 /* -Fe /filename -> change CheckPkg to real packagename */
255 if (!pkgdb_open(ReadOnly
))
256 err(EXIT_FAILURE
, "cannot open pkgdb");
258 s
= pkgdb_retrieve(CheckPkg
);
261 errx(EXIT_FAILURE
, "No matching pkg for %s.", CheckPkg
);
262 CheckPkg
= xstrdup(s
);
266 return CheckForPkg(CheckPkg
);
270 return CheckForBestPkg(BestCheckPkg
);
274 /* Get all the remaining package names, if any */
275 if (File2Pkg
&& Which
== WHICH_LIST
)
276 if (!pkgdb_open(ReadOnly
)) {
277 err(EXIT_FAILURE
, "cannot open pkgdb");
280 /* pkgdb: if -F flag given, don't add pkgnames to the "pkgs"
281 * queue but rather resolve the given filenames to pkgnames
282 * using pkgdb_retrieve, then add them. */
286 s
= pkgdb_retrieve(*argv
);
290 TAILQ_INSERT_TAIL(&pkgs
, lpp
, lp_link
);
292 errx(EXIT_FAILURE
, "No matching pkg for %s.", *argv
);
294 if (ispkgpattern(*argv
)) {
295 switch (add_installed_pkgs_by_pattern(*argv
, &pkgs
)) {
297 errx(EXIT_FAILURE
, "No matching pkg for %s.", *argv
);
299 errx(EXIT_FAILURE
, "Error during search in pkgdb for %s", *argv
);
304 dbdir
= pkgdb_get_dir();
305 if (**argv
== '/' && strncmp(*argv
, dbdir
, strlen(dbdir
)) == 0) {
306 *argv
+= strlen(dbdir
) + 1;
307 if ((*argv
)[strlen(*argv
) - 1] == '/') {
308 (*argv
)[strlen(*argv
) - 1] = 0;
311 lpp
= alloc_lpkg(*argv
);
312 TAILQ_INSERT_TAIL(&pkgs
, lpp
, lp_link
);
321 /* If no packages, yelp */
322 if (TAILQ_FIRST(&pkgs
) == NULL
&& Which
== WHICH_LIST
&& !CheckPkg
)
323 warnx("missing package name(s)"), usage();
325 rc
= pkg_perform(&pkgs
);