Remove INTLLIBS from librazor_la_LIBADD.
This partially reverts 611c84a3f4b4538a65d186050608c17adbf17770.
It's not clear what motivated the initial inclusion of INTLLIBS
here since the net effect is only seen in librazor.la and not
in razor.pc and librazor.la is not normally packaged. Certainly
neither the static nor the dynamic versions of librazor currently
use libintl. At best this would cause the linker to search a
static libintl for undefined symbols without finding any; at worse
it causes a static build of plover using librazor.la to fail if
no static version of libintl is installed.
2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
4 * Copyright (C) 2009, 2011-2012 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 *install_root = "";
46 static const char *repo_filename = system_repo_filename;
47 static const char *yum_url;
49 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
52 update_packages(struct razor_transaction *trans,
53 struct razor_install_iterator *ii, struct razor_set *system,
54 struct razor_set *next, struct razor_atomic *atomic,
55 struct razor_relocations *relocations,
56 enum razor_stage_type stage);
58 update_system(struct razor_root *root, struct razor_relocations *relocations,
59 struct razor_transaction *trans, struct razor_set *next,
62 static struct razor_package_iterator *
63 create_iterator_from_argv(struct razor_set *set, int argc, const char *argv[])
65 struct razor_package_query *query;
66 struct razor_package_iterator *iter;
67 struct razor_package *package;
68 const char *name, *pattern;
72 return razor_package_iterator_create(set);
74 query = razor_package_query_create(set);
76 for (i = 0; i < argc; i++) {
77 iter = razor_package_iterator_create(set);
80 while (razor_package_iterator_next(iter, &package,
81 RAZOR_DETAIL_NAME, &name,
83 if (fnmatch(pattern, name, 0) != 0)
86 razor_package_query_add_package(query, package);
89 razor_package_iterator_destroy(iter);
93 "no package matches \"%s\"\n", pattern);
96 return razor_package_query_finish(query);
99 #define LIST_PACKAGES_ONLY_NAMES 0x01
102 list_packages(struct razor_package_iterator *iter, uint32_t flags)
104 struct razor_package *package;
105 const char *name, *version, *arch;
107 while (razor_package_iterator_next(iter, &package,
108 RAZOR_DETAIL_NAME, &name,
109 RAZOR_DETAIL_VERSION, &version,
110 RAZOR_DETAIL_ARCH, &arch,
111 RAZOR_DETAIL_LAST)) {
112 if (flags & LIST_PACKAGES_ONLY_NAMES)
113 printf("%s\n", name);
115 printf("%s-%s.%s\n", name, version, arch);
120 command_list(int argc, const char *argv[])
122 struct razor_package_iterator *pi;
123 struct razor_error *error = NULL;
124 struct razor_set *set;
128 if (i < argc && strcmp(argv[i], "--only-names") == 0) {
129 flags |= LIST_PACKAGES_ONLY_NAMES;
133 set = razor_root_open_read_only(install_root, &error);
135 fprintf(stderr, "%s\n", razor_error_get_msg(error));
136 razor_error_free(error);
140 pi = create_iterator_from_argv(set, argc - i, argv + i);
141 list_packages(pi, flags);
142 razor_package_iterator_destroy(pi);
143 razor_set_unref(set);
149 list_package_properties(struct razor_set *set,
150 struct razor_package *package, uint32_t type)
152 struct razor_property_iterator *pi;
153 struct razor_property *property;
154 const char *name, *version;
157 pi = razor_property_iterator_create(set, package);
158 while (razor_property_iterator_next(pi, &property,
159 &name, &flags, &version)) {
160 if ((flags & RAZOR_PROPERTY_TYPE_MASK) != type)
163 if (version[0] != '\0')
165 razor_property_relation_to_string(property),
168 if (flags & ~(RAZOR_PROPERTY_RELATION_MASK | RAZOR_PROPERTY_TYPE_MASK)) {
170 if (flags & RAZOR_PROPERTY_PRE)
172 if (flags & RAZOR_PROPERTY_POST)
174 if (flags & RAZOR_PROPERTY_PREUN)
176 if (flags & RAZOR_PROPERTY_POSTUN)
182 razor_property_iterator_destroy(pi);
186 list_properties(int argc, const char *argv[], uint32_t type)
188 struct razor_set *set;
189 struct razor_error *error = NULL;
190 struct razor_package *package;
191 struct razor_package_iterator *pi;
192 const char *name, *version, *arch;
194 set = razor_root_open_read_only(install_root, &error);
196 fprintf(stderr, "%s\n", razor_error_get_msg(error));
197 razor_error_free(error);
201 pi = create_iterator_from_argv(set, argc, argv);
202 while (razor_package_iterator_next(pi, &package,
203 RAZOR_DETAIL_NAME, &name,
204 RAZOR_DETAIL_VERSION, &version,
205 RAZOR_DETAIL_ARCH, &arch,
207 list_package_properties(set, package, type);
208 razor_package_iterator_destroy(pi);
209 razor_set_unref(set);
215 command_list_requires(int argc, const char *argv[])
217 return list_properties(argc, argv, RAZOR_PROPERTY_REQUIRES);
221 command_list_provides(int argc, const char *argv[])
223 return list_properties(argc, argv, RAZOR_PROPERTY_PROVIDES);
227 command_list_obsoletes(int argc, const char *argv[])
229 return list_properties(argc, argv, RAZOR_PROPERTY_OBSOLETES);
233 command_list_conflicts(int argc, const char *argv[])
235 return list_properties(argc, argv, RAZOR_PROPERTY_CONFLICTS);
239 command_list_scripts(int argc, const char *argv[])
241 struct razor_set *set;
242 struct razor_error *error = NULL;
243 struct razor_package *package;
244 struct razor_package_iterator *pi;
245 const char *preunprog, *preun, *postunprog, *postun;
247 set = razor_root_open_read_only(install_root, &error);
249 fprintf(stderr, "%s\n", razor_error_get_msg(error));
250 razor_error_free(error);
254 pi = create_iterator_from_argv(set, argc, argv);
255 while (razor_package_iterator_next(pi, &package,
256 RAZOR_DETAIL_PREUNPROG, &preunprog,
257 RAZOR_DETAIL_PREUN, &preun,
258 RAZOR_DETAIL_POSTUNPROG, &postunprog,
259 RAZOR_DETAIL_POSTUN, &postun,
260 RAZOR_DETAIL_LAST)) {
261 if (preun && *preun) {
262 printf("preuninstall scriptlet");
263 if (preunprog && *preunprog)
264 printf(" (using %s)",preunprog);
265 printf(":\n%s\n",preun);
267 if (postun && *postun) {
268 printf("postuninstall scriptlet");
269 if (postunprog && *postunprog)
270 printf(" (using %s)",postunprog);
271 printf(":\n%s\n",postun);
274 razor_package_iterator_destroy(pi);
275 razor_set_unref(set);
281 command_list_files(int argc, const char *argv[])
283 struct razor_error *error = NULL;
284 struct razor_set *set;
286 set = razor_root_open_read_only(install_root, &error);
288 fprintf(stderr, "%s\n", razor_error_get_msg(error));
289 razor_error_free(error);
293 razor_set_list_files(set, argv[0]);
294 razor_set_unref(set);
300 command_list_file_packages(int argc, const char *argv[])
302 struct razor_error *error = NULL;
303 struct razor_set *set;
304 struct razor_package_iterator *pi;
306 set = razor_root_open_read_only(install_root, &error);
308 fprintf(stderr, "%s\n", razor_error_get_msg(error));
309 razor_error_free(error);
313 pi = razor_package_iterator_create_for_file(set, argv[0]);
314 list_packages(pi, 0);
315 razor_package_iterator_destroy(pi);
317 razor_set_unref(set);
323 command_list_package_files(int argc, const char *argv[])
325 struct razor_error *error = NULL;
326 struct razor_set *set;
327 struct razor_package_iterator *pi;
328 struct razor_package *package;
329 const char *name, *version, *arch;
331 set = razor_root_open_read_only(install_root, &error);
333 fprintf(stderr, "%s\n", razor_error_get_msg(error));
334 razor_error_free(error);
338 pi = create_iterator_from_argv(set, argc, argv);
339 while (razor_package_iterator_next(pi, &package,
340 RAZOR_DETAIL_NAME, &name,
341 RAZOR_DETAIL_VERSION, &version,
342 RAZOR_DETAIL_ARCH, &arch,
344 razor_set_list_package_files(set, package);
345 razor_package_iterator_destroy(pi);
347 razor_set_unref(set);
353 list_property_packages(const char *ref_name,
354 const char *ref_version,
357 struct razor_error *error = NULL;
358 struct razor_set *set;
359 struct razor_property *property;
360 struct razor_property_iterator *prop_iter;
361 struct razor_package_iterator *pkg_iter;
362 const char *name, *version;
365 if (ref_name == NULL)
368 set = razor_root_open_read_only(install_root, &error);
370 fprintf(stderr, "%s\n", razor_error_get_msg(error));
371 razor_error_free(error);
375 prop_iter = razor_property_iterator_create(set, NULL);
376 while (razor_property_iterator_next(prop_iter, &property,
377 &name, &flags, &version)) {
378 if (strcmp(ref_name, name) != 0)
381 (flags & RAZOR_PROPERTY_RELATION_MASK) == RAZOR_PROPERTY_EQUAL &&
382 strcmp(ref_version, version) != 0)
384 if ((flags & RAZOR_PROPERTY_TYPE_MASK) != type)
388 razor_package_iterator_create_for_property(set,
390 list_packages(pkg_iter, 0);
391 razor_package_iterator_destroy(pkg_iter);
393 razor_property_iterator_destroy(prop_iter);
395 razor_set_unref(set);
401 command_what_requires(int argc, const char *argv[])
403 return list_property_packages(argv[0], argv[1],
404 RAZOR_PROPERTY_REQUIRES);
408 command_what_provides(int argc, const char *argv[])
410 return list_property_packages(argv[0], argv[1],
411 RAZOR_PROPERTY_PROVIDES);
415 show_progress(void *clientp,
416 double dltotal, double dlnow, double ultotal, double ulnow)
418 const char *file = clientp;
420 if (!dlnow < dltotal)
421 fprintf(stderr, "\rdownloading %s, %dkB/%dkB",
422 file, (int) dlnow / 1024, (int) dltotal / 1024);
428 download_if_missing(const char *url, const char *file)
440 curl = curl_easy_init();
444 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
445 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
446 curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress);
447 curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, file);
449 if (stat(file, &buf) < 0) {
450 fp = fopen(file, "wb");
453 "failed to open %s for writing\n", file);
456 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
457 curl_easy_setopt(curl, CURLOPT_URL, url);
458 res = curl_easy_perform(curl);
460 if (res != CURLE_OK) {
461 fprintf(stderr, "curl error: %s\n", error);
465 res = curl_easy_getinfo(curl,
466 CURLINFO_RESPONSE_CODE, &response);
467 if (res != CURLE_OK) {
468 fprintf(stderr, "curl error: %s\n", error);
472 if (response != 200) {
473 fprintf(stderr, " - failed %ld\n", response);
477 fprintf(stderr, "\n");
480 curl_easy_cleanup(curl);
483 #endif /* HAVE_CURL */
486 #define YUM_URL "http://download.fedora.redhat.com" \
487 "/pub/fedora/linux/development/i386/os"
490 command_import_yum(int argc, const char *argv[])
493 struct razor_set *set;
494 struct razor_atomic *atomic;
497 printf("downloading from %s.\n", yum_url);
498 snprintf(buffer, sizeof buffer,
499 "%s/repodata/primary.xml.gz", yum_url);
500 if (download_if_missing(buffer, "primary.xml.gz") < 0)
502 snprintf(buffer, sizeof buffer,
503 "%s/repodata/filelists.xml.gz", yum_url);
504 if (download_if_missing(buffer, "filelists.xml.gz") < 0)
507 set = razor_set_create_from_yum();
510 atomic = razor_atomic_open("Yum import repository");
511 razor_set_write(set, atomic, rawhide_repo_filename, RAZOR_SECTION_ALL);
512 retval = razor_atomic_commit(atomic);
513 razor_set_unref(set);
515 fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
517 printf("wrote %s\n", rawhide_repo_filename);
518 razor_atomic_destroy(atomic);
525 command_import_rpmdb(int argc, const char *argv[])
527 struct razor_set *set;
528 struct razor_root *root;
529 struct razor_error *error = NULL;
530 struct razor_atomic *atomic;
533 root = razor_root_open(install_root, &error);
535 fprintf(stderr, "%s\n", razor_error_get_msg(error));
536 razor_error_free(error);
540 set = razor_set_create_from_rpmdb();
544 atomic = razor_atomic_open("Import RPM database");
546 retval = razor_root_update(root, set, atomic);
549 fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
551 razor_atomic_destroy(atomic);
553 razor_root_close(root);
560 mark_packages_for_update(struct razor_transaction *trans,
561 struct razor_set *set, const char *pattern)
563 struct razor_package_iterator *pi;
564 struct razor_package *package;
568 pi = razor_package_iterator_create(set);
569 while (razor_package_iterator_next(pi, &package,
570 RAZOR_DETAIL_NAME, &name,
571 RAZOR_DETAIL_LAST)) {
572 if (pattern && fnmatch(pattern, name, 0) == 0) {
573 razor_transaction_update_package(trans, package);
577 razor_package_iterator_destroy(pi);
583 mark_packages_for_removal(struct razor_transaction *trans,
584 struct razor_set *set, const char *pattern)
586 struct razor_package_iterator *pi;
587 struct razor_package *package;
591 pi = razor_package_iterator_create(set);
592 while (razor_package_iterator_next(pi, &package,
593 RAZOR_DETAIL_NAME, &name,
594 RAZOR_DETAIL_LAST)) {
595 if (pattern && fnmatch(pattern, name, 0) == 0) {
596 razor_transaction_remove_package(trans, package);
600 razor_package_iterator_destroy(pi);
606 command_remove(int argc, const char *argv[])
608 struct razor_set *system, *upstream, *next;
609 struct razor_transaction *trans;
610 struct razor_error *error = NULL;
611 struct razor_root *root;
614 root = razor_root_open(install_root, &error);
616 fprintf(stderr, "%s\n", razor_error_get_msg(error));
617 razor_error_free(error);
621 system = razor_root_get_system_set(root);
622 upstream = razor_set_create_without_root();
623 trans = razor_transaction_create(system, upstream);
624 razor_set_unref(upstream);
625 for (i = 0; i < argc; i++) {
626 if (mark_packages_for_removal(trans, system, argv[i]) == 0) {
627 fprintf(stderr, "no match for %s\n", argv[i]);
628 razor_transaction_destroy(trans);
629 razor_root_close(root);
634 razor_transaction_resolve(trans);
635 retval = razor_transaction_describe(trans);
637 razor_transaction_destroy(trans);
638 razor_root_close(root);
642 next = razor_transaction_commit(trans);
644 retval = update_system(root, NULL, trans, next, "Remove");
646 razor_transaction_destroy(trans);
647 razor_root_close(root);
648 razor_set_unref(next);
654 print_diff(enum razor_diff_action action,
655 struct razor_package *package,
661 if (action == RAZOR_DIFF_ACTION_ADD)
662 printf("install %s-%s.%s\n", name, version, arch);
663 if (action == RAZOR_DIFF_ACTION_REMOVE)
664 printf("remove %s-%s.%s\n", name, version, arch);
668 command_diff(int argc, const char *argv[])
670 struct razor_error *error = NULL;
671 struct razor_set *set, *updated;
673 set = razor_root_open_read_only(install_root, &error);
675 updated = razor_set_open(rawhide_repo_filename, 0, &error);
678 if (updated == NULL) {
679 fprintf(stderr, "%s\n", razor_error_get_msg(error));
680 razor_error_free(error);
682 razor_set_unref(set);
686 razor_set_diff(set, updated, print_diff, NULL);
688 razor_set_unref(set);
689 razor_set_unref(updated);
695 command_import_rpms(int argc, const char *argv[])
699 struct razor_importer *importer;
700 struct razor_set *set;
701 struct razor_rpm *rpm;
702 struct razor_error *error=NULL;
703 struct razor_atomic *atomic;
704 int len, imported_count = 0;
706 const char *dirname = argv[0];
709 if (dirname == NULL) {
710 fprintf(stderr, "usage: razor import-rpms DIR\n");
714 dir = opendir(dirname);
716 fprintf(stderr, "couldn't read dir %s\n", dirname);
720 importer = razor_importer_create();
722 while (de = readdir(dir), de != NULL) {
723 len = strlen(de->d_name);
724 if (len < 5 || strcmp(de->d_name + len - 4, ".rpm") != 0)
726 snprintf(filename, sizeof filename,
727 "%s/%s", dirname, de->d_name);
728 rpm = razor_rpm_open(filename, &error);
730 fprintf(stderr, "%s\n", razor_error_get_msg(error));
731 razor_error_free(error);
735 if (razor_importer_add_rpm(importer, rpm)) {
736 fprintf(stderr, "couldn't import %s\n", filename);
739 razor_rpm_close(rpm);
741 printf("\rimporting %d", ++imported_count);
746 razor_importer_destroy(importer);
750 printf("\nsaving\n");
751 set = razor_importer_finish(importer);
753 atomic = razor_atomic_open("Update system database");
754 razor_set_write(set, atomic, repo_filename, RAZOR_SECTION_ALL);
755 razor_set_unref(set);
756 retval = razor_atomic_commit(atomic);
758 fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
760 printf("wrote %s\n", repo_filename);
761 razor_atomic_destroy(atomic);
767 rpm_filename(const char *name, const char *version, const char *arch)
772 v = strchr(version, ':');
778 return razor_concat(name, "-", v, ".", arch, ".rpm", NULL);
782 download_packages(struct razor_set *system, struct razor_set *next)
784 struct razor_install_iterator *ii;
785 struct razor_package *package;
786 enum razor_install_action action;
787 const char *name, *version, *arch;
788 char *file, *url, *s;
789 int errors = 0, count;
791 ii = razor_set_create_install_iterator(system, next);
792 while (razor_install_iterator_next(ii, &package, &action, &count)) {
793 if (action != RAZOR_INSTALL_ACTION_ADD)
796 razor_package_get_details(next, package,
797 RAZOR_DETAIL_NAME, &name,
798 RAZOR_DETAIL_VERSION, &version,
799 RAZOR_DETAIL_ARCH, &arch,
802 s = rpm_filename(name, version, arch);
803 url = razor_concat(yum_url, "/Packages/", s, NULL);
804 file = razor_concat("rpms/", s, NULL);
806 if (download_if_missing(url, file) < 0)
811 razor_install_iterator_destroy(ii);
814 fprintf(stderr, "failed to download %d packages\n", errors);
821 static struct razor_set *
822 relocate_packages(struct razor_set *set, struct razor_atomic *atomic,
823 struct razor_relocations *relocations)
826 struct razor_importer *importer;
827 struct razor_property_iterator *prop_iter;
828 struct razor_package_iterator *pkg_iter;
829 struct razor_file_iterator *file_iter;
830 struct razor_package *package;
831 struct razor_property *property;
832 struct razor_rpm *rpm;
833 struct razor_error *error=NULL;
834 const char *name, *version, *arch, *summary, *desc, *url, *license;
835 const char *preunprog, *preun, *postunprog, *postun;
836 const char *install_prefix;
837 const char *const *prefixes;
841 importer = razor_importer_create();
842 pkg_iter = razor_package_iterator_create(set);
844 while (razor_package_iterator_next(pkg_iter, &package,
845 RAZOR_DETAIL_NAME, &name,
846 RAZOR_DETAIL_VERSION, &version,
847 RAZOR_DETAIL_ARCH, &arch,
848 RAZOR_DETAIL_SUMMARY, &summary,
849 RAZOR_DETAIL_DESCRIPTION, &desc,
850 RAZOR_DETAIL_URL, &url,
851 RAZOR_DETAIL_LICENSE, &license,
852 RAZOR_DETAIL_PREUNPROG, &preunprog,
853 RAZOR_DETAIL_PREUN, &preun,
854 RAZOR_DETAIL_POSTUNPROG, &postunprog,
855 RAZOR_DETAIL_POSTUN, &postun,
856 RAZOR_DETAIL_LAST)) {
857 s = rpm_filename(name, version, arch);
858 file = razor_concat("rpms/", s, NULL);
860 rpm = razor_rpm_open(file, &error);
863 razor_atomic_abort(atomic, razor_error_get_msg(error));
864 razor_error_free(error);
865 razor_package_iterator_destroy(pkg_iter);
866 razor_importer_destroy(importer);
870 razor_relocations_set_rpm(relocations, rpm);
872 razor_importer_begin_package(importer, name, version, arch);
873 razor_importer_add_details(importer,
874 summary, desc, url, license);
876 razor_rpm_get_details(rpm, RAZOR_DETAIL_PREFIXES, &prefixes,
878 for (i = 0; prefixes && prefixes[i]; i++) {
879 install_prefix = razor_relocations_apply(relocations,
881 razor_importer_add_install_prefix(importer,
885 razor_rpm_close(rpm);
887 prop_iter = razor_property_iterator_create(set, package);
888 while (razor_property_iterator_next(prop_iter, &property,
889 &name, &flags, &version))
890 razor_importer_add_property(importer,
891 name, flags, version);
892 razor_property_iterator_destroy(prop_iter);
894 file_iter = razor_file_iterator_create(set, package, 0);
895 while (razor_file_iterator_next(file_iter, &name)) {
896 name = razor_relocations_apply(relocations, name);
897 razor_importer_add_file(importer, name);
899 razor_file_iterator_destroy(file_iter);
901 razor_importer_add_script(importer, RAZOR_PROPERTY_PREUN,
903 razor_importer_add_script(importer, RAZOR_PROPERTY_POSTUN,
906 razor_importer_finish_package(importer);
909 razor_package_iterator_destroy(pkg_iter);
910 return razor_importer_finish(importer);
914 install_package(struct razor_transaction *trans, struct razor_set *set,
915 struct razor_atomic *atomic, struct razor_package *package,
916 struct razor_relocations *relocations, int install_count,
917 enum razor_stage_type stage)
920 const char *name, *version, *arch;
922 struct razor_rpm *rpm;
923 struct razor_error *error=NULL;
925 razor_package_get_details(set, package,
926 RAZOR_DETAIL_NAME, &name,
927 RAZOR_DETAIL_VERSION, &version,
928 RAZOR_DETAIL_ARCH, &arch,
931 if (stage & RAZOR_STAGE_SCRIPTS_PRE)
932 printf("install %s-%s\n", name, version);
934 s = rpm_filename(name, version, arch);
935 file = razor_concat("rpms/", s, NULL);
937 rpm = razor_rpm_open(file, &error);
940 razor_atomic_abort(atomic, razor_error_get_msg(error));
941 fprintf(stderr, "%s\n", razor_error_get_msg(error));
942 razor_error_free(error);
946 razor_rpm_set_relocations(rpm, relocations);
947 razor_transaction_fixup_package(trans, package, rpm);
948 retval = razor_rpm_install(rpm, atomic, install_root, install_count,
951 s = rpm_filename(name, version, arch);
952 fprintf(stderr, "%s: %s\n", s,
953 razor_atomic_get_error_msg(atomic));
956 razor_rpm_close(rpm);
961 * Returns 0 on success, -1 on failure and 1 if a RAZOR_INSTALL_ACTION_COMMIT
962 * is met (in which case the action is consumed).
965 update_packages(struct razor_transaction *trans,
966 struct razor_install_iterator *ii, struct razor_set *system,
967 struct razor_set *next, struct razor_atomic *atomic,
968 struct razor_relocations *relocations,
969 enum razor_stage_type stage)
971 struct razor_package *package;
972 enum razor_install_action action;
973 int retval = 0, count;
975 while (!retval && razor_install_iterator_next(ii, &package, &action,
977 if (action == RAZOR_INSTALL_ACTION_ADD) {
978 if (install_package(trans, next, atomic, package,
979 relocations, count, stage))
981 } else if (action == RAZOR_INSTALL_ACTION_REMOVE) {
982 if (razor_package_remove(system, next, atomic, package,
983 install_root, count, stage))
985 } else if (action == RAZOR_INSTALL_ACTION_COMMIT)
993 update_system(struct razor_root *root, struct razor_relocations *relocations,
994 struct razor_transaction *trans, struct razor_set *next,
997 struct razor_set *system, *set;
998 struct razor_atomic *atomic;
999 struct razor_install_iterator *ii;
1004 description = razor_concat(verb, " packages", NULL);
1006 system = razor_set_ref(razor_root_get_system_set(root));
1008 ii = razor_set_create_install_iterator(system, next);
1011 pos = razor_install_iterator_tell(ii);
1013 atomic = razor_atomic_open(description);
1015 r = update_packages(trans, ii, system, next, atomic,
1016 relocations, RAZOR_STAGE_SCRIPTS_PRE);
1018 fprintf(stderr, "%s aborted\n", verb);
1021 razor_install_iterator_seek(ii, pos);
1022 r = update_packages(trans, ii, system, next, atomic,
1023 relocations, RAZOR_STAGE_FILES);
1026 set = razor_install_iterator_commit_set(ii);
1027 razor_root_update(root, set, atomic);
1028 razor_set_unref(set);
1030 razor_root_update(root, next, atomic);
1032 retval = razor_atomic_commit(atomic);
1034 fprintf(stderr, "%s\n",
1035 razor_atomic_get_error_msg(atomic));
1037 razor_install_iterator_seek(ii, pos);
1038 update_packages(trans, ii, system, next,
1039 atomic, relocations,
1040 RAZOR_STAGE_SCRIPTS_POST);
1044 razor_atomic_destroy(atomic);
1045 } while(!retval && r == 1);
1047 razor_set_unref(system);
1055 command_install_or_update(int argc, const char *argv[], int do_update)
1057 struct razor_relocations *relocations = NULL;
1058 struct razor_set *system, *upstream, *next, *set;
1059 struct razor_transaction *trans;
1060 struct razor_error *error = NULL;
1061 struct razor_atomic *atomic;
1062 struct razor_root *root;
1063 int i, retval, len, dependencies = 1;
1066 for (i = 0; i < argc; i++) {
1067 if (strcmp(argv[i], "--no-dependencies") == 0)
1069 else if (strcmp(argv[i], "--relocate") == 0) {
1071 if (i >= argc || strchr(argv[i], '=') == NULL) {
1073 "Usage: razor %s [OPTION...] RPM\n",
1074 do_update ? "update" : "install");
1075 fprintf(stderr, "Options:\n");
1076 fprintf(stderr, " [--no-dependencies]\n");
1078 " [--relocate OLDPATH=NEWPATH] RPM\n");
1081 len = strchr(argv[i], '=') - argv[i];
1082 oldpath = malloc(len + 1);
1083 strncpy(oldpath, argv[i], len);
1084 oldpath[len] = '\0';
1086 relocations = razor_relocations_create();
1087 razor_relocations_add(relocations, oldpath,
1094 upstream = razor_set_open(rawhide_repo_filename, 0, &error);
1095 if (upstream == NULL) {
1096 fprintf(stderr, "%s\n", razor_error_get_msg(error));
1097 razor_error_free(error);
1102 atomic = razor_atomic_open("Update packages");
1104 atomic = razor_atomic_open("Install packages");
1107 set = relocate_packages(upstream, atomic, relocations);
1109 fprintf(stderr, "%s\n",
1110 razor_atomic_get_error_msg(atomic));
1111 razor_atomic_destroy(atomic);
1112 razor_set_unref(upstream);
1115 razor_set_unref(upstream);
1119 root = razor_root_open(install_root, &error);
1121 fprintf(stderr, "%s\n", razor_error_get_msg(error));
1122 razor_error_free(error);
1123 razor_atomic_destroy(atomic);
1124 razor_set_unref(upstream);
1126 razor_relocations_destroy(relocations);
1130 system = razor_root_get_system_set(root);
1131 trans = razor_transaction_create(system, upstream);
1133 if (i == argc && do_update)
1134 razor_transaction_update_all(trans);
1135 for (; i < argc; i++) {
1137 mark_packages_for_update(trans, system, argv[i]))
1139 if (mark_packages_for_update(trans, upstream, argv[i]) == 0) {
1140 fprintf(stderr, "no package matched %s\n", argv[i]);
1141 razor_transaction_destroy(trans);
1142 razor_root_close(root);
1143 razor_set_unref(upstream);
1144 razor_atomic_destroy(atomic);
1146 razor_relocations_destroy(relocations);
1152 razor_transaction_resolve(trans);
1153 if (razor_transaction_describe(trans) > 0) {
1154 razor_transaction_destroy(trans);
1155 razor_set_unref(upstream);
1156 razor_root_close(root);
1157 razor_atomic_destroy(atomic);
1159 razor_relocations_destroy(relocations);
1164 if (razor_atomic_create_dir(atomic, "rpms",
1165 S_IRWXU | S_IRWXG | S_IRWXO) ||
1166 razor_atomic_commit(atomic)) {
1167 fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
1168 razor_transaction_destroy(trans);
1169 razor_set_unref(upstream);
1170 razor_root_close(root);
1171 razor_atomic_destroy(atomic);
1173 razor_relocations_destroy(relocations);
1177 razor_atomic_destroy(atomic);
1179 next = razor_transaction_commit(trans);
1181 if (download_packages(system, next) < 0) {
1182 razor_set_unref(next);
1183 razor_transaction_destroy(trans);
1184 razor_set_unref(upstream);
1185 razor_root_close(root);
1186 razor_atomic_destroy(atomic);
1188 razor_relocations_destroy(relocations);
1192 retval = update_system(root, relocations, trans, next,
1193 do_update ? "Update" : "Install");
1195 razor_set_unref(upstream);
1196 razor_root_close(root);
1198 razor_transaction_destroy(trans);
1200 razor_relocations_destroy(relocations);
1202 razor_set_unref(next);
1208 command_update(int argc, const char *argv[])
1210 return command_install_or_update(argc, argv, 1);
1214 command_install(int argc, const char *argv[])
1216 return command_install_or_update(argc, argv, 0);
1220 command_init(int argc, const char *argv[])
1223 struct razor_error *error = NULL;
1225 retval = razor_root_create(install_root, &error);
1227 fprintf(stderr, "%s\n", razor_error_get_msg(error));
1228 razor_error_free(error);
1230 printf("Created install root\n");
1236 command_download(int argc, const char *argv[])
1238 struct razor_error *error = NULL;
1239 struct razor_atomic *atomic;
1240 struct razor_set *set;
1241 struct razor_package_iterator *pi;
1242 struct razor_package *package;
1243 const char *pattern = argv[0], *name, *version, *arch;
1244 char url[256], file[256];
1247 set = razor_set_open(rawhide_repo_filename, 0, &error);
1249 fprintf(stderr, "%s\n", razor_error_get_msg(error));
1250 razor_error_free(error);
1254 atomic = razor_atomic_open("Download packages");
1256 if (razor_atomic_create_dir(atomic, "rpms",
1257 S_IRWXU | S_IRWXG | S_IRWXO)) {
1258 fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
1259 razor_atomic_destroy(atomic);
1263 if (razor_atomic_commit(atomic)) {
1264 fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
1265 razor_atomic_destroy(atomic);
1268 razor_atomic_destroy(atomic);
1270 pi = razor_package_iterator_create(set);
1271 while (razor_package_iterator_next(pi, &package,
1272 RAZOR_DETAIL_NAME, &name,
1273 RAZOR_DETAIL_VERSION, &version,
1274 RAZOR_DETAIL_ARCH, &arch,
1275 RAZOR_DETAIL_LAST)) {
1276 if (pattern && fnmatch(pattern, name, 0) != 0)
1280 snprintf(url, sizeof url,
1281 "%s/Packages/%s-%s.%s.rpm",
1282 yum_url, name, version, arch);
1283 snprintf(file, sizeof file,
1284 "rpms/%s-%s.%s.rpm", name, version, arch);
1285 download_if_missing(url, file);
1287 razor_package_iterator_destroy(pi);
1288 razor_set_unref(set);
1291 fprintf(stderr, "no packages matched \"%s\"\n", pattern);
1292 else if (matches == 1)
1293 fprintf(stderr, "downloaded 1 package\n");
1295 fprintf(stderr, "downloaded %d packages\n", matches);
1301 command_info(int argc, const char *argv[])
1303 struct razor_error *error = NULL;
1304 struct razor_set *set;
1305 struct razor_package_iterator *pi;
1306 struct razor_package *package;
1307 const char *pattern = argv[0], *name, *version, *arch;
1308 const char *summary, *description, *url, *license;
1310 set = razor_root_open_read_only(install_root, &error);
1312 fprintf(stderr, "%s\n", razor_error_get_msg(error));
1313 razor_error_free(error);
1317 pi = razor_package_iterator_create(set);
1318 while (razor_package_iterator_next(pi, &package,
1319 RAZOR_DETAIL_NAME, &name,
1320 RAZOR_DETAIL_VERSION, &version,
1321 RAZOR_DETAIL_ARCH, &arch,
1322 RAZOR_DETAIL_LAST)) {
1323 if (pattern && fnmatch(pattern, name, 0) != 0)
1326 razor_package_get_details (set, package,
1327 RAZOR_DETAIL_SUMMARY, &summary,
1328 RAZOR_DETAIL_DESCRIPTION, &description,
1329 RAZOR_DETAIL_URL, &url,
1330 RAZOR_DETAIL_LICENSE, &license,
1333 printf ("Name: %s\n", name);
1334 printf ("Arch: %s\n", arch);
1335 printf ("Version: %s\n", version);
1336 printf ("URL: %s\n", url);
1337 printf ("License: %s\n", license);
1338 printf ("Summary: %s\n", summary);
1339 printf ("Description:\n");
1340 printf ("%s\n", description);
1343 razor_package_iterator_destroy(pi);
1344 razor_set_unref(set);
1349 #define SEARCH_MAX 256
1352 command_search(int argc, const char *argv[])
1354 struct razor_error *error = NULL;
1355 struct razor_set *set;
1356 struct razor_package_iterator *pi;
1357 struct razor_package *package;
1358 char pattern[SEARCH_MAX];
1359 const char *name, *version, *arch;
1360 const char *summary, *description, *url, *license;
1363 fprintf(stderr, "must specify a search term\n");
1367 snprintf(pattern, sizeof pattern, "*%s*", argv[0]);
1369 set = razor_set_open(rawhide_repo_filename, 0, &error);
1371 fprintf(stderr, "%s\n", razor_error_get_msg(error));
1372 razor_error_free(error);
1376 pi = razor_package_iterator_create(set);
1377 while (razor_package_iterator_next(pi, &package,
1378 RAZOR_DETAIL_NAME, &name,
1379 RAZOR_DETAIL_VERSION, &version,
1380 RAZOR_DETAIL_ARCH, &arch,
1381 RAZOR_DETAIL_SUMMARY, &summary,
1382 RAZOR_DETAIL_DESCRIPTION, &description,
1383 RAZOR_DETAIL_URL, &url,
1384 RAZOR_DETAIL_LICENSE, &license,
1385 RAZOR_DETAIL_LAST)) {
1386 if (!fnmatch(pattern, name, FNM_CASEFOLD) ||
1387 !fnmatch(pattern, url, FNM_CASEFOLD) ||
1388 !fnmatch(pattern, summary, FNM_CASEFOLD) ||
1389 !fnmatch(pattern, description, FNM_CASEFOLD))
1390 printf("%s-%s.%s: %s\n", name, version, arch, summary);
1392 razor_package_iterator_destroy(pi);
1393 razor_set_unref(set);
1400 const char *description;
1401 int (*func)(int argc, const char *argv[]);
1402 } razor_commands[] = {
1403 { "list", "list all packages", command_list },
1404 { "list-requires", "list all requires for the given package", command_list_requires },
1405 { "list-provides", "list all provides for the given package", command_list_provides },
1406 { "list-obsoletes", "list all obsoletes for the given package", command_list_obsoletes },
1407 { "list-conflicts", "list all conflicts for the given package", command_list_conflicts },
1408 { "list-scripts", "list all scripts for the given package", command_list_scripts },
1409 { "list-files", "list files for package set", command_list_files },
1410 { "list-file-packages", "list packages owning file", command_list_file_packages },
1411 { "list-package-files", "list files in package", command_list_package_files },
1412 { "what-requires", "list the packages that have the given requires", command_what_requires },
1413 { "what-provides", "list the packages that have the given provides", command_what_provides },
1414 { "import-yum", "import yum metadata files", command_import_yum },
1416 { "import-rpmdb", "import the system rpm database", command_import_rpmdb },
1418 { "import-rpms", "import rpms from the given directory", command_import_rpms },
1419 { "update", "update all or specified packages", command_update },
1420 { "remove", "remove specified packages", command_remove },
1421 { "diff", "show diff between two package sets", command_diff },
1422 { "install", "install rpm", command_install },
1423 { "init", "init razor root", command_init },
1424 { "download", "download packages", command_download },
1425 { "info", "display package details", command_info },
1426 { "search", "search package details", command_search }
1435 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
1436 printf(" %-20s%s\n",
1437 razor_commands[i].name, razor_commands[i].description);
1443 main(int argc, const char *argv[])
1448 repo = getenv("RAZOR_REPO");
1450 repo_filename = repo;
1452 root = getenv("RAZOR_ROOT");
1454 install_root = root;
1456 yum_url = getenv("YUM_URL");
1457 if (yum_url == NULL)
1460 if (getenv("RAZOR_NO_ROOT_NAME_CHECKS"))
1461 razor_disable_root_name_checks(1);
1466 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
1467 if (strcmp(razor_commands[i].name, argv[1]) == 0)
1468 return razor_commands[i].func(argc - 2, argv + 2);