acc hate AI with a passion
This commit is contained in:
parent
d533cad870
commit
aadf2b2af9
2 changed files with 16 additions and 24 deletions
|
|
@ -1,10 +1,9 @@
|
|||
-- Forgejo-based installer for Sophie's Storage Solution
|
||||
local repo_api = "https://git.sad.ovh/api/v1/repos/sophie/storage-solution"
|
||||
local raw_base = "https://git.sad.ovh/sophie/storage-solution/raw/branch/main"
|
||||
local branch = "main"
|
||||
local download_root = "storage-solution"
|
||||
local remote_folder = "src"
|
||||
|
||||
-- Get latest commit hash for branch
|
||||
local function fetch_commit_hash()
|
||||
local url = repo_api .. "/branches/" .. branch
|
||||
local response = http.get(url)
|
||||
|
|
@ -17,7 +16,6 @@ local function fetch_commit_hash()
|
|||
return data.commit.id
|
||||
end
|
||||
|
||||
-- Fetch file/folder listing from Forgejo API
|
||||
local function fetch_repo_tree(path)
|
||||
local url = repo_api .. "/contents" .. (path and ("/" .. path) or "")
|
||||
local response = http.get(url)
|
||||
|
|
@ -29,10 +27,8 @@ local function fetch_repo_tree(path)
|
|||
return textutils.unserializeJSON(body)
|
||||
end
|
||||
|
||||
-- Download a single file
|
||||
local function download_file(path)
|
||||
local url = raw_base .. "/" .. path
|
||||
local local_path = download_root .. "/" .. path
|
||||
local function download_file(remote_path, local_path)
|
||||
local url = raw_base .. "/" .. remote_path
|
||||
fs.makeDir(fs.getDir(local_path))
|
||||
local response = http.get(url)
|
||||
if response then
|
||||
|
|
@ -42,35 +38,34 @@ local function download_file(path)
|
|||
file.close()
|
||||
end
|
||||
response.close()
|
||||
print("Downloaded: " .. path)
|
||||
print("Downloaded: " .. local_path)
|
||||
else
|
||||
print("Failed to download: " .. url)
|
||||
end
|
||||
end
|
||||
|
||||
-- Recursively traverse Forgejo folders
|
||||
local function traverse_and_download(path)
|
||||
local tree = fetch_repo_tree(path)
|
||||
local function traverse_and_download(remote_path, local_prefix)
|
||||
local tree = fetch_repo_tree(remote_path)
|
||||
for _, entry in ipairs(tree) do
|
||||
if entry.type == "file" then
|
||||
download_file(entry.path)
|
||||
local local_path = local_prefix .. "/" .. fs.getName(entry.path)
|
||||
download_file(entry.path, local_path)
|
||||
elseif entry.type == "dir" then
|
||||
traverse_and_download(entry.path)
|
||||
local new_remote = entry.path
|
||||
local new_local = local_prefix .. "/" .. fs.getName(entry.path)
|
||||
traverse_and_download(new_remote, new_local)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Get current remote commit hash
|
||||
local remote_hash = fetch_commit_hash()
|
||||
print("Latest commit: " .. remote_hash)
|
||||
|
||||
-- Check for existing version
|
||||
if fs.exists(download_root) then
|
||||
if fs.exists(download_root .. "/version") then
|
||||
local f = fs.open(download_root .. "/version", "r")
|
||||
local local_hash = f.readAll()
|
||||
f.close()
|
||||
|
||||
if local_hash == remote_hash then
|
||||
print("Already up to date (commit " .. remote_hash:sub(1,7) .. ").")
|
||||
shell.run(download_root .. "/main.lua")
|
||||
|
|
@ -85,14 +80,11 @@ if fs.exists(download_root) then
|
|||
end
|
||||
end
|
||||
|
||||
-- Create root directory
|
||||
fs.makeDir(download_root)
|
||||
|
||||
-- Download everything
|
||||
print("Fetching repository tree from Forgejo...")
|
||||
traverse_and_download("")
|
||||
print("Fetching src/ directory from Forgejo...")
|
||||
traverse_and_download(remote_folder, download_root)
|
||||
|
||||
-- Save commit hash as version
|
||||
local f = fs.open(download_root .. "/version", "w")
|
||||
f.write(remote_hash)
|
||||
f.close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue