Link to curl and download yum files automatically.
10 static const char *repo_filename = "system.repo";
11 static const char *rawhide_repo_filename = "rawhide.repo";
12 static const char *updated_repo_filename = "system-updated.repo";
15 command_list(int argc, const char *argv[])
17 struct razor_set *set;
19 set = razor_set_open(repo_filename);
20 razor_set_list(set, argv[0]);
21 razor_set_destroy(set);
27 command_list_requires(int argc, const char *argv[])
29 struct razor_set *set;
31 set = razor_set_open(repo_filename);
32 razor_set_list_properties(set, argv[0], RAZOR_PROPERTY_REQUIRES);
33 razor_set_destroy(set);
39 command_list_provides(int argc, const char *argv[])
41 struct razor_set *set;
43 set = razor_set_open(repo_filename);
44 razor_set_list_properties(set, argv[0], RAZOR_PROPERTY_PROVIDES);
45 razor_set_destroy(set);
51 command_list_obsoletes(int argc, const char *argv[])
53 struct razor_set *set;
55 set = razor_set_open(repo_filename);
56 razor_set_list_properties(set, argv[0], RAZOR_PROPERTY_OBSOLETES);
57 razor_set_destroy(set);
63 command_list_conflicts(int argc, const char *argv[])
65 struct razor_set *set;
67 set = razor_set_open(repo_filename);
68 razor_set_list_properties(set, argv[0], RAZOR_PROPERTY_CONFLICTS);
69 razor_set_destroy(set);
75 command_list_files(int argc, const char *argv[])
77 struct razor_set *set;
79 set = razor_set_open(repo_filename);
82 razor_set_list_files(set, argv[0]);
83 razor_set_destroy(set);
89 command_list_file_packages(int argc, const char *argv[])
91 struct razor_set *set;
93 set = razor_set_open(repo_filename);
96 razor_set_list_file_packages(set, argv[0]);
97 razor_set_destroy(set);
103 command_list_package_files(int argc, const char *argv[])
105 struct razor_set *set;
107 set = razor_set_open(repo_filename);
110 razor_set_list_package_files(set, argv[0]);
111 razor_set_destroy(set);
117 command_what_requires(int argc, const char *argv[])
119 struct razor_set *set;
121 set = razor_set_open(repo_filename);
122 razor_set_list_property_packages(set, argv[0], argv[1],
123 RAZOR_PROPERTY_REQUIRES);
124 razor_set_destroy(set);
130 command_what_provides(int argc, const char *argv[])
132 struct razor_set *set;
134 set = razor_set_open(repo_filename);
135 razor_set_list_property_packages(set, argv[0], argv[1],
136 RAZOR_PROPERTY_PROVIDES);
137 razor_set_destroy(set);
142 #define REPO_URL "http://download.fedora.redhat.com" \
143 "/pub/fedora/linux/development/i386/os/repodata"
146 command_import_yum(int argc, const char *argv[])
148 struct razor_set *set;
153 curl = curl_easy_init();
157 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
158 fp = fopen("primary.xml.gz", "w");
159 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
160 curl_easy_setopt(curl, CURLOPT_URL, REPO_URL "/primary.xml.gz");
161 res = curl_easy_perform(curl);
164 fp = fopen("filelists.xml.gz", "w");
165 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
166 curl_easy_setopt(curl, CURLOPT_URL, REPO_URL "/filelists.xml.gz");
167 res = curl_easy_perform(curl);
170 curl_easy_cleanup(curl);
172 set = razor_set_create_from_yum();
175 razor_set_write(set, rawhide_repo_filename);
176 razor_set_destroy(set);
177 printf("wrote %s\n", rawhide_repo_filename);
183 command_import_rpmdb(int argc, const char *argv[])
185 struct razor_set *set;
187 set = razor_set_create_from_rpmdb();
190 razor_set_write(set, repo_filename);
191 razor_set_destroy(set);
192 printf("wrote %s\n", repo_filename);
198 command_validate(int argc, const char *argv[])
200 struct razor_set *set;
202 set = razor_set_open(repo_filename);
205 razor_set_list_unsatisfied(set);
206 razor_set_destroy(set);
212 command_update(int argc, const char *argv[])
214 struct razor_set *set, *upstream;
216 set = razor_set_open(repo_filename);
217 upstream = razor_set_open(rawhide_repo_filename);
218 if (set == NULL || upstream == NULL)
220 set = razor_set_update(set, upstream, argc, argv);
221 razor_set_write(set, updated_repo_filename);
222 razor_set_destroy(set);
223 razor_set_destroy(upstream);
224 printf("wrote system-updated.repo\n");
230 print_diff(const char *name,
231 const char *old_version, const char *new_version, void *data)
234 printf("removing %s %s\n", name, old_version);
236 printf("install %s %s\n", name, new_version);
240 command_diff(int argc, const char *argv[])
242 struct razor_set *set, *updated;
244 set = razor_set_open(repo_filename);
245 updated = razor_set_open(updated_repo_filename);
246 if (set == NULL || updated == NULL)
249 razor_set_diff(set, updated, print_diff, NULL);
251 razor_set_destroy(set);
252 razor_set_destroy(updated);
259 const char *description;
260 int (*func)(int argc, const char *argv[]);
261 } razor_commands[] = {
262 { "list", "list all packages", command_list },
263 { "list-requires", "list all requires for the given package", command_list_requires },
264 { "list-provides", "list all provides for the give package", command_list_provides },
265 { "list-obsoletes", "list all obsoletes for the give package", command_list_obsoletes },
266 { "list-conflicts", "list all conflicts for the give package", command_list_conflicts },
267 { "list-files", "list files for package set", command_list_files },
268 { "list-file-packages", "list packages owning file", command_list_file_packages },
269 { "list-package-files", "list files in package", command_list_package_files },
270 { "what-requires", "list the packages that have the given requires", command_what_requires },
271 { "what-provides", "list the packages that have the given provides", command_what_provides },
272 { "import-yum", "import yum filelist.xml on stdin", command_import_yum },
273 { "import-rpmdb", "import the system rpm database", command_import_rpmdb },
274 { "validate", "validate a package set", command_validate },
275 { "update", "update all or specified packages", command_update },
276 { "diff", "show diff between two package sets", command_diff }
285 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
287 razor_commands[i].name, razor_commands[i].description);
293 main(int argc, const char *argv[])
298 repo = getenv("RAZOR_REPO");
300 repo_filename = repo;
305 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
306 if (strcmp(razor_commands[i].name, argv[1]) == 0)
307 return razor_commands[i].func(argc - 2, argv + 2);