void pkg_install_show_variable(const char *var_name) { struct config_variable *var; const char *tmp_value = NULL; for (var = config_variables; var->name != NULL; ++var) { if (strcmp(var->name, var_name) == 0) break; } if (var->name == NULL) { var->name = var_name; var->var = &tmp_value; } pkg_install_config(); if (*var->var != NULL) puts(*var->var); }
int main(int argc, char *argv[]) { Boolean use_default_sfx = TRUE; Boolean show_basename_only = FALSE; char lsdir[MaxPathSize]; char sfx[MaxPathSize]; char *lsdirp = NULL; int ch; setprogname(argv[0]); if (argc < 2) usage(); while ((ch = getopt(argc, argv, Options)) != -1) switch (ch) { case 'C': config_file = optarg; break; case 'K': pkgdb_set_dir(optarg, 3); break; case 'S': sfx[0] = 0x0; use_default_sfx = FALSE; break; case 'V': show_version(); /* NOTREACHED */ case 'b': show_basename_only = TRUE; break; case 'd': (void) strlcpy(lsdir, optarg, sizeof(lsdir)); lsdirp = lsdir; break; case 'q': quiet = 1; break; case 's': (void) strlcpy(sfx, optarg, sizeof(sfx)); use_default_sfx = FALSE; break; case 'v': ++verbose; break; default: usage(); /* NOTREACHED */ } argc -= optind; argv += optind; if (argc <= 0) { usage(); } /* * config-var is reading the config file implicitly, * so skip it here. */ if (strcasecmp(argv[0], "config-var") != 0) pkg_install_config(); if (use_default_sfx) (void) strlcpy(sfx, DEFAULT_SFX, sizeof(sfx)); if (strcasecmp(argv[0], "pmatch") == 0) { char *pattern, *pkg; argv++; /* "pmatch" */ if (argv[0] == NULL || argv[1] == NULL) { usage(); } pattern = argv[0]; pkg = argv[1]; if (pkg_match(pattern, pkg)) { return 0; } else { return 1; } } else if (strcasecmp(argv[0], "rebuild") == 0) { rebuild(); printf("Done.\n"); } else if (strcasecmp(argv[0], "rebuild-tree") == 0) { rebuild_tree(); printf("Done.\n"); } else if (strcasecmp(argv[0], "check") == 0) { argv++; /* "check" */ check(argv); if (!quiet) { printf("Done.\n"); } } else if (strcasecmp(argv[0], "lsall") == 0) { argv++; /* "lsall" */ while (*argv != NULL) { /* args specified */ int rc; const char *basep, *dir; dir = lsdirp ? lsdirp : dirname_of(*argv); basep = basename_of(*argv); if (show_basename_only) rc = match_local_files(dir, use_default_sfx, 1, basep, lsbasepattern, NULL); else rc = match_local_files(dir, use_default_sfx, 1, basep, lspattern, __UNCONST(dir)); if (rc == -1) errx(EXIT_FAILURE, "Error from match_local_files(\"%s\", \"%s\", ...)", dir, basep); argv++; } } else if (strcasecmp(argv[0], "lsbest") == 0) { argv++; /* "lsbest" */ while (*argv != NULL) { /* args specified */ const char *basep, *dir; char *p; dir = lsdirp ? lsdirp : dirname_of(*argv); basep = basename_of(*argv); p = find_best_matching_file(dir, basep, use_default_sfx, 1); if (p) { if (show_basename_only) printf("%s\n", p); else printf("%s/%s\n", dir, p); free(p); } argv++; } } else if (strcasecmp(argv[0], "list") == 0 || strcasecmp(argv[0], "dump") == 0) { pkgdb_dump(); } else if (strcasecmp(argv[0], "add") == 0) { struct pkgdb_count count; count.files = 0; count.directories = 0; count.packages = 0; for (++argv; *argv != NULL; ++argv) add_pkg(*argv, &count); } else if (strcasecmp(argv[0], "set") == 0) { argv++; /* "set" */ set_unset_variable(argv, FALSE); } else if (strcasecmp(argv[0], "unset") == 0) { argv++; /* "unset" */ set_unset_variable(argv, TRUE); } else if (strcasecmp(argv[0], "config-var") == 0) { argv++; if (argv == NULL || argv[1] != NULL) errx(EXIT_FAILURE, "config-var takes exactly one argument"); pkg_install_show_variable(argv[0]); } else if (strcasecmp(argv[0], "check-license") == 0) { if (argv[1] == NULL) errx(EXIT_FAILURE, "check-license takes exactly one argument"); load_license_lists(); switch (acceptable_pkg_license(argv[1])) { case 0: puts("no"); return 0; case 1: puts("yes"); return 0; case -1: errx(EXIT_FAILURE, "invalid license condition"); } } else if (strcasecmp(argv[0], "check-single-license") == 0) { if (argv[1] == NULL) errx(EXIT_FAILURE, "check-license takes exactly one argument"); load_license_lists(); switch (acceptable_license(argv[1])) { case 0: puts("no"); return 0; case 1: puts("yes"); return 0; case -1: errx(EXIT_FAILURE, "invalid license"); } } #ifndef BOOTSTRAP else if (strcasecmp(argv[0], "findbest") == 0) { struct url *url; char *output; int rc; process_pkg_path(); rc = 0; for (++argv; *argv != NULL; ++argv) { url = find_best_package(NULL, *argv, 1); if (url == NULL) { rc = 1; continue; } output = fetchStringifyURL(url); puts(output); fetchFreeURL(url); free(output); } return rc; } else if (strcasecmp(argv[0], "fetch-pkg-vulnerabilities") == 0) { fetch_pkg_vulnerabilities(--argc, ++argv); } else if (strcasecmp(argv[0], "check-pkg-vulnerabilities") == 0) { check_pkg_vulnerabilities(--argc, ++argv); } else if (strcasecmp(argv[0], "audit") == 0) { audit_pkgdb(--argc, ++argv); } else if (strcasecmp(argv[0], "audit-pkg") == 0) { audit_pkg(--argc, ++argv); } else if (strcasecmp(argv[0], "audit-batch") == 0) { audit_batch(--argc, ++argv); } else if (strcasecmp(argv[0], "audit-history") == 0) { audit_history(--argc, ++argv); } else if (strcasecmp(argv[0], "check-signature") == 0) { struct archive *pkg; int rc; rc = 0; for (--argc, ++argv; argc > 0; --argc, ++argv) { char *archive_name; pkg = open_archive(*argv, &archive_name); if (pkg == NULL) { warnx("%s could not be opened", *argv); continue; } if (pkg_full_signature_check(archive_name, &pkg)) rc = 1; free(archive_name); if (!pkg) archive_read_finish(pkg); } return rc; } else if (strcasecmp(argv[0], "x509-sign-package") == 0) { #ifdef HAVE_SSL --argc; ++argv; if (argc != 4) errx(EXIT_FAILURE, "x509-sign-package takes exactly four arguments"); pkg_sign_x509(argv[0], argv[1], argv[2], argv[3]); #else errx(EXIT_FAILURE, "OpenSSL support is not included"); #endif } else if (strcasecmp(argv[0], "gpg-sign-package") == 0) { --argc; ++argv; if (argc != 2) errx(EXIT_FAILURE, "gpg-sign-package takes exactly two arguments"); pkg_sign_gpg(argv[0], argv[1]); } #endif else { usage(); } return 0; }
int main(int argc, char **argv) { char *CheckPkg = NULL; char *BestCheckPkg = NULL; lpkg_t *lpp; int ch; int rc; setprogname(argv[0]); while ((ch = getopt(argc, argv, Options)) != -1) switch (ch) { case '.': /* for backward compatibility */ break; case 'a': Which = WHICH_ALL; break; case 'B': Flags |= SHOW_BUILD_INFO; break; case 'b': Flags |= SHOW_BUILD_VERSION; break; case 'c': Flags |= SHOW_COMMENT; break; case 'D': Flags |= SHOW_DISPLAY; break; case 'd': Flags |= SHOW_DESC; break; case 'E': BestCheckPkg = optarg; break; case 'e': CheckPkg = optarg; break; case 'f': Flags |= SHOW_PLIST; break; case 'F': File2Pkg = 1; break; case 'I': Flags |= SHOW_INDEX; break; case 'i': Flags |= SHOW_INSTALL; break; case 'K': pkgdb_set_dir(optarg, 3); break; case 'k': Flags |= SHOW_DEINSTALL; break; case 'L': Flags |= SHOW_FILES; break; case 'l': InfoPrefix = optarg; break; case 'm': Flags |= SHOW_MTREE; break; case 'N': Flags |= SHOW_BLD_DEPENDS; break; case 'n': Flags |= SHOW_DEPENDS; break; case 'p': Flags |= SHOW_PREFIX; break; case 'Q': Flags |= SHOW_BI_VAR; BuildInfoVariable = optarg; break; case 'q': Quiet = TRUE; break; case 'r': Flags |= SHOW_FULL_REQBY; break; case 'R': Flags |= SHOW_REQBY; break; case 's': Flags |= SHOW_PKG_SIZE; break; case 'S': Flags |= SHOW_ALL_SIZE; break; case 'u': Which = WHICH_USER; break; case 'v': Verbose = TRUE; /* Reasonable definition of 'everything' */ Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL | SHOW_DEINSTALL | SHOW_DISPLAY | SHOW_MTREE | SHOW_REQBY | SHOW_BLD_DEPENDS | SHOW_DEPENDS | SHOW_PKG_SIZE | SHOW_ALL_SIZE; break; case 'V': show_version(); /* NOTREACHED */ case 'X': Flags |= SHOW_SUMMARY; break; case 'h': case '?': default: usage(); /* NOTREACHED */ } argc -= optind; argv += optind; pkg_install_config(); if (argc == 0 && !Flags && !CheckPkg) { /* No argument or relevant flags specified - assume -I */ Flags = SHOW_INDEX; /* assume -a if neither -u nor -a is given */ if (Which == WHICH_LIST) Which = WHICH_ALL; } if (CheckPkg != NULL && BestCheckPkg != NULL) { warnx("-E and -e are mutally exlusive"); usage(); } if (argc != 0 && CheckPkg != NULL) { warnx("can't give any additional arguments to -e"); usage(); } if (argc != 0 && BestCheckPkg != NULL) { warnx("can't give any additional arguments to -E"); usage(); } if (argc != 0 && Which != WHICH_LIST) { warnx("can't use both -a/-u and package name"); usage(); } /* Set some reasonable defaults */ if (!Flags) Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY | SHOW_DEPENDS | SHOW_DISPLAY; /* -Fe /filename -> change CheckPkg to real packagename */ if (CheckPkg) { if (File2Pkg) { char *s; if (!pkgdb_open(ReadOnly)) err(EXIT_FAILURE, "cannot open pkgdb"); s = pkgdb_retrieve(CheckPkg); if (s == NULL) errx(EXIT_FAILURE, "No matching pkg for %s.", CheckPkg); CheckPkg = xstrdup(s); pkgdb_close(); } return CheckForPkg(CheckPkg); } if (BestCheckPkg) return CheckForBestPkg(BestCheckPkg); TAILQ_INIT(&pkgs); /* Get all the remaining package names, if any */ if (File2Pkg && Which == WHICH_LIST) if (!pkgdb_open(ReadOnly)) { err(EXIT_FAILURE, "cannot open pkgdb"); } while (*argv) { /* pkgdb: if -F flag given, don't add pkgnames to the "pkgs" * queue but rather resolve the given filenames to pkgnames * using pkgdb_retrieve, then add them. */ if (File2Pkg) { char *s; s = pkgdb_retrieve(*argv); if (s) { lpp = alloc_lpkg(s); TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); } else errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); } else { if (ispkgpattern(*argv)) { switch (add_installed_pkgs_by_pattern(*argv, &pkgs)) { case 0: errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); case -1: errx(EXIT_FAILURE, "Error during search in pkgdb for %s", *argv); } } else { const char *dbdir; dbdir = pkgdb_get_dir(); if (**argv == '/' && strncmp(*argv, dbdir, strlen(dbdir)) == 0) { *argv += strlen(dbdir) + 1; if ((*argv)[strlen(*argv) - 1] == '/') { (*argv)[strlen(*argv) - 1] = 0; } } lpp = alloc_lpkg(*argv); TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); } } argv++; } if (File2Pkg) pkgdb_close(); /* If no packages, yelp */ if (TAILQ_FIRST(&pkgs) == NULL && Which == WHICH_LIST && !CheckPkg) warnx("missing package name(s)"), usage(); rc = pkg_perform(&pkgs); exit(rc); /* NOTREACHED */ }
int main(int argc, char **argv) { int ch, error=0; lpkg_head_t pkgs; setprogname(argv[0]); while ((ch = getopt(argc, argv, Options)) != -1) { switch (ch) { case 'A': Automatic = TRUE; break; case 'C': config_file = optarg; case 'P': Destdir = optarg; break; case 'f': Force = TRUE; ForceDepends = TRUE; break; case 'I': NoInstall = TRUE; break; case 'K': pkgdb_set_dir(optarg, 3); break; case 'L': NoView = TRUE; break; case 'R': NoRecord = TRUE; break; case 'm': OverrideMachine = optarg; break; case 'n': Fake = TRUE; Verbose = TRUE; break; case 'p': Prefix = optarg; break; case 'U': ReplaceSame = 1; Replace = 1; break; case 'u': Replace = 1; break; case 'V': show_version(); /* NOTREACHED */ case 'v': Verbose = TRUE; break; case 'W': Viewbase = optarg; break; case 'w': View = optarg; break; case 'h': case '?': default: usage(); break; } } argc -= optind; argv += optind; pkg_install_config(); if (Destdir != NULL) { char *pkgdbdir; pkgdbdir = xasprintf("%s/%s", Destdir, config_pkg_dbdir); pkgdb_set_dir(pkgdbdir, 4); free(pkgdbdir); } process_pkg_path(); TAILQ_INIT(&pkgs); if (argc == 0) { /* If no packages, yelp */ warnx("missing package name(s)"); usage(); } if (strcasecmp(do_license_check, "no") == 0) LicenseCheck = 0; else if (strcasecmp(do_license_check, "yes") == 0) LicenseCheck = 1; else if (strcasecmp(do_license_check, "always") == 0) LicenseCheck = 2; else errx(1, "Unknown value of the configuration variable" "CHECK_LICENSE"); if (LicenseCheck) load_license_lists(); /* Get all the remaining package names, if any */ for (; argc > 0; --argc, ++argv) { lpkg_t *lpp; if (IS_STDIN(*argv)) lpp = alloc_lpkg("-"); else lpp = alloc_lpkg(*argv); TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); } error += pkg_perform(&pkgs); if (error != 0) { warnx("%d package addition%s failed", error, error == 1 ? "" : "s"); exit(1); } exit(0); }
int main(int argc, char **argv) { int ch; setprogname(argv[0]); while ((ch = getopt(argc, argv, Options)) != -1) switch (ch) { case 'v': Verbose = TRUE; break; case 'E': create_views = 1; break; case 'F': CompressionType = optarg; break; case 'I': realprefix = optarg; break; case 'O': PlistOnly = 1; break; case 'U': update_pkgdb = 0; break; case 'p': Prefix = optarg; break; case 's': SizePkg = optarg; break; case 'S': SizeAll = optarg; break; case 'f': Contents = optarg; break; case 'c': Comment = optarg; break; case 'd': Desc = optarg; break; case 'g': DefaultGroup = optarg; break; case 'i': Install = optarg; break; case 'K': pkgdb_set_dir(optarg, 3); break; case 'k': DeInstall = optarg; break; case 'l': RelativeLinks = 1; break; case 'L': warnx("Obsolete -L option ignored"); break; case 'u': DefaultOwner = optarg; break; case 'D': Display = optarg; break; case 'n': Preserve = optarg; break; case 'P': Pkgdeps = optarg; break; case 'T': BuildPkgdeps = optarg; break; case 'C': Pkgcfl = optarg; break; case 'b': BuildVersion = optarg; break; case 'B': BuildInfo = optarg; break; case 'V': show_version(); /* NOTREACHED */ case '?': default: usage(); break; } argc -= optind; argv += optind; pkg_install_config(); if (argc == 0) { warnx("missing package name"); usage(); } if (argc != 1) { warnx("only one package name allowed"); usage(); } if (pkg_perform(*argv)) return 0; if (Verbose) { if (PlistOnly) warnx("package registration failed"); else warnx("package creation failed"); } return 1; }