aboutsummaryrefslogtreecommitdiff
path: root/src/install_pkg.c
blob: 2f4f88f6b4576001e5253296c5811c1411a2b281 (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "install_pkg.h"
#include "add_repo.h"
#include "fetch_src.h"
#include "build.h"
#include "copy_install.h"
#include "link_install.h"
#include "lua_state.h"
#include "name_from_url.h"
#include "vars.h"

void install_pkg(Pkg pkg) {
    if (!pkg.is_local) {
        printf("%sfetching %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
        fetch_src(pkg);
        if (is_verbose) printf("%sfetched %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
    }

    printf("%sbuilding %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
    build(pkg);
    if (is_verbose) printf("%sbuilt %s%s%s\n", print_pkgit, green, pkg.name, color_reset);

    printf("%sinstalling %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
    if (is_auto_installed) {
      if (is_symlink_install) {
          link_install(pkg.src);
      } else {
          copy_install(pkg.src);
      }
    }
    printf("%sinstalled %s%s%s\n", print_success, green, pkg.name, color_reset);

    bool repo_exists = false;
    for (size_t i = 0; i < cached_repos_count; i++) {
        char *repo_name = name_from_url(cached_repos[i].source_value);
        if (strcmp(repo_name, pkg.name) == 0) {
            repo_exists = true;
        }
        free(repo_name);
    }

    if (!repo_exists) {
        printf("%sadding %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
        if (pkg.url && strlen(pkg.url) > 0) {
            add_repo(pkg.url, pkg.name);
        }
        printf("%sadded %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
    } else {
        if (is_verbose) printf("%srepo already exists, done\n", print_pkgit);
    }
}