/ runclient.lua
runclient.lua
 1  --[[
 2      ToasterGen Spin
 3  
 4      Copyright (C) 2025 Clifton Toaster Reid <cliftontreid@duck.com>
 5  
 6      This library is free software: you can redistribute it and/or modify
 7      it under the terms of the GNU Lesser General Public License as published by
 8      the Free Software Foundation, either version 3 of the License, or
 9      (at your option) any later version.
10  
11      This library is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14      GNU Lesser General Public License for more details.
15  
16      You should have received a copy of the GNU Lesser General Public License
17      along with this library. If not, see <https://www.gnu.org/licenses/>.
18  ]]
19  
20  local files = {
21      "install.lua",
22      "tools/config.lua",
23      "src/log.lua",
24      "src/toml.lua",
25      "src/semver.lua",
26  }
27  local gh_repo = "https://raw.githubusercontent.com/cliftontoaster-reid/cc-roulette/main/"
28  -- download everything inside /.var/
29  local function downloadFiles()
30      for _, file in ipairs(files) do
31          local url = gh_repo .. file
32          -- check if the file exists
33          if not fs.exists("/.var/" .. file) then
34              print("Downloading: " .. file)
35              local response = http.get(url)
36              if response then
37                  local content = response.readAll()
38                  -- create the directory if it doesn't exist
39                  if not fs.exists("/.var") then
40                      fs.makeDir("/.var")
41                      fs.makeDir("/.var/tools")
42                      fs.makeDir("/.var/src")
43                  end
44                  local f = fs.open("/.var/" .. file, "w")
45                  f.write(content)
46                  f.close()
47                  print("Downloaded: " .. file)
48              else
49                  print("Failed to download: " .. file)
50              end
51          end
52      end
53  end
54  
55  downloadFiles()
56  
57  shell.setDir("/.var")
58  if shell.run("install") then
59      print("Installation completed successfully.")
60  else
61      error("Installation failed.")
62  end
63  
64  shell.setDir("/")
65  shell.run("tools/roulette/spin.lua")