|
11 | 11 | #include "common/clib-validate.h"
|
12 | 12 | #include "debug/debug.h"
|
13 | 13 | #include "fs/fs.h"
|
14 |
| -#include "http-get/http-get.h" |
15 | 14 | #include "logger/logger.h"
|
16 | 15 | #include "parson/parson.h"
|
17 |
| -#include "str-replace/str-replace.h" |
18 | 16 | #include "version.h"
|
19 | 17 | #include <clib-secrets.h>
|
20 | 18 | #include <curl/curl.h>
|
21 |
| -#include <libgen.h> |
22 | 19 | #include <limits.h>
|
23 | 20 | #include <registry-manager.h>
|
24 | 21 | #include <repository.h>
|
25 | 22 | #include <stdio.h>
|
26 | 23 | #include <stdlib.h>
|
27 | 24 | #include <string.h>
|
| 25 | +#include "clib-package-installer.h" |
28 | 26 |
|
29 | 27 | #define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60
|
30 | 28 |
|
@@ -65,8 +63,9 @@ static struct options opts = {0};
|
65 | 63 |
|
66 | 64 | static const char *manifest_names[] = {"clib.json", "package.json", NULL};
|
67 | 65 |
|
68 |
| -static clib_package_opts_t package_opts = {0}; |
69 | 66 | static clib_package_t *root_package = NULL;
|
| 67 | +static clib_secrets_t secrets = NULL; |
| 68 | +static registries_t registries = NULL; |
70 | 69 |
|
71 | 70 | /**
|
72 | 71 | * Option setters.
|
@@ -286,27 +285,18 @@ static int install_package(const char *slug) {
|
286 | 285 | }
|
287 | 286 | }
|
288 | 287 |
|
289 |
| - // Read local config files. |
290 |
| - clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json"); |
291 |
| - repository_init(secrets); // The repository requires the secrets for authentication. |
292 |
| - clib_package_t *package = clib_package_load_local_manifest(0); |
293 |
| - |
294 |
| - registries_t registries = registry_manager_init_registries(package->registries, secrets); |
295 |
| - registry_manager_fetch_registries(registries); |
296 | 288 | registry_package_ptr_t package_info = registry_manger_find_package(registries, slug);
|
297 | 289 | if (!package_info) {
|
298 | 290 | debug(&debugger, "Package %s not found in any registry.", slug);
|
299 | 291 | return -1;
|
300 | 292 | }
|
301 | 293 |
|
302 |
| - |
303 | 294 | pkg = clib_package_new_from_slug_and_url(slug, registry_package_get_href(package_info), opts.verbose);
|
304 | 295 | if (NULL == pkg)
|
305 | 296 | return -1;
|
306 | 297 |
|
307 | 298 | if (root_package && root_package->prefix) {
|
308 | 299 | package_opts.prefix = root_package->prefix;
|
309 |
| - clib_package_set_opts(package_opts); |
310 | 300 | }
|
311 | 301 |
|
312 | 302 | rc = clib_package_install(pkg, opts.dir, opts.verbose);
|
@@ -425,38 +415,34 @@ int main(int argc, char *argv[]) {
|
425 | 415 | realpath(opts.prefix, prefix);
|
426 | 416 | unsigned long int size = strlen(prefix) + 1;
|
427 | 417 | opts.prefix = malloc(size);
|
428 |
| - memset((void *)opts.prefix, 0, size); |
429 |
| - memcpy((void *)opts.prefix, prefix, size); |
| 418 | + memset((void *) opts.prefix, 0, size); |
| 419 | + memcpy((void *) opts.prefix, prefix, size); |
430 | 420 | }
|
431 | 421 |
|
432 | 422 | clib_cache_init(CLIB_PACKAGE_CACHE_TIME);
|
433 | 423 |
|
434 |
| - package_opts.skip_cache = opts.skip_cache; |
435 |
| - package_opts.prefix = opts.prefix; |
436 |
| - package_opts.global = opts.global; |
437 |
| - package_opts.force = opts.force; |
438 |
| - package_opts.token = opts.token; |
| 424 | + clib_package_opts_t install_package_opts; |
| 425 | + install_package_opts.skip_cache = opts.skip_cache; |
| 426 | + install_package_opts.prefix = opts.prefix; |
| 427 | + install_package_opts.global = opts.global; |
| 428 | + install_package_opts.force = opts.force; |
| 429 | + install_package_opts.token = opts.token; |
439 | 430 |
|
440 | 431 | #ifdef HAVE_PTHREADS
|
441 |
| - package_opts.concurrency = opts.concurrency; |
| 432 | + install_package_opts.concurrency = opts.concurrency; |
442 | 433 | #endif
|
443 | 434 |
|
444 |
| - clib_package_set_opts(package_opts); |
| 435 | + clib_package_set_opts(install_package_opts); |
445 | 436 |
|
446 |
| - if (!root_package) { |
447 |
| - const char *name = NULL; |
448 |
| - char *json = NULL; |
449 |
| - unsigned int i = 0; |
| 437 | + // Read local config files. |
| 438 | + secrets = clib_secrets_load_from_file("clib_secrets.json"); |
| 439 | + root_package = clib_package_load_local_manifest(0); |
450 | 440 |
|
451 |
| - do { |
452 |
| - name = manifest_names[i]; |
453 |
| - json = fs_read(name); |
454 |
| - } while (NULL != manifest_names[++i] && !json); |
| 441 | + repository_init(secrets); // The repository requires the secrets for authentication. |
| 442 | + registries = registry_manager_init_registries(root_package->registries, secrets); |
| 443 | + registry_manager_fetch_registries(registries); |
455 | 444 |
|
456 |
| - if (json) { |
457 |
| - root_package = clib_package_new(json, opts.verbose); |
458 |
| - } |
459 |
| - } |
| 445 | + clib_package_installer_init(registries, secrets); |
460 | 446 |
|
461 | 447 | int code = 0 == program.argc ? install_local_packages()
|
462 | 448 | : install_packages(program.argc, program.argv);
|
|
0 commit comments