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