aboutsummaryrefslogtreecommitdiff
path: root/spm.c
blob: 3607117b5f87bfe0b655aea08f2a2a91d8f49e18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * SPM - Simple Package Manager
 * @file spm.c
 */
#include "spm.h"

int main(int argc, char *argv[]) {
    // not much to see here yet
    // at the moment this will all be random tests, for better or worse
    // everything here is subject to change without notice

    // Initialize configuration data
    init_config_global();
    show_global_config();

    // Ensure external programs are available for use.
    check_runtime_environment();

    // Install a package to test things out
    char *match;
    char *package;
    const char *root = "/tmp/root";
    if ((match = find_package("python")) == NULL) {
        fprintf(SYSERROR);
        exit(1);
    }
    if ((package = basename(match)) == NULL) {
        fprintf(stderr, "Unable to derive package name from package path:\n\t-> %s\n", match);
        exit(1);
    }

    Dependencies *deps = NULL;
    dep_init(&deps);

    if (dep_all(&deps, package) < 0) {
        dep_free(&deps);
        free_global_config();
        exit(1);
    }

    printf("%s requires:\n", package);
    dep_show(&deps);

    // Install dependencies first
    for (int i = 0; i < deps->records; i++) {
        if (install(root, deps->list[i]) < 0) {
            fprintf(SYSERROR);
            exit(errno);
        }
    }
    // Install package
    if (install(root, package) < 0) {
        fprintf(SYSERROR);
        exit(errno);
    }

    dep_free(&deps);
    free_global_config();
    return 0;
}