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