cleanup & download location
This commit is contained in:
@@ -1,41 +1,12 @@
|
|||||||
-- Leave empty for public repos, or add "your-token-here"
|
-- Leave empty for public repos, or add "your-token-here"
|
||||||
local GIT_TOKEN = ""
|
local GIT_TOKEN = ""
|
||||||
|
|
||||||
|
local GIT_OUTPUT_LOCATION = "/home"
|
||||||
|
|
||||||
-- Update config
|
-- Update config
|
||||||
local GIT_URL = "https://git.ejebring.com/eejebring/CC-tweaked-Gitea-Client/raw/branch/main/git.lua"
|
local UPDATE_URL = "https://git.ejebring.com/eejebring/CC-tweaked-Gitea-Client/raw/branch/main/git.lua"
|
||||||
local GIT_FILE = "git.lua"
|
local GIT_FILE = "git.lua"
|
||||||
|
|
||||||
-- Parse a Gitea URL like: https://gitea.example.com/owner/repo or /owner/repo/branch/filename
|
|
||||||
-- local function parseGiteaURL(url)
|
|
||||||
-- local protocol, domain, path = url:match("^(https?://([^/]+))(/[^?]*)")
|
|
||||||
-- if not protocol then
|
|
||||||
-- protocol, domain, path = "https://gitea.local", "gitea.local", url
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- -- Remove trailing slashes and clean path
|
|
||||||
-- path = path:gsub("/+$", "")
|
|
||||||
|
|
||||||
-- -- Extract components from path (format: /owner/repo or /owner/repo/branch)
|
|
||||||
-- local parts = {}
|
|
||||||
-- for segment in path:gmatch("[^/]+") do
|
|
||||||
-- if segment ~= "" then table.insert(parts, segment) end
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- if #parts < 2 then
|
|
||||||
-- return nil, "Invalid URL format. Expected: https://domain.com/owner/repo"
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- local owner = parts[1]
|
|
||||||
-- local repo = parts[2]
|
|
||||||
-- local branch = parts[3] or "master"
|
|
||||||
|
|
||||||
-- return {
|
|
||||||
-- base = protocol .. "/" .. domain,
|
|
||||||
-- owner = owner,
|
|
||||||
-- repo = repo,
|
|
||||||
-- branch = branch
|
|
||||||
-- }
|
|
||||||
-- end
|
|
||||||
|
|
||||||
---@param str string
|
---@param str string
|
||||||
---@param comp string
|
---@param comp string
|
||||||
function string.beginsWith(str, comp)
|
function string.beginsWith(str, comp)
|
||||||
@@ -134,12 +105,8 @@ end
|
|||||||
|
|
||||||
local function cloneRepo(url)
|
local function cloneRepo(url)
|
||||||
local urlInfo = parseGiteaURL(url)
|
local urlInfo = parseGiteaURL(url)
|
||||||
-- if not info then error(err) end
|
|
||||||
|
|
||||||
print("Cloning: " .. urlInfo.owner .. "/" .. urlInfo.repo .. "@" .. urlInfo.branch)
|
print("Cloning: " .. urlInfo.owner .. "/" .. urlInfo.repo .. "@" .. urlInfo.branch)
|
||||||
|
|
||||||
-- local treeUrl = ("%s/api/v1/repos/%s/%s/git/trees/%s?recursive=1"):format(info.base, info.owner, info.repo,info.branch)
|
|
||||||
|
|
||||||
local req = { url = urlInfo.treeUrl }
|
local req = { url = urlInfo.treeUrl }
|
||||||
if GIT_TOKEN ~= "" then
|
if GIT_TOKEN ~= "" then
|
||||||
req.headers = { Authorization = "token " .. GIT_TOKEN }
|
req.headers = { Authorization = "token " .. GIT_TOKEN }
|
||||||
@@ -157,7 +124,7 @@ local function cloneRepo(url)
|
|||||||
local count = 0
|
local count = 0
|
||||||
for _, node in ipairs(tree.tree) do
|
for _, node in ipairs(tree.tree) do
|
||||||
if node.type == "blob" then
|
if node.type == "blob" then
|
||||||
local localPath = ("git/%s/%s/%s"):format(urlInfo.owner, urlInfo.repo, node.path)
|
local localPath = ("%s/%s/%s"):format(GIT_OUTPUT_LOCATION, urlInfo.repo, node.path)
|
||||||
local dir = fs.getDir(localPath)
|
local dir = fs.getDir(localPath)
|
||||||
|
|
||||||
if not fs.isDir(dir) then fs.makeDir(dir) end
|
if not fs.isDir(dir) then fs.makeDir(dir) end
|
||||||
@@ -167,14 +134,14 @@ local function cloneRepo(url)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print(("Cloned %d files to /home/git/%s/%s"):format(count, urlInfo.owner, urlInfo.repo))
|
print(("Cloned %d files to %s/%s"):format(count, GIT_OUTPUT_LOCATION, urlInfo.repo))
|
||||||
end
|
end
|
||||||
|
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
if args[1] == "clone" and args[2] then
|
if args[1] == "clone" and args[2] then
|
||||||
cloneRepo(args[2])
|
cloneRepo(args[2])
|
||||||
elseif args[1] == "update" then
|
elseif args[1] == "update" then
|
||||||
local resp = http.get(GIT_URL)
|
local resp = http.get(UPDATE_URL)
|
||||||
if not resp then error("Failed to download update.") end
|
if not resp then error("Failed to download update.") end
|
||||||
local code = resp.readAll()
|
local code = resp.readAll()
|
||||||
if not code then error("Recived empty response from server.") end
|
if not code then error("Recived empty response from server.") end
|
||||||
|
|||||||
Reference in New Issue
Block a user