2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
4 * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 #include <curl/curl.h>
42 static const char system_repo_filename[] = "system.rzdb";
43 static const char next_repo_filename[] = "system-next.rzdb";
44 static const char rawhide_repo_filename[] = "rawhide.rzdb";
45 static const char updated_repo_filename[] = "system-updated.rzdb";
46 static const char *install_root = "";
47 static const char *repo_filename = system_repo_filename;
48 static const char *yum_url;
50 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
52 static struct razor_package_iterator *
53 create_iterator_from_argv(struct razor_set *set, int argc, const char *argv[])
55 struct razor_package_query *query;
56 struct razor_package_iterator *iter;
57 struct razor_package *package;
58 const char *name, *pattern;
62 return razor_package_iterator_create(set);
64 query = razor_package_query_create(set);
66 for (i = 0; i < argc; i++) {
67 iter = razor_package_iterator_create(set);
70 while (razor_package_iterator_next(iter, &package,
71 RAZOR_DETAIL_NAME, &name,
73 if (fnmatch(pattern, name, 0) != 0)
76 razor_package_query_add_package(query, package);
79 razor_package_iterator_destroy(iter);
83 "no package matches \"%s\"\n", pattern);
86 return razor_package_query_finish(query);
89 #define LIST_PACKAGES_ONLY_NAMES 0x01
92 list_packages(struct razor_package_iterator *iter, uint32_t flags)
94 struct razor_package *package;
95 const char *name, *version, *arch;
97 while (razor_package_iterator_next(iter, &package,
98 RAZOR_DETAIL_NAME, &name,
99 RAZOR_DETAIL_VERSION, &version,
100 RAZOR_DETAIL_ARCH, &arch,
101 RAZOR_DETAIL_LAST)) {
102 if (flags & LIST_PACKAGES_ONLY_NAMES)
103 printf("%s\n", name);
105 printf("%s-%s.%s\n", name, version, arch);
110 command_list(int argc, const char *argv[])
112 struct razor_package_iterator *pi;
113 struct razor_set *set;
117 if (i < argc && strcmp(argv[i], "--only-names") == 0) {
118 flags |= LIST_PACKAGES_ONLY_NAMES;
122 set = razor_root_open_read_only(install_root);
126 pi = create_iterator_from_argv(set, argc - i, argv + i);
127 list_packages(pi, flags);
128 razor_package_iterator_destroy(pi);
129 razor_set_destroy(set);
135 list_package_properties(struct razor_set *set,
136 struct razor_package *package, uint32_t type)
138 struct razor_property_iterator *pi;
139 struct razor_property *property;
140 const char *name, *version;
143 pi = razor_property_iterator_create(set, package);
144 while (razor_property_iterator_next(pi, &property,
145 &name, &flags, &version)) {
146 if ((flags & RAZOR_PROPERTY_TYPE_MASK) != type)
149 if (version[0] != '\0')
151 razor_property_relation_to_string(property),
154 if (flags & ~(RAZOR_PROPERTY_RELATION_MASK | RAZOR_PROPERTY_TYPE_MASK)) {
156 if (flags & RAZOR_PROPERTY_PRE)
158 if (flags & RAZOR_PROPERTY_POST)
160 if (flags & RAZOR_PROPERTY_PREUN)
162 if (flags & RAZOR_PROPERTY_POSTUN)
168 razor_property_iterator_destroy(pi);
172 list_properties(int argc, const char *argv[], uint32_t type)
174 struct razor_set *set;
175 struct razor_package *package;
176 struct razor_package_iterator *pi;
177 const char *name, *version, *arch;
179 set = razor_root_open_read_only(install_root);
183 pi = create_iterator_from_argv(set, argc, argv);
184 while (razor_package_iterator_next(pi, &package,
185 RAZOR_DETAIL_NAME, &name,
186 RAZOR_DETAIL_VERSION, &version,
187 RAZOR_DETAIL_ARCH, &arch,
189 list_package_properties(set, package, type);
190 razor_package_iterator_destroy(pi);
191 razor_set_destroy(set);
197 command_list_requires(int argc, const char *argv[])
199 return list_properties(argc, argv, RAZOR_PROPERTY_REQUIRES);
203 command_list_provides(int argc, const char *argv[])
205 return list_properties(argc, argv, RAZOR_PROPERTY_PROVIDES);
209 command_list_obsoletes(int argc, const char *argv[])
211 return list_properties(argc, argv, RAZOR_PROPERTY_OBSOLETES);
215 command_list_conflicts(int argc, const char *argv[])
217 return list_properties(argc, argv, RAZOR_PROPERTY_CONFLICTS);
221 command_list_files(int argc, const char *argv[])
223 struct razor_set *set;
225 set = razor_root_open_read_only(install_root);
229 razor_set_list_files(set, argv[0]);
230 razor_set_destroy(set);
236 command_list_file_packages(int argc, const char *argv[])
238 struct razor_set *set;
239 struct razor_package_iterator *pi;
241 set = razor_root_open_read_only(install_root);
245 pi = razor_package_iterator_create_for_file(set, argv[0]);
246 list_packages(pi, 0);
247 razor_package_iterator_destroy(pi);
249 razor_set_destroy(set);
255 command_list_package_files(int argc, const char *argv[])
257 struct razor_set *set;
258 struct razor_package_iterator *pi;
259 struct razor_package *package;
260 const char *name, *version, *arch;
262 set = razor_root_open_read_only(install_root);
266 pi = create_iterator_from_argv(set, argc, argv);
267 while (razor_package_iterator_next(pi, &package,
268 RAZOR_DETAIL_NAME, &name,
269 RAZOR_DETAIL_VERSION, &version,
270 RAZOR_DETAIL_ARCH, &arch,
272 razor_set_list_package_files(set, package);
273 razor_package_iterator_destroy(pi);
275 razor_set_destroy(set);
281 list_property_packages(const char *ref_name,
282 const char *ref_version,
285 struct razor_set *set;
286 struct razor_property *property;
287 struct razor_property_iterator *prop_iter;
288 struct razor_package_iterator *pkg_iter;
289 const char *name, *version;
292 if (ref_name == NULL)
295 set = razor_root_open_read_only(install_root);
299 prop_iter = razor_property_iterator_create(set, NULL);
300 while (razor_property_iterator_next(prop_iter, &property,
301 &name, &flags, &version)) {
302 if (strcmp(ref_name, name) != 0)
305 (flags & RAZOR_PROPERTY_RELATION_MASK) == RAZOR_PROPERTY_EQUAL &&
306 strcmp(ref_version, version) != 0)
308 if ((flags & RAZOR_PROPERTY_TYPE_MASK) != type)
312 razor_package_iterator_create_for_property(set,
314 list_packages(pkg_iter, 0);
315 razor_package_iterator_destroy(pkg_iter);
317 razor_property_iterator_destroy(prop_iter);
319 razor_set_destroy(set);
325 command_what_requires(int argc, const char *argv[])
327 return list_property_packages(argv[0], argv[1],
328 RAZOR_PROPERTY_REQUIRES);
332 command_what_provides(int argc, const char *argv[])
334 return list_property_packages(argv[0], argv[1],
335 RAZOR_PROPERTY_PROVIDES);
339 show_progress(void *clientp,
340 double dltotal, double dlnow, double ultotal, double ulnow)
342 const char *file = clientp;
344 if (!dlnow < dltotal)
345 fprintf(stderr, "\rdownloading %s, %dkB/%dkB",
346 file, (int) dlnow / 1024, (int) dltotal / 1024);
352 download_if_missing(const char *url, const char *file)
364 curl = curl_easy_init();
368 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
369 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
370 curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress);
371 curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, file);
373 if (stat(file, &buf) < 0) {
374 fp = fopen(file, "wb");
377 "failed to open %s for writing\n", file);
380 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
381 curl_easy_setopt(curl, CURLOPT_URL, url);
382 res = curl_easy_perform(curl);
384 if (res != CURLE_OK) {
385 fprintf(stderr, "curl error: %s\n", error);
389 res = curl_easy_getinfo(curl,
390 CURLINFO_RESPONSE_CODE, &response);
391 if (res != CURLE_OK) {
392 fprintf(stderr, "curl error: %s\n", error);
396 if (response != 200) {
397 fprintf(stderr, " - failed %ld\n", response);
401 fprintf(stderr, "\n");
404 curl_easy_cleanup(curl);
407 #endif /* HAVE_CURL */
410 #define YUM_URL "http://download.fedora.redhat.com" \
411 "/pub/fedora/linux/development/i386/os"
414 command_import_yum(int argc, const char *argv[])
416 struct razor_set *set;
419 printf("downloading from %s.\n", yum_url);
420 snprintf(buffer, sizeof buffer,
421 "%s/repodata/primary.xml.gz", yum_url);
422 if (download_if_missing(buffer, "primary.xml.gz") < 0)
424 snprintf(buffer, sizeof buffer,
425 "%s/repodata/filelists.xml.gz", yum_url);
426 if (download_if_missing(buffer, "filelists.xml.gz") < 0)
429 set = razor_set_create_from_yum();
432 if (razor_set_write(set, rawhide_repo_filename, RAZOR_REPO_FILE_MAIN)) {
433 perror(rawhide_repo_filename);
436 if (razor_set_write(set, "rawhide-details.rzdb",
437 RAZOR_REPO_FILE_DETAILS)) {
438 perror("rawhide-details.rzdb");
441 if (razor_set_write(set, "rawhide-files.rzdb", RAZOR_REPO_FILE_FILES)) {
442 perror("rawhide-files.rzdb");
445 razor_set_destroy(set);
446 printf("wrote %s\n", rawhide_repo_filename);
453 command_import_rpmdb(int argc, const char *argv[])
455 struct razor_set *set;
456 struct razor_root *root;
458 root = razor_root_open(install_root);
462 set = razor_set_create_from_rpmdb();
466 razor_root_update(root, set);
468 return razor_root_commit(root);
473 mark_packages_for_update(struct razor_transaction *trans,
474 struct razor_set *set, const char *pattern)
476 struct razor_package_iterator *pi;
477 struct razor_package *package;
481 pi = razor_package_iterator_create(set);
482 while (razor_package_iterator_next(pi, &package,
483 RAZOR_DETAIL_NAME, &name,
484 RAZOR_DETAIL_LAST)) {
485 if (pattern && fnmatch(pattern, name, 0) == 0) {
486 razor_transaction_update_package(trans, package);
490 razor_package_iterator_destroy(pi);
496 mark_packages_for_removal(struct razor_transaction *trans,
497 struct razor_set *set, const char *pattern)
499 struct razor_package_iterator *pi;
500 struct razor_package *package;
504 pi = razor_package_iterator_create(set);
505 while (razor_package_iterator_next(pi, &package,
506 RAZOR_DETAIL_NAME, &name,
507 RAZOR_DETAIL_LAST)) {
508 if (pattern && fnmatch(pattern, name, 0) == 0) {
509 razor_transaction_remove_package(trans, package);
513 razor_package_iterator_destroy(pi);
519 command_update(int argc, const char *argv[])
521 struct razor_set *set, *upstream;
522 struct razor_transaction *trans;
525 set = razor_root_open_read_only(install_root);
529 upstream = razor_set_open(rawhide_repo_filename);
530 if (upstream == NULL ||
531 razor_set_open_details(upstream, "rawhide-details.rzdb") ||
532 razor_set_open_files(upstream, "rawhide-files.rzdb"))
535 trans = razor_transaction_create(set, upstream);
537 razor_transaction_update_all(trans);
538 for (i = 0; i < argc; i++) {
539 if (mark_packages_for_update(trans, set, argv[i]) == 0) {
540 fprintf(stderr, "no match for %s\n", argv[i]);
545 razor_transaction_resolve(trans);
546 errors = razor_transaction_describe(trans);
548 fprintf(stderr, "unresolved dependencies\n");
552 set = razor_transaction_finish(trans);
553 razor_set_write(set, updated_repo_filename, RAZOR_REPO_FILE_MAIN);
554 razor_set_destroy(set);
555 razor_set_destroy(upstream);
556 printf("wrote system-updated.rzdb\n");
562 command_remove(int argc, const char *argv[])
564 struct razor_set *set, *upstream;
565 struct razor_transaction *trans;
568 set = razor_root_open_read_only(install_root);
572 upstream = razor_set_create();
573 trans = razor_transaction_create(set, upstream);
574 for (i = 0; i < argc; i++) {
575 if (mark_packages_for_removal(trans, set, argv[i]) == 0) {
576 fprintf(stderr, "no match for %s\n", argv[i]);
581 razor_transaction_resolve(trans);
582 errors = razor_transaction_describe(trans);
586 set = razor_transaction_finish(trans);
587 razor_set_write(set, updated_repo_filename, RAZOR_REPO_FILE_MAIN);
588 razor_set_destroy(set);
589 razor_set_destroy(upstream);
590 printf("wrote system-updated.rzdb\n");
596 print_diff(enum razor_diff_action action,
597 struct razor_package *package,
603 if (action == RAZOR_DIFF_ACTION_ADD)
604 printf("install %s-%s.%s\n", name, version, arch);
605 if (action == RAZOR_DIFF_ACTION_REMOVE)
606 printf("remove %s-%s.%s\n", name, version, arch);
610 command_diff(int argc, const char *argv[])
612 struct razor_set *set, *updated;
614 set = razor_root_open_read_only(install_root);
615 updated = razor_set_open(updated_repo_filename);
616 if (set == NULL || updated == NULL)
619 razor_set_diff(set, updated, print_diff, NULL);
621 razor_set_destroy(set);
622 razor_set_destroy(updated);
628 command_import_rpms(int argc, const char *argv[])
632 struct razor_importer *importer;
633 struct razor_set *set;
634 struct razor_rpm *rpm;
635 int len, imported_count = 0;
637 const char *dirname = argv[0];
639 if (dirname == NULL) {
640 fprintf(stderr, "usage: razor import-rpms DIR\n");
644 dir = opendir(dirname);
646 fprintf(stderr, "couldn't read dir %s\n", dirname);
650 importer = razor_importer_create();
652 while (de = readdir(dir), de != NULL) {
653 len = strlen(de->d_name);
654 if (len < 5 || strcmp(de->d_name + len - 4, ".rpm") != 0)
656 snprintf(filename, sizeof filename,
657 "%s/%s", dirname, de->d_name);
658 rpm = razor_rpm_open(filename);
661 "failed to open rpm \"%s\"\n", filename);
664 if (razor_importer_add_rpm(importer, rpm)) {
665 fprintf(stderr, "couldn't import %s\n", filename);
668 razor_rpm_close(rpm);
670 printf("\rimporting %d", ++imported_count);
675 razor_importer_destroy(importer);
679 printf("\nsaving\n");
680 set = razor_importer_finish(importer);
682 razor_set_write(set, repo_filename, RAZOR_REPO_FILE_MAIN);
683 razor_set_write(set, "system-details.rzdb", RAZOR_REPO_FILE_DETAILS);
684 razor_set_write(set, "system-files.rzdb", RAZOR_REPO_FILE_FILES);
685 razor_set_destroy(set);
686 printf("wrote %s\n", repo_filename);
692 rpm_filename(const char *name, const char *version, const char *arch)
694 static char file[PATH_MAX];
698 v = strchr(version, ':');
704 snprintf(file, sizeof file, "%s-%s.%s.rpm", name, v, arch);
710 download_packages(struct razor_set *system, struct razor_set *next)
712 struct razor_install_iterator *ii;
713 struct razor_package *package;
714 struct razor_set *set;
715 enum razor_install_action action;
716 const char *name, *version, *arch;
717 char file[PATH_MAX], url[256];
718 int errors = 0, count;
720 ii = razor_set_create_install_iterator(system, next);
721 while (razor_install_iterator_next(ii, &set, &package,
723 if (action == RAZOR_INSTALL_ACTION_REMOVE)
726 razor_package_get_details(set, package,
727 RAZOR_DETAIL_NAME, &name,
728 RAZOR_DETAIL_VERSION, &version,
729 RAZOR_DETAIL_ARCH, &arch,
732 snprintf(url, sizeof url,
734 yum_url, rpm_filename(name, version, arch));
735 snprintf(file, sizeof file,
736 "rpms/%s", rpm_filename(name, version, arch));
737 if (download_if_missing(url, file) < 0)
740 razor_install_iterator_destroy(ii);
743 fprintf(stderr, "failed to download %d packages\n", errors);
750 static struct razor_set *
751 relocate_packages(struct razor_set *set, struct razor_relocations *relocations)
753 struct razor_importer *importer;
754 struct razor_property_iterator *prop_iter;
755 struct razor_package_iterator *pkg_iter;
756 struct razor_file_iterator *file_iter;
757 struct razor_package *package;
758 struct razor_property *property;
759 struct razor_rpm *rpm;
760 const char *name, *version, *arch, *summary, *desc, *url, *license;
764 importer = razor_importer_create();
765 pkg_iter = razor_package_iterator_create(set);
767 while (razor_package_iterator_next(pkg_iter, &package,
768 RAZOR_DETAIL_NAME, &name,
769 RAZOR_DETAIL_VERSION, &version,
770 RAZOR_DETAIL_ARCH, &arch,
771 RAZOR_DETAIL_SUMMARY, &summary,
772 RAZOR_DETAIL_DESCRIPTION, &desc,
773 RAZOR_DETAIL_URL, &url,
774 RAZOR_DETAIL_LICENSE, &license,
775 RAZOR_DETAIL_LAST)) {
776 snprintf(file, sizeof file,
777 "rpms/%s", rpm_filename(name, version, arch));
778 rpm = razor_rpm_open(file);
780 fprintf(stderr, "failed to open rpm %s\n", file);
781 razor_package_iterator_destroy(pkg_iter);
782 razor_importer_destroy(importer);
786 razor_relocations_set_rpm(relocations, rpm);
787 razor_rpm_close(rpm);
789 razor_importer_begin_package(importer, name, version, arch);
790 razor_importer_add_details(importer,
791 summary, desc, url, license);
793 prop_iter = razor_property_iterator_create(set, package);
794 while (razor_property_iterator_next(prop_iter, &property,
795 &name, &flags, &version))
796 razor_importer_add_property(importer,
797 name, flags, version);
798 razor_property_iterator_destroy(prop_iter);
800 file_iter = razor_file_iterator_create(set, package);
801 while (razor_file_iterator_next(file_iter, &name)) {
802 name = razor_relocations_apply(relocations, name);
803 razor_importer_add_file(importer, name);
805 razor_file_iterator_destroy(file_iter);
807 razor_importer_finish_package(importer);
810 razor_package_iterator_destroy(pkg_iter);
811 return razor_importer_finish(importer);
815 install_packages(struct razor_set *system, struct razor_set *next,
816 struct razor_relocations *relocations)
818 struct razor_install_iterator *ii;
819 struct razor_package *package;
820 struct razor_set *set;
821 enum razor_install_action action;
822 struct razor_rpm *rpm;
823 const char *name, *version, *arch;
827 ii = razor_set_create_install_iterator(system, next);
828 while (razor_install_iterator_next(ii, &set, &package,
830 if (action == RAZOR_INSTALL_ACTION_REMOVE)
833 razor_package_get_details(set, package,
834 RAZOR_DETAIL_NAME, &name,
835 RAZOR_DETAIL_VERSION, &version,
836 RAZOR_DETAIL_ARCH, &arch,
839 printf("install %s-%s\n", name, version);
841 snprintf(file, sizeof file,
842 "rpms/%s", rpm_filename(name, version, arch));
843 rpm = razor_rpm_open(file);
845 fprintf(stderr, "failed to open rpm %s\n", file);
849 razor_rpm_set_relocations(rpm, relocations);
850 if (razor_rpm_install(rpm, install_root) < 0) {
852 "failed to install rpm %s\n", file);
855 razor_rpm_close(rpm);
857 razor_install_iterator_destroy(ii);
863 command_install(int argc, const char *argv[])
865 struct razor_root *root;
866 struct razor_relocations *relocations=NULL;
867 struct razor_set *system, *upstream, *next, *set;
868 struct razor_transaction *trans;
869 int i, len, dependencies = 1;
872 root = razor_root_open(install_root);
876 for (i = 0; i < argc; i++) {
877 if (strcmp(argv[i], "--no-dependencies") == 0)
879 else if (strcmp(argv[i], "--relocate") == 0) {
881 if (i >= argc || strchr(argv[i], '=') == NULL) {
883 "Usage: razor install [OPTION...] RPM\n");
884 fprintf(stderr, "Options:\n");
885 fprintf(stderr, " [--no-dependencies]\n");
887 " [--relocate OLDPATH=NEWPATH] RPM\n");
890 len = strchr(argv[i], '=') - argv[i];
891 oldpath = malloc(len + 1);
892 strncpy(oldpath, argv[i], len);
895 relocations = razor_relocations_create();
896 razor_relocations_add(relocations, oldpath,
903 system = razor_root_get_system_set(root);
904 upstream = razor_set_open(rawhide_repo_filename);
905 if (upstream == NULL ||
906 razor_set_open_details(upstream, "rawhide-details.rzdb") ||
907 razor_set_open_files(upstream, "rawhide-files.rzdb")) {
908 fprintf(stderr, "couldn't open rawhide repo\n");
909 razor_root_close(root);
914 set = relocate_packages(upstream, relocations);
915 razor_set_destroy(upstream);
919 trans = razor_transaction_create(system, upstream);
921 for (; i < argc; i++) {
922 if (mark_packages_for_update(trans, upstream, argv[i]) == 0) {
923 fprintf(stderr, "no package matched %s\n", argv[i]);
924 razor_root_close(root);
930 razor_transaction_resolve(trans);
931 if (razor_transaction_describe(trans) > 0) {
932 razor_root_close(root);
937 next = razor_transaction_finish(trans);
939 razor_root_update(root, next);
941 if (mkdir("rpms", 0777) && errno != EEXIST) {
942 fprintf(stderr, "failed to create rpms directory.\n");
943 razor_root_close(root);
947 if (download_packages(system, next) < 0) {
948 razor_root_close(root);
952 install_packages(system, next, relocations);
955 razor_relocations_destroy(relocations);
956 razor_set_destroy(next);
957 razor_set_destroy(upstream);
959 return razor_root_commit(root);
963 command_init(int argc, const char *argv[])
965 return razor_root_create(install_root);
969 command_download(int argc, const char *argv[])
971 struct razor_set *set;
972 struct razor_package_iterator *pi;
973 struct razor_package *package;
974 const char *pattern = argv[0], *name, *version, *arch;
975 char url[256], file[256];
978 if (mkdir("rpms", 0777) && errno != EEXIST) {
979 fprintf(stderr, "failed to create rpms directory.\n");
983 set = razor_set_open(rawhide_repo_filename);
984 pi = razor_package_iterator_create(set);
985 while (razor_package_iterator_next(pi, &package,
986 RAZOR_DETAIL_NAME, &name,
987 RAZOR_DETAIL_VERSION, &version,
988 RAZOR_DETAIL_ARCH, &arch,
989 RAZOR_DETAIL_LAST)) {
990 if (pattern && fnmatch(pattern, name, 0) != 0)
994 snprintf(url, sizeof url,
995 "%s/Packages/%s-%s.%s.rpm",
996 yum_url, name, version, arch);
997 snprintf(file, sizeof file,
998 "rpms/%s-%s.%s.rpm", name, version, arch);
999 download_if_missing(url, file);
1001 razor_package_iterator_destroy(pi);
1002 razor_set_destroy(set);
1005 fprintf(stderr, "no packages matched \"%s\"\n", pattern);
1006 else if (matches == 1)
1007 fprintf(stderr, "downloaded 1 package\n");
1009 fprintf(stderr, "downloaded %d packages\n", matches);
1015 command_info(int argc, const char *argv[])
1017 struct razor_set *set;
1018 struct razor_package_iterator *pi;
1019 struct razor_package *package;
1020 const char *pattern = argv[0], *name, *version, *arch;
1021 const char *summary, *description, *url, *license;
1023 set = razor_root_open_read_only(install_root);
1027 pi = razor_package_iterator_create(set);
1028 while (razor_package_iterator_next(pi, &package,
1029 RAZOR_DETAIL_NAME, &name,
1030 RAZOR_DETAIL_VERSION, &version,
1031 RAZOR_DETAIL_ARCH, &arch,
1032 RAZOR_DETAIL_LAST)) {
1033 if (pattern && fnmatch(pattern, name, 0) != 0)
1036 razor_package_get_details (set, package,
1037 RAZOR_DETAIL_SUMMARY, &summary,
1038 RAZOR_DETAIL_DESCRIPTION, &description,
1039 RAZOR_DETAIL_URL, &url,
1040 RAZOR_DETAIL_LICENSE, &license,
1043 printf ("Name: %s\n", name);
1044 printf ("Arch: %s\n", arch);
1045 printf ("Version: %s\n", version);
1046 printf ("URL: %s\n", url);
1047 printf ("License: %s\n", license);
1048 printf ("Summary: %s\n", summary);
1049 printf ("Description:\n");
1050 printf ("%s\n", description);
1053 razor_package_iterator_destroy(pi);
1054 razor_set_destroy(set);
1059 #define SEARCH_MAX 256
1062 command_search(int argc, const char *argv[])
1064 struct razor_set *set;
1065 struct razor_package_iterator *pi;
1066 struct razor_package *package;
1067 char pattern[SEARCH_MAX];
1068 const char *name, *version, *arch;
1069 const char *summary, *description, *url, *license;
1072 fprintf(stderr, "must specify a search term\n");
1076 snprintf(pattern, sizeof pattern, "*%s*", argv[0]);
1078 set = razor_set_open(rawhide_repo_filename);
1082 if (razor_set_open_details(set, "rawhide-details.rzdb"))
1085 pi = razor_package_iterator_create(set);
1086 while (razor_package_iterator_next(pi, &package,
1087 RAZOR_DETAIL_NAME, &name,
1088 RAZOR_DETAIL_VERSION, &version,
1089 RAZOR_DETAIL_ARCH, &arch,
1090 RAZOR_DETAIL_SUMMARY, &summary,
1091 RAZOR_DETAIL_DESCRIPTION, &description,
1092 RAZOR_DETAIL_URL, &url,
1093 RAZOR_DETAIL_LICENSE, &license,
1094 RAZOR_DETAIL_LAST)) {
1095 if (!fnmatch(pattern, name, FNM_CASEFOLD) ||
1096 !fnmatch(pattern, url, FNM_CASEFOLD) ||
1097 !fnmatch(pattern, summary, FNM_CASEFOLD) ||
1098 !fnmatch(pattern, description, FNM_CASEFOLD))
1099 printf("%s-%s.%s: %s\n", name, version, arch, summary);
1101 razor_package_iterator_destroy(pi);
1102 razor_set_destroy(set);
1109 const char *description;
1110 int (*func)(int argc, const char *argv[]);
1111 } razor_commands[] = {
1112 { "list", "list all packages", command_list },
1113 { "list-requires", "list all requires for the given package", command_list_requires },
1114 { "list-provides", "list all provides for the given package", command_list_provides },
1115 { "list-obsoletes", "list all obsoletes for the given package", command_list_obsoletes },
1116 { "list-conflicts", "list all conflicts for the given package", command_list_conflicts },
1117 { "list-files", "list files for package set", command_list_files },
1118 { "list-file-packages", "list packages owning file", command_list_file_packages },
1119 { "list-package-files", "list files in package", command_list_package_files },
1120 { "what-requires", "list the packages that have the given requires", command_what_requires },
1121 { "what-provides", "list the packages that have the given provides", command_what_provides },
1122 { "import-yum", "import yum metadata files", command_import_yum },
1124 { "import-rpmdb", "import the system rpm database", command_import_rpmdb },
1126 { "import-rpms", "import rpms from the given directory", command_import_rpms },
1127 { "update", "update all or specified packages", command_update },
1128 { "remove", "remove specified packages", command_remove },
1129 { "diff", "show diff between two package sets", command_diff },
1130 { "install", "install rpm", command_install },
1131 { "init", "init razor root", command_init },
1132 { "download", "download packages", command_download },
1133 { "info", "display package details", command_info },
1134 { "search", "search package details", command_search }
1143 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
1144 printf(" %-20s%s\n",
1145 razor_commands[i].name, razor_commands[i].description);
1151 main(int argc, const char *argv[])
1156 repo = getenv("RAZOR_REPO");
1158 repo_filename = repo;
1160 root = getenv("RAZOR_ROOT");
1162 install_root = root;
1164 yum_url = getenv("YUM_URL");
1165 if (yum_url == NULL)
1168 if (getenv("RAZOR_NO_ROOT_NAME_CHECKS"))
1169 razor_disable_root_name_checks(1);
1174 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
1175 if (strcmp(razor_commands[i].name, argv[1]) == 0)
1176 return razor_commands[i].func(argc - 2, argv + 2);