|
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@43
|
12 |
|
|
krh@43
|
13 |
static const char *repo_filename = "system.repo";
|
|
krh@44
|
14 |
static const char *rawhide_repo_filename = "rawhide.repo";
|
|
krh@44
|
15 |
static const char *updated_repo_filename = "system-updated.repo";
|
|
krh@43
|
16 |
|
|
krh@43
|
17 |
static int
|
|
krh@43
|
18 |
command_list(int argc, const char *argv[])
|
|
krh@43
|
19 |
{
|
|
krh@43
|
20 |
struct razor_set *set;
|
|
krh@92
|
21 |
struct razor_package_iterator *pi;
|
|
krh@92
|
22 |
struct razor_package *package;
|
|
krh@92
|
23 |
const char *pattern = argv[0], *name, *version;
|
|
krh@43
|
24 |
|
|
krh@43
|
25 |
set = razor_set_open(repo_filename);
|
|
krh@92
|
26 |
pi = razor_package_iterator_create(set);
|
|
krh@92
|
27 |
while (razor_package_iterator_next(pi, &package, &name, &version)) {
|
|
krh@92
|
28 |
if (pattern && fnmatch(pattern, name, 0) != 0)
|
|
krh@92
|
29 |
continue;
|
|
krh@92
|
30 |
|
|
krh@92
|
31 |
printf("%s-%s\n", name, version);
|
|
krh@92
|
32 |
}
|
|
krh@92
|
33 |
razor_package_iterator_destroy(pi);
|
|
krh@92
|
34 |
razor_set_destroy(set);
|
|
krh@92
|
35 |
|
|
krh@92
|
36 |
return 0;
|
|
krh@92
|
37 |
}
|
|
krh@92
|
38 |
|
|
krh@92
|
39 |
static int
|
|
krh@92
|
40 |
list_properties(const char *package_name,
|
|
krh@92
|
41 |
enum razor_property_type required_type)
|
|
krh@92
|
42 |
{
|
|
krh@92
|
43 |
struct razor_set *set;
|
|
krh@92
|
44 |
struct razor_property *property;
|
|
krh@92
|
45 |
struct razor_package *package;
|
|
krh@92
|
46 |
struct razor_property_iterator *pi;
|
|
krh@92
|
47 |
const char *name, *version;
|
|
krh@92
|
48 |
enum razor_property_type type;
|
|
krh@92
|
49 |
|
|
krh@92
|
50 |
set = razor_set_open(repo_filename);
|
|
krh@92
|
51 |
if (package_name)
|
|
krh@92
|
52 |
package = razor_set_get_package(set, package_name);
|
|
krh@92
|
53 |
else
|
|
krh@92
|
54 |
package = NULL;
|
|
krh@92
|
55 |
|
|
krh@92
|
56 |
pi = razor_property_iterator_create(set, package);
|
|
krh@92
|
57 |
while (razor_property_iterator_next(pi, &property,
|
|
krh@92
|
58 |
&name, &version, &type)) {
|
|
krh@92
|
59 |
if (type != required_type)
|
|
krh@92
|
60 |
continue;
|
|
krh@92
|
61 |
if (version[0] == '\0')
|
|
krh@92
|
62 |
printf("%s\n", name);
|
|
krh@92
|
63 |
else
|
|
krh@92
|
64 |
printf("%s-%s\n", name, version);
|
|
krh@92
|
65 |
}
|
|
krh@92
|
66 |
razor_property_iterator_destroy(pi);
|
|
krh@92
|
67 |
|
|
krh@43
|
68 |
razor_set_destroy(set);
|
|
krh@43
|
69 |
|
|
krh@43
|
70 |
return 0;
|
|
krh@43
|
71 |
}
|
|
krh@43
|
72 |
|
|
krh@43
|
73 |
static int
|
|
krh@43
|
74 |
command_list_requires(int argc, const char *argv[])
|
|
krh@43
|
75 |
{
|
|
krh@92
|
76 |
return list_properties(argv[0], RAZOR_PROPERTY_REQUIRES);
|
|
krh@43
|
77 |
}
|
|
krh@43
|
78 |
|
|
krh@43
|
79 |
static int
|
|
krh@43
|
80 |
command_list_provides(int argc, const char *argv[])
|
|
krh@43
|
81 |
{
|
|
krh@92
|
82 |
return list_properties(argv[0], RAZOR_PROPERTY_PROVIDES);
|
|
krh@43
|
83 |
}
|
|
krh@43
|
84 |
|
|
krh@43
|
85 |
static int
|
|
krh@67
|
86 |
command_list_obsoletes(int argc, const char *argv[])
|
|
krh@67
|
87 |
{
|
|
krh@92
|
88 |
return list_properties(argv[0], RAZOR_PROPERTY_OBSOLETES);
|
|
krh@67
|
89 |
}
|
|
krh@67
|
90 |
|
|
krh@67
|
91 |
static int
|
|
krh@67
|
92 |
command_list_conflicts(int argc, const char *argv[])
|
|
krh@67
|
93 |
{
|
|
krh@92
|
94 |
return list_properties(argv[0], RAZOR_PROPERTY_CONFLICTS);
|
|
krh@67
|
95 |
}
|
|
krh@67
|
96 |
|
|
krh@67
|
97 |
static int
|
|
krh@48
|
98 |
command_list_files(int argc, const char *argv[])
|
|
krh@48
|
99 |
{
|
|
krh@48
|
100 |
struct razor_set *set;
|
|
krh@48
|
101 |
|
|
krh@48
|
102 |
set = razor_set_open(repo_filename);
|
|
krh@48
|
103 |
if (set == NULL)
|
|
krh@48
|
104 |
return 1;
|
|
krh@49
|
105 |
razor_set_list_files(set, argv[0]);
|
|
krh@48
|
106 |
razor_set_destroy(set);
|
|
krh@48
|
107 |
|
|
krh@48
|
108 |
return 0;
|
|
krh@48
|
109 |
}
|
|
krh@48
|
110 |
|
|
krh@48
|
111 |
static int
|
|
krh@52
|
112 |
command_list_file_packages(int argc, const char *argv[])
|
|
krh@52
|
113 |
{
|
|
krh@52
|
114 |
struct razor_set *set;
|
|
krh@52
|
115 |
|
|
krh@52
|
116 |
set = razor_set_open(repo_filename);
|
|
krh@52
|
117 |
if (set == NULL)
|
|
krh@52
|
118 |
return 1;
|
|
krh@52
|
119 |
razor_set_list_file_packages(set, argv[0]);
|
|
krh@52
|
120 |
razor_set_destroy(set);
|
|
krh@52
|
121 |
|
|
krh@52
|
122 |
return 0;
|
|
krh@52
|
123 |
}
|
|
krh@52
|
124 |
|
|
krh@56
|
125 |
static int
|
|
krh@56
|
126 |
command_list_package_files(int argc, const char *argv[])
|
|
krh@56
|
127 |
{
|
|
krh@56
|
128 |
struct razor_set *set;
|
|
krh@56
|
129 |
|
|
krh@56
|
130 |
set = razor_set_open(repo_filename);
|
|
krh@56
|
131 |
if (set == NULL)
|
|
krh@56
|
132 |
return 1;
|
|
krh@56
|
133 |
razor_set_list_package_files(set, argv[0]);
|
|
krh@56
|
134 |
razor_set_destroy(set);
|
|
krh@56
|
135 |
|
|
krh@56
|
136 |
return 0;
|
|
krh@56
|
137 |
}
|
|
krh@52
|
138 |
|
|
krh@101
|
139 |
static void
|
|
krh@101
|
140 |
list_packages_for_property(struct razor_set *set,
|
|
krh@101
|
141 |
struct razor_property *property)
|
|
krh@101
|
142 |
{
|
|
krh@101
|
143 |
struct razor_package_iterator *pi;
|
|
krh@101
|
144 |
struct razor_package *package;
|
|
krh@101
|
145 |
const char *name, *version;
|
|
krh@101
|
146 |
|
|
krh@101
|
147 |
pi = razor_package_iterator_create_for_property(set, property);
|
|
krh@101
|
148 |
while (razor_package_iterator_next(pi, &package, &name, &version))
|
|
krh@101
|
149 |
printf("%s-%s\n", name, version);
|
|
krh@101
|
150 |
razor_package_iterator_destroy(pi);
|
|
krh@101
|
151 |
}
|
|
krh@101
|
152 |
|
|
krh@52
|
153 |
static int
|
|
krh@100
|
154 |
list_property_packages(const char *ref_name,
|
|
krh@100
|
155 |
const char *ref_version,
|
|
krh@100
|
156 |
enum razor_property_type ref_type)
|
|
krh@43
|
157 |
{
|
|
krh@43
|
158 |
struct razor_set *set;
|
|
krh@100
|
159 |
struct razor_property *property;
|
|
krh@100
|
160 |
struct razor_property_iterator *pi;
|
|
krh@100
|
161 |
const char *name, *version;
|
|
krh@100
|
162 |
enum razor_property_type type;
|
|
krh@100
|
163 |
|
|
krh@100
|
164 |
if (ref_name == NULL)
|
|
krh@100
|
165 |
return 0;
|
|
krh@43
|
166 |
|
|
krh@43
|
167 |
set = razor_set_open(repo_filename);
|
|
krh@100
|
168 |
if (set == NULL)
|
|
krh@100
|
169 |
return 1;
|
|
krh@100
|
170 |
|
|
krh@100
|
171 |
pi = razor_property_iterator_create(set, NULL);
|
|
krh@100
|
172 |
while (razor_property_iterator_next(pi, &property,
|
|
krh@100
|
173 |
&name, &version, &type)) {
|
|
krh@100
|
174 |
if (strcmp(ref_name, name) != 0)
|
|
krh@100
|
175 |
continue;
|
|
krh@100
|
176 |
if (ref_version && strcmp(ref_version, version) != 0)
|
|
krh@100
|
177 |
continue;
|
|
krh@100
|
178 |
if (ref_type != type)
|
|
krh@100
|
179 |
continue;
|
|
krh@100
|
180 |
|
|
krh@101
|
181 |
list_packages_for_property(set, property);
|
|
krh@100
|
182 |
}
|
|
krh@100
|
183 |
razor_property_iterator_destroy(pi);
|
|
krh@43
|
184 |
|
|
krh@43
|
185 |
return 0;
|
|
krh@43
|
186 |
}
|
|
krh@43
|
187 |
|
|
krh@43
|
188 |
static int
|
|
krh@100
|
189 |
command_what_requires(int argc, const char *argv[])
|
|
krh@100
|
190 |
{
|
|
krh@100
|
191 |
return list_property_packages(argv[0], argv[1],
|
|
krh@100
|
192 |
RAZOR_PROPERTY_REQUIRES);
|
|
krh@100
|
193 |
}
|
|
krh@100
|
194 |
|
|
krh@100
|
195 |
static int
|
|
krh@43
|
196 |
command_what_provides(int argc, const char *argv[])
|
|
krh@43
|
197 |
{
|
|
krh@100
|
198 |
return list_property_packages(argv[0], argv[1],
|
|
krh@100
|
199 |
RAZOR_PROPERTY_PROVIDES);
|
|
krh@43
|
200 |
}
|
|
krh@43
|
201 |
|
|
krh@73
|
202 |
static int
|
|
krh@73
|
203 |
show_progress(void *clientp,
|
|
krh@73
|
204 |
double dltotal, double dlnow, double ultotal, double ulnow)
|
|
krh@73
|
205 |
{
|
|
krh@73
|
206 |
const char *file = clientp;
|
|
krh@73
|
207 |
|
|
krh@73
|
208 |
if (!dlnow < dltotal)
|
|
krh@73
|
209 |
fprintf(stderr, "\rdownloading %s, %dkB/%dkB",
|
|
krh@73
|
210 |
file, (int) dlnow / 1024, (int) dltotal / 1024);
|
|
krh@73
|
211 |
else
|
|
krh@73
|
212 |
fprintf(stderr, "\n");
|
|
krh@73
|
213 |
|
|
krh@73
|
214 |
return 0;
|
|
krh@73
|
215 |
}
|
|
krh@73
|
216 |
|
|
krh@73
|
217 |
static int
|
|
krh@73
|
218 |
download_if_missing(CURL *curl, const char *url, const char *file)
|
|
krh@73
|
219 |
{
|
|
krh@73
|
220 |
struct stat buf;
|
|
krh@73
|
221 |
char error[256];
|
|
krh@73
|
222 |
FILE *fp;
|
|
krh@73
|
223 |
CURLcode res;
|
|
krh@73
|
224 |
char buffer[256];
|
|
krh@73
|
225 |
|
|
krh@73
|
226 |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
|
|
krh@73
|
227 |
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
|
|
krh@73
|
228 |
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress);
|
|
krh@73
|
229 |
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, file);
|
|
krh@73
|
230 |
|
|
krh@73
|
231 |
if (stat(file, &buf) < 0) {
|
|
krh@73
|
232 |
fp = fopen(file, "w");
|
|
krh@73
|
233 |
snprintf(buffer, sizeof buffer, "%s/%s", url, file);
|
|
krh@73
|
234 |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
|
krh@73
|
235 |
curl_easy_setopt(curl, CURLOPT_URL, buffer);
|
|
krh@73
|
236 |
res = curl_easy_perform(curl);
|
|
krh@73
|
237 |
fclose(fp);
|
|
krh@73
|
238 |
if (res != CURLE_OK) {
|
|
krh@73
|
239 |
fprintf(stderr, "curl error: %s\n", error);
|
|
krh@73
|
240 |
unlink(file);
|
|
krh@73
|
241 |
return -1;
|
|
krh@73
|
242 |
}
|
|
krh@73
|
243 |
}
|
|
krh@73
|
244 |
|
|
krh@73
|
245 |
return 0;
|
|
krh@73
|
246 |
}
|
|
krh@73
|
247 |
|
|
krh@71
|
248 |
#define REPO_URL "http://download.fedora.redhat.com" \
|
|
krh@71
|
249 |
"/pub/fedora/linux/development/i386/os/repodata"
|
|
krh@71
|
250 |
|
|
krh@43
|
251 |
static int
|
|
krh@43
|
252 |
command_import_yum(int argc, const char *argv[])
|
|
krh@43
|
253 |
{
|
|
krh@43
|
254 |
struct razor_set *set;
|
|
krh@71
|
255 |
CURL *curl;
|
|
krh@71
|
256 |
|
|
krh@71
|
257 |
curl = curl_easy_init();
|
|
krh@71
|
258 |
if (curl == NULL)
|
|
krh@71
|
259 |
return 1;
|
|
krh@71
|
260 |
|
|
krh@73
|
261 |
if (download_if_missing(curl, REPO_URL, "primary.xml.gz") < 0)
|
|
krh@73
|
262 |
return -1;
|
|
krh@73
|
263 |
if (download_if_missing(curl, REPO_URL, "filelists.xml.gz") < 0)
|
|
krh@73
|
264 |
return -1;
|
|
krh@71
|
265 |
curl_easy_cleanup(curl);
|
|
krh@43
|
266 |
|
|
krh@70
|
267 |
set = razor_set_create_from_yum();
|
|
krh@43
|
268 |
if (set == NULL)
|
|
krh@43
|
269 |
return 1;
|
|
krh@43
|
270 |
razor_set_write(set, rawhide_repo_filename);
|
|
krh@43
|
271 |
razor_set_destroy(set);
|
|
krh@43
|
272 |
printf("wrote %s\n", rawhide_repo_filename);
|
|
krh@43
|
273 |
|
|
krh@43
|
274 |
return 0;
|
|
krh@43
|
275 |
}
|
|
krh@43
|
276 |
|
|
krh@43
|
277 |
static int
|
|
krh@43
|
278 |
command_import_rpmdb(int argc, const char *argv[])
|
|
krh@43
|
279 |
{
|
|
krh@43
|
280 |
struct razor_set *set;
|
|
krh@43
|
281 |
|
|
krh@43
|
282 |
set = razor_set_create_from_rpmdb();
|
|
krh@43
|
283 |
if (set == NULL)
|
|
krh@43
|
284 |
return 1;
|
|
krh@43
|
285 |
razor_set_write(set, repo_filename);
|
|
krh@43
|
286 |
razor_set_destroy(set);
|
|
krh@43
|
287 |
printf("wrote %s\n", repo_filename);
|
|
krh@43
|
288 |
|
|
krh@43
|
289 |
return 0;
|
|
krh@43
|
290 |
}
|
|
krh@43
|
291 |
|
|
krh@43
|
292 |
static int
|
|
krh@43
|
293 |
command_validate(int argc, const char *argv[])
|
|
krh@43
|
294 |
{
|
|
krh@43
|
295 |
struct razor_set *set;
|
|
krh@43
|
296 |
|
|
krh@43
|
297 |
set = razor_set_open(repo_filename);
|
|
krh@43
|
298 |
if (set == NULL)
|
|
krh@43
|
299 |
return 1;
|
|
krh@43
|
300 |
razor_set_list_unsatisfied(set);
|
|
krh@43
|
301 |
razor_set_destroy(set);
|
|
krh@43
|
302 |
|
|
krh@43
|
303 |
return 0;
|
|
krh@43
|
304 |
}
|
|
krh@43
|
305 |
|
|
krh@43
|
306 |
static int
|
|
krh@43
|
307 |
command_update(int argc, const char *argv[])
|
|
krh@43
|
308 |
{
|
|
krh@43
|
309 |
struct razor_set *set, *upstream;
|
|
krh@43
|
310 |
|
|
krh@43
|
311 |
set = razor_set_open(repo_filename);
|
|
krh@43
|
312 |
upstream = razor_set_open(rawhide_repo_filename);
|
|
krh@43
|
313 |
if (set == NULL || upstream == NULL)
|
|
krh@43
|
314 |
return 1;
|
|
krh@45
|
315 |
set = razor_set_update(set, upstream, argc, argv);
|
|
krh@44
|
316 |
razor_set_write(set, updated_repo_filename);
|
|
krh@43
|
317 |
razor_set_destroy(set);
|
|
krh@43
|
318 |
razor_set_destroy(upstream);
|
|
krh@43
|
319 |
printf("wrote system-updated.repo\n");
|
|
krh@43
|
320 |
|
|
krh@43
|
321 |
return 0;
|
|
krh@43
|
322 |
}
|
|
krh@43
|
323 |
|
|
krh@44
|
324 |
static void
|
|
krh@44
|
325 |
print_diff(const char *name,
|
|
krh@44
|
326 |
const char *old_version, const char *new_version, void *data)
|
|
krh@44
|
327 |
{
|
|
krh@44
|
328 |
if (old_version)
|
|
krh@44
|
329 |
printf("removing %s %s\n", name, old_version);
|
|
krh@44
|
330 |
else
|
|
krh@44
|
331 |
printf("install %s %s\n", name, new_version);
|
|
krh@44
|
332 |
}
|
|
krh@44
|
333 |
|
|
krh@44
|
334 |
static int
|
|
krh@44
|
335 |
command_diff(int argc, const char *argv[])
|
|
krh@44
|
336 |
{
|
|
krh@44
|
337 |
struct razor_set *set, *updated;
|
|
krh@44
|
338 |
|
|
krh@44
|
339 |
set = razor_set_open(repo_filename);
|
|
krh@44
|
340 |
updated = razor_set_open(updated_repo_filename);
|
|
krh@44
|
341 |
if (set == NULL || updated == NULL)
|
|
krh@44
|
342 |
return 1;
|
|
krh@44
|
343 |
|
|
krh@44
|
344 |
razor_set_diff(set, updated, print_diff, NULL);
|
|
krh@44
|
345 |
|
|
krh@44
|
346 |
razor_set_destroy(set);
|
|
krh@44
|
347 |
razor_set_destroy(updated);
|
|
krh@44
|
348 |
|
|
krh@44
|
349 |
return 0;
|
|
krh@44
|
350 |
}
|
|
krh@44
|
351 |
|
|
krh@74
|
352 |
static int
|
|
krh@75
|
353 |
command_import_rpms(int argc, const char *argv[])
|
|
krh@74
|
354 |
{
|
|
krh@75
|
355 |
DIR *dir;
|
|
krh@75
|
356 |
struct dirent *de;
|
|
krh@75
|
357 |
struct razor_importer *importer;
|
|
krh@75
|
358 |
struct razor_set *set;
|
|
krh@77
|
359 |
struct razor_rpm *rpm;
|
|
krh@75
|
360 |
int len;
|
|
krh@75
|
361 |
char filename[256];
|
|
krh@75
|
362 |
const char *dirname = argv[0];
|
|
krh@75
|
363 |
|
|
krh@75
|
364 |
if (dirname == NULL) {
|
|
krh@75
|
365 |
fprintf(stderr, "usage: razor import-rpms DIR\n");
|
|
krh@75
|
366 |
return -1;
|
|
krh@75
|
367 |
}
|
|
krh@75
|
368 |
|
|
krh@75
|
369 |
dir = opendir(dirname);
|
|
krh@75
|
370 |
if (dir == NULL) {
|
|
krh@75
|
371 |
fprintf(stderr, "couldn't read dir %s\n", dirname);
|
|
krh@75
|
372 |
return -1;
|
|
krh@75
|
373 |
}
|
|
krh@75
|
374 |
|
|
krh@75
|
375 |
importer = razor_importer_new();
|
|
krh@75
|
376 |
|
|
krh@75
|
377 |
while (de = readdir(dir), de != NULL) {
|
|
krh@75
|
378 |
len = strlen(de->d_name);
|
|
krh@75
|
379 |
if (len < 5 || strcmp(de->d_name + len - 4, ".rpm") != 0)
|
|
krh@75
|
380 |
continue;
|
|
krh@75
|
381 |
snprintf(filename, sizeof filename,
|
|
krh@75
|
382 |
"%s/%s", dirname, de->d_name);
|
|
krh@77
|
383 |
rpm = razor_rpm_open(filename);
|
|
krh@77
|
384 |
if (rpm == NULL) {
|
|
krh@77
|
385 |
fprintf(stderr,
|
|
krh@77
|
386 |
"failed to open rpm \"%s\"\n", filename);
|
|
krh@77
|
387 |
continue;
|
|
krh@77
|
388 |
}
|
|
krh@77
|
389 |
if (razor_importer_add_rpm(importer, rpm)) {
|
|
krh@75
|
390 |
fprintf(stderr, "couldn't import %s\n", filename);
|
|
krh@75
|
391 |
break;
|
|
krh@75
|
392 |
}
|
|
krh@77
|
393 |
razor_rpm_close(rpm);
|
|
krh@75
|
394 |
}
|
|
krh@75
|
395 |
|
|
krh@75
|
396 |
if (de != NULL) {
|
|
krh@75
|
397 |
razor_importer_destroy(importer);
|
|
krh@75
|
398 |
return -1;
|
|
krh@75
|
399 |
}
|
|
krh@75
|
400 |
|
|
krh@75
|
401 |
set = razor_importer_finish(importer);
|
|
krh@75
|
402 |
|
|
krh@75
|
403 |
razor_set_write(set, repo_filename);
|
|
krh@75
|
404 |
razor_set_destroy(set);
|
|
krh@75
|
405 |
printf("wrote %s\n", repo_filename);
|
|
krh@74
|
406 |
|
|
krh@74
|
407 |
return 0;
|
|
krh@74
|
408 |
}
|
|
krh@74
|
409 |
|
|
krh@77
|
410 |
static int
|
|
krh@77
|
411 |
command_install(int argc, const char *argv[])
|
|
krh@77
|
412 |
{
|
|
krh@77
|
413 |
struct razor_rpm *rpm;
|
|
krh@77
|
414 |
const char *filename = argv[0];
|
|
krh@77
|
415 |
struct stat buf;
|
|
krh@77
|
416 |
const char root[] = "install";
|
|
krh@77
|
417 |
|
|
krh@77
|
418 |
if (stat(root, &buf) < 0) {
|
|
krh@77
|
419 |
if (mkdir(root, 0777) < 0) {
|
|
krh@77
|
420 |
fprintf(stderr,
|
|
krh@77
|
421 |
"could not create install root \"%s\"\n",
|
|
krh@77
|
422 |
root);
|
|
krh@77
|
423 |
return -1;
|
|
krh@77
|
424 |
}
|
|
krh@77
|
425 |
fprintf(stderr, "created install root \"%s\"\n", root);
|
|
krh@77
|
426 |
} else if (!S_ISDIR(buf.st_mode)) {
|
|
krh@77
|
427 |
fprintf(stderr,
|
|
krh@77
|
428 |
"install root \"%s\" exists, but is not a directory\n",
|
|
krh@77
|
429 |
root);
|
|
krh@77
|
430 |
return -1;
|
|
krh@77
|
431 |
}
|
|
krh@77
|
432 |
|
|
krh@77
|
433 |
rpm = razor_rpm_open(filename);
|
|
krh@77
|
434 |
if (rpm == NULL) {
|
|
krh@77
|
435 |
fprintf(stderr, "failed to open rpm %s\n", filename);
|
|
krh@77
|
436 |
return -1;
|
|
krh@77
|
437 |
}
|
|
krh@77
|
438 |
if (razor_rpm_install(rpm, root) < 0) {
|
|
krh@77
|
439 |
fprintf(stderr, "failed to install rpm %s\n", filename);
|
|
krh@77
|
440 |
return -1;
|
|
krh@77
|
441 |
}
|
|
krh@77
|
442 |
|
|
krh@77
|
443 |
razor_rpm_close(rpm);
|
|
krh@77
|
444 |
|
|
krh@77
|
445 |
return 0;
|
|
krh@77
|
446 |
}
|
|
krh@77
|
447 |
|
|
krh@43
|
448 |
static struct {
|
|
krh@43
|
449 |
const char *name;
|
|
krh@43
|
450 |
const char *description;
|
|
krh@43
|
451 |
int (*func)(int argc, const char *argv[]);
|
|
krh@43
|
452 |
} razor_commands[] = {
|
|
krh@43
|
453 |
{ "list", "list all packages", command_list },
|
|
krh@67
|
454 |
{ "list-requires", "list all requires for the given package", command_list_requires },
|
|
krh@75
|
455 |
{ "list-provides", "list all provides for the given package", command_list_provides },
|
|
krh@75
|
456 |
{ "list-obsoletes", "list all obsoletes for the given package", command_list_obsoletes },
|
|
krh@75
|
457 |
{ "list-conflicts", "list all conflicts for the given package", command_list_conflicts },
|
|
krh@48
|
458 |
{ "list-files", "list files for package set", command_list_files },
|
|
krh@52
|
459 |
{ "list-file-packages", "list packages owning file", command_list_file_packages },
|
|
krh@56
|
460 |
{ "list-package-files", "list files in package", command_list_package_files },
|
|
krh@43
|
461 |
{ "what-requires", "list the packages that have the given requires", command_what_requires },
|
|
krh@43
|
462 |
{ "what-provides", "list the packages that have the given provides", command_what_provides },
|
|
krh@75
|
463 |
{ "import-yum", "import yum metadata files", command_import_yum },
|
|
krh@43
|
464 |
{ "import-rpmdb", "import the system rpm database", command_import_rpmdb },
|
|
krh@75
|
465 |
{ "import-rpms", "import rpms from the given directory", command_import_rpms },
|
|
krh@43
|
466 |
{ "validate", "validate a package set", command_validate },
|
|
krh@44
|
467 |
{ "update", "update all or specified packages", command_update },
|
|
krh@77
|
468 |
{ "diff", "show diff between two package sets", command_diff },
|
|
krh@77
|
469 |
{ "install", "install rpm", command_install }
|
|
krh@43
|
470 |
};
|
|
krh@43
|
471 |
|
|
krh@43
|
472 |
static int
|
|
krh@43
|
473 |
usage(void)
|
|
krh@43
|
474 |
{
|
|
krh@43
|
475 |
int i;
|
|
krh@43
|
476 |
|
|
krh@43
|
477 |
printf("usage:\n");
|
|
krh@43
|
478 |
for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
|
|
krh@43
|
479 |
printf(" %-20s%s\n",
|
|
krh@43
|
480 |
razor_commands[i].name, razor_commands[i].description);
|
|
krh@43
|
481 |
|
|
krh@43
|
482 |
return 1;
|
|
krh@43
|
483 |
}
|
|
krh@43
|
484 |
|
|
krh@43
|
485 |
int
|
|
krh@43
|
486 |
main(int argc, const char *argv[])
|
|
krh@43
|
487 |
{
|
|
krh@43
|
488 |
char *repo;
|
|
krh@43
|
489 |
int i;
|
|
krh@43
|
490 |
|
|
krh@43
|
491 |
repo = getenv("RAZOR_REPO");
|
|
krh@43
|
492 |
if (repo != NULL)
|
|
krh@43
|
493 |
repo_filename = repo;
|
|
krh@43
|
494 |
|
|
krh@43
|
495 |
if (argc < 2)
|
|
krh@43
|
496 |
return usage();
|
|
krh@43
|
497 |
|
|
krh@43
|
498 |
for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
|
|
krh@43
|
499 |
if (strcmp(razor_commands[i].name, argv[1]) == 0)
|
|
krh@43
|
500 |
return razor_commands[i].func(argc - 2, argv + 2);
|
|
krh@43
|
501 |
|
|
krh@43
|
502 |
return usage();
|
|
krh@43
|
503 |
}
|