aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordacctal <dacctalyt@gmail.com>2026-04-03 14:56:05 +0000
committerdacctal <dacctalyt@gmail.com>2026-04-03 14:56:05 +0000
commited78991edc4755c0276dcb4eb454b43fa38296fc (patch)
tree460da5399e34e1dce7a293cb22578da15977d895 /src
parent2a6b92ed130ade1ea7542ee210e6957427a0aa81 (diff)
countless changes
Diffstat (limited to 'src')
-rw-r--r--src/add_repo.cc20
-rw-r--r--src/build.cc14
-rw-r--r--src/build_map.cc24
-rw-r--r--src/build_pkg.cc17
-rw-r--r--src/build_systems.cc111
-rw-r--r--src/cmd_out.cc2
-rw-r--r--src/copy_install.cc33
-rw-r--r--src/create_pkg.cc19
-rw-r--r--src/ensure_repo.cc24
-rw-r--r--src/fetch_git.cc18
-rw-r--r--src/fetch_pwd.cc3
-rw-r--r--src/fetch_src.cc5
-rw-r--r--src/help.cc6
-rw-r--r--src/install_pkg.cc36
-rw-r--r--src/is_updated.cc8
-rw-r--r--src/link_install.cc31
-rw-r--r--src/list_pkgs.cc10
-rw-r--r--src/lua_build.cc10
-rw-r--r--src/main.cc83
-rw-r--r--src/name_from_url.cc1
-rw-r--r--src/remove_pkg.cc25
-rw-r--r--src/setup_dirs.cc3
-rw-r--r--src/setup_pkgit.cc5
-rw-r--r--src/setup_repo.cc32
-rw-r--r--src/update_all.cc11
-rw-r--r--src/update_pkg.cc17
-rw-r--r--src/vars.cc22
27 files changed, 344 insertions, 246 deletions
diff --git a/src/add_repo.cc b/src/add_repo.cc
new file mode 100644
index 0000000..3de06dc
--- /dev/null
+++ b/src/add_repo.cc
@@ -0,0 +1,20 @@
+#include <fstream>
+#include <string>
+
+#include "add_repo.hh"
+#include "vars.hh"
+
+void add_repo(std::string repo, std::string repo_name) {
+ std::ifstream rfile(repo_file);
+ std::string rfile_line;
+ std::string rfile_contents;
+ while (getline(rfile, rfile_line)) {
+ rfile_contents += rfile_line + "\n";
+ }
+ rfile.close();
+
+ std::ofstream wfile;
+ wfile.open(repo_file);
+ wfile << rfile_contents << "repos[\"" << repo_name << "\"] = \"" << repo << "\"" << std::endl;
+ wfile.close();
+}
diff --git a/src/build.cc b/src/build.cc
index 0195412..c378dda 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -1,13 +1,19 @@
#include <filesystem>
+#include <iostream>
-#include "lua_build.cc"
+#include "build.hh"
+#include "lua_build.hh"
+#include "vars.hh"
void build(std::filesystem::path build_dir) {
if (build_dir != std::filesystem::current_path().string()) {
std::filesystem::current_path(build_dir);
}
- for (auto const &dir_entry : std::filesystem::directory_iterator(fs::current_path().string())) {
- if (dir_entry.path().filename() == "bldit") { system("./bldit"); }
- else { lua_build(build_dir.c_str()); }
+ for (auto const &dir_entry : std::filesystem::directory_iterator(std::filesystem::current_path().string())) {
+ if (dir_entry.path().filename() == "bldit") { system("./bldit"); return; }
}
+ for (auto const &dir_entry : std::filesystem::directory_iterator(std::filesystem::current_path().string())) {
+ if (lua_build(build_dir.c_str())) { return; }
+ }
+ std::cout << print_error << "no usable build system was found\n";
}
diff --git a/src/build_map.cc b/src/build_map.cc
deleted file mode 100644
index b7c1a02..0000000
--- a/src/build_map.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <functional>
-
-#include "build_systems.cc"
-
-const std::map<std::string, std::function<void()>> builds = {
- {"bldit", bldit_build},
- {"compile.sh", compilesh_build},
- {"build.sh", buildsh_build},
- {"autogen.sh", autogen_build},
- {"configure", autotools_build},
- {"configure.ac", autotools_build},
- {"Makefile", make_build},
- {"Makefile.am", make_build},
- {"CMakeLists.txt", cmake_build},
- {"meson.build", meson_build},
- {"build.ninja", ninja_build},
- {"Cargo.toml", cargo_build},
- {"go.mod", go_build},
- {"gradle.build", gradle_build},
- {"pnpm-lock.yaml", pnpm_build},
- {"pyproject.toml", python_build},
- {"build.zig", zig_build}
-};
-
diff --git a/src/build_pkg.cc b/src/build_pkg.cc
deleted file mode 100644
index 7627e16..0000000
--- a/src/build_pkg.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <functional>
-
-#include "build_map.cc"
-
-void build_pkg(std::filesystem::path build_dir) {
- if (build_dir != fs::current_path().string()) {
- fs::current_path(build_dir);
- }
- for (auto const &dir_entry :
- fs::directory_iterator(fs::current_path().string())) {
- for (auto build : builds) {
- if (dir_entry.path().filename() == build.first) {
- build.second();
- }
- }
- }
-}
diff --git a/src/build_systems.cc b/src/build_systems.cc
deleted file mode 100644
index a6364ec..0000000
--- a/src/build_systems.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <filesystem>
-
-#include "../include/toml.hh"
-
-#include "vars.cc"
-
-void autogen_build() {
- system("./autogen.sh");
- system("make");
-}
-
-void autotools_build() {
- system("./configure");
- for (auto const& dir_entry : fs::directory_iterator(fs::current_path().string())) {
- if (dir_entry.path().filename() == "CMakeLists.txt") {
- fs::create_directories("build");
- fs::current_path("build");
- system("cmake ..");
- }
- }
- for (auto const& dir_entry : fs::directory_iterator(fs::current_path().string())) {
- if (dir_entry.path().filename() == "Makefile") {
- system("make");
- }
- }
-}
-
-void bldit_build() {
- system("./bldit");
-}
-
-void buildsh_build() {
- system("./build.sh");
-}
-
-void compilesh_build() {
- system("./compile.sh");
-}
-
-void cargo_build() {
- system("cargo build --release");
-}
-
-void cmake_build() {
- fs::create_directories("build");
- fs::current_path("build");
- system("cmake ..");
- system("make");
-}
-
-void go_build() {
- for (auto const& dir_entry : fs::directory_iterator(fs::current_path().string())) {
- if (dir_entry.path().filename() == "main.go") {
- system("go build main.go");
- }
- }
-}
-
-void gradle_build() {
- system("gradle build");
-}
-
-void make_build() {
- for (auto const& dir_entry : fs::directory_iterator(fs::current_path().string())) {
- if (dir_entry.path().filename() == "autogen.sh") {
- autogen_build();
- return;
- }
- }
- for (auto const& dir_entry : fs::directory_iterator(fs::current_path().string())) {
- if (dir_entry.path().filename() == "configure.ac") {
- autotools_build();
- return;
- }
- }
- system("make");
-}
-
-void meson_build() {
- system("meson setup --wipe build");
- system("meson compile -C build");
-}
-
-void ninja_build() {
- system("ninja");
-}
-
-void nim_build() {
- system("nimble build");
-}
-
-void pnpm_build() {
- system("pnpm install");
- system("pnpm run build");
-}
-
-void python_build() {
- toml::parse_result pyproject_toml = toml::parse_file("pyproject.toml");
- std::string pypkg = pyproject_toml["project"]["name"].ref<std::string>();
- std::string commands[] = {
- "export PIPX_BIN_DIR=" + bin,
- "pipx install " + pypkg
- };
- for (int i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) {
- system(commands[i].c_str());
- }
-}
-
-void zig_build() {
- system("zig build");
-}
diff --git a/src/cmd_out.cc b/src/cmd_out.cc
index a855add..3a59f2e 100644
--- a/src/cmd_out.cc
+++ b/src/cmd_out.cc
@@ -4,6 +4,8 @@
#include <string>
#include <array>
+#include "cmd_out.hh"
+
std::string cmd_out(const char* cmd) {
std::array<char, 128> buffer;
std::string result;
diff --git a/src/copy_install.cc b/src/copy_install.cc
new file mode 100644
index 0000000..4e6294e
--- /dev/null
+++ b/src/copy_install.cc
@@ -0,0 +1,33 @@
+#include <filesystem>
+#include <iostream>
+#include <string>
+#include <unistd.h>
+
+#include "copy_install.hh"
+#include "vars.hh"
+
+void copy_install(std::filesystem::path build_dir) {
+ for (auto const& dir_entry : std::filesystem::recursive_directory_iterator(build_dir)) {
+ if (dir_entry.path().extension().string().rfind(".so", 0) == 0) {
+ if (!std::filesystem::exists(lib+"/"+dir_entry.path().filename().string())) {
+ copy(dir_entry, lib+"/"+dir_entry.path().filename().string());
+ if (is_verbose) { std::cout << print_pkgit << "copied library: " << dir_entry << "\n"; }
+ } else { /*std::cout << print_pkgit << "library already exists: " << dir_entry << "\n";*/ }
+
+ } else if (!access(dir_entry.path().c_str(), X_OK) && !is_directory(dir_entry.path())) {
+ if (!std::filesystem::exists(bin+"/"+dir_entry.path().filename().string()) &&
+ dir_entry.path().filename().string() != "bldit" &&
+ dir_entry.path().filename().string() != "build.sh" &&
+ dir_entry.path().filename().string() != "compile.sh") {
+ copy(dir_entry, bin+"/"+dir_entry.path().filename().string());
+ if (is_verbose) { std::cout << print_pkgit << "copied executable: " << dir_entry << "\n"; }
+ } else { /*std::cout << print_pkgit << "executable already exists: " << dir_entry << "\n";*/ }
+
+ } else if (dir_entry.path().extension() == ".h") {
+ if (!std::filesystem::exists(include+"/"+dir_entry.path().filename().string())) {
+ copy(dir_entry, include+"/"+dir_entry.path().filename().string());
+ if (is_verbose) { std::cout << print_pkgit << "copied include: " << dir_entry << "\n"; }
+ } else { /*std::cout << print_pkgit << "include already exists: " << dir_entry << "\n";*/ }
+ }
+ }
+}
diff --git a/src/create_pkg.cc b/src/create_pkg.cc
index 5cea49e..564c11f 100644
--- a/src/create_pkg.cc
+++ b/src/create_pkg.cc
@@ -1,18 +1,31 @@
+#include <iostream>
#include <string>
#include <filesystem>
-#include "vars.cc"
-#include "name_from_url.cc"
+#include "create_pkg.hh"
+#include "name_from_url.hh"
+#include "vars.hh"
Pkg create_pkg(std::string arg) {
Pkg pkg;
+ bool is_in_repos = false;
+
+ for (auto repo : repos) {
+ if (arg == repo.first) { is_in_repos = true; }
+ }
if (arg.rfind("http", 0) == 0) {
pkg.url = arg;
pkg.name = name_from_url(arg);
} else if (arg == ".") {
pkg.url = "";
- pkg.name = name_from_url(fs::current_path().string());
+ pkg.name = name_from_url(std::filesystem::current_path().string());
+ } else if (is_in_repos) {
+ pkg.url = repos[arg];
+ pkg.name = arg;
+ } else {
+ std::cout << print_error << "'" << arg << "'" << " is not a valid package";
+ exit(1);
}
pkg.ver = "HEAD";
diff --git a/src/ensure_repo.cc b/src/ensure_repo.cc
new file mode 100644
index 0000000..2a33c2c
--- /dev/null
+++ b/src/ensure_repo.cc
@@ -0,0 +1,24 @@
+#include <iostream>
+#include <fstream>
+
+#include "ensure_repo.hh"
+#include "vars.hh"
+
+void ensure_repo() {
+ if (!std::filesystem::exists(repo_file)) {
+ std::cout << "repo file does not exist" << std::endl;
+ std::ofstream file;
+ file.open(repo_file);
+
+ if (!file.is_open()) {
+ std::cout << print_error << "repo file not created" << std::endl;
+ return;
+ }
+
+ file << "repos = {}" << std::endl;
+ file << "repos[\"pkgit\"] = https://git.symlinx.net/pkgit" << std::endl;
+
+ std::cout << repo_file << std::endl;
+ file.close();
+ }
+}
diff --git a/src/fetch_git.cc b/src/fetch_git.cc
index b8df6bb..6c07e69 100644
--- a/src/fetch_git.cc
+++ b/src/fetch_git.cc
@@ -1,19 +1,23 @@
#include <cstring>
-#include "vars.cc"
+#include "fetch_git.hh"
+#include "vars.hh"
int fetch_git(Pkg pkg) {
std::string clone_cmds[] = {
- "git -c advice.detachedHead=false clone --depth 1 " + pkg.url +
+ "git -c advice.detachedHead=false clone --depth=1 " + pkg.url +
" " + pkg.src.c_str(),
+ "git -c advice.detachedHead=false clone " + pkg.url +
+ " " + pkg.src.c_str(),
+ "git -c advice.detachedHead=false clone --branch " + pkg.ver +
+ " --depth=1 " + pkg.url + " " + pkg.src.c_str(),
"git -c advice.detachedHead=false clone --branch " + pkg.ver +
- " --depth 1 " + pkg.url + " " + pkg.src.c_str()
+ " " + pkg.url + " " + pkg.src.c_str()
};
if (strcmp(pkg.ver.c_str(), "HEAD") == 0) {
- if (WEXITSTATUS(system(clone_cmds[0].c_str())) == 0x10) { return 0; }
- else { return 1; }
+ if (system(clone_cmds[0].c_str()) != 0) { system(clone_cmds[1].c_str()); }
} else {
- if (WEXITSTATUS(system(clone_cmds[1].c_str())) == 0x10) { return 0; }
- else { return 1; }
+ if (system(clone_cmds[2].c_str()) != 0) { system(clone_cmds[3].c_str()); }
}
+ return 0;
}
diff --git a/src/fetch_pwd.cc b/src/fetch_pwd.cc
index dbd5fcf..aa61063 100644
--- a/src/fetch_pwd.cc
+++ b/src/fetch_pwd.cc
@@ -1,4 +1,5 @@
-#include "vars.cc"
+#include "fetch_pwd.hh"
+#include "vars.hh"
void fetch_pwd(Pkg pkg) {
std::filesystem::copy(std::filesystem::current_path(), pkg.src);
diff --git a/src/fetch_src.cc b/src/fetch_src.cc
index 3e5cca3..0b79a94 100644
--- a/src/fetch_src.cc
+++ b/src/fetch_src.cc
@@ -1,8 +1,9 @@
#include <stdlib.h>
-#include "fetch_git.cc"
+#include "fetch_src.hh"
+#include "fetch_git.hh"
void fetch_src(Pkg pkg) {
- if (fs::exists(pkg.src)) { fs::remove_all(pkg.src); }
+ if (std::filesystem::exists(pkg.src)) { std::filesystem::remove_all(pkg.src); }
if (pkg.url == "") { std::filesystem::create_directories(pkg.src); return; }
else if (fetch_git(pkg) == 0) { return; } else { exit(EXIT_FAILURE); }
diff --git a/src/help.cc b/src/help.cc
index a4d022a..026144c 100644
--- a/src/help.cc
+++ b/src/help.cc
@@ -1,6 +1,7 @@
#include <iostream>
-#include "vars.cc"
+#include "vars.hh"
+#include "help.hh"
void help() {
std::cout << ""+bold_magenta+" , \n";
@@ -26,8 +27,7 @@ void help() {
std::cout << ""+color_reset+"│├── "+green+"-v"+color_reset+", "+yellow+"--verbose"+blue+"[tag] "+gray+"# give full output of install\n";
std::cout << ""+color_reset+"│├── "+green+"-t:"+color_reset+", "+yellow+"--tag:"+blue+"[tag] "+gray+"# specify a version\n";
std::cout << ""+color_reset+"│└── "+green+"-l:"+color_reset+", "+yellow+"--list:"+blue+"[filename] "+gray+"# install from a package list\n";
- std::cout << ""+color_reset+"├┬ "+green+"r"+color_reset+", "+yellow+"remove "+blue+"[pkgs] "+gray+"# remove an installed package\n";
- std::cout << ""+color_reset+"│└── "+green+"-r:"+color_reset+", "+yellow+"--repo:"+blue+"[repo] "+gray+"# remove a repo\n";
+ std::cout << ""+color_reset+"├─ "+green+"r"+color_reset+", "+yellow+"remove "+blue+"[pkgs] "+gray+"# remove an installed package\n";
std::cout << ""+color_reset+"├─ "+green+"f"+color_reset+", "+yellow+"files "+blue+"[pkgs] "+gray+"# list all files of a package\n";
std::cout << ""+color_reset+"├─ "+green+"s"+color_reset+", "+yellow+"search "+blue+"[pkgs] "+gray+"# search for packages\n";
std::cout << ""+color_reset+"├─ "+green+"l"+color_reset+", "+yellow+"list "+gray+"# list installed packages\n";
diff --git a/src/install_pkg.cc b/src/install_pkg.cc
index 13cef81..3f0bd75 100644
--- a/src/install_pkg.cc
+++ b/src/install_pkg.cc
@@ -1,10 +1,36 @@
-#include "fetch_src.cc"
-#include "build.cc"
-#include "link_install.cc"
+#include <iostream>
+
+#include "add_repo.hh"
+#include "fetch_src.hh"
+#include "build.hh"
+#include "copy_install.hh"
+#include "install_pkg.hh"
+#include "link_install.hh"
+#include "vars.hh"
void install_pkg(Pkg pkg) {
+ std::cout << print_pkgit << "fetching source..." << std::endl;
fetch_src(pkg);
- //build_pkg(pkg.src);
+
+ std::cout << print_pkgit << "building..." << std::endl;
build(pkg.src.c_str());
- link_install(pkg.src);
+
+ std::cout << print_pkgit << "installing..." << std::endl;
+ if (is_symlink_install) { link_install(pkg.src); }
+ else { copy_install(pkg.src); }
+
+ bool repo_exists = false;
+ for (auto repo : repos) {
+ if (repo.first == pkg.name) {
+ repo_exists = true;
+ }
+ }
+
+ if (!repo_exists) {
+ std::cout << print_pkgit << "adding repository..." << std::endl;
+ add_repo(pkg.url, pkg.name);
+ std::cout << print_pkgit << "done!" << std::endl;
+ } else {
+ std::cout << print_pkgit << "repo already exists, done!" << std::endl;
+ }
}
diff --git a/src/is_updated.cc b/src/is_updated.cc
index 96c7fe6..f166dd8 100644
--- a/src/is_updated.cc
+++ b/src/is_updated.cc
@@ -1,6 +1,12 @@
-#include "cmd_out.cc"
+#include <filesystem>
+
+#include "is_updated.hh"
+#include "cmd_out.hh"
bool is_updated(std::string src) {
+ if (src != std::filesystem::current_path().string()) {
+ std::filesystem::current_path(src);
+ }
if (cmd_out("git pull") == "Already up to date.") { return true; }
return false;
}
diff --git a/src/link_install.cc b/src/link_install.cc
index f4d9777..26c2b30 100644
--- a/src/link_install.cc
+++ b/src/link_install.cc
@@ -3,31 +3,30 @@
#include <string>
#include <unistd.h>
-#include "vars.cc"
-
-namespace fs = std::filesystem;
+#include "link_install.hh"
+#include "vars.hh"
void link_install(std::filesystem::path build_dir) {
- for (auto const& dir_entry : fs::recursive_directory_iterator(build_dir))
+ for (auto const& dir_entry : std::filesystem::recursive_directory_iterator(build_dir))
if (dir_entry.path().extension().string().rfind(".so", 0) == 0) {
- if (!fs::exists(lib+"/"+dir_entry.path().filename().string())) {
+ if (!std::filesystem::exists(lib+"/"+dir_entry.path().filename().string())) {
create_symlink(dir_entry, lib+"/"+dir_entry.path().filename().string());
- std::cout << print_pkgit << "linked library: " << dir_entry << "\n";
- } else { std::cout << print_pkgit << "library already exists: " << dir_entry << "\n"; }
+ if (is_verbose) { std::cout << print_pkgit << "linked library: " << dir_entry << "\n"; }
+ } else { /*std::cout << print_pkgit << "library already exists: " << dir_entry << "\n";*/ }
} else if (!access(dir_entry.path().c_str(), X_OK) && !is_directory(dir_entry.path())) {
- if (!fs::exists(bin+"/"+dir_entry.path().filename().string()) &&
- dir_entry.path().filename().string() == "bldit" &&
- dir_entry.path().filename().string() == "build.sh" &&
- dir_entry.path().filename().string() == "compile.sh") {
+ if (!std::filesystem::exists(bin+"/"+dir_entry.path().filename().string()) &&
+ dir_entry.path().filename().string() != "bldit" &&
+ dir_entry.path().filename().string() != "build.sh" &&
+ dir_entry.path().filename().string() != "compile.sh") {
create_symlink(dir_entry, bin+"/"+dir_entry.path().filename().string());
- std::cout << print_pkgit << "linked executable: " << dir_entry << "\n";
- } else { std::cout << print_pkgit << "executable already exists: " << dir_entry << "\n"; }
+ if (is_verbose) { std::cout << print_pkgit << "linked executable: " << dir_entry << "\n"; }
+ } else { /*std::cout << print_pkgit << "executable already exists: " << dir_entry << "\n";*/ }
} else if (dir_entry.path().extension() == ".h") {
- if (!fs::exists(include+"/"+dir_entry.path().filename().string())) {
+ if (!std::filesystem::exists(include+"/"+dir_entry.path().filename().string())) {
create_symlink(dir_entry, include+"/"+dir_entry.path().filename().string());
- std::cout << print_pkgit << "linked include: " << dir_entry << "\n";
- } else { std::cout << print_pkgit << "include already exists: " << dir_entry << "\n"; }
+ if (is_verbose) { std::cout << print_pkgit << "linked include: " << dir_entry << "\n"; }
+ } else { /*std::cout << print_pkgit << "include already exists: " << dir_entry << "\n";*/ }
}
}
diff --git a/src/list_pkgs.cc b/src/list_pkgs.cc
new file mode 100644
index 0000000..487a75c
--- /dev/null
+++ b/src/list_pkgs.cc
@@ -0,0 +1,10 @@
+#include <iostream>
+
+#include "list_pkgs.hh"
+#include "vars.hh"
+
+void list_pkgs() {
+ for (auto repo : repos) {
+ std::cout << repo.first << std::endl;
+ }
+}
diff --git a/src/lua_build.cc b/src/lua_build.cc
index b75e2f3..7d89450 100644
--- a/src/lua_build.cc
+++ b/src/lua_build.cc
@@ -5,11 +5,12 @@
#include <lua5.1/lauxlib.h>
#include <lua5.1/lualib.h>
-#include "vars.cc"
+#include "lua_build.hh"
+#include "vars.hh"
std::map<std::string, int> build_files;
-void lua_build (const char *path) {
+bool lua_build(const char *path) {
lua_State *L = lua_open();
luaL_openlibs(L);
@@ -47,12 +48,11 @@ void lua_build (const char *path) {
std::cout << "calling lua build function according to key filename '"<< key << "'...\n";
if (lua_pcall(L, 1, 0, 0) != 0) {
std::cout << print_error << "lua build function failed to run\n";
+ break;
}
if (build_found) { break; }
}
lua_pop(L, 1);
}
- if (!build_found) {
- std::cout << print_error << "no usable build system was found\n";
- }
+ return build_found;
}
diff --git a/src/main.cc b/src/main.cc
index bcc45df..b732c1b 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,37 +1,74 @@
#include <string>
#include <cstring>
#include <filesystem>
+#include <iostream>
-#include "create_pkg.cc"
-#include "help.cc"
-#include "setup_pkgit.cc"
-#include "install_pkg.cc"
+#include "add_repo.hh"
+#include "build.hh"
+#include "create_pkg.hh"
+#include "help.hh"
+#include "install_pkg.hh"
+#include "list_pkgs.hh"
+#include "name_from_url.hh"
+#include "remove_pkg.hh"
+#include "setup_pkgit.hh"
+#include "update_all.hh"
+#include "vars.hh"
int main(int argc, char *argv[]) {
setup_pkgit();
Pkg pkg;
- if (argv[1]) {
- if (strcmp(argv[1], "build") == 0 || strcmp(argv[1], "b") == 0) {
- if (argv[2]) {
- build(argv[2]);
- } else {
- build(fs::current_path().string().c_str());
- }
- } else if (strcmp(argv[1], "install") == 0 || strcmp(argv[1], "i") == 0) {
- pkg = create_pkg(argv[2]);
- if (argv[2]) {
- install_pkg(pkg);
- } else {
- std::cout << print_error << "Not enough arguments! Try: `pkgit install [url]`";
- }
- } else if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "h") == 0) {
- help();
- } else if (strcmp(argv[1], "type") == 0) {
- link_install(fs::current_path().string());
+ if (!argv[1]) { help(); return 0; }
+
+ for (int i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "--link") == 0 || strcmp(argv[i], "-l") == 0) {
+ is_symlink_install = true;
+ }
+ if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
+ is_verbose = true;
+ }
+ }
+
+ if (strcmp(argv[1], "add") == 0 || strcmp(argv[1], "a") == 0) {
+ if (argv[2]) {
+ add_repo(argv[2], name_from_url(argv[2]));
} else {
- help();
+ std::cout << print_error << "Not enough arguments! Try: `pkgit add [url]`";
}
+
+ } else if (strcmp(argv[1], "build") == 0 || strcmp(argv[1], "b") == 0) {
+ if (argv[2]) {
+ build(argv[2]);
+ } else {
+ build(std::filesystem::current_path().string().c_str());
+ }
+
+ } else if (strcmp(argv[1], "install") == 0 || strcmp(argv[1], "i") == 0) {
+ pkg = create_pkg(argv[2]);
+ if (argv[2]) {
+ install_pkg(pkg);
+ } else {
+ std::cout << print_error << "Not enough arguments! Try: `pkgit install [url/pkg]`";
+ }
+
+ } else if (strcmp(argv[1], "remove") == 0 || strcmp(argv[1], "r") == 0) {
+ pkg = create_pkg(argv[2]);
+ if (argv[2]) {
+ remove_pkg(pkg);
+ } else {
+ std::cout << print_error << "Not enough arguments! Try: `pkgit remove [url/pkg]`";
+ }
+
+ } else if (strcmp(argv[1], "update") == 0 || strcmp(argv[1], "u") == 0) {
+ update_all();
+
+ } else if (strcmp(argv[1], "list") == 0 || strcmp(argv[1], "l") == 0) {
+ list_pkgs();
+
+ } else if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "h") == 0) {
+ help();
+
} else {
help();
}
diff --git a/src/name_from_url.cc b/src/name_from_url.cc
index 2aaddac..56a2830 100644
--- a/src/name_from_url.cc
+++ b/src/name_from_url.cc
@@ -1,4 +1,5 @@
#include <string>
+#include "name_from_url.hh"
std::string name_from_url(std::string url) {
return url.substr(url.find_last_of('/') + 1);
diff --git a/src/remove_pkg.cc b/src/remove_pkg.cc
new file mode 100644
index 0000000..fa41bbc
--- /dev/null
+++ b/src/remove_pkg.cc
@@ -0,0 +1,25 @@
+#include <filesystem>
+#include <iostream>
+#include <string>
+#include <unistd.h>
+
+#include "remove_pkg.hh"
+#include "vars.hh"
+
+void remove_pkg(Pkg pkg) {
+ for (auto const& dir_entry : std::filesystem::recursive_directory_iterator(pkg.src)) {
+ if (dir_entry.path().extension().string().rfind(".so", 0) == 0) {
+ std::filesystem::remove(lib+"/"+dir_entry.path().filename().string());
+ std::cout << print_pkgit << "removed library: " << dir_entry << "\n";
+
+ } else if (!access(dir_entry.path().c_str(), X_OK) && !is_directory(dir_entry.path())) {
+ std::filesystem::remove(bin+"/"+dir_entry.path().filename().string());
+ std::cout << print_pkgit << "removed executable: " << dir_entry << "\n";
+
+ } else if (dir_entry.path().extension() == ".h") {
+ std::filesystem::remove(include+"/"+dir_entry.path().filename().string());
+ std::cout << print_pkgit << "removed include: " << dir_entry << "\n";
+ }
+ }
+ remove_all(pkg.src.parent_path());
+}
diff --git a/src/setup_dirs.cc b/src/setup_dirs.cc
index 457c13d..f0be153 100644
--- a/src/setup_dirs.cc
+++ b/src/setup_dirs.cc
@@ -1,6 +1,7 @@
#include <filesystem>
-#include "vars.cc"
+#include "setup_dirs.hh"
+#include "vars.hh"
void setup_dirs() {
for(unsigned int a = 0; a < sizeof(all_dirs)/sizeof(all_dirs[0]); a++) {
diff --git a/src/setup_pkgit.cc b/src/setup_pkgit.cc
index 3184044..398cd93 100644
--- a/src/setup_pkgit.cc
+++ b/src/setup_pkgit.cc
@@ -1,5 +1,8 @@
-#include "setup_dirs.cc"
+#include "setup_pkgit.hh"
+#include "setup_dirs.hh"
+#include "setup_repo.hh"
void setup_pkgit() {
setup_dirs();
+ setup_repo();
}
diff --git a/src/setup_repo.cc b/src/setup_repo.cc
index 8a21d45..402238f 100644
--- a/src/setup_repo.cc
+++ b/src/setup_repo.cc
@@ -1,4 +1,36 @@
+#include <iostream>
+#include <lua5.1/lua.h>
+#include <lua5.1/lauxlib.h>
+#include <lua5.1/lualib.h>
+#include "setup_repo.hh"
+#include "ensure_repo.hh"
+#include "vars.hh"
void setup_repo() {
+ ensure_repo();
+
+ 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";
+ }
+
+ lua_getglobal(L, "repos");
+
+ if (!lua_istable(L, -1)) {
+ std::cout << print_error << "lua variable 'repos' 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);
+
+ repos[key] = value;
+
+ lua_pop(L, 1);
+ }
}
diff --git a/src/update_all.cc b/src/update_all.cc
new file mode 100644
index 0000000..5af2e67
--- /dev/null
+++ b/src/update_all.cc
@@ -0,0 +1,11 @@
+#include "update_all.hh"
+#include "create_pkg.hh"
+#include "update_pkg.hh"
+#include "vars.hh"
+
+void update_all() {
+ for (auto repo : repos) {
+ Pkg pkg = create_pkg(repo.second);
+ update_pkg(pkg);
+ }
+}
diff --git a/src/update_pkg.cc b/src/update_pkg.cc
index 4b35793..881beff 100644
--- a/src/update_pkg.cc
+++ b/src/update_pkg.cc
@@ -1,12 +1,11 @@
-#include "is_updated.cc"
-#include "build_pkg.cc"
-#include "link_install.cc"
-#include "vars.cc"
+#include <filesystem>
+#include <iostream>
+
+#include "update_pkg.hh"
+#include "is_updated.hh"
+#include "install_pkg.hh"
void update_pkg(Pkg pkg) {
- if (is_updated(pkg.src)) {
- build_pkg(pkg.src);
- link_install(pkg.src);
- }
- else { std::cout << print_skipped << pkg.name << " is already up to date."; }
+ if (is_updated(pkg.src)) { std::cout << print_skipped << pkg.name << " is already up to date."; return; }
+ install_pkg(pkg);
}
diff --git a/src/vars.cc b/src/vars.cc
index b4c2abe..5c0e6cb 100644
--- a/src/vars.cc
+++ b/src/vars.cc
@@ -1,21 +1,18 @@
-#ifndef vars
-#define vars
-
+#include <map>
#include <string>
-#include <filesystem>
-namespace fs = std::filesystem;
+#include "vars.hh"
-struct Pkg {
- std::string url;
- std::string name;
- std::string ver;
- fs::path src;
-};
+std::map<std::string, std::string> repos;
+
+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 repo_file = config_dir + "/repos.lua";
const std::string bin = home_dir + "/.local/bin";
const std::string lib = home_dir + "/.local/lib";
@@ -23,6 +20,7 @@ const std::string include = home_dir + "/.local/include";
const std::string pkgblds = home_dir + "/.local/share/pkgit";
const std::string all_dirs[] = {
+ config_dir,
bin,
lib,
include,
@@ -73,5 +71,3 @@ const std::string color_reset = "\e[0m";
const std::string print_pkgit = bold_yellow + "[" + bold_magenta + "pkgit" + bold_yellow + "]\t" + color_reset;
const std::string print_skipped = print_pkgit + blue + "[SKIPPED]\t" + color_reset;
const std::string print_error = print_pkgit + red + "[ERROR]\t" + color_reset;
-
-#endif