diff options
| -rw-r--r-- | TODO.md | 3 | ||||
| -rw-r--r-- | config/init.lua | 45 | ||||
| -rw-r--r-- | include/declare.h | 4 | ||||
| -rw-r--r-- | src/cla_parse.c | 2 | ||||
| -rw-r--r-- | src/create_pkg.c | 29 | ||||
| -rw-r--r-- | src/declare.c | 17 | ||||
| -rw-r--r-- | src/fetch_git.c | 2 | ||||
| -rw-r--r-- | src/fetch_src.c | 4 | ||||
| -rw-r--r-- | src/lua_state.c | 12 | ||||
| -rw-r--r-- | src/remove.c | 11 | ||||
| -rw-r--r-- | src/setup_dirs.c | 15 | ||||
| -rw-r--r-- | src/update_all.c | 29 | ||||
| -rw-r--r-- | src/vars.c | 12 |
13 files changed, 107 insertions, 78 deletions
@@ -9,9 +9,8 @@ - [x] lua config primary(/etc) / secondary(.config) checks - [x] lua variables for install paths - [x] lua dependency listing -- [ ] lua custom source fetching methods - [ ] version management - - [ ] (maybe) diffs to change versions +- [ ] (maybe) lua custom source fetching methods - [ ] (maybe) lua custom install methods for sandboxed builds - [ ] (maybe) branch selection - [ ] (maybe) install to store directory diff --git a/config/init.lua b/config/init.lua index 47647e4..9fd5cea 100644 --- a/config/init.lua +++ b/config/init.lua @@ -1,33 +1,32 @@ local home = os.getenv("HOME") local prefix = home.."/.local" install_directories = { - bin = prefix.."/bin", - include = prefix.."/include", - lib = prefix.."/lib", - src = prefix.."/src", - pkgblds = home.."/.local/share/pkgit", + bin = prefix.."/bin", + include = prefix.."/include", + lib = prefix.."/lib", + src = prefix.."/.local/share/pkgit", } repositories = { - pkgit = { - url = "https://git.symlinx.net/pkgit", - }, - beaker = { - url = "https://git.symlinx.net/beaker", - dependencies = {}, - }, + pkgit = { + url = "https://git.symlinx.net/pkgit", + }, + beaker = { + url = "https://git.symlinx.net/beaker", + dependencies = {}, + }, } build_systems = { - Makefile = { - build = function() - os.execute("make") - end, - }, - ["CMakeLists.txt"] = { - build = function() - os.execute("cmake -B build") - os.execute("cmake --build build") - end, - }, + ["Makefile"] = { + build = function() + os.execute("make") + end, + }, + ["CMakeLists.txt"] = { + build = function() + os.execute("cmake -B build") + os.execute("cmake --build build") + end, + }, }
\ No newline at end of file diff --git a/include/declare.h b/include/declare.h new file mode 100644 index 0000000..daf2b5b --- /dev/null +++ b/include/declare.h @@ -0,0 +1,4 @@ +#ifndef DECLARE +#define DECLARE +void declare(); +#endif diff --git a/src/cla_parse.c b/src/cla_parse.c index 18a9ece..91dca3f 100644 --- a/src/cla_parse.c +++ b/src/cla_parse.c @@ -7,6 +7,7 @@ #include "add_repo.h" #include "build.h" #include "create_pkg.h" +#include "declare.h" #include "help.h" #include "install_pkg.h" #include "list_pkgs.h" @@ -77,6 +78,7 @@ void cla_parse(int argc, char **argv) { } }); COMMAND("update", "u", { update_all(); }); + COMMAND("declare", "d", { declare(); }); COMMAND("list", "l", { list_pkgs(); }); COMMAND("--version", "-v", { printf("%s\n", version); }); COMMAND("--help", "-h", { help(); }); diff --git a/src/create_pkg.c b/src/create_pkg.c index eed9ef1..5bd91fa 100644 --- a/src/create_pkg.c +++ b/src/create_pkg.c @@ -14,40 +14,49 @@ Pkg create_pkg(const char *arg, const char *target) { pkg.ver = "HEAD"; pkg.is_local = false; + char* argver = strchr(arg, '@'); + char* new_arg = strdup(arg); + if (argver) { + argver += 1; + pkg.ver = argver; + int char_location = 0; + while (arg[char_location] != '@') { char_location++; } + new_arg[char_location] = '\0'; + } + init_lua_state(); cache_repos(); bool is_in_repos = false; for (size_t i = 0; i < cached_repos_count; i++) { - if (strcmp(arg, cached_repos[i].source_key) == 0) { + if (strcmp(new_arg, cached_repos[i].source_key) == 0) { is_in_repos = true; break; } } - if (strncmp(arg, "http", 4) == 0) { - pkg.url = strdup(arg); - pkg.name = name_from_url(arg); - } else if (strcmp(arg, ".") == 0) { + if (strncmp(new_arg, "http", 4) == 0) { + pkg.url = strdup(new_arg); + pkg.name = name_from_url(new_arg); + } else if (strcmp(new_arg, ".") == 0) { pkg.url = ""; getcwd(pkg.src, MAX_PATH_LEN); pkg.name = name_from_url(pkg.src); pkg.is_local = true; } else if (is_in_repos) { for (size_t i = 0; i < cached_repos_count; i++) { - if (strcmp(arg, cached_repos[i].source_key) == 0) { + if (strcmp(new_arg, cached_repos[i].source_key) == 0) { pkg.url = strdup(cached_repos[i].source_value); break; } } - pkg.name = strdup(arg); + pkg.name = strdup(new_arg); } else { - printf("%s'%s' is not a valid package\n", print_error, arg); - exit(1); + printf("%s'%s' is not a valid package\n", print_error, new_arg); + exit(EXIT_FAILURE); } cache_install_directories(); - if (!pkg.is_local) { char src_dir[MAX_PATH_LEN]; snprintf(src_dir, sizeof(src_dir), "%s/%s/%s", get_install_dir("src"), pkg.name, pkg.ver); diff --git a/src/declare.c b/src/declare.c new file mode 100644 index 0000000..2ba42fb --- /dev/null +++ b/src/declare.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "declare.h" +#include "create_pkg.h" +#include "update_pkg.h" +#include "lua_state.h" + +void declare() { + init_lua_state(); + cache_repos(); + for (size_t i = 0; i < cached_repos_count; i++) { + Pkg pkg = create_pkg(cached_repos[i].source_value, "default"); + update_pkg(pkg); + } +} diff --git a/src/fetch_git.c b/src/fetch_git.c index 04f6428..85275d3 100644 --- a/src/fetch_git.c +++ b/src/fetch_git.c @@ -23,7 +23,6 @@ int fetch_git(Pkg pkg) { argv[i++] = pkg.url; argv[i++] = pkg.src; argv[i] = NULL; - execvp("git", (char *const *)argv); _exit(127); } @@ -31,7 +30,6 @@ int fetch_git(Pkg pkg) { int status; waitpid(pid, &status, 0); int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1; - if (result != 0) { printf("clone failed\n"); } diff --git a/src/fetch_src.c b/src/fetch_src.c index 044ef12..f05557a 100644 --- a/src/fetch_src.c +++ b/src/fetch_src.c @@ -22,23 +22,19 @@ static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, s void fetch_src(Pkg pkg) { printf("%starget source directory: %s\n", print_pkgit, pkg.src); - if (file_exists(pkg.src)) { printf("%s%s already exists. deleting...\n", print_pkgit, pkg.src); nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS); } - if (strcmp(pkg.url, "") == 0) { printf("%screating directory %s...\n", print_pkgit, pkg.src); mkdir_p(pkg.src); return; } - if (fetch_git(pkg) == 0) { printf("%scloned into %s...\n", print_pkgit, pkg.src); return; } - printf("%sno fetch methods worked.\n", print_error); exit(EXIT_FAILURE); }
\ No newline at end of file diff --git a/src/lua_state.c b/src/lua_state.c index 7ff8758..6d3d023 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -179,7 +179,6 @@ void cache_repos() { lua_pop(L, 1); return; } - lua_pushnil(L); while (lua_next(L, -2) != 0) { const char *repo_name = lua_tostring(L, -2); @@ -188,22 +187,18 @@ void cache_repos() { lua_pop(L, 1); continue; } - Repo *repo = &cached_repos[cached_repos_count]; repo->source_key = strdup(repo_name); - lua_getfield(L, -1, "url"); const char *url = lua_tostring(L, -1); repo->source_value = url ? strdup(url) : strdup(""); lua_pop(L, 1); - lua_getfield(L, -1, "dependencies"); if (!lua_istable(L, -1)) { lua_pop(L, 2); cached_repos_count++; continue; } - lua_pushnil(L); while (lua_next(L, -2) != 0) { const char *depname = lua_tostring(L, -2); @@ -211,11 +206,9 @@ void cache_repos() { lua_getfield(L, -1, "url"); const char *dep_url = lua_tostring(L, -1); lua_pop(L, 1); - lua_getfield(L, -1, "version"); const char *dep_version = lua_tostring(L, -1); lua_pop(L, 1); - Dependency *dep = realloc(repo->dependencies, (repo->dep_count + 1) * sizeof(Dependency)); if (dep) { repo->dependencies = dep; @@ -267,7 +260,6 @@ bool config_build(const char *path) { lua_pop(L, 1); return false; } - lua_pushnil(L); while (lua_next(L, -2) != 0) { const char *key = lua_tostring(L, -2); @@ -275,25 +267,21 @@ bool config_build(const char *path) { lua_pop(L, 1); continue; } - char file_path[MAX_PATH_LEN]; snprintf(file_path, sizeof(file_path), "%s/%s", path, key); if (access(file_path, F_OK) != 0) { lua_pop(L, 1); continue; } - lua_getfield(L, -1, "build"); if (!lua_isfunction(L, -1)) { lua_pop(L, 1); continue; } - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { lua_pop(L, 1); continue; } - lua_pop(L, 1); lua_pop(L, 1); return true; diff --git a/src/remove.c b/src/remove.c index ac8e8f9..1282d44 100644 --- a/src/remove.c +++ b/src/remove.c @@ -21,11 +21,12 @@ // FILE* file_ptr = fopen(dirent_ptr->d_name, "r"); // if (!file_ptr) { continue; } // if (strcmp(get_filename_ext(dirent_ptr->d_name), ".so") == 0) { -// remove(strcat(install_directories[], dirent_ptr->d_name)); -// } else if (!access(dir_entry.path().c_str(), X_OK) && !is_directory(dir_entry.path())) { -// std::filesystem::remove(install_directories["bin"]+"/"+dir_entry.path().filename().string()); -// } else if (dir_entry.path().extension() == ".h") { -// std::filesystem::remove(install_directories["include"]+"/"+dir_entry.path().filename().string()); +// remove(strcat(map_get(&cached_install_directories, "lib"), strcat("/", dirent_ptr->d_name))); +// } else if (!access(dirent_ptr->d_name, X_OK) && stat_buf.st_mode != S_IFDIR) { +// remove(strcat(map_get(&cached_install_directories, "bin"), strcat("/", dirent_ptr->d_name))); +// } else if (strcmp(get_filename_ext(dirent_ptr->d_name), ".h") == 0) { +// remove(strcat(map_get(&cached_install_directories, "include"), strcat("/", dirent_ptr->d_name))); +// } // } // } //} diff --git a/src/setup_dirs.c b/src/setup_dirs.c index c3ec272..413f02d 100644 --- a/src/setup_dirs.c +++ b/src/setup_dirs.c @@ -7,13 +7,12 @@ #include "vars.h" void setup_dirs() { - mkdir_p(config_dir); - - for (int i = 0; i < 5; i++) { - if (install_directories[i] && strlen(install_directories[i]) > 0) { - if (!file_exists(install_directories[i])) { - mkdir_p(install_directories[i]); - } - } + mkdir_p(config_dir); + for (int i = 0; i < 5; i++) { + if (install_directories[i] && strlen(install_directories[i]) > 0) { + if (!file_exists(install_directories[i])) { + mkdir_p(install_directories[i]); + } } + } }
\ No newline at end of file diff --git a/src/update_all.c b/src/update_all.c index 1018f65..ff0f54d 100644 --- a/src/update_all.c +++ b/src/update_all.c @@ -1,17 +1,34 @@ +#include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> #include "update_all.h" +#include "files.h" #include "create_pkg.h" #include "update_pkg.h" #include "lua_state.h" +#include "set_install_directories.h" +#include "vars.h" void update_all() { - init_lua_state(); - cache_repos(); - for (size_t i = 0; i < cached_repos_count; i++) { - Pkg pkg = create_pkg(cached_repos[i].source_value, "default"); - update_pkg(pkg); - } + init_lua_state(); + cache_repos(); + struct dirent* dirent_ptr; + DIR* dir_ptr; + if ((dir_ptr = opendir(src)) == NULL) { + fprintf(stderr, "%scould not open %s\n", print_pkgit, src); + } + while ((dirent_ptr = readdir(dir_ptr)) != NULL) { + if (strcmp(dirent_ptr->d_name, "..") == 0 || strcmp(dirent_ptr->d_name, ".") == 0) continue; + struct stat stat_buf; + FILE* file_ptr = fopen(dirent_ptr->d_name, "r"); + if (!file_ptr) { continue; } + Pkg pkg = create_pkg(dirent_ptr->d_name, "default"); + update_pkg(pkg); + } + closedir(dir_ptr); }
\ No newline at end of file @@ -23,7 +23,7 @@ char repo_file[MAX_PATH_LEN] = {0}; char bin[MAX_PATH_LEN] = {0}; char lib[MAX_PATH_LEN] = {0}; char inc[MAX_PATH_LEN] = {0}; -char pkgblds[MAX_PATH_LEN] = {0}; +char src[MAX_PATH_LEN] = {0}; char *install_directories[5] = {NULL}; @@ -151,13 +151,13 @@ void init_vars() { snprintf(bin, MAX_PATH_LEN, "%s/.local/bin", home_dir); snprintf(lib, MAX_PATH_LEN, "%s/.local/lib", home_dir); snprintf(inc, MAX_PATH_LEN, "%s/.local/include", home_dir); - snprintf(pkgblds, MAX_PATH_LEN, "%s/.local/share/pkgit", home_dir); + snprintf(src, MAX_PATH_LEN, "%s/.local/share/pkgit", home_dir); install_directories[0] = config_dir; - install_directories[1] = bin; - install_directories[2] = lib; - install_directories[3] = inc; - install_directories[4] = pkgblds; + install_directories[1] = strdup(get_install_dir("bin")); + install_directories[2] = strdup(get_install_dir("lib")); + install_directories[3] = strdup(get_install_dir("inc")); + install_directories[4] = strdup(get_install_dir("src")); static char print_pkgit_buf[256]; snprintf(print_pkgit_buf, sizeof(print_pkgit_buf), "%s[%s%s%s]\t%s", |
