aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules1
-rw-r--r--lpm.c19
-rw-r--r--lpm.lua76
3 files changed, 75 insertions, 21 deletions
diff --git a/.gitmodules b/.gitmodules
index 3755286..9f578cd 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,6 +4,7 @@
[submodule "lib/libgit2"]
path = lib/libgit2
url = https://github.com/libgit2/libgit2.git
+ branch = main
[submodule "lib/openssl"]
path = lib/openssl
url = https://github.com/openssl/openssl.git
diff --git a/lpm.c b/lpm.c
index ba9bcc0..8538923 100644
--- a/lpm.c
+++ b/lpm.c
@@ -369,6 +369,17 @@ int lpm_fetch(lua_State* L) {
}
+int lpm_set_certs(lua_State* L) {
+ const char* type = luaL_checkstring(L, 1);
+ const char* path = luaL_checkstring(L, 2);
+ if (strcmp(type, "dir") == 0)
+ git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, NULL, path);
+ else
+ git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, path, NULL);
+ return 0;
+}
+
+
int lpm_status(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
git_repository* repository;
@@ -393,7 +404,8 @@ static const luaL_Reg system_lib[] = {
{ "init", lpm_init }, // Initializes a git repository with the specified remote.
{ "fetch", lpm_fetch }, // Updates a git repository with the specified remote.
{ "reset", lpm_reset }, // Updates a git repository to the specified commit/hash/branch.
- { "status", lpm_status } // Returns the git repository in question's current branch, if any, and commit hash.
+ { "status", lpm_status }, // Returns the git repository in question's current branch, if any, and commit hash.
+ { "set_certs", lpm_set_certs } // Returns the git repository in question's current branch, if any, and commit hash.
};
#ifndef LPM_VERSION
@@ -416,13 +428,16 @@ int main(int argc, char* argv[]) {
lua_setglobal(L, "VERSION");
lua_setglobal(L, "ARGV");
#if _WIN32
+ lus_pushliteral(L, "windows");
lua_pushliteral(L, "\\");
#else
+ lua_pushliteral(L, "posix");
lua_pushliteral(L, "/");
#endif
lua_setglobal(L, "PATHSEP");
+ lua_setglobal(L, "PLATFORM");
if (luaL_loadbuffer(L, lpm_lua, lpm_lua_len, "lpm.lua")) {
- //if (luaL_loadfile(L, "lpm.lua")) {
+ // if (luaL_loadfile(L, "lpm.lua")) {
fprintf(stderr, "internal error when starting the application: %s\n", lua_tostring(L, -1));
return -1;
}
diff --git a/lpm.lua b/lpm.lua
index d164671..e054e39 100644
--- a/lpm.lua
+++ b/lpm.lua
@@ -1,4 +1,4 @@
-setmetatable(_G, { __newindex = function(t, k) error("cannot set global variable: " .. k, 2) end })
+setmetatable(_G, { __index = function(t, k) if not rawget(t, k) then error("cannot get undefined global variable: " .. k, 2) end end, __newindex = function(t, k) error("cannot set global variable: " .. k, 2) end })
-- Begin rxi JSON library.
local json = { _version = "0.1.2" }
@@ -419,7 +419,7 @@ end
function common.slice(t, i, l)
local n = {}
- for j = i, i+l do
+ for j = i, l ~= nil and (i - l) or #t do
table.insert(n, t[j])
end
return n
@@ -641,12 +641,21 @@ end
-- in the cases where we don't have a manifest, assume generalized structure, take plugins folder, trawl through it, build manifest that way
--- assuming each .lua file under the `plugins` folder is a plugin.
+-- assuming each .lua file under the `plugins` folder is a plugin. also parse the README, if present, and see if any of the plugins
function Repository:generate_manifest()
if not self.commit and not self.branch then error("requires an instantiation") end
local path = self.local_path .. PATHSEP .. (self.commit or self.branch)
local plugin_dir = system.stat(path .. PATHSEP .. "plugins") and PATHSEP .. "plugins" .. PATHSEP or PATHSEP
- local plugins = {}
+ local plugins, plugin_map = {}, {}
+ if system.stat(path .. PATHSEP .. "README.md") then -- If there's a README, parse it for a table like in our primary repository.
+ for line in io.lines(path .. PATHSEP .. "README.md") do
+ local _, _, name, path, description = line:find("^%s*%|%s*%[`(%w+)%??.-`%]%((.-)%).-%|%s*(.-)%s*%|%s*$")
+ if name then
+ plugin_map[name] = { name = name, description = description }
+ plugin_map[path:find("^http") and "remote" or "path"] = path
+ end
+ end
+ end
for i, file in ipairs(system.ls(path .. plugin_dir)) do
if file:find("%.lua$") then
local plugin = { description = nil, name = common.basename(file):gsub("%.lua$", ""), dependencies = {}, mod_version = 3, version = "1.0", tags = {}, path = plugin_dir .. file }
@@ -658,6 +667,7 @@ function Repository:generate_manifest()
local _, _, required_plugin = line:find("require [\"']plugins.([%w_]+)")
if required_plugin then if required_plugin ~= plugin.name then plugin.dependencies[required_plugin] = ">=1.0" end end
end
+ if plugin_map[plugin.name] then plugin = common.merge(plugin, plugin_map[plugin.name]) end
table.insert(plugins, plugin)
end
end
@@ -913,23 +923,21 @@ end
local function run_command(ARGS)
if not ARGS[2]:find("%S") then return end
- if ARGS[2] == "repo" and ARGV[3] == "add" then lpm_repo_add(table.unpack(slice(ARGS, 4)))
- elseif ARGS[2] == "repo" and ARGS[3] == "rm" then lpm_repo_rm(table.unpack(slice(ARGS, 4)))
- elseif ARGS[2] == "add" then lpm_repo_add(table.unpack(slice(ARGS, 3)))
- elseif ARGS[2] == "rm" then lpm_repo_rm(table.unpack(slice(ARGS, 3)))
- elseif ARGS[2] == "update" then lpm_repo_update(table.unpack(slice(ARGS, 3)))
- elseif ARGS[2] == "repo" and ARGS[3] == "update" then lpm_repo_update(table.unpack(slice(ARGS, 4)))
+ if ARGS[2] == "repo" and ARGV[3] == "add" then lpm_repo_add(table.unpack(common.slice(ARGS, 4)))
+ elseif ARGS[2] == "repo" and ARGS[3] == "rm" then lpm_repo_rm(table.unpack(common.slice(ARGS, 4)))
+ elseif ARGS[2] == "add" then lpm_repo_add(table.unpack(common.slice(ARGS, 3)))
+ elseif ARGS[2] == "rm" then lpm_repo_rm(table.unpack(common.slice(ARGS, 3)))
+ elseif ARGS[2] == "update" then lpm_repo_update(table.unpack(common.slice(ARGS, 3)))
+ elseif ARGS[2] == "repo" and ARGS[3] == "update" then lpm_repo_update(table.unpack(common.slice(ARGS, 4)))
elseif ARGS[2] == "repo" and ARGS[3] == "list" then return lpm_repo_list()
- elseif ARGS[2] == "plugin" and ARGS[3] == "install" then lpm_plugin_install(table.unpack(slice(ARGS, 4)))
- elseif ARGS[2] == "plugin" and ARGS[3] == "uninstall" then lpm_plugin_uninstall(table.unpack(slice(ARGS, 4)))
+ elseif ARGS[2] == "plugin" and ARGS[3] == "install" then lpm_plugin_install(table.unpack(common.slice(ARGS, 4)))
+ elseif ARGS[2] == "plugin" and ARGS[3] == "uninstall" then lpm_plugin_uninstall(table.unpack(common.slice(ARGS, 4)))
elseif ARGS[2] == "plugin" and ARGS[3] == "list" then return lpm_plugin_list()
- elseif ARGS[2] == "install" then lpm_plugin_install(table.unpack(slice(ARGS, 3)))
- elseif ARGS[2] == "uninstall" then lpm_plugin_uninstall(table.unpack(slice(ARGS, 3)))
+ elseif ARGS[2] == "install" then lpm_plugin_install(table.unpack(common.slice(ARGS, 3)))
+ elseif ARGS[2] == "uninstall" then lpm_plugin_uninstall(table.unpack(common.slice(ARGS, 3)))
elseif ARGS[2] == "list" then return lpm_plugin_list()
elseif ARGS[2] == "purge" then lpm_purge()
- else
- error("unknown command: " .. ARGS[2])
- end
+ else error("unknown command: " .. ARGS[2]) end
if JSON then
io.stdout:write(json.encode({ actions = actions, warnings = warnings }))
end
@@ -940,7 +948,7 @@ xpcall(function()
local ARGS = parse_arguments(ARGV, {
json = "flag", userdir = "string", cachedir = "string", version = "flag", verbose = "flag",
quiet = "flag", version = "string", modversion = "string", remotes = "flag", help = "flag",
- remotes = "flag"
+ remotes = "flag", ssl_cert = "string"
})
if ARGS["version"] then
io.stdout:write(VERSION .. "\n")
@@ -950,7 +958,7 @@ xpcall(function()
io.stderr:write([[
Usage: lpm COMMAND [--json] [--userdir=directory] [--cachedir=directory]
[--verbose] [--lite-version=2.1] [--mod-version=3] [--quiet] [--version]
- [--help] [--remotes]
+ [--help] [--remotes] [--ssl_certs=directory/file]
LPM is a package manager for `lite-xl`, written in C (and packed-in lua).
@@ -995,6 +1003,7 @@ Flags have the following effects:
--remotes Automatically adds any specified remotes in the repository to
the end of the resolution list.
--help Displays this help text.
+ --ssl_certs Sets the SSL certificate store to specified location.
]]
)
return 0
@@ -1012,6 +1021,35 @@ Flags have the following effects:
AUTO_PULL_REMOTES = ARGS["remotes"]
if not system.stat(USERDIR) then error("can't find user directory " .. USERDIR) end
CACHEDIR = ARGS["cachedir"] or os.getenv("LPM_CACHE") or USERDIR .. PATHSEP .. "lpm"
+
+ if ARGS["ssl_cert"] then
+ local stat = system.stat(path)
+ if not stat then error("can't find " .. path) end
+ system.set_certs(stat.type, path)
+ elseif not os.getenv("SSL_CERT_DIR") and not os.getenv("SSL_CERT_FILE") then
+ local paths = {
+ "/etc/ssl/certs/ca-certificates.crt", -- Debian/Ubuntu/Gentoo etc.
+ "/etc/pki/tls/certs/ca-bundle.crt", -- Fedora/RHEL 6
+ "/etc/ssl/ca-bundle.pem", -- OpenSUSE
+ "/etc/pki/tls/cacert.pem", -- OpenELEC
+ "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", -- CentOS/RHEL 7
+ "/etc/ssl/cert.pem", -- Alpine Linux
+ "/etc/ssl/certs", -- SLES10/SLES11, https://golang.org/issue/12139
+ "/system/etc/security/cacerts", -- Android
+ "/usr/local/share/certs", -- FreeBSD
+ "/etc/pki/tls/certs", -- Fedora/RHEL
+ "/etc/openssl/certs", -- NetBSD
+ "/var/ssl/certs", -- AIX
+ }
+ for i, path in ipairs(paths) do
+ local stat = system.stat(path)
+ if stat then
+ system.set_certs(stat.type, path)
+ break
+ end
+ end
+ end
+
repositories = {}
repositories = { Repository.new({ remote = "https://github.com/lite-xl/lite-xl-plugins.git", branch = "master" }), Repository.new({ remote = "https://github.com/lite-xl/lite-xl-plugins.git", branch = "2.1" }) }
local original_repositories = {}