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 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 raw_base = "https://git.sad.ovh/sophie/storage-solution/raw/branch/main"
|
||||||
local branch = "main"
|
local branch = "main"
|
||||||
local download_root = "storage-solution"
|
local download_root = "storage-solution"
|
||||||
|
local remote_folder = "src"
|
||||||
|
|
||||||
-- Get latest commit hash for branch
|
|
||||||
local function fetch_commit_hash()
|
local function fetch_commit_hash()
|
||||||
local url = repo_api .. "/branches/" .. branch
|
local url = repo_api .. "/branches/" .. branch
|
||||||
local response = http.get(url)
|
local response = http.get(url)
|
||||||
|
|
@ -17,7 +16,6 @@ local function fetch_commit_hash()
|
||||||
return data.commit.id
|
return data.commit.id
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Fetch file/folder listing from Forgejo API
|
|
||||||
local function fetch_repo_tree(path)
|
local function fetch_repo_tree(path)
|
||||||
local url = repo_api .. "/contents" .. (path and ("/" .. path) or "")
|
local url = repo_api .. "/contents" .. (path and ("/" .. path) or "")
|
||||||
local response = http.get(url)
|
local response = http.get(url)
|
||||||
|
|
@ -29,10 +27,8 @@ local function fetch_repo_tree(path)
|
||||||
return textutils.unserializeJSON(body)
|
return textutils.unserializeJSON(body)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Download a single file
|
local function download_file(remote_path, local_path)
|
||||||
local function download_file(path)
|
local url = raw_base .. "/" .. remote_path
|
||||||
local url = raw_base .. "/" .. path
|
|
||||||
local local_path = download_root .. "/" .. path
|
|
||||||
fs.makeDir(fs.getDir(local_path))
|
fs.makeDir(fs.getDir(local_path))
|
||||||
local response = http.get(url)
|
local response = http.get(url)
|
||||||
if response then
|
if response then
|
||||||
|
|
@ -42,35 +38,34 @@ local function download_file(path)
|
||||||
file.close()
|
file.close()
|
||||||
end
|
end
|
||||||
response.close()
|
response.close()
|
||||||
print("Downloaded: " .. path)
|
print("Downloaded: " .. local_path)
|
||||||
else
|
else
|
||||||
print("Failed to download: " .. url)
|
print("Failed to download: " .. url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Recursively traverse Forgejo folders
|
local function traverse_and_download(remote_path, local_prefix)
|
||||||
local function traverse_and_download(path)
|
local tree = fetch_repo_tree(remote_path)
|
||||||
local tree = fetch_repo_tree(path)
|
|
||||||
for _, entry in ipairs(tree) do
|
for _, entry in ipairs(tree) do
|
||||||
if entry.type == "file" then
|
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
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get current remote commit hash
|
|
||||||
local remote_hash = fetch_commit_hash()
|
local remote_hash = fetch_commit_hash()
|
||||||
print("Latest commit: " .. remote_hash)
|
print("Latest commit: " .. remote_hash)
|
||||||
|
|
||||||
-- Check for existing version
|
|
||||||
if fs.exists(download_root) then
|
if fs.exists(download_root) then
|
||||||
if fs.exists(download_root .. "/version") then
|
if fs.exists(download_root .. "/version") then
|
||||||
local f = fs.open(download_root .. "/version", "r")
|
local f = fs.open(download_root .. "/version", "r")
|
||||||
local local_hash = f.readAll()
|
local local_hash = f.readAll()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if local_hash == remote_hash then
|
if local_hash == remote_hash then
|
||||||
print("Already up to date (commit " .. remote_hash:sub(1,7) .. ").")
|
print("Already up to date (commit " .. remote_hash:sub(1,7) .. ").")
|
||||||
shell.run(download_root .. "/main.lua")
|
shell.run(download_root .. "/main.lua")
|
||||||
|
|
@ -85,14 +80,11 @@ if fs.exists(download_root) then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create root directory
|
|
||||||
fs.makeDir(download_root)
|
fs.makeDir(download_root)
|
||||||
|
|
||||||
-- Download everything
|
print("Fetching src/ directory from Forgejo...")
|
||||||
print("Fetching repository tree from Forgejo...")
|
traverse_and_download(remote_folder, download_root)
|
||||||
traverse_and_download("")
|
|
||||||
|
|
||||||
-- Save commit hash as version
|
|
||||||
local f = fs.open(download_root .. "/version", "w")
|
local f = fs.open(download_root .. "/version", "w")
|
||||||
f.write(remote_hash)
|
f.write(remote_hash)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue