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