diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/args.c | 33 | ||||
| -rw-r--r-- | src/args.h | 20 | ||||
| -rw-r--r-- | src/build.c | 82 | ||||
| -rw-r--r-- | src/build.h | 20 | ||||
| -rw-r--r-- | src/config.c | 53 | ||||
| -rw-r--r-- | src/config.h | 30 | ||||
| -rw-r--r-- | src/download.c | 36 | ||||
| -rw-r--r-- | src/download.h | 21 | ||||
| -rw-r--r-- | src/hash.c | 32 | ||||
| -rw-r--r-- | src/hash.h | 21 | ||||
| -rw-r--r-- | src/log.c | 52 | ||||
| -rw-r--r-- | src/log.h | 23 | ||||
| -rw-r--r-- | src/main.c | 30 | ||||
| -rw-r--r-- | src/package.c | 72 | ||||
| -rw-r--r-- | src/package.h | 27 | ||||
| -rw-r--r-- | src/package_list.c | 52 | ||||
| -rw-r--r-- | src/package_list.h | 24 | ||||
| -rw-r--r-- | src/paths.c | 30 | ||||
| -rw-r--r-- | src/paths.h | 24 | ||||
| -rw-r--r-- | src/pow_lua.c | 126 | ||||
| -rw-r--r-- | src/pow_lua.h | 25 | ||||
| -rw-r--r-- | src/repo.c | 59 | ||||
| -rw-r--r-- | src/repo.h | 27 | ||||
| -rw-r--r-- | src/source.c | 21 | ||||
| -rw-r--r-- | src/source.h | 21 | ||||
| -rw-r--r-- | src/utils.c | 21 | ||||
| -rw-r--r-- | src/utils.h | 21 |
27 files changed, 912 insertions, 91 deletions
@@ -1,4 +1,25 @@ +/* + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "args.h" +#include "log.h" #include "stdbool.h" #include "stdio.h" @@ -30,7 +51,7 @@ int pow_args_parse(int argc, char **argv, pow_args *args) { if (next_flag_config) { if (!strncmp(arg, "-", sizeof("-") - 1)) { - printf("Missing argument for -c\n"); + pow_log_error("Missing argument for -c"); return 1; } @@ -44,7 +65,7 @@ int pow_args_parse(int argc, char **argv, pow_args *args) { if (next_flag_package) { if (!strncmp(arg, "-", sizeof("-") - 1)) { - printf("Missing package argument\n"); + pow_log_error("Missing package argument"); return 1; } @@ -77,7 +98,7 @@ int pow_args_parse(int argc, char **argv, pow_args *args) { switch (c) { case 'S': { if (flags & POW_FLAG_SYNC) { - printf("flag double defined, skipping\n"); + pow_log_info("flag double defined, skipping"); } flags |= POW_FLAG_SYNC; @@ -87,7 +108,7 @@ int pow_args_parse(int argc, char **argv, pow_args *args) { }; case 'Q': { if (flags & POW_FLAG_QUERY) { - printf("flag double defined, skipping\n"); + pow_log_info("flag double defined, skipping"); } flags |= POW_FLAG_QUERY; @@ -98,7 +119,7 @@ int pow_args_parse(int argc, char **argv, pow_args *args) { } case 'I': { if (flags & POW_FLAG_INSTALL) { - printf("flag double defined, skipping\n"); + pow_log_info("flag double defined, skipping"); } flags |= POW_FLAG_INSTALL; @@ -115,7 +136,7 @@ int pow_args_parse(int argc, char **argv, pow_args *args) { } if (next_flag_config) { - printf("Missing argument for -c\n"); + pow_log_error("Missing argument for -c"); } if (!args->cfg_path) @@ -1,3 +1,23 @@ +/* + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "stddef.h" #define DEFAULT_CONFIG_PATH "/etc/pow/opts.lua" diff --git a/src/build.c b/src/build.c index 5558720..3df8148 100644 --- a/src/build.c +++ b/src/build.c @@ -1,6 +1,28 @@ +/* + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "build.h" #include "package.h" +#include "log.h" #include "paths.h" +#include "package_list.h" #include "download.h" #include "lauxlib.h" @@ -12,7 +34,7 @@ int pow_package_build(pow_package *pkg) { if (pkg->pkg_ref == LUA_NOREF) { - printf("error! pkg_ref is equal to LUA_NOREF\n"); + pow_log_error("error! pkg_ref is equal to LUA_NOREF"); return 1; } @@ -24,31 +46,79 @@ int pow_package_build(pow_package *pkg) { int err = pow_create_dir_for_package(&tmp_path); if (err) { - printf("error creating temp dir for package\n"); + pow_log_error("error creating temp dir for package"); return 1; } if ((err = chdir(tmp_path))) { - printf("uh oh oops %d\n", err); + pow_log_error("uh oh oops %d", err); return 1; } - printf("building package %s\n", pkg->name); + pow_log_info("building package %s", pkg->name); if (pow_download_source(pkg->sources[0], tmp_path)) { - printf("failed to get sources\n"); + pow_log_error("failed to get sources"); return 1; } lua_getfield(pkg->L, -1, "build"); + + if (lua_isnil(pkg->L, -1)) { + pow_log_error("invalid package schema, build is not defined"); + + lua_pop(pkg->L, 1); + + return 1; + } + + if (!lua_isfunction(pkg->L, -1)) { + pow_log_error("invalid package schema, build is not a function"); + + lua_pop(pkg->L, 1); + + return 1; + } + + if (lua_pcall(pkg->L, 0, 0, 0) != LUA_OK) { + free(tmp_path); + + pow_log_error("error running script: %s", lua_tostring(pkg->L, -1)); + + lua_pop(pkg->L, 1); + + return 1; + } + + lua_getfield(pkg->L, -1, "install"); + + if (lua_isnil(pkg->L, -1)) { + pow_log_error("invalid package schema, install is not defined"); + + lua_pop(pkg->L, 1); + + return 1; + } + + if (!lua_isfunction(pkg->L, -1)) { + pow_log_error("invalid package schema, install is not a function"); + + lua_pop(pkg->L, 1); + + return 1; + } + + pow_log_info("build finished, installing"); if (lua_pcall(pkg->L, 0, 0, 0) != LUA_OK) { free(tmp_path); - printf("error running script: %s\n", lua_tostring(pkg->L, -1)); + pow_log_error("error running script: %s", lua_tostring(pkg->L, -1)); + + lua_pop(pkg->L, 1); return 1; } diff --git a/src/build.h b/src/build.h index eea6c75..e8c46d3 100644 --- a/src/build.h +++ b/src/build.h @@ -1,3 +1,23 @@ +/* + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "package.h" int pow_package_build(pow_package *pkg); diff --git a/src/config.c b/src/config.c index d01499d..0f0c166 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,26 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "config.h" +#include "log.h" #include "lauxlib.h" #include "lualib.h" @@ -27,13 +49,13 @@ int pow_open_config(pow_config *cfg, char *path) { err = lua_pcall(L, 0, 1, 0); if (err) { - printf("%s\n", lua_tostring(L, -1)); + pow_log_error("%s\n", lua_tostring(L, -1)); return 1; } if (!lua_istable(L, -1)) { - printf("bad config. you must return a table.\n"); + pow_log_error("bad config. you must return a table.\n"); return 1; } @@ -42,7 +64,7 @@ int pow_open_config(pow_config *cfg, char *path) { // and push repos to -1 if (lua_istable(L, -1)) { - size_t repo_count = lua_rawlen(L, -1); + size_t repo_count = lua_objlen(L, -1); for (size_t i = 1; i <= repo_count; i++) { lua_rawgeti(L, -1, i); @@ -53,7 +75,7 @@ int pow_open_config(pow_config *cfg, char *path) { if (!repo) { lua_pop(L, 1); - printf("malloc for repo failed, what the fuck? something really bad " + pow_log_error("malloc for repo failed, what the fuck? something really bad " "happened i guess\n"); return 1; @@ -72,7 +94,7 @@ int pow_open_config(pow_config *cfg, char *path) { free(repo); - printf( + pow_log_error( "malloc for path failed, what the fuck? something really bad " "happened i guess\n"); @@ -81,7 +103,7 @@ int pow_open_config(pow_config *cfg, char *path) { repo->path = path_dup; } else { - printf("invalid (or non existent) path for repo\n"); + pow_log_error("invalid (or non existent) path for repo"); lua_pop(L, 1); lua_pop(L, 1); @@ -95,7 +117,7 @@ int pow_open_config(pow_config *cfg, char *path) { realloc(cfg->repos, (cfg->repos_count + 1) * sizeof(*repos)); if (!repos) { - printf("failed realloc! bad things coming\n"); + pow_log_error("failed realloc! bad things coming\n"); lua_pop(L, 1); lua_pop(L, 1); @@ -115,6 +137,22 @@ int pow_open_config(pow_config *cfg, char *path) { lua_pop(L, 1); } + + lua_pop(L, 1); + + lua_getfield(L, -1, "makeopts"); + + if (!lua_isstring(L, -1)) { + pow_log_info("no makeopts specified"); + } else { + cfg->makeopts = strdup(lua_tostring(L, -1)); + + if (!cfg->makeopts) { + pow_log_error("failed to strdup makeopts"); + + return 1; + } + } } return 0; @@ -127,6 +165,7 @@ int pow_close_config(pow_config *cfg) { } free(cfg->repos); + free(cfg->makeopts); lua_close(cfg->L); diff --git a/src/config.h b/src/config.h index e672267..3eb5dde 100644 --- a/src/config.h +++ b/src/config.h @@ -1,14 +1,42 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#ifndef POW_CONFIG_H +#define POW_CONFIG_H + #include "repo.h" #include "lua.h" #include <stddef.h> -typedef struct { +typedef struct pow_config { pow_repo **repos; size_t repos_count; + char *makeopts; + lua_State *L; } pow_config; int pow_open_config(pow_config *cfg, char *path); int pow_close_config(pow_config *cfg); + +#endif diff --git a/src/download.c b/src/download.c index 0554ee5..814fe36 100644 --- a/src/download.c +++ b/src/download.c @@ -1,4 +1,26 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "hash.h" +#include "log.h" #include "package.h" #include "curl/curl.h" @@ -17,7 +39,7 @@ int pow_download_file(char *path, char *url) { CURL *curl = curl_easy_init(); if (!curl) { - printf("failed to init curl\n"); + pow_log_error("failed to init curl"); return 1; } @@ -32,7 +54,7 @@ int pow_download_file(char *path, char *url) { pagefile = fopen(path, "wb"); if (!pagefile) { - printf("failed to open file to download\n"); + pow_log_error("failed to open file to download"); curl_easy_cleanup(curl); @@ -56,10 +78,10 @@ int pow_download_source(pow_package_source *src, const char *prefix) { snprintf(full_path, len, "%s/%s", prefix, src->out); - printf("downloading source file: %s", src->in); + pow_log_info("downloading source file: %s", src->in); if (pow_download_file(full_path, src->in)) { - printf("failed to download sources, aborting\n"); + pow_log_error("failed to download sources, aborting"); free(full_path); @@ -67,15 +89,15 @@ int pow_download_source(pow_package_source *src, const char *prefix) { } if (pow_check_blake2b_hash(full_path, src->hash)) { - printf("hash mismatch. something is going wrong with downloading the file " - "or it may be tampered with.\n"); + pow_log_error("hash mismatch. something is going wrong with downloading the file " + "or it may be tampered with."); free(full_path); return 1; } - printf("hash verification succeeded, going through."); + pow_log_info("hashes match, %s", src->hash); free(full_path); diff --git a/src/download.h b/src/download.h index 53b991e..a5e963a 100644 --- a/src/download.h +++ b/src/download.h @@ -1,3 +1,24 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "package.h" int pow_download_file(char *path, char *url); @@ -1,4 +1,26 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "hash.h" +#include "log.h" #include <blake2.h> #include <stdint.h> @@ -10,7 +32,7 @@ int pow_check_blake2b_hash(char *path, char *target_hash) { FILE *fp = fopen(path, "rb"); if (!fp) { - printf("failed to open file to check hash\n"); + pow_log_error("failed to open file to check hash"); return 1; } @@ -20,7 +42,7 @@ int pow_check_blake2b_hash(char *path, char *target_hash) { fseek(fp, 0, SEEK_SET); if (fsize < 0) { - printf("error: ftell\n"); + pow_log_error("error: ftell"); fclose(fp); @@ -33,13 +55,13 @@ int pow_check_blake2b_hash(char *path, char *target_hash) { buf = malloc((size_t)fsize); if (!buf) { - fprintf(stderr, "out of memory\n"); + pow_log_error("out of memory"); fclose(fp); return 1; } if (fread(buf, 1, (size_t)fsize, fp) != (size_t)fsize) { - fprintf(stderr, "read error\n"); + pow_log_error("read error"); free(buf); fclose(fp); return 1; @@ -50,7 +72,7 @@ int pow_check_blake2b_hash(char *path, char *target_hash) { uint8_t digest[BLAKE2B_OUTBYTES]; if (blake2b(digest, buf, NULL, BLAKE2B_OUTBYTES, (size_t)fsize, 0) != 0) { - fprintf(stderr, "blake2b failed\n"); + pow_log_error("blake2b failed"); free(buf); return 1; } @@ -1 +1,22 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + int pow_check_blake2b_hash(char *path, char *target_hash); diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..ed91161 --- /dev/null +++ b/src/log.c @@ -0,0 +1,52 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#include "stdio.h" +#include "stdarg.h" + +void pow_log_info(char* fmt, ...) { + va_list args; + + printf("\e[36m[pow!]\e[0m \e[1;37m[INFO]\e[0m "); + + va_start(args, fmt); + + vprintf(fmt, args); + + printf("\n"); + + va_end(args); +} + +void pow_log_error(char* fmt, ...) { + va_list args; + + printf("\e[36m[pow!]\e[0m \e[1;31m[ERROR]\e[0m "); + + va_start(args, fmt); + + vprintf(fmt, args); + + printf("\n"); + + va_end(args); +} + diff --git a/src/log.h b/src/log.h new file mode 100644 index 0000000..c15d112 --- /dev/null +++ b/src/log.h @@ -0,0 +1,23 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +void pow_log_info(char* fmt, ...); +void pow_log_error(char* fmt, ...); @@ -1,7 +1,29 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "args.h" #include "build.h" #include "config.h" #include "repo.h" +#include "log.h" #include "curl/curl.h" #include "stdio.h" @@ -27,15 +49,15 @@ int main(int argc, char *argv[]) { pow_open_config(&config, args.cfg_path); if (args.flags & POW_FLAG_QUERY) { - pow_repo_check_package(config.repos, config.repos_count, args.package); + pow_repo_check_package(&config, args.package); } if (args.flags & POW_FLAG_SYNC) { pow_package *pkg = malloc(sizeof(pow_package)); - if (pow_repo_get_package(config.repos, config.repos_count, pkg, + if (pow_repo_get_package(&config, pkg, args.package)) { - printf("error getting package\n"); + pow_log_error("failed to get package"); return 1; } @@ -46,7 +68,7 @@ int main(int argc, char *argv[]) { } if (args.flags == 0) { - printf("no command specified\n"); + pow_log_error("no command specified"); } pow_close_config(&config); diff --git a/src/package.c b/src/package.c index 6aeee65..9c538f7 100644 --- a/src/package.c +++ b/src/package.c @@ -1,3 +1,24 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "package.h" #include "lauxlib.h" @@ -6,13 +27,14 @@ #include "pow_lua.h" #include "stdio.h" #include "string.h" +#include "log.h" #include <lua.h> -int extract_package_info(lua_State *L, pow_package *pkg) { +int pow_extract_package_info(lua_State *L, pow_package *pkg) { lua_getfield(L, -1, "name"); if (!lua_isstring(L, -1)) { - printf("invalid package, name is not string (or doesn't exist)\n"); + pow_log_error("invalid package, name is not string (or doesn't exist)"); return 1; } @@ -20,7 +42,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { pkg->name = strdup(lua_tostring(L, -1)); if (!pkg->name) { - printf("strdup failed trying to get package name\n"); + pow_log_error("strdup failed trying to get package name"); return 1; } @@ -32,7 +54,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { if (!lua_isstring(L, -1)) { free(pkg->name); - printf("invalid package, version is not string (or doesn't exist)\n"); + pow_log_error("invalid package, version is not string (or doesn't exist)"); return 1; } @@ -44,7 +66,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { if (!pkg->version) { free(pkg->name); - printf("strdup failed trying to get package name\n"); + pow_log_error("strdup failed trying to get package name"); return 1; } @@ -55,14 +77,14 @@ int extract_package_info(lua_State *L, pow_package *pkg) { free(pkg->name); free(pkg->version); - printf("sources is not table or doesn't exist\n"); + pow_log_error("sources is not table or doesn't exist"); return 1; } - size_t sources_len = lua_rawlen(L, -1); + size_t sources_len = lua_objlen(L, -1); - for (size_t i = 0; i < sources_len; i++) { + for (size_t i = 0; i < sources_len; i++) { lua_pushinteger(L, i + 1); lua_gettable(L, -2); @@ -75,7 +97,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { pow_package_source *src = malloc(sizeof(pow_package_source)); if (!src) { - printf("failed to malloc pow_package_source\n"); + pow_log_error("failed to malloc pow_package_source\n"); return 1; } @@ -83,7 +105,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { if (!lua_isstring(L, -1)) { lua_pop(L, 1); - printf("path is not string\n"); + pow_log_error("path is not string"); return 1; } @@ -91,7 +113,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { const char *in = strdup(lua_tostring(L, -1)); if (!in) { - printf("failed to strdup path?"); + pow_log_error("failed to strdup path?"); return 1; } @@ -105,7 +127,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { if (!lua_isstring(L, -1)) { lua_pop(L, 1); - printf("out is not string\n"); + pow_log_error("out is not string"); return 1; } @@ -117,7 +139,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { lua_pop(L, 1); - printf("out strdup failed?\n"); + pow_log_error("out strdup failed?"); return 1; } @@ -132,7 +154,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { free(in); free(out); - printf("hash is not string?\n"); + pow_log_error("hash is not string?"); return 1; } @@ -143,7 +165,7 @@ int extract_package_info(lua_State *L, pow_package *pkg) { free(in); free(out); - printf("failed to strdup hash\n"); + pow_log_error("failed to strdup hash"); return 1; } @@ -158,15 +180,15 @@ int extract_package_info(lua_State *L, pow_package *pkg) { pkg->sources[pkg->source_count - 1] = src; lua_pop(L, 1); - lua_pop(L, 1); } lua_pop(L, 1); - + lua_pop(L, 1); + return 0; } -int pow_package_open(pow_package *pkg, const char *path) { +int pow_package_open(pow_package *pkg, pow_config *cfg, const char *path) { FILE *fp; int c; int err; @@ -174,7 +196,7 @@ int pow_package_open(pow_package *pkg, const char *path) { fp = fopen(path, "r"); if (!fp) { - printf("error opening package definition, doesn't exist?\n"); + pow_log_error("error opening package definition, doesn't exist?"); return 1; } @@ -194,12 +216,12 @@ int pow_package_open(pow_package *pkg, const char *path) { fclose(fp); free(package_buffer); - printf("failed to realloc package buffer\n"); + pow_log_error("failed to realloc package buffer"); return 1; } - printf("reallocated package buffer due to size constraints\n"); + pow_log_info("reallocated package buffer due to size constraints"); package_buffer = tmp; } @@ -216,7 +238,7 @@ int pow_package_open(pow_package *pkg, const char *path) { pkg->L = L; luaL_openlibs(L); - pow_lua_load(L); + pow_lua_load(L, cfg); luaL_loadstring(L, package_buffer); @@ -225,13 +247,13 @@ int pow_package_open(pow_package *pkg, const char *path) { free(package_buffer); if (err) { - printf("%s\n", lua_tostring(L, -1)); + pow_log_error("%s", lua_tostring(L, -1)); return 1; } if (!lua_istable(L, -1)) { - printf("invalid package, scripts must return table\n"); + pow_log_error("invalid package, scripts must return table"); return 1; } @@ -239,7 +261,7 @@ int pow_package_open(pow_package *pkg, const char *path) { pkg->source_count = 0; pkg->sources = NULL; - extract_package_info(L, pkg); + pow_extract_package_info(L, pkg); pkg->path = path; pkg->pkg_ref = luaL_ref(L, LUA_REGISTRYINDEX); diff --git a/src/package.h b/src/package.h index c52a4a6..fa592df 100644 --- a/src/package.h +++ b/src/package.h @@ -1,3 +1,24 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #ifndef POW_PACKAGE_H #define POW_PACKAGE_H @@ -6,6 +27,8 @@ #include "source.h" +typedef struct pow_config pow_config; + typedef struct { const char *name; const char *version; @@ -16,6 +39,8 @@ typedef struct { pow_package_source **sources; size_t source_count; + struct pow_package **deps; + size_t *arch; lua_State *L; @@ -23,7 +48,7 @@ typedef struct { int pkg_ref; } pow_package; -int pow_package_open(pow_package *pkg, const char *path); +int pow_package_open(pow_package *pkg, pow_config *cfg, const char *path); int pow_package_close(pow_package *pkg); #endif diff --git a/src/package_list.c b/src/package_list.c new file mode 100644 index 0000000..54cc9e6 --- /dev/null +++ b/src/package_list.c @@ -0,0 +1,52 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#include "package_list.h" +#include "paths.h" +#include "log.h" +#include "stdio.h" +#include "stdlib.h" + +int pow_get_package_list(pow_package **pkgs) { + FILE* file = fopen("/etc/pow/world", "r"); + + if (!file) { + pow_log_error("failed to open world file\n"); + + return 1; + } + + char *line = malloc(64); + + if (!line) { + pow_log_error("failed to malloc line while reading world file\n"); + + return 1; + } + + while (fgets(line, 63, file)) { + printf("%s", line); + } + + free(line); + + fclose(file); +} diff --git a/src/package_list.h b/src/package_list.h new file mode 100644 index 0000000..c7da692 --- /dev/null +++ b/src/package_list.h @@ -0,0 +1,24 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#include "package.h" + +int pow_get_package_list(pow_package **pkgs); diff --git a/src/paths.c b/src/paths.c index b8d7cd5..d3108b8 100644 --- a/src/paths.c +++ b/src/paths.c @@ -1,4 +1,26 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "paths.h" +#include "log.h" #include "errno.h" #include "stdio.h" @@ -7,12 +29,12 @@ #include "sys/stat.h" #include "unistd.h" -char template[] = "/tmp/pow/XXXXXX"; +char template[] = "/var/tmp/pow/XXXXXX"; int pow_create_dir_for_package(char **path) { - if (mkdir("/tmp/pow", 0700)) { + if (mkdir("/var/tmp/pow", 0700)) { if (errno != EEXIST) { - printf("failed to create temp dir\n"); + pow_log_error("failed to create temp dir\n"); return 1; } @@ -27,7 +49,7 @@ int pow_create_dir_for_package(char **path) { strcpy(new_path, template); if (!mkdtemp(new_path)) { - printf("failed to make dir\n"); + pow_log_error("failed to make dir\n"); free(new_path); return 1; diff --git a/src/paths.h b/src/paths.h index 5f77932..0c7c295 100644 --- a/src/paths.h +++ b/src/paths.h @@ -1 +1,25 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#define POW_PREFIX "/etc/pow" +#define POW_WORLD_PATH POW_PREFIX/world + int pow_create_dir_for_package(char **path); diff --git a/src/pow_lua.c b/src/pow_lua.c index 7cf14b4..1d2f81a 100644 --- a/src/pow_lua.c +++ b/src/pow_lua.c @@ -1,10 +1,36 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "pow_lua.h" +#include "config.h" +#include "log.h" #include "archive.h" +#include "stdio.h" #include "archive_entry.h" #include "lauxlib.h" #include "stdlib.h" +#include "unistd.h" #include "string.h" +#include "sys/sendfile.h" int pow_lua_extract(lua_State *L) { int r; @@ -45,9 +71,9 @@ int pow_lua_extract(lua_State *L) { if (r == ARCHIVE_EOF) break; if (r < ARCHIVE_OK) - printf("warn while unpacking: %s\n", archive_error_string(a)); + pow_log_info("warn while unpacking: %s", archive_error_string(a)); if (r < ARCHIVE_WARN) { - printf("error while unpacking: %s\n", archive_error_string(a)); + pow_log_error("error while unpacking: %s", archive_error_string(a)); lua_pop(L, 1); @@ -58,7 +84,7 @@ int pow_lua_extract(lua_State *L) { if (!error_msg) { lua_pushstring(L, "error while unpacking and failed to malloc to push " "real error message"); - printf("error while unpacking and failed to push real error message\n"); + pow_log_error("error while unpacking and failed to push real error message"); return 2; } @@ -119,11 +145,101 @@ int pow_lua_extract(lua_State *L) { return 1; } -luaL_Reg libpow[] = {{"extract", pow_lua_extract}, {NULL, NULL}}; -int pow_lua_load(lua_State *L) { +int pow_lua_install(lua_State *L) { + if (!lua_isstring(L, 1)) { + lua_pushnil(L); + lua_pushstring(L, "arg 1 must be string (src)"); + + return 2; + } + + if (!lua_isstring(L, 2)) { + lua_pushnil(L); + lua_pushstring(L, "arg 2 must be string (dest)"); + + return 2; + } + + char *src = strdup(lua_tostring(L, 1)); + + if (!src) { + pow_log_error("failed to strdup source string"); + + return 2; + } + + char *dest = strdup(lua_tostring(L, 2)); + + if (!dest) { + free(src); + + pow_log_error("failed to strdup dest string"); + + return 2; + } + + pow_log_info("installing: %s to %s", src, dest); + + FILE *src_stream = fopen(src, "r"); + + if (!src_stream) { + free(src); + free(dest); + + pow_log_error("failed to open source file %s while installing", src); + + return 2; + } + + FILE *dest_stream = fopen(dest, "w"); + + if (!dest_stream) { + free(src); + free(dest); + + fclose(src_stream); + + pow_log_error("failed to open destination file %s for writing while installing", dest); + + return 2; + } + + int src_fd = fileno(src_stream); + int dest_fd = fileno(dest_stream); + + struct stat src_stat = {0}; + int result = fstat(src_fd, &src_stat); + + off_t copied = 0; + while (result == 0 && copied < src_stat.st_size) { + ssize_t written = sendfile(dest_fd, src_fd, &copied, SIZE_MAX); + copied += written; + + if (written == -1) { + result = -1; + } + } + + if (fchmod(dest_fd, src_stat.st_mode) == -1) { + pow_log_error("failed to set permission bits, expect breakage!"); + } + + return 1; +} + +luaL_Reg libpow[] = {{"extract", pow_lua_extract}, {"install", pow_lua_install}, {NULL, NULL}}; + +int pow_lua_load(lua_State *L, pow_config *cfg) { luaL_newlib(L, libpow); + lua_createtable(L, 0, 1); + + lua_pushstring(L, cfg->makeopts); + lua_setfield(L, -2, "makeopts"); + + lua_setfield(L, -2, "config"); + lua_setglobal(L, "pow"); return 0; diff --git a/src/pow_lua.h b/src/pow_lua.h index 2196ae9..af3f987 100644 --- a/src/pow_lua.h +++ b/src/pow_lua.h @@ -1,3 +1,26 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "lua.h" -int pow_lua_load(lua_State *L); +typedef struct pow_config pow_config; + +int pow_lua_load(lua_State *L, pow_config *cfg); @@ -1,4 +1,27 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "repo.h" +#include "config.h" +#include "log.h" #include "dirent.h" #include "limits.h" @@ -7,10 +30,10 @@ #include "stdio.h" #include <lua.h> -int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, +int pow_repo_get_package(pow_config *cfg, pow_package *pkg, const char *query) { - if (!repos) { - printf("no repos defined in your config, please define them\n"); + if (!cfg->repos) { + pow_log_error("no repos defined in your config, please define them"); return 1; } @@ -18,21 +41,21 @@ int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, DIR *dp; struct dirent *ep; - for (size_t i = 0; i < repo_count; i++) { + for (size_t i = 0; i < cfg->repos_count; i++) { char *package_path = malloc(PATH_MAX); if (!package_path) { - printf("failed to allocate package_path, sizeof %d\n", PATH_MAX); + pow_log_error("failed to allocate package_path, sizeof %d", PATH_MAX); return 1; } int written = - snprintf(package_path, PATH_MAX, "%s/%s", repos[i]->path, query); + snprintf(package_path, PATH_MAX, "%s/%s", cfg->repos[i]->path, query); if (written >= PATH_MAX) { - printf("something went seriously wrong. the path for the package %s is " - "too long?\n", + pow_log_error("something went seriously wrong. the path for the package %s is " + "too long?", query); free(package_path); @@ -48,14 +71,14 @@ int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, continue; } - printf("found package %s in repo %s\n", query, repos[i]->path); + pow_log_info("found package %s in repo %s", query, cfg->repos[i]->path); char *full_path = malloc(PATH_MAX); if (!full_path) { free(package_path); - printf("failed to malloc full path for build script\n"); + pow_log_error("failed to malloc full path for build script"); return 1; } @@ -63,9 +86,9 @@ int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, written = snprintf(full_path, PATH_MAX, "%s/%s", package_path, "build.lua"); if (written >= PATH_MAX) { - printf("something went seriously wrong. the path for the package build " + pow_log_error("something went seriously wrong. the path for the package build " "script %s is " - "too long?\n", + "too long?", query); free(package_path); @@ -76,29 +99,31 @@ int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, free(package_path); - pow_package_open(pkg, full_path); + pow_package_open(pkg, cfg, full_path); free(full_path); closedir(dp); + + return 0; } - return 0; + return 1; } -int pow_repo_check_package(pow_repo **repos, size_t repo_count, +int pow_repo_check_package(pow_config *cfg, const char *query) { int err; pow_package *pkg = malloc(sizeof(pow_package)); if (!pkg) { - printf("failed to malloc pow_package\n"); + pow_log_error("failed to malloc pow_package"); return 1; } - err = pow_repo_get_package(repos, repo_count, pkg, query); + err = pow_repo_get_package(cfg, pkg, query); if (err) { return 1; @@ -1,9 +1,32 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #ifndef _POW_REPO_H #define _POW_REPO_H #include "package.h" #include "stddef.h" +typedef struct pow_config pow_config; + #define POW_X86_64 1 #define POW_ARM 2 @@ -11,10 +34,10 @@ typedef struct { const char *path; } pow_repo; -int pow_repo_check_package(pow_repo **repos, size_t repo_count, +int pow_repo_check_package(pow_config *cfg, const char *query); -int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, +int pow_repo_get_package(pow_config *cfg, pow_package *pkg, const char *query); #endif diff --git a/src/source.c b/src/source.c index 5b6aa9b..0a7543d 100644 --- a/src/source.c +++ b/src/source.c @@ -1,3 +1,24 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "source.h" #include "stdlib.h" diff --git a/src/source.h b/src/source.h index 84dad4b..820c176 100644 --- a/src/source.h +++ b/src/source.h @@ -1,3 +1,24 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #ifndef POW_SOURCE_H #define POW_SOURCE_H diff --git a/src/utils.c b/src/utils.c index 19dc193..aba4b14 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,3 +1,24 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "utils.h" #include "string.h" diff --git a/src/utils.h b/src/utils.h index 1c5163b..dcee5db 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,3 +1,24 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "stdbool.h" bool string_has_prefix(const char *pre, const char *str); |
