aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordacctal <dacctal@symlinx.net>2026-06-22 07:33:06 +0000
committerdacctal <dacctal@symlinx.net>2026-06-22 07:33:06 +0000
commita18b7108f1648dc69e06bb21e84ec48a2dd60f60 (patch)
tree1693a64a18913d751b0e9a23609218bf0d24f01c
parent7cde9aeb5dccce578c1eed13cf1ed2c61e446800 (diff)
command line args are much nicer, and versions are properly disciplined1.0.0
-rw-r--r--README.md210
-rw-r--r--TODO.md2
-rw-r--r--bldit.lua12
-rw-r--r--config/init.lua258
-rw-r--r--include/is_updated.h1
-rw-r--r--include/lua_state.h4
-rw-r--r--include/vars.h1
-rw-r--r--src/build.c2
-rw-r--r--src/cla_parse.c22
-rw-r--r--src/create_pkg.c2
-rw-r--r--src/help.c26
-rw-r--r--src/is_updated.c32
-rw-r--r--src/lua_build.c2
-rw-r--r--src/lua_state.c107
-rw-r--r--src/set_install_directories.c1
-rw-r--r--src/update_pkg.c3
-rw-r--r--src/vars.c1
17 files changed, 449 insertions, 237 deletions
diff --git a/README.md b/README.md
index f860000..1d3a2ab 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ make
## Using pkgit
```
-pkgit build
+pkgit --build
```
Both methods will create an executable in the root directory of the project.
@@ -51,9 +51,34 @@ make install PREFIX="~/.local"
```
# Usage
+## Command Syntax
+The structure in which you type commands into pkgit is very standard:
+```
+pkgit [--flag|-f] <package>
+```
+
+Flags have two types; long, and short.
+The short type of each command uses the first letter of its long counterpart.
+For example:
+Long: `pkgit --install`
+Short: `pkgit -i`
+
+If you use the short version of commands,
+you can chain them together into one argument:
+```
+pkgit -qif <package>
+```
+
+This example uses the `--quiet`, `--install`, and `--force` flags to:
+ --quiet: minimize logs to stdout
+ --install: install a package
+ --force: even if already installed, will force the package to be installed
+
## Installing Packages
### Pre-installation
-Before you use any programs that you installed with pkgit, you need to specify the path of the binaries in your shell's configuration.
+Before you use any programs that you installed with pkgit,
+you need to specify the path of the binaries in your shell's configuration.
+
For most users, this is the command:
```sh
export PATH="$HOME/.local/bin:$PATH"
@@ -70,199 +95,100 @@ setenv PATH $HOME/.local/bin:$PATH
### Basic install
Assuming you have already added its respective repo, you can install a package by specifying its name:
```
-pkgit install [pkg_name]
+pkgit --install [pkg_name]
```
Or you can use the short command:
```
-pkgit i [pkg_name]
+pkgit -i [pkg_name]
```
### Specific version install
You can specify a version of any package based on its tags with '@' separating the name from the version:
```
-pkgit install [pkg_name]@[version]
+pkgit --install [pkg_name]@[version]
```
### Specific target install
You can specify a target of any package based on its configuration in bldit.lua or init.lua with ',' separating the name from the target:
```
-pkgit install [pkg_name],[target]
+pkgit --install [pkg_name],[target]
```
### Combined target and version install
You can specify both the target and the version of any package you install in the same command (order does not matter as long as the package name is first):
```
-pkgit install [pkg_name],[target]@[version]
+pkgit --install [pkg_name],[target]@[version]
```
```
-pkgit install [pkg_name]@[version],[target]
+pkgit --install [pkg_name]@[version],[target]
```
### Repo install
If you haven't added the package's repository yet, or you just want to be specific, you can install the package using its git URL:
```
-pkgit install [url.git]
+pkgit --install [url.git]
```
This also works with the target and version syntax.
### Local install
If you want to install a package from a local code repository, and want to take advantage of pkgit's build system autodetection, you can enter that repository's root directory and install it from there:
```
-pkgit install .
+pkgit --install .
```
## Building packages
*FOR DEVELOPERS*
You can also use pkgit as a sort of meta-build-system to automatically compile any supported project with the build command:
```
-pkgit build [/path/to/project]
+pkgit --build [/path/to/project]
```
This can also be done without specifying the path (`pkgit build`) if you're in the project's root directory
## Removing Packages
Removing (uninstalling) a package is as simple as it seems:
```
-pkgit remove [pkg_name]
+pkgit --remove [pkg_name]
```
Or the short command:
```
-pkgit r [pkg_name]
+pkgit -r [pkg_name]
```
## Updating Packages
You can easily update your installed packages by running:
```
-pkgit update
+pkgit --update
```
Or the short command:
```
-pkgit u
+pkgit -u
```
## Declaring Packages
If you prefer a declarative approach, you can use the config file (read below) as a package declaration file.
When you're ready, you can declare all your packages at once with:
```
-pkgit declare
+pkgit --declare
```
Or the short command:
```
-pkgit d
+pkgit -d
```
## Dependency Management
-As it is, pkgit is capable of dependency management, but you will likely have to specify the dependency URLs for each package you install in `<config_directory>/pkgit/init.lua`. There's not a universal way to check for dependencies without using an existing package manager (unless the package you're installing has a bldit.lua).
+As it is, pkgit is capable of dependency management, but you will likely have to specify the dependency URLs for each package you install in `<config_directory>/pkgit/init.lua`.
+There's not a universal way to check for dependencies without using an existing package manager (unless the package you're installing has a bldit.lua).
-### Configuring pkgit
+## Configuring pkgit
Thankfully, this is a very simple process.
To configure pkgit, you have one centralized configuration file: `<config_directory>/pkgit/init.lua`
Thanks to liblua, pkgit pushes a package.path variable directly to your configuration file.
This means that you can require any sub-file/directory, without wrestling with `require()`.
-The overall structure of the configuration file looks like this:
-```lua
---[[
-- install directories -
-this is where every package you
-get with pkgit is installed,
-with respect to each of it's
-files' types:
-
-install_directories = {
- bin = "...",
- include = "...",
- lib = "...",
- src = "...",
-}
-
-it is recommended that you create
-a prefix variable to prepend to
-these directories, like so:
-]]
-local prefix = os.getenv("HOME").."/.local" -- for user-level installs
-install_directories = {
- bin = prefix.."/bin",
- include = prefix.."/include",
- lib = prefix.."/lib",
- src = prefix.."/src",
-}
-
---[[
-- your repositories -
-this is where you store your
-own custom urls, dependencies,
-and functions to install
-whatever programs you desire.
-]]
-repositories = {
- example_name = {
- url = "https://...",
- version = "v0.0.0", -- can be a tag or branch
- dependencies = {
- ...
- },
- build = function() ... end
- pre_install = function() ... end
- install = function() ... end
- post_install = function() ... end
- uninstall = function() ... end
- }
-}
---[[
-pkgit also creates a 'repos.lua' file in
-your config directory, which you can
-require here to automatically add repos
-that you install from.
-]]
-require('repos')
-
---[[
-- standard build systems -
-will be auto-detected if required
-functions aren't in 'repositories'
-or a repo's 'bldit.lua'
-]]
-build_systems = {
- ["filename.extension"] = {
- build = function() ... end
- pre_install = function() ... end
- install = function() ... end
- post_install = function() ... end
- uninstall = function() ... end
- }
-}
-```
-
-For each dependency, all you need to do is paste the dependency's remote git URL in its own url variable.
-
-Here's an example for mush:
-```lua
-repositories = {
- mush = {
- url = "https://github.com/dacctal/mush",
- dependencies = {
- mpv = { url = "https://github.com/mpv-player/mpv" },
-
- ["yt-dlp"] = { url = "https://github.com/yt-dlp/yt-dlp" },
- --[[
- for dependencies with names that contain illegal
- characters in lua, you'll want to wrap them in
- [""] to avoid problems.
- ]]
-
- ffmpeg = { url = "https://github.com/FFmpeg/FFmpeg" },
- curl = { url = "https://github.com/curl/curl" },
- mutagen = { url = "https://github.com/quodlibet/mutagen" }
- }
- }
-}
-```
-
-That's it! pkgit will read from this file and resolve these
-dependencies automatically.
-
-### [DEVELOPER]: bldit.lua
+The overall structure of the configuration file is explained in detail in `config/init.lua`
+
+## [DEVELOPER]: bldit.lua
If you want your own package's dependencies, version, compilation,
and other aspects to be properly resolved in pkgit, you can create a
`bldit.lua` file in the root directory of your project's git repo.
@@ -270,44 +196,8 @@ and other aspects to be properly resolved in pkgit, you can create a
Do not name it anything other than `bldit.lua`, otherwise pkgit
will not find the file.
-> [!WARNING]
-> Recursive dependency management does NOT work in pkgit, so you may want to list your dependencies accordingly.
-
-Example `bldit.lua` that works for pkgit:
-```lua
-bldit_version = "0.0.0"
-package_version = "0.0.0"
---[[
-versions have to be strings,
-because some devs like to
-have fun and whimsical
-version numbers :D
-]]
-
-global_dependencies = {}
--- dependencies for all targets
-
-targets = {
- default = {
- dependencies = {},
- -- target-specific dependencies
- build = function(name)
- os.execute("make")
- end,
- pre_install = function() end,
- install = function(prefix)
- os.execute("make install")
- end,
- post_install = function() end,
- uninstall = function() end,
- }
- --[[
- could also have targets for 'client'
- or 'server.' useful for monorepos
- and related use-cases.
- ]]
-}
-```
+A great example for `bldit.lua` is right here in the pkgit repository!
+Check it out if you want to know how it's structured.
# Contributing to pkgit
If you want to contribute to pkgit, please refer to CONTRIBUTING.md
diff --git a/TODO.md b/TODO.md
index d353f95..4bae78f 100644
--- a/TODO.md
+++ b/TODO.md
@@ -11,6 +11,6 @@
- [x] lua dependency listing
- [x] version management
- [x] lua uninstall function
+- [-] git commit signature checks
- [ ] (maybe) lua custom install methods for sandboxed builds
- [ ] (maybe) install to store directory
-- [ ] (maybe) git commit signature checks
diff --git a/bldit.lua b/bldit.lua
index 9967448..d2b503b 100644
--- a/bldit.lua
+++ b/bldit.lua
@@ -17,24 +17,24 @@ global_dependencies = {
targets = {
default = {
build = function()
- os.execute("make")
+ return os.execute("make")
end,
install = function()
- os.execute("make install")
+ return os.execute("make install PREFIX="..prefix)
end,
uninstall = function()
- os.execute("make uninstall")
+ return os.execute("make uninstall PREFIX="..prefix)
end,
},
quiet = {
build = function()
- local output = io.popen("make"):read("*a")
+ return os.execute("make &>/tmp/pkgit_build.log")
end,
install = function()
- local output = io.popen("make install"):read("*a")
+ return os.execute("make install PREFIX="..prefix.." &>/tmp/pkgit_build.log")
end,
uninstall = function()
- local output = io.popen("make uninstall"):read("*a")
+ return os.execute("make uninstall PREFIX="..prefix.." &>/tmp/pkgit_build.log")
end,
},
}
diff --git a/config/init.lua b/config/init.lua
index f3c36d5..ee885aa 100644
--- a/config/init.lua
+++ b/config/init.lua
@@ -1,45 +1,247 @@
+--[[ introduction
+
+ this is the pkgit configuration template.
+ every configuration file is written in lua,
+ the embeddable high-level programming language.
+
+ for info on how to write lua, check out
+ this website for documentation:
+ https://www.lua.org/pil/contents.html
+
+ all variables that are
+ set by default are designed to
+ work out of the box. be sure to
+ keep the global variables global,
+ as they need to be global in
+ order for them to work with
+ each other effectively.
+
+ `local install_directories`, for
+ example, will not work well in
+ most cases.
+
+]]
+
+--[[ prefix
+
+ the prefix variable is necessary
+ for custom install paths, which
+ bldit maintainers should be
+ respecting with their recipes.
+
+ if you want to install packages
+ without root, it's easist to
+ create a home variable and
+ append that to your prefix.
+
+]]
local home = os.getenv("HOME")
-local prefix = home.."/.local"
+prefix = home.."/.local"
+
+--[[ install_directories
+
+ install_directories is an essential
+ table that pkgit needs in order to
+ function. this is how it determines
+ where you install your packages to.
+
+ it's most convenient when combined
+ with `prefix` which allows for a
+ more dynamic definition of your
+ install directories.
+
+]]
install_directories = {
- bin = prefix.."/bin",
- include = prefix.."/include",
- lib = prefix.."/lib",
- src = prefix.."/share/pkgit",
+ bin = prefix.."/bin", -- binaries (executables)
+ -- the value of `bin` should also be set in your shell's $PATH
+ include = prefix.."/include", -- C headers
+ lib = prefix.."/lib", -- libraries (shared objects)
+ src = prefix.."/share/pkgit", -- source code
}
+--[[ repositories
+
+ this is where all your repos need to
+ end up. every repo has a name, which
+ can be written out normally
+ (`name = {...}`), or for some repos,
+ it might be necessary to wrap it in
+ quotes (`["name"] = {...}`).
+ that name can be used in a pkgit
+ command to be installed.
+ ( `pkgit --install [repo]` )
+
+ each of these repos must be structured
+ as a lua table. the structure is
+ demonstrated below.
+
+]]
repositories = {
pkgit = {
url = "https://git.symlinx.net/pkgit",
+ --[[ repo example
+
+ no targets table or dependencies are actually needed in
+ this specific case, pkgit has a bldit.lua which guarantees
+ that it will compile & install (as long as `install_directories`
+ and `prefix` are set up).
+
+ if you do make a targets table here, it will take priority
+ over the bldit.lua in the repo, and your build system
+ autodetection config ( `build_systems = {...}` )
+
+ more about `targets` in the global `build_systems` table.
+
+ ]]
+ --dependencies = {
+ -- name = {
+ -- url = {...},
+ -- version = "...",
+ -- target = "...",
+ -- },
+ --},
+ --targets = {
+ -- default = {
+ -- build = function()
+ -- return os.execute("make")
+ --
+ -- -- ^ make sure to return the exit code of os.execute ^ --
+ --
+ -- end,
+ -- install = function()
+ -- return os.execute("make install PREFIX="..prefix)
+ -- end,
+ -- uninstall = function()
+ -- return os.execute("make uninstall PREFIX="..prefix)
+ -- end,
+ -- }
+ --}
},
}
+--[[ build_systems
+
+ this table contains all of the automatic
+ build system detection necessary for pkgit
+ to work without bldit.lua or `repositories = {...}`.
+
+ this works by creating a table named after the
+ filename associated with the build system that
+ is found in the root directory of a package.
+
+ by associating a filename with a build system,
+ pkgit can dynamically compile and install any
+ package, given that they use the build system
+ according to the standard (or otherwise
+ generally popular) usage guidelines.
+
+]]
build_systems = {
["Makefile"] = {
- build = function()
- os.execute("make")
- end,
- install = function()
- os.execute("make install PREFIX="..prefix)
- end,
- uninstall = function()
- os.execute("make uninstall PREFIX="..prefix)
- end,
+ --[[ targets
+
+ briefly mentioned above in `repositories`,
+ the `targets` subtable is a standard that's
+ consistent across all the different methods
+ to build a package using pkgit; meaning
+ you can write the same `targets` subtable
+ in `repositories.<pkg>`, `bldit.lua`, and
+ right here in `build_systems`.
+
+ this template comes with two templates;
+ `default` and `quiet`. the first is pretty
+ self-explanatory; this is what you'd define
+ as the default intended behavior of the
+ build system.
+
+ `quiet` is similar to `default`, in the sense
+ that it inherits the default intended behavior,
+ except that it does so while printing nothing
+ to the terminal. instead, ideally, it would
+ output its logs to a temporary file accessible
+ by the user running the command.
+
+ this is why the default logs in this example
+ are located in `/tmp` and not `/var/log`,
+ because the user typically has full access to
+ `/tmp`, and normally not `/var/log`.
+
+ ]]
+ targets = {
+ default = {
+ build = function()
+ return os.execute("make")
+ end,
+ install = function()
+ return os.execute("make install PREFIX="..prefix)
+ end,
+ uninstall = function()
+ return os.execute("make uninstall PREFIX="..prefix)
+ end,
+ },
+ quiet = {
+ build = function()
+ return os.execute("make &>/tmp/pkgit_build.log")
+ end,
+ install = function()
+ return os.execute("make install PREFIX="..prefix.." &>/tmp/pkgit_build.log")
+ end,
+ uninstall = function()
+ return os.execute("make uninstall PREFIX="..prefix.." &>/tmp/pkgit_build.log")
+ end,
+ },
+ }
},
["meson.build"] = {
- build = function()
- os.execute("meson setup build --prefix "..prefix.." && meson compile -C build")
- end,
- install = function()
- os.execute("cd build && meson install")
- end,
- uninstall = function()
- os.execute("cd build && ninja uninstall")
- end,
+ targets = {
+ default = {
+ build = function()
+ return os.execute("meson setup build --prefix "..prefix.." && meson compile -C build")
+ end,
+ install = function()
+ return os.execute("cd build && meson install")
+ end,
+ uninstall = function()
+ return os.execute("cd build && ninja uninstall")
+ end,
+ },
+ quiet = {
+ build = function()
+ return os.execute("meson setup build --prefix "..prefix.." &>/tmp/pkgit_build.log && meson compile -C build &>/tmp/pkgit_build.log")
+ end,
+ install = function()
+ return os.execute("cd build && meson install &>/tmp/pkgit_build.log")
+ end,
+ uninstall = function()
+ return os.execute("cd build && ninja uninstall &>/tmp/pkgit_build.log")
+ end,
+ },
+ }
},
["CMakeLists.txt"] = {
- build = function()
- os.execute("cmake -B build")
- os.execute("cmake --build build")
- end,
+ targets = {
+ default = {
+ build = function()
+ return os.execute("cmake -B build && cmake --build build")
+ end,
+ install = function()
+ return os.execute("cmake --build . --target install")
+ end,
+ uninstall = function()
+ return os.execute("xargs rm < install_manifest.txt")
+ end,
+ },
+ quiet = {
+ build = function()
+ return os.execute("cmake -B build &>/tmp/pkgit_build.log && cmake --build build &>/tmp/pkgit_build.log")
+ end,
+ install = function()
+ return os.execute("cmake --build . --target install &>/tmp/pkgit_build.log")
+ end,
+ uninstall = function()
+ return os.execute("xargs rm < install_manifest.txt &>/tmp/pkgit_build.log")
+ end,
+ },
+ }
},
-} \ No newline at end of file
+}
diff --git a/include/is_updated.h b/include/is_updated.h
index 7532b32..a5ba31f 100644
--- a/include/is_updated.h
+++ b/include/is_updated.h
@@ -2,5 +2,6 @@
#define IS_UPDATED_H
bool is_updated(const char *src);
+bool is_bldit_usable();
#endif \ No newline at end of file
diff --git a/include/lua_state.h b/include/lua_state.h
index f8af0a2..f8564b9 100644
--- a/include/lua_state.h
+++ b/include/lua_state.h
@@ -20,6 +20,7 @@ lua_State* get_lua_state(void);
void cache_repos(void);
void cache_build_systems(void);
void cache_install_directories(void);
+void cache_prefix_directory(void);
bool repo_build(const char *repository, const char *target);
bool repo_install(const char *repository, const char *target);
bool repo_uninstall(const char *repository, const char *target);
@@ -30,4 +31,7 @@ bool config_build(const char *path, const char *target);
bool config_install(const char *path, const char *target);
bool config_uninstall(const char *path, const char *target);
+char* bldit_getver(void);
+char* bldit_pkg_getver(void);
+
#endif \ No newline at end of file
diff --git a/include/vars.h b/include/vars.h
index 98cd829..58cf634 100644
--- a/include/vars.h
+++ b/include/vars.h
@@ -57,6 +57,7 @@ extern bool is_forced;
extern bool config_exists;
extern char home_dir[MAX_PATH_LEN];
+extern char prefix_dir[MAX_PATH_LEN];
extern char root_config[MAX_PATH_LEN];
extern bool is_root_config;
diff --git a/src/build.c b/src/build.c
index e5be9b2..5e96f52 100644
--- a/src/build.c
+++ b/src/build.c
@@ -4,6 +4,8 @@
#include <unistd.h>
#include "build.h"
+
+#include "is_updated.h"
#include "lua_build.h"
#include "vars.h"
diff --git a/src/cla_parse.c b/src/cla_parse.c
index 964a38b..20f7c44 100644
--- a/src/cla_parse.c
+++ b/src/cla_parse.c
@@ -104,9 +104,6 @@ void parse_flags(int argc, char **argv, Pkg pkg) {
if (argv[i][1] == '-') {
COMMAND("--quiet", "-q", { is_verbose = false; });
COMMAND("--force", "-f", { is_forced = true; });
- COMMAND("--version", "-v", { printf("%s\n", version); });
- COMMAND("--help", "-h", { help(); });
- COMMAND("--check", "-c", { resolve_deps(); });
} else {
mod_flags(argv, i);
cmd_flags(argc, argv, i, pkg);
@@ -116,14 +113,17 @@ void parse_flags(int argc, char **argv, Pkg pkg) {
void parse_cmds(int argc, char **argv, Pkg pkg) {
for (int i = 1; i < argc; i++) {
- COMMAND("add", "a", { cmd_add(argv, i); });
- COMMAND("build", "b", { cmd_build(argc, argv, i, pkg); });
- COMMAND("install", "i", { cmd_install(argc, argv, i, pkg); });
- COMMAND("remove", "r", { cmd_remove(argc, argv, i, pkg); });
- COMMAND("update", "u", { update_all(); });
- COMMAND("declare", "d", { declare(); });
- COMMAND("list", "l", { list_pkgs(); });
- COMMAND("search", "s", { search(argv[i + 1]); });
+ COMMAND("--add", "a", { cmd_add(argv, i); });
+ COMMAND("--build", "b", { cmd_build(argc, argv, i, pkg); });
+ COMMAND("--install", "i", { cmd_install(argc, argv, i, pkg); });
+ COMMAND("--remove", "r", { cmd_remove(argc, argv, i, pkg); });
+ COMMAND("--update", "u", { update_all(); });
+ COMMAND("--declare", "d", { declare(); });
+ COMMAND("--list", "l", { list_pkgs(); });
+ COMMAND("--search", "s", { search(argv[i + 1]); });
+ COMMAND("--version", "v", { printf("%s\n", version); });
+ COMMAND("--help", "h", { help(); });
+ COMMAND("--check", "c", { resolve_deps(); });
}
}
diff --git a/src/create_pkg.c b/src/create_pkg.c
index 2ce3588..b65b49c 100644
--- a/src/create_pkg.c
+++ b/src/create_pkg.c
@@ -82,7 +82,7 @@ Pkg create_pkg(const char *arg) {
pkg.target = trgptr + 1;
*trgptr = '\0';
} else {
- pkg.target = "default";
+ pkg.target = is_verbose ? "default" : "quiet";
}
bool is_in_repos = false;
diff --git a/src/help.c b/src/help.c
index f2286e3..659caad 100644
--- a/src/help.c
+++ b/src/help.c
@@ -17,20 +17,20 @@ void help() {
printf("%s%s%s\n", magenta, version, color_reset);
}
printf("\n");
- printf("%ssubcommands%s:\n", red, color_reset);
- printf("%s %sa%s, %sadd %s[url] %s# add a repo\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %sb%s, %sbuild %s[path] %s# build a package\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %sd%s, %sdeclare %s# install all packages\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %ss%s, %ssearch %s[pkgs] %s# find a package from your repos\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %si%s, %sinstall %s[pkgs, urls] %s# install a package/repo\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %sr%s, %sremove %s[pkgs] %s# remove an installed package\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %sl%s, %slist %s# list all installed packages\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %su%s, %supdate %s# update all installed packages\n", color_reset, green, color_reset, yellow, gray);
- printf("\n");
- printf("%sflags%s:\n", red, color_reset);
+ printf("%ssubcommand flags%s:\n", red, color_reset);
+ printf("%s %s-a%s, %s--add %s[url] %s# add a repo\n", color_reset, green, color_reset, yellow, blue, gray);
+ printf("%s %s-b%s, %s--build %s[path] %s# build a package\n", color_reset, green, color_reset, yellow, blue, gray);
+ printf("%s %s-d%s, %s--declare %s# install all packages\n", color_reset, green, color_reset, yellow, gray);
+ printf("%s %s-s%s, %s--search %s[pkgs] %s# find a package from your repos\n", color_reset, green, color_reset, yellow, blue, gray);
+ printf("%s %s-i%s, %s--install %s[pkgs, urls] %s# install a package/repo\n", color_reset, green, color_reset, yellow, blue, gray);
+ printf("%s %s-r%s, %s--remove %s[pkgs] %s# remove an installed package\n", color_reset, green, color_reset, yellow, blue, gray);
+ printf("%s %s-l%s, %s--list %s# list all installed packages\n", color_reset, green, color_reset, yellow, gray);
+ printf("%s %s-u%s, %s--update %s# update all installed packages\n", color_reset, green, color_reset, yellow, gray);
printf("%s %s-h%s, %s--help %s# display this help message\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %s-q%s, %s--quiet %s# run without logging to terminal\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %s-f%s, %s--force %s# force an operation like 'install'\n", color_reset, green, color_reset, yellow, gray);
printf("%s %s-v%s, %s--version %s# display version number\n", color_reset, green, color_reset, yellow, gray);
printf("%s %s-c%s, %s--check %s# run package checks\n", color_reset, green, color_reset, yellow, gray);
+ printf("\n");
+ printf("%smodifier flags%s:\n", red, color_reset);
+ printf("%s %s-q%s, %s--quiet %s# run without logging to terminal\n", color_reset, green, color_reset, yellow, gray);
+ printf("%s %s-f%s, %s--force %s# force an operation like 'install'\n", color_reset, green, color_reset, yellow, gray);
}
diff --git a/src/is_updated.c b/src/is_updated.c
index 68e6d2e..6ed53d3 100644
--- a/src/is_updated.c
+++ b/src/is_updated.c
@@ -5,15 +5,33 @@
#include <unistd.h>
#include "is_updated.h"
+
#include "cmd_out.h"
+#include "lua_state.h"
bool is_updated(const char *src) {
- if (src && strlen(src) > 0 && chdir(src) != 0) {
- return false;
- }
-
- char *output = cmd_out("git pull");
- bool result = (strstr(output, "Already up to date.") != NULL);
- free(output);
+ bool result = false;
+ if (src && strlen(src) > 0 && chdir(src) != 0) return result;
+ char *bldit_pkgver = bldit_pkg_getver();
+ char *git_tag = cmd_out("git tag | tail -n 1");
+ result = (strstr(git_tag, bldit_pkgver) != NULL);
+ char *git_pull = cmd_out("git pull");
+ result = (strstr(git_pull, "Already up to date.") != NULL);
+ free(git_tag);
+ free(git_pull);
return result;
+}
+
+bool is_bldit_usable() {
+ char* bldit_version = bldit_getver();
+ if (strcmp(bldit_version, version) == 0) return true;
+ bool prev_pass = false;
+ for (int i = 0; i < strlen(bldit_version); i++) {
+ if (bldit_version[i] == '.') continue;
+ if ((bldit_version[i] - '0') <= (version[i] - '0')) {
+ prev_pass = ((bldit_version[i] - '0') != (version[i] - '0'));
+ continue;
+ } else return prev_pass;
+ }
+ return true;
} \ No newline at end of file
diff --git a/src/lua_build.c b/src/lua_build.c
index 269482d..7a289fd 100644
--- a/src/lua_build.c
+++ b/src/lua_build.c
@@ -2,6 +2,8 @@
#include <stdbool.h>
#include "lua_build.h"
+
+#include "is_updated.h"
#include "lua_state.h"
#include "vars.h"
diff --git a/src/lua_state.c b/src/lua_state.c
index 4d3c4b5..fcaf90c 100644
--- a/src/lua_state.c
+++ b/src/lua_state.c
@@ -6,6 +6,7 @@
#include "create_pkg.h"
#include "install_pkg.h"
+#include "is_updated.h"
#include "lua_state.h"
#include "vars.h"
@@ -81,6 +82,19 @@ void free_lua_state() {
lua_State *get_lua_state() { return L; }
+void cache_prefix_directory() {
+ lua_getglobal(L, "prefix");
+ if (!lua_isstring(L, -1)) {
+ printf(
+ "%s init.lua: 'prefix' is not a string.\n",
+ print_error
+ );
+ return;
+ }
+ snprintf(prefix_dir, MAX_PATH_LEN, "%s", lua_tostring(L, -1));
+ lua_pop(L, 1);
+}
+
void cache_install_directories() {
if (!config_loaded || !lua_istable(L, -1)) {
lua_getglobal(L, "install_directories");
@@ -155,7 +169,15 @@ bool target_loop_build(
lua_pop(L, 3);
return false;
}
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
+ if (lua_pcall(L, 0, 1, 0) != LUA_OK) {
+ printf(
+ "%s %s: 'targets.%s.build' function borked: %s\n",
+ print_error, lua_file, target, lua_tostring(L, -1)
+ );
+ lua_pop(L, 3);
+ return false;
+ }
+ if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) if (is_verbose) {
printf(
"%s %s: 'targets.%s.build' failed: %s\n",
print_error, lua_file, target, lua_tostring(L, -1)
@@ -163,7 +185,7 @@ bool target_loop_build(
lua_pop(L, 3);
return false;
}
- lua_pop(L, 2);
+ lua_pop(L, 3);
return true;
}
@@ -366,25 +388,58 @@ bool repo_uninstall(const char *repository, const char *target) {
return target_loop_success;
}
+char* bldit_getver() {
+ init_bldit();
+ lua_getglobal(B, "bldit_version");
+ if (!lua_isstring(B, -1)) {
+ if (is_verbose)
+ printf("%s bldit.lua: 'bldit_version' is not a string.\n", print_warning);
+ return NULL;
+ }
+ const char* bldit_version = lua_tostring(B, -1);
+ return strdup(bldit_version);
+}
+
+char* bldit_pkg_getver() {
+ init_bldit();
+ lua_getglobal(B, "package_version");
+ if (!lua_isstring(B, -1)) {
+ if (is_verbose)
+ printf("%s bldit.lua: 'package_version' is not a string.\n", print_warning);
+ return NULL;
+ }
+ const char* package_version = lua_tostring(B, -1);
+ return strdup(package_version);
+}
+
bool bldit(const char *target) {
lua_State *B = luaL_newstate();
luaL_openlibs(B);
if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
- if (is_verbose) printf("%s cannot run bldit script: %s\n", print_warning, lua_tostring(B, -1));
+ if (is_verbose) printf(
+ "%s cannot run bldit script: %s\n",
+ print_warning, lua_tostring(B, -1)
+ );
lua_close(B);
return false;
}
- lua_getglobal(B, "bldit_version");
- if (!lua_isstring(B, -1)) {
- if (is_verbose) printf("%s bldit.lua: 'bldit_version' is not a string.\n", print_warning);
+ if (!is_bldit_usable()) {
+ printf(
+ "%s bldit version is newer than the installed pkgit version\n",
+ print_error
+ );
+ printf(
+ "%s consider updating pkgit\n",
+ print_pkgit
+ );
+ if (!is_forced) return false;
}
- lua_getglobal(B, "package_version");
- if (!lua_isstring(B, -1)) {
- if (is_verbose) printf("%s bldit.lua: 'package_version' is not a string.\n", print_warning);
- }
+ lua_pushfstring(B, "%s", prefix_dir);
+ lua_setglobal(B, "prefix");
+ lua_pop(B, 1);
lua_getglobal(B, "dependencies");
if (!lua_istable(B, -1)) {
@@ -421,6 +476,22 @@ bool bldit_install(const char *target) {
return false;
}
+ if (!is_bldit_usable()) {
+ printf(
+ "%s bldit version is newer than the installed pkgit version\n",
+ print_error
+ );
+ printf(
+ "%s consider updating pkgit\n",
+ print_pkgit
+ );
+ if (!is_forced) return false;
+ }
+
+ lua_pushfstring(B, "%s", prefix_dir);
+ lua_setglobal(B, "prefix");
+ lua_pop(B, 1);
+
lua_getglobal(B, "targets");
if (!lua_istable(B, -1)) {
if (is_verbose) printf(
@@ -451,6 +522,22 @@ bool bldit_uninstall(const char *target) {
return false;
}
+ if (!is_bldit_usable()) {
+ printf(
+ "%s bldit version is newer than the installed pkgit version\n",
+ print_error
+ );
+ printf(
+ "%s consider updating pkgit\n",
+ print_pkgit
+ );
+ if (!is_forced) return false;
+ }
+
+ lua_pushfstring(B, "%s", prefix_dir);
+ lua_setglobal(B, "prefix");
+ lua_pop(B, 1);
+
lua_getglobal(B, "targets");
if (!lua_istable(B, -1)) {
if (is_verbose) printf(
diff --git a/src/set_install_directories.c b/src/set_install_directories.c
index 95bd505..b99e227 100644
--- a/src/set_install_directories.c
+++ b/src/set_install_directories.c
@@ -8,6 +8,7 @@
void set_install_directories() {
lua_State *L = get_lua_state();
+ cache_prefix_directory();
lua_getglobal(L, "install_directories");
if (!lua_istable(L, -1)) {
printf(
diff --git a/src/update_pkg.c b/src/update_pkg.c
index c926d4b..52c4c9e 100644
--- a/src/update_pkg.c
+++ b/src/update_pkg.c
@@ -1,8 +1,11 @@
#include <stdio.h>
+#include <string.h>
#include "update_pkg.h"
+
#include "is_updated.h"
#include "install_pkg.h"
+#include "lua_state.h"
void update_pkg(Pkg pkg) {
if (is_updated(pkg.src)) {
diff --git a/src/vars.c b/src/vars.c
index 2848c4a..b205941 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -15,6 +15,7 @@ bool is_forced = false;
bool config_exists = false;
char home_dir[MAX_PATH_LEN] = {0};
+char prefix_dir[MAX_PATH_LEN] = {0};
char root_config[MAX_PATH_LEN] = "/etc/pkgit/init.lua";
bool is_root_config = false;