aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.md2
-rw-r--r--include/vars.hh2
-rwxr-xr-xpkgitbin0 -> 222176 bytes
-rw-r--r--src/cla_parse.cc12
-rw-r--r--src/create_pkg.cc2
-rw-r--r--src/main.cc6
-rw-r--r--src/read_config.cc40
-rw-r--r--src/vars.cc12
8 files changed, 67 insertions, 9 deletions
diff --git a/TODO.md b/TODO.md
index b420bf5..9ee5035 100644
--- a/TODO.md
+++ b/TODO.md
@@ -6,7 +6,7 @@
- [x] lua build systems
- [x] lua repos
- [x] CLA parsing
-- [ ] lua config primary(/etc) / secondary(.config) checks
+- [x] lua config primary(/etc) / secondary(.config) checks
- [ ] lua variables for install paths
- [ ] lua dependency listing
- [ ] lua custom source fetching methods
diff --git a/include/vars.hh b/include/vars.hh
index c309ea8..448b6df 100644
--- a/include/vars.hh
+++ b/include/vars.hh
@@ -19,6 +19,8 @@ struct Pkg {
extern const std::string home_dir;
+extern const std::string root_config;
+extern bool is_root_config;
extern const std::string config_dir;
extern const std::string config_file;
extern const std::string repo_file;
diff --git a/pkgit b/pkgit
new file mode 100755
index 0000000..ae5a2da
--- /dev/null
+++ b/pkgit
Binary files differ
diff --git a/src/cla_parse.cc b/src/cla_parse.cc
index d1810d3..c721fb9 100644
--- a/src/cla_parse.cc
+++ b/src/cla_parse.cc
@@ -35,8 +35,10 @@ void cla_parse(int argc, char** argv) {
for (int j = i+1; i < argc; j++) {
if (argv[j]) {
add_repo(argv[j], name_from_url(argv[j]));
+ return;
} else {
std::cout << print_error << "Not enough arguments! Try: `pkgit add [url]`";
+ return;
}
}
@@ -44,8 +46,10 @@ void cla_parse(int argc, char** argv) {
for (int j = i+1; i < argc; j++) {
if (argv[j]) {
build(argv[j]);
+ return;
} else {
build(std::filesystem::current_path().string().c_str());
+ return;
}
}
@@ -54,8 +58,10 @@ void cla_parse(int argc, char** argv) {
pkg = create_pkg(argv[j]);
if (argv[j]) {
install_pkg(pkg);
+ return;
} else {
std::cout << print_error << "Not enough arguments! Try: `pkgit install [url/pkg]`";
+ return;
}
}
@@ -64,22 +70,28 @@ void cla_parse(int argc, char** argv) {
pkg = create_pkg(argv[j]);
if (argv[j]) {
remove_pkg(pkg);
+ return;
} else {
std::cout << print_error << "Not enough arguments! Try: `pkgit remove [url/pkg]`";
+ return;
}
}
} else if (strcmp(argv[i], "update") == 0 || strcmp(argv[i], "u") == 0) {
update_all();
+ return;
} else if (strcmp(argv[i], "list") == 0 || strcmp(argv[i], "l") == 0) {
list_pkgs();
+ return;
} else if (strcmp(argv[i], "help") == 0 || strcmp(argv[i], "h") == 0) {
help();
+ return;
} else {
help();
+ return;
}
}
}
diff --git a/src/create_pkg.cc b/src/create_pkg.cc
index 564c11f..458150c 100644
--- a/src/create_pkg.cc
+++ b/src/create_pkg.cc
@@ -24,7 +24,7 @@ Pkg create_pkg(std::string arg) {
pkg.url = repos[arg];
pkg.name = arg;
} else {
- std::cout << print_error << "'" << arg << "'" << " is not a valid package";
+ std::cout << print_error << "'" << arg << "'" << " is not a valid package" << std::endl;
exit(1);
}
diff --git a/src/main.cc b/src/main.cc
index ec4d108..dd00010 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,10 +1,6 @@
-#include <string>
-#include <cstring>
-#include <filesystem>
-#include <iostream>
-
#include "cla_parse.hh"
#include "setup_pkgit.hh"
+#include "vars.hh"
int main(int argc, char *argv[]) {
setup_pkgit();
diff --git a/src/read_config.cc b/src/read_config.cc
new file mode 100644
index 0000000..560b978
--- /dev/null
+++ b/src/read_config.cc
@@ -0,0 +1,40 @@
+extern "C" {
+#include <luajit-2.1/lua.h>
+#include <luajit-2.1/lauxlib.h>
+#include <luajit-2.1/lualib.h>
+}
+
+#include <vars.hh>
+
+void set_install_directories() {
+ lua_State *L = lua_open();
+ luaL_openlibs(L);
+
+ if (luaL_loadfile(L, config_file.c_str()) || lua_pcall(L, 0, 0, 0)){
+ std::cout << print_error << "cannot run configuration script: " << lua_tostring(L, -1) << "\n";
+ return;
+ }
+
+ lua_getglobal(L, "install_directories");
+
+ if (!lua_istable(L, -1)) {
+ std::cout << print_error << "lua variable 'install_directories' is not a table.\n";
+ }
+
+ lua_pushnil(L);
+
+ while (lua_next(L, -2) != 0) {
+ const char *key = lua_tostring(L, -2);
+ const char *value = lua_tostring(L, -1);
+
+ install_dirs[key] = value;
+
+ lua_pop(L, 1);
+ }
+
+ bin = install_dirs["bin"];
+ lib = install_dirs["lib"];
+ include = install_dirs["include"];
+ pkgblds = install_dirs["pkgblds"];
+
+}
diff --git a/src/vars.cc b/src/vars.cc
index 5c0e6cb..38e39bb 100644
--- a/src/vars.cc
+++ b/src/vars.cc
@@ -1,19 +1,27 @@
+#include <filesystem>
#include <map>
#include <string>
#include "vars.hh"
std::map<std::string, std::string> repos;
+std::map<std::string, std::string> install_directories;
bool is_symlink_install = false;
bool is_verbose = false;
const std::string home_dir = std::getenv("HOME");
-const std::string config_dir = home_dir + "/.config/pkgit";
-const std::string config_file = home_dir + "/.config/pkgit/init.lua";
+const std::string root_config = "/etc/pkgit/init.lua";
+const std::string home_config = home_dir + "/.config/pkgit";
+bool is_root_config = std::filesystem::exists(root_config);
+
+const std::string config_dir = is_root_config ? "/etc/pkgit" : home_dir + "/.config/pkgit";
+const std::string config_file = config_dir + "/init.lua";
const std::string repo_file = config_dir + "/repos.lua";
+bool config_exists = std::filesystem::exists(root_config) || std::filesystem::exists(home_config);
+
const std::string bin = home_dir + "/.local/bin";
const std::string lib = home_dir + "/.local/lib";
const std::string include = home_dir + "/.local/include";