diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | LICENSE | 340 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README.md | 29 | ||||
| -rw-r--r-- | config.lua.example | 2 | ||||
| -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 |
32 files changed, 1277 insertions, 100 deletions
@@ -1,3 +1,4 @@ pow compile_commands.json out +*.swp @@ -1,7 +1,339 @@ -Copyright © 2026 foreverk238 <forever2k38@disroot.org> + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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/>. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Moe Ghoul>, 1 April 1989 + Moe Ghoul, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -6,7 +6,7 @@ RM = rm -rf CFLAGS=-Wall -Wpedantic -LIBFLAGS=$(shell pkg-config --cflags --libs lua5.5) $(shell pkg-config --cflags --libs libarchive) $(shell pkg-config --cflags --libs libcurl) $(shell pkg-config --cflags --libs libb2) +LIBFLAGS=$(shell pkg-config --cflags --libs luajit) $(shell pkg-config --cflags --libs libarchive) $(shell pkg-config --cflags --libs libcurl) $(shell pkg-config --cflags --libs libb2) DEBUG_CFLAGS=-g -fsanitize=leak SRC_DIR=src @@ -1,14 +1,35 @@  +## what is pow? + pow! is a versatile, source based package manager made by [the einfach linux team](https://einfach.forever2k38.net). -It is primarily used in [einfach linux](https://einfach.forever2k38.net). +It is primarily used in [einfach linux](https://einfach.forever2k38.net) itself. + +## why + +pow! was built to accommodate the needs of einfach linux. however, it is very versatile and may be used outside of einfach linux (this is, of course, unsupported). + +## compilation + +`make` + +I know, very hard. + +## usage + + +### for users + +Install a package: `pow -S dev-lang/luajit` + +Query information about a package `pow -Q dev-lang/luajit` -## package schemas +### for package maintainers -Package schemas (our equivalent of PKGBUILDs) are written in [Lua](https://lua.org). Lua is a simple and fast embedded scripting language. +docs for package maintainers aren't available yet, hold on tight! ## license -This project is licensed under the MIT license. Please see the LICENSE file in this repository. +This project is licensed under the GPLv2 license ONLY. Later versions of the GPL are NOT ALLOWED. Please see the LICENSE file in this repository. diff --git a/config.lua.example b/config.lua.example index d3b21dc..2aa79e4 100644 --- a/config.lua.example +++ b/config.lua.example @@ -6,4 +6,6 @@ config.repos = { }, } +config.makeopts = "-j12" + return config @@ -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); |
