main.c
author Kristian H?gsberg <krh@redhat.com>
Mon Apr 07 12:09:50 2008 -0400 (2008-04-07)
changeset 203 e0047e89db07
parent 202 e8594c82dffc
child 204 60badcb3d8ea
permissions -rw-r--r--
Handle arch correctly in command_download() and print some status at the end.
     1 #include <stdlib.h>
     2 #include <stddef.h>
     3 #include <stdio.h>
     4 #include <stdint.h>
     5 #include <string.h>
     6 #include <sys/stat.h>
     7 #include <unistd.h>
     8 #include <fcntl.h>
     9 #include <dirent.h>
    10 #include <curl/curl.h>
    11 #include <fnmatch.h>
    12 #include "razor.h"
    13 #include "razor-internal.h"
    14 
    15 static const char system_repo_filename[] = "system.repo";
    16 static const char next_repo_filename[] = "system-next.repo";
    17 static const char rawhide_repo_filename[] = "rawhide.repo";
    18 static const char updated_repo_filename[] = "system-updated.repo";
    19 static const char razor_root_path[] = "/var/lib/razor";
    20 static const char root[] = "install";
    21 static const char *repo_filename = system_repo_filename;
    22 
    23 static int
    24 command_list(int argc, const char *argv[])
    25 {
    26 	struct razor_set *set;
    27 	struct razor_package_iterator *pi;
    28 	struct razor_package *package;
    29 	const char *pattern, *name, *version, *arch;
    30 	int only_names = 0, i = 0;
    31 
    32 	if (i < argc && strcmp(argv[i], "--only-names") == 0) {
    33 		only_names = 1;
    34 		i++;
    35 	}
    36 
    37 	pattern = argv[i];
    38 	set = razor_set_open(repo_filename);
    39 	pi = razor_package_iterator_create(set);
    40 	while (razor_package_iterator_next(pi, &package,
    41 					   &name, &version, &arch)) {
    42 		if (pattern && fnmatch(pattern, name, 0) != 0)
    43 			continue;
    44 
    45 		if (only_names)
    46 			printf("%s\n", name);
    47 		else
    48 			printf("%s-%s.%s\n", name, version, arch);
    49 	}
    50 	razor_package_iterator_destroy(pi);
    51 	razor_set_destroy(set);
    52 
    53 	return 0;
    54 }
    55 
    56 static int
    57 list_properties(const char *package_name,
    58 		enum razor_property_type required_type)
    59 {
    60 	struct razor_set *set;
    61 	struct razor_property *property;
    62 	struct razor_package *package;
    63 	struct razor_property_iterator *pi;
    64 	const char *name, *version;
    65 	enum razor_property_type type;
    66 	enum razor_version_relation relation;
    67 
    68 	set = razor_set_open(repo_filename);
    69 	if (package_name)
    70 		package = razor_set_get_package(set, package_name);
    71 	else
    72 		package = NULL;
    73 
    74 	pi = razor_property_iterator_create(set, package);
    75 	while (razor_property_iterator_next(pi, &property,
    76 					    &name, &relation, &version,
    77 					    &type)) {
    78 		if (type != required_type)
    79 			continue;
    80 		if (version[0] == '\0')
    81 			printf("%s\n", name);
    82 		else
    83 			printf("%s %s %s\n", name,
    84 			       razor_version_relations[relation], version);
    85 	}
    86 	razor_property_iterator_destroy(pi);
    87 
    88 	razor_set_destroy(set);
    89 
    90 	return 0;
    91 }
    92 
    93 static int
    94 command_list_requires(int argc, const char *argv[])
    95 {
    96 	return list_properties(argv[0], RAZOR_PROPERTY_REQUIRES);
    97 }
    98 
    99 static int
   100 command_list_provides(int argc, const char *argv[])
   101 {
   102 	return list_properties(argv[0], RAZOR_PROPERTY_PROVIDES);
   103 }
   104 
   105 static int
   106 command_list_obsoletes(int argc, const char *argv[])
   107 {
   108 	return list_properties(argv[0], RAZOR_PROPERTY_OBSOLETES);
   109 }
   110 
   111 static int
   112 command_list_conflicts(int argc, const char *argv[])
   113 {
   114 	return list_properties(argv[0], RAZOR_PROPERTY_CONFLICTS);
   115 }
   116 
   117 static int
   118 command_list_files(int argc, const char *argv[])
   119 {
   120 	struct razor_set *set;
   121 
   122 	set = razor_set_open(repo_filename);
   123 	if (set == NULL)
   124 		return 1;
   125 	razor_set_list_files(set, argv[0]);
   126 	razor_set_destroy(set);
   127 
   128 	return 0;
   129 }
   130 
   131 static int
   132 command_list_file_packages(int argc, const char *argv[])
   133 {
   134 	struct razor_set *set;
   135 	struct razor_package_iterator *pi;
   136 	struct razor_package *package;
   137 	const char *name, *version, *arch;
   138 
   139 	set = razor_set_open(repo_filename);
   140 	if (set == NULL)
   141 		return 1;
   142 
   143 	pi = razor_package_iterator_create_for_file(set, argv[0]);
   144 	while (razor_package_iterator_next(pi, &package,
   145 					   &name, &version, &arch))
   146 		printf("%s-%s\n", name, version);
   147 	razor_package_iterator_destroy(pi);
   148 
   149 	razor_set_destroy(set);
   150 
   151 	return 0;
   152 }
   153 
   154 static int
   155 command_list_package_files(int argc, const char *argv[])
   156 {
   157 	struct razor_set *set;
   158 
   159 	set = razor_set_open(repo_filename);
   160 	if (set == NULL)
   161 		return 1;
   162 	razor_set_list_package_files(set, argv[0]);
   163 	razor_set_destroy(set);
   164 
   165 	return 0;
   166 }
   167 
   168 static void
   169 list_packages_for_property(struct razor_set *set,
   170 			   struct razor_property *property)
   171 {
   172 	struct razor_package_iterator *pi;
   173 	struct razor_package *package;
   174 	const char *name, *version, *arch;
   175 
   176 	pi = razor_package_iterator_create_for_property(set, property);
   177 	while (razor_package_iterator_next(pi, &package,
   178 					   &name, &version, &arch))
   179 		printf("%s-%s.%s\n", name, version, arch);
   180 	razor_package_iterator_destroy(pi);
   181 }
   182 
   183 static int
   184 list_property_packages(const char *ref_name,
   185 		       const char *ref_version,
   186 		       enum razor_property_type ref_type)
   187 {
   188 	struct razor_set *set;
   189 	struct razor_property *property;
   190 	struct razor_property_iterator *pi;
   191 	const char *name, *version;
   192 	enum razor_property_type type;
   193 	enum razor_version_relation relation;
   194 
   195 	if (ref_name == NULL)
   196 		return 0;
   197 
   198 	set = razor_set_open(repo_filename);
   199 	if (set == NULL)
   200 		return 1;
   201 
   202 	pi = razor_property_iterator_create(set, NULL);
   203 	while (razor_property_iterator_next(pi, &property,
   204 					    &name, &relation, &version,
   205 					    &type)) {
   206 		if (strcmp(ref_name, name) != 0)
   207 			continue;
   208 		if (ref_version && relation == RAZOR_VERSION_EQUAL &&
   209 		    strcmp(ref_version, version) != 0)
   210 			continue;
   211 		if (ref_type != type)
   212 			continue;
   213 
   214 		list_packages_for_property(set, property);
   215 	}
   216 	razor_property_iterator_destroy(pi);
   217 
   218 	return 0;
   219 }
   220 
   221 static int
   222 command_what_requires(int argc, const char *argv[])
   223 {
   224 	return list_property_packages(argv[0], argv[1],
   225 				      RAZOR_PROPERTY_REQUIRES);
   226 }
   227 
   228 static int
   229 command_what_provides(int argc, const char *argv[])
   230 {
   231 	return list_property_packages(argv[0], argv[1],
   232 				      RAZOR_PROPERTY_PROVIDES);
   233 }
   234 
   235 static int
   236 show_progress(void *clientp,
   237 	      double dltotal, double dlnow, double ultotal, double ulnow)
   238 {
   239 	const char *file = clientp;
   240 
   241 	if (!dlnow < dltotal)
   242 		fprintf(stderr, "\rdownloading %s, %dkB/%dkB",
   243 			file, (int) dlnow / 1024, (int) dltotal / 1024);
   244 
   245 	return 0;
   246 }
   247 
   248 static int
   249 download_if_missing(const char *url, const char *file)
   250 {
   251 	CURL *curl;
   252 	struct stat buf;
   253 	char error[256];
   254 	FILE *fp;
   255 	CURLcode res;
   256 
   257 	curl = curl_easy_init();
   258 	if (curl == NULL)
   259 		return 1;
   260 
   261 	curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
   262 	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
   263 	curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress);
   264 	curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, file);
   265 
   266 	if (stat(file, &buf) < 0) {
   267 		fp = fopen(file, "w");
   268 		curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
   269 		curl_easy_setopt(curl, CURLOPT_URL, url);
   270 		res = curl_easy_perform(curl);
   271 		fclose(fp);
   272 		if (res != CURLE_OK) {
   273 			fprintf(stderr, "curl error: %s\n", error);
   274 			unlink(file);
   275 			return -1;
   276 		}
   277 		fprintf(stderr, "\n");
   278 	}
   279 
   280 	curl_easy_cleanup(curl);
   281 
   282 	return 0;
   283 }
   284 
   285 #define REPO_URL "http://download.fedora.redhat.com" \
   286 	"/pub/fedora/linux/development/i386/os"
   287 
   288 static int
   289 command_import_yum(int argc, const char *argv[])
   290 {
   291 	struct razor_set *set;
   292 
   293 	if (download_if_missing(REPO_URL "/repodata/primary.xml.gz",
   294 				"primary.xml.gz") < 0)
   295 		return -1;
   296 	if (download_if_missing(REPO_URL "/repodata/filelists.xml.gz",
   297 				"filelists.xml.gz") < 0)
   298 		return -1;
   299 
   300 	set = razor_set_create_from_yum();
   301 	if (set == NULL)
   302 		return 1;
   303 	razor_set_write(set, rawhide_repo_filename);
   304 	razor_set_destroy(set);
   305 	printf("wrote %s\n", rawhide_repo_filename);
   306 
   307 	return 0;
   308 }
   309 
   310 static int
   311 command_import_rpmdb(int argc, const char *argv[])
   312 {
   313 	struct razor_set *set;
   314 
   315 	set = razor_set_create_from_rpmdb();
   316 	if (set == NULL)
   317 		return 1;
   318 	razor_set_write(set, repo_filename);
   319 	razor_set_destroy(set);
   320 	printf("wrote %s\n", repo_filename);
   321 
   322 	return 0;
   323 }
   324 
   325 static int
   326 command_validate(int argc, const char *argv[])
   327 {
   328 	struct razor_set *set;
   329 
   330 	set = razor_set_open(repo_filename);
   331 	if (set == NULL)
   332 		return 1;
   333 	razor_set_list_unsatisfied(set);
   334 	razor_set_destroy(set);
   335 
   336 	return 0;
   337 }
   338 
   339 static int
   340 command_update(int argc, const char *argv[])
   341 {
   342 	struct razor_set *set, *upstream;
   343 	struct razor_transaction *trans;
   344 	int errors;
   345 
   346 	set = razor_set_open(repo_filename);
   347 	upstream = razor_set_open(rawhide_repo_filename);
   348 	if (set == NULL || upstream == NULL)
   349 		return 1;
   350 	trans = razor_transaction_create(set, upstream, argc, argv, 0, NULL);
   351 	errors = razor_transaction_describe(trans);
   352 	if (errors)
   353 		return 1;
   354 
   355 	set = razor_transaction_finish(trans);
   356 	razor_set_write(set, updated_repo_filename);
   357 	razor_set_destroy(set);
   358 	razor_set_destroy(upstream);
   359 	printf("wrote system-updated.repo\n");
   360 
   361 	return 0;
   362 }
   363 
   364 static int
   365 command_remove(int argc, const char *argv[])
   366 {
   367 	struct razor_set *set;
   368 	struct razor_transaction *trans;
   369 	int errors;
   370 
   371 	set = razor_set_open(repo_filename);
   372 	if (set == NULL)
   373 		return 1;
   374 	trans = razor_transaction_create(set, NULL, 0, NULL, argc, argv);
   375 	errors = razor_transaction_describe(trans);
   376 	if (errors)
   377 		return 1;
   378 
   379 	set = razor_transaction_finish(trans);
   380 	razor_set_write(set, updated_repo_filename);
   381 	razor_set_destroy(set);
   382 	printf("wrote system-updated.repo\n");
   383 
   384 	return 0;
   385 }
   386 
   387 static void
   388 print_diff(const char *name,
   389 	   const char *old_version, const char *new_version, const char *arch,
   390 	   void *data)
   391 {
   392 	if (old_version)
   393 		printf("removing %s %s\n", name, old_version);
   394 	else
   395 		printf("install %s %s\n", name, new_version);
   396 }
   397 
   398 static int
   399 command_diff(int argc, const char *argv[])
   400 {
   401 	struct razor_set *set, *updated;
   402 
   403 	set = razor_set_open(repo_filename);
   404 	updated = razor_set_open(updated_repo_filename);
   405 	if (set == NULL || updated == NULL)
   406 		return 1;
   407 
   408 	razor_set_diff(set, updated, print_diff, NULL);	
   409 
   410 	razor_set_destroy(set);
   411 	razor_set_destroy(updated);
   412 
   413 	return 0;
   414 }
   415 
   416 static int
   417 command_import_rpms(int argc, const char *argv[])
   418 {
   419 	DIR *dir;
   420 	struct dirent *de;
   421 	struct razor_importer *importer;
   422 	struct razor_set *set;
   423 	struct razor_rpm *rpm;
   424 	int len;
   425 	char filename[256];
   426 	const char *dirname = argv[0];
   427 
   428 	if (dirname == NULL) {
   429 		fprintf(stderr, "usage: razor import-rpms DIR\n");
   430 		return -1;
   431 	}
   432 
   433 	dir = opendir(dirname);
   434 	if (dir == NULL) {
   435 		fprintf(stderr, "couldn't read dir %s\n", dirname);
   436 		return -1;
   437 	}
   438 
   439 	importer = razor_importer_new();
   440 
   441 	while (de = readdir(dir), de != NULL) {
   442 		len = strlen(de->d_name);
   443 		if (len < 5 || strcmp(de->d_name + len - 4, ".rpm") != 0)
   444 		    continue;
   445 		snprintf(filename, sizeof filename,
   446 			 "%s/%s", dirname, de->d_name);
   447 		rpm = razor_rpm_open(filename);
   448 		if (rpm == NULL) {
   449 			fprintf(stderr,
   450 				"failed to open rpm \"%s\"\n", filename);
   451 			continue;
   452 		}
   453 		if (razor_importer_add_rpm(importer, rpm)) {
   454 			fprintf(stderr, "couldn't import %s\n", filename);
   455 			break;
   456 		}
   457 		razor_rpm_close(rpm);
   458 	}
   459 
   460 	if (de != NULL) {
   461 		razor_importer_destroy(importer);
   462 		return -1;
   463 	}
   464 
   465 	set = razor_importer_finish(importer);
   466 
   467 	razor_set_write(set, repo_filename);
   468 	razor_set_destroy(set);
   469 	printf("wrote %s\n", repo_filename);
   470 
   471 	return 0;
   472 }
   473 
   474 static void
   475 download_package(const char *name,
   476 		 const char *old_version,
   477 		 const char *new_version,
   478 		 const char *arch,
   479 		 void *data)
   480 {
   481 	char file[PATH_MAX], url[256];
   482 	const char *v;
   483 
   484 	if (old_version)
   485 		return;
   486 
   487 	/* Skip epoch */
   488 	v = strchr(new_version, ':');
   489 	if (v != NULL)
   490 		v = v + 1;
   491 	else
   492 		v = new_version;
   493 
   494 	snprintf(url, sizeof url,
   495 		 REPO_URL "/Packages/%s-%s.%s.rpm", name, v, arch);
   496 	snprintf(file, sizeof file,
   497 		 "rpms/%s-%s.%s.rpm", name, v, arch);
   498 	if (download_if_missing(url, file) < 0)
   499 		fprintf(stderr, "failed to download %s\n", name);
   500 }
   501 
   502 static void
   503 install_package(const char *name,
   504 		const char *old_version,
   505 		const char *new_version,
   506 		const char *arch,
   507 		void *data)
   508 {
   509 	const char *v, *root = data;
   510 	char file[PATH_MAX];
   511 	struct razor_rpm *rpm;
   512 
   513 	if (old_version) {
   514 		printf("removing %s %s not handled\n", name, old_version);
   515 		return;
   516 	}
   517 
   518 	/* Skip epoch */
   519 	v = strchr(new_version, ':');
   520 	if (v != NULL)
   521 		v = v + 1;
   522 	else
   523 		v = new_version;
   524 
   525 	printf("install %s %s\n", name, v);
   526 	snprintf(file, sizeof file, "rpms/%s-%s.%s.rpm", name, v, arch);
   527 
   528  	rpm = razor_rpm_open(file);
   529 	if (rpm == NULL) {
   530 		fprintf(stderr, "failed to open rpm %s\n", file);
   531 		return;
   532 	}
   533 	if (razor_rpm_install(rpm, root) < 0) {
   534 		fprintf(stderr,
   535 			"failed to install rpm %s\n", file);
   536 		return;
   537 	}
   538 	razor_rpm_close(rpm);
   539 }
   540 
   541 static int
   542 command_install(int argc, const char *argv[])
   543 {
   544 	struct razor_set *system, *upstream, *next;
   545 	struct razor_transaction *trans;
   546 	char path[PATH_MAX], new_path[PATH_MAX];
   547 	int errors, fd;
   548 
   549 	/* Create the new next repo file up front to ensure exclusive
   550 	 * access. */
   551 	snprintf(new_path, sizeof new_path,
   552 		 "%s%s/%s", root, razor_root_path, next_repo_filename);
   553 	fd = open(new_path, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0666);
   554 	if (fd < 0) {
   555 		fprintf(stderr, "failed to get lock file, "
   556 			"maybe previous operation crashed?\n");
   557 
   558 		/* FIXME: Use fcntl advisory locking to figure out
   559 		 * whether previous operation crashed or is still in
   560 		 * progress. */
   561 
   562 		return -1;
   563 	}
   564 
   565 	upstream = razor_set_open(rawhide_repo_filename);
   566 	snprintf(path, sizeof path,
   567 		 "%s%s/%s", root, razor_root_path, system_repo_filename);
   568 	system = razor_set_open(path);
   569 	if (system == NULL || upstream == NULL) {
   570 		unlink(new_path);
   571 		return 1;
   572 	}
   573 	trans = razor_transaction_create(system, upstream,
   574 					 argc, argv, 0, NULL);
   575 	errors = razor_transaction_describe(trans);
   576 	if (errors) {
   577 		unlink(new_path);
   578 		return 1;
   579 	}
   580 
   581 	next = razor_transaction_finish(trans);
   582 
   583 	razor_set_write_to_fd(next, fd);
   584 	printf("wrote %s\n", new_path);
   585 
   586 	razor_set_diff(system, next, download_package, NULL);	
   587 
   588 	/* FIXME: We need to figure out the right install order here,
   589 	 * so the post and pre scripts can run. */
   590 	razor_set_diff(system, next, install_package, (void *) root);
   591 
   592 	razor_set_destroy(next);
   593 	razor_set_destroy(system);
   594 	razor_set_destroy(upstream);
   595 
   596 	/* Make it so. */
   597 	rename(new_path, path);
   598 	printf("renamed %s to %s\n", new_path, path);
   599 
   600 	return 0;
   601 }
   602 
   603 static int
   604 command_init(int argc, const char *argv[])
   605 {
   606 	struct stat buf;
   607 	struct razor_set *set;
   608 	char path[PATH_MAX];
   609 
   610 	if (stat(root, &buf) < 0) {
   611 		if (mkdir(root, 0777) < 0) {
   612 			fprintf(stderr,
   613 				"could not create install root \"%s\"\n",
   614 				root);
   615 			return -1;
   616 		}
   617 		fprintf(stderr, "created install root \"%s\"\n", root);
   618 	} else if (!S_ISDIR(buf.st_mode)) {
   619 		fprintf(stderr,
   620 			"install root \"%s\" exists, but is not a directory\n",
   621 			root);
   622 		return -1;
   623 	}
   624 
   625 	if (razor_create_dir(root, razor_root_path) < 0) {
   626 		fprintf(stderr, "could not create %s%s\n",
   627 			root, razor_root_path);
   628 		return -1;
   629 	}
   630 
   631 	set = razor_set_create();
   632 	snprintf(path, sizeof path, "%s%s/%s",
   633 		 root, razor_root_path, system_repo_filename);
   634 	if (razor_set_write(set, path) < 0) {
   635 		fprintf(stderr, "could not write initial package set\n");
   636 		return -1;
   637 	}
   638 	razor_set_destroy(set);
   639 
   640 	return 0;
   641 }
   642 
   643 static int
   644 command_download(int argc, const char *argv[])
   645 {
   646 	struct razor_set *set;
   647 	struct razor_package_iterator *pi;
   648 	struct razor_package *package;
   649 	const char *pattern = argv[0], *name, *version, *arch;
   650 	char url[256], file[256];
   651 	int matches = 0;
   652 
   653 	set = razor_set_open(rawhide_repo_filename);
   654 	pi = razor_package_iterator_create(set);
   655 	while (razor_package_iterator_next(pi, &package,
   656 					   &name, &version, &arch)) {
   657 		if (pattern && fnmatch(pattern, name, 0) != 0)
   658 			continue;
   659 
   660 		matches++;
   661 		snprintf(url, sizeof url,
   662 			 REPO_URL "/Packages/%s-%s.%s.rpm",
   663 			 name, version, arch);
   664 		snprintf(file, sizeof file,
   665 			 "rpms/%s-%s.%s.rpm", name, version, arch);
   666 		if (download_if_missing(url, file) < 0)
   667 			fprintf(stderr, "failed to download %s\n", name);
   668 	}
   669 	razor_package_iterator_destroy(pi);
   670 	razor_set_destroy(set);
   671 
   672 	if (matches == 0)
   673 		fprintf(stderr, "no packages matched \"%s\"\n", pattern);
   674 	else if (matches == 1)
   675 		fprintf(stderr, "downloaded 1 package\n");
   676 	else
   677 		fprintf(stderr, "downloaded %d package\n", matches);
   678 
   679 	return 0;
   680 }
   681 
   682 static struct {
   683 	const char *name;
   684 	const char *description;
   685 	int (*func)(int argc, const char *argv[]);
   686 } razor_commands[] = {
   687 	{ "list", "list all packages", command_list },
   688 	{ "list-requires", "list all requires for the given package", command_list_requires },
   689 	{ "list-provides", "list all provides for the given package", command_list_provides },
   690 	{ "list-obsoletes", "list all obsoletes for the given package", command_list_obsoletes },
   691 	{ "list-conflicts", "list all conflicts for the given package", command_list_conflicts },
   692 	{ "list-files", "list files for package set", command_list_files },
   693 	{ "list-file-packages", "list packages owning file", command_list_file_packages },
   694 	{ "list-package-files", "list files in package", command_list_package_files },
   695 	{ "what-requires", "list the packages that have the given requires", command_what_requires },
   696 	{ "what-provides", "list the packages that have the given provides", command_what_provides },
   697 	{ "import-yum", "import yum metadata files", command_import_yum },
   698 	{ "import-rpmdb", "import the system rpm database", command_import_rpmdb },
   699 	{ "import-rpms", "import rpms from the given directory", command_import_rpms },
   700 	{ "validate", "validate a package set", command_validate },
   701 	{ "update", "update all or specified packages", command_update },
   702 	{ "remove", "remove specified packages", command_remove },
   703 	{ "diff", "show diff between two package sets", command_diff },
   704 	{ "install", "install rpm", command_install },
   705 	{ "init", "init razor root", command_init },
   706 	{ "download", "download packages", command_download }
   707 };
   708 
   709 static int
   710 usage(void)
   711 {
   712 	int i;
   713 
   714 	printf("usage:\n");
   715 	for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
   716 		printf("  %-20s%s\n",
   717 		       razor_commands[i].name, razor_commands[i].description);
   718 
   719 	return 1;
   720 }
   721 
   722 int
   723 main(int argc, const char *argv[])
   724 {
   725 	char *repo;
   726 	int i;
   727 
   728 	repo = getenv("RAZOR_REPO");
   729 	if (repo != NULL)
   730 		repo_filename = repo;
   731 
   732 	if (argc < 2)
   733 		return usage();
   734 
   735 	for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
   736 		if (strcmp(razor_commands[i].name, argv[1]) == 0)
   737 			return razor_commands[i].func(argc - 2, argv + 2);
   738 
   739 	return usage();
   740 }