Beispiel #1
0
int main(int argc, char **argv)
{
	struct arguments arguments;

	arguments.action = 0;
	arguments.no_favorite_repo = 0;
	arguments.no_favorite_version = 0;
	arguments.no_deps = 1;
	arguments.all = 0;
	arguments.args = NULL;

	if (argc < 2) {
		char *fake_arg[2];
		fake_arg[0] = "ilenia";
		fake_arg[1] = "--help";
		argp_parse(&argp, 2, fake_arg, 0, 0, &arguments);
	}

	argp_parse(&argp, argc, argv, 0, 0, &arguments);

	if (parse_ileniarc() != 0)
		return (EXIT_FAILURE);

	ilenia_repos = build_repolist();

	if (arguments.action == ACT_CACHE) {
		FILE *file;
		if ((file = fopen(CACHE, "w")))
			fclose(file);
	}

	ilenia_favoriterepo = get_favorite(FAVORITE_REPO);
	ilenia_favoriteversion = get_favorite(FAVORITE_VERSION);
	ilenia_aliases = aliaseslist_build();
	ilenia_ports = lsports();
	ilenia_pkgs = lspkgs();
	ilenia_favoritepkgmk = pkgmklist_build();

	if (arguments.action > 21 || arguments.action == 0)
		error("%s", "please perform an action at a time!");

	int confront_options =
	    arguments.no_favorite_repo + arguments.no_favorite_version;

	int update_options = arguments.no_deps;
	if (confront_options)
		update_options = confront_options * update_options;

	int status = EXIT_SUCCESS;

	if (arguments.action == ACT_UPDATE) {
		if (arguments.args == NULL) {
			status = update_all_repos();
			return (EXIT_SUCCESS);
		}
		while (arguments.args) {
			status = update_repo(arguments.args->data);
			arguments.args = arguments.args->next;
		}
	}

	if (arguments.action == ACT_LIST) {
		if (arguments.args == NULL) {
			pkglist_print(ilenia_ports);
			return (EXIT_SUCCESS);
		}
		while (arguments.args) {
			if (repolist_exists(arguments.args->data,
					    ilenia_repos)) {
				warning("repository %s not found!\n",
					arguments.args->data);
				arguments.args = arguments.args->next;
				continue;
			}
			pkglist_print(pkglist_select_from_repo
				      (arguments.args->data,
				       ilenia_ports));
			arguments.args = arguments.args->next;
		}
	}

	if (arguments.action == ACT_SEARCH) {
		if (arguments.args == NULL)
			error("action search requires an argument!");
		while (arguments.args) {
			pkglist_print(pkglist_find_like
				      (arguments.args->data,
				       ilenia_ports));
			arguments.args = arguments.args->next;
		}
	}

	if (arguments.action == ACT_INFO) {
		if (arguments.args == NULL)
			error("action info requires an argument!");
		while (arguments.args) {
			info(arguments.args->data, confront_options);
			arguments.args = arguments.args->next;
		}
	}

	if (arguments.action == ACT_DIFF)
		pkglist_confront(DIFF, confront_options, 1);

	if (arguments.action == ACT_UPDATED)
		pkglist_confront(UPDATED, confront_options, 1);

	if (arguments.action == ACT_DEPENDENCIES) {
		if (arguments.args == NULL)
			error("action dependencies requires an argument!");
		while (arguments.args) {
			print_dependencies(arguments.args->data);
			arguments.args = arguments.args->next;
		}
	}

	if (arguments.action == ACT_UPDATE_PKG) {
		if (arguments.args == NULL) {
			status = update_system(update_options);
			return status;
		}
		while (arguments.args) {
			status =
			    update_pkg(update_options,
				       arguments.args->data);
			arguments.args = arguments.args->next;
		}
	}

	if (arguments.action == ACT_DEPENDENTS) {
		if (arguments.args == NULL)
			error("action dependents requires an argument!");
		while (arguments.args) {
			print_dependents(arguments.args->data,
					 arguments.all);
			arguments.args = arguments.args->next;
		}
	}

	if (arguments.action == ACT_REMOVE) {
		if (arguments.args == NULL)
			error("action remove requires an argument!");
		while (arguments.args) {
			status =
			    remove_pkg(arguments.args->data,
				       arguments.no_deps, arguments.all);
			arguments.args = arguments.args->next;
		}
	}


	if (arguments.action == ACT_REPOSITORY_LIST) {
		while (ilenia_repos != NULL) {
			printf("name %s path %s\n", ilenia_repos->name,
			       ilenia_repos->path);
			ilenia_repos = ilenia_repos->next;
		}
	}

	return status;
}
Beispiel #2
0
/* remove mode */
int
remove_mode(char *pkgspec)
{
	encap_list_t *ver_l;
	char buf[MAXPATHLEN], name[MAXPATHLEN], ver[MAXPATHLEN] = "";
	encap_listptr_t lp;
	int i;

	if (verbose)
		printf("epkg: removing package %s...\n", pkgspec);

	/* if versioning is off, simply remove the specified package */
	if (!BIT_ISSET(epkg_opts, EPKG_OPT_VERSIONING))
		return remove_pkg(pkgspec);

	if (verbose)
		printf("  > reading Encap source directory...\n");

	ver_l = encap_list_new(LIST_USERFUNC, (encap_cmpfunc_t)encap_vercmp);
	if (ver_l == NULL)
	{
		fprintf(stderr, "    ! encap_list_new(): %s\n",
			strerror(errno));
		return -1;
	}

	i = encap_find_versions(source, pkgspec, version_list_add, ver_l);
	if (i == 0)
	{
		encap_pkgspec_parse(pkgspec, name, sizeof(name),
				    ver, sizeof(ver), NULL, 0, NULL, 0);
		i = encap_find_versions(source, name,
					version_list_add, ver_l);
		if (i == 0)
		{
			fprintf(stderr, "    ! no versions of package %s "
				"found!\n", pkgspec);
			return -1;
		}
	}
	else
		strlcpy(name, pkgspec, sizeof(name));
	if (i == -2)
		return -1;
	if (i == -1)
	{
		fprintf(stderr, "    ! encap_find_versions(): %s\n",
			strerror(errno));
		return -1;
	}

	if (ver[0] == '\0')
		i = remove_package_versionlist(name, ver_l);
	else
	{
		encap_listptr_reset(&lp);
		if (encap_list_search(ver_l, &lp, ver,
				      (encap_matchfunc_t)ver_match) == 0)
		{
			encap_pkgspec_join(buf, sizeof(buf), name, ver);
			fprintf(stderr, "    ! package %s not found!\n", buf);
			return -1;
		}
		encap_list_del(ver_l, &lp);
		i = remove_pkg(pkgspec);
	}

	encap_list_free(ver_l, (encap_freefunc_t)free);
	return i;
}