示例#1
0
文件: main.c 项目: Spenser309/CS551
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);
}
示例#2
0
文件: perform.c 项目: ryo/netbsd-src
int
pkg_perform(const char *pkg)
{
    char   *cp;
    FILE   *pkg_in;
    package_t plist;
    const char *full_pkg, *suffix;
    char *allocated_pkg;
    int retval;

    /* Break the package name into base and desired suffix (if any) */
    if ((cp = strrchr(pkg, '.')) != NULL) {
        allocated_pkg = xmalloc(cp - pkg + 1);
        memcpy(allocated_pkg, pkg, cp - pkg);
        allocated_pkg[cp - pkg] = '\0';
        suffix = cp + 1;
        full_pkg = pkg;
        pkg = allocated_pkg;
    } else {
        allocated_pkg = NULL;
        full_pkg = pkg;
        suffix = "tgz";
    }

    /* Preliminary setup */
    sanity_check();
    if (Verbose && !PlistOnly)
        printf("Creating package %s\n", pkg);
    get_dash_string(&Comment);
    get_dash_string(&Desc);
    if (IS_STDIN(Contents))
        pkg_in = stdin;
    else {
        pkg_in = fopen(Contents, "r");
        if (!pkg_in)
            errx(2, "unable to open contents file '%s' for input", Contents);
    }

    plist.head = plist.tail = NULL;

    /* Stick the dependencies, if any, at the top */
    if (Pkgdeps)
        register_depends(&plist, Pkgdeps, 0);

    /*
     * Put the build dependencies after the dependencies.
     * This works due to the evaluation order in pkg_add.
     */
    if (BuildPkgdeps)
        register_depends(&plist, BuildPkgdeps, 1);

    /* Put the conflicts directly after the dependencies, if any */
    if (Pkgcfl) {
        if (Verbose && !PlistOnly)
            printf("Registering conflicts:");
        while (Pkgcfl) {
            cp = strsep(&Pkgcfl, " \t\n");
            if (*cp) {
                add_plist(&plist, PLIST_PKGCFL, cp);
                if (Verbose && !PlistOnly)
                    printf(" %s", cp);
            }
        }
        if (Verbose && !PlistOnly)
            printf(".\n");
    }

    /* Slurp in the packing list */
    append_plist(&plist, pkg_in);

    if (pkg_in != stdin)
        fclose(pkg_in);

    /* Prefix should override the packing list */
    if (Prefix) {
        delete_plist(&plist, FALSE, PLIST_CWD, NULL);
        add_plist_top(&plist, PLIST_CWD, Prefix);
    }
    /*
         * Run down the list and see if we've named it, if not stick in a name
         * at the top.
         */
    if (find_plist(&plist, PLIST_NAME) == NULL) {
        add_plist_top(&plist, PLIST_NAME, basename_of(pkg));
    }

    /* Make first "real contents" pass over it */
    check_list(&plist, basename_of(pkg));

    /*
         * We're just here for to dump out a revised plist for the FreeBSD ports
         * hack.  It's not a real create in progress.
         */
    if (PlistOnly) {
        write_plist(&plist, stdout, realprefix);
        retval = TRUE;
    } else {
#ifdef BOOTSTRAP
        warnx("Package building is not supported in bootstrap mode");
        retval = FALSE;
#else
        retval = pkg_build(pkg, full_pkg, suffix, &plist);
#endif
    }

    /* Cleanup */
    free(Comment);
    free(Desc);
    free_plist(&plist);

    free(allocated_pkg);

    return retval;
}