From aadf2b2af970406811fe223ceab727a5b34eb75a Mon Sep 17 00:00:00 2001 From: yourfriendoss Date: Tue, 11 Nov 2025 18:00:17 +0200 Subject: [PATCH] acc hate AI with a passion --- README.md => readme.md | 0 src/.main-installer.lua | 40 ++++++++++++++++------------------------ 2 files changed, 16 insertions(+), 24 deletions(-) rename README.md => readme.md (100%) diff --git a/README.md b/readme.md similarity index 100% rename from README.md rename to readme.md diff --git a/src/.main-installer.lua b/src/.main-installer.lua index 77096ba..739a982 100644 --- a/src/.main-installer.lua +++ b/src/.main-installer.lua @@ -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,41 +38,40 @@ 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) .. ").") + print("Already up to date (commit " .. remote_hash:sub(1,7) .. ").") shell.run(download_root .. "/main.lua") return else - print("Outdated (" .. local_hash:sub(1, 7) .. " -> " .. remote_hash:sub(1, 7) .. "), reinstalling...") + print("Outdated (" .. local_hash:sub(1,7) .. " -> " .. remote_hash:sub(1,7) .. "), reinstalling...") fs.delete(download_root) end else @@ -85,17 +80,14 @@ 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() -print("Installed Sophie's Storage Solution (commit " .. remote_hash:sub(1, 7) .. ")") +print("Installed Sophie's Storage Solution (commit " .. remote_hash:sub(1,7) .. ")") shell.run(download_root .. "/main.lua")