installer.lua
  1. local owner = "Zonk1987"
  2. local repo = "CC-Tweaked"
  3. local apiUrl = "api.github.com .. owner .. "/" .. repo .. "/contents/"
  4.  
  5. local function clear()
  6. term.clear()
  7. term.setCursorPos(1, 1)
  8. end
  9.  
  10. clear()
  11. if term.isColor() then term.setTextColor(colors.cyan) end
  12. print("=======================================")
  13. print(" Zonk's CC-Tweaked Installer ")
  14. print("=======================================")
  15. if term.isColor() then term.setTextColor(colors.white) end
  16. print("Fetching projects from GitHub...\n")
  17.  
  18. -- Fetch root contents
  19. local response = http.get(apiUrl)
  20. if not response then
  21. if term.isColor() then term.setTextColor(colors.red) end
  22. print("Error: Could not connect to GitHub API.")
  23. print("Check your internet connection or HTTP API settings in CC.")
  24. return
  25. end
  26.  
  27. local responseData = response.readAll()
  28. response.close()
  29.  
  30. local data = textutils.unserializeJSON(responseData)
  31. if not data then
  32. if term.isColor() then term.setTextColor(colors.red) end
  33. print("Error parsing GitHub response.")
  34. return
  35. end
  36.  
  37. if data.message and string.find(string.lower(data.message), "api rate limit") then
  38. if term.isColor() then term.setTextColor(colors.red) end
  39. print("GitHub API Rate Limit exceeded!")
  40. print("Please try again later.")
  41. return
  42. end
  43.  
  44. local projects = {}
  45. for i, item in ipairs(data) do
  46. -- Only include directories, ignore hidden folders (.git) and the installer folder itself
  47. if item.type == "dir" and item.name ~= "installer" and not string.match(item.name, "^%.") then
  48. table.insert(projects, item)
  49. end
  50. end
  51.  
  52. if #projects == 0 then
  53. print("No projects found in the repository.")
  54. return
  55. end
  56.  
  57. while true do
  58. clear()
  59. if term.isColor() then term.setTextColor(colors.cyan) end
  60. print("=======================================")
  61. print(" Zonk's CC-Tweaked Installer ")
  62. print("=======================================")
  63. if term.isColor() then term.setTextColor(colors.white) end
  64. print("Select a project to install:\n")
  65.  
  66. for i, proj in ipairs(projects) do
  67. if term.isColor() then term.setTextColor(colors.yellow) end
  68. term.write("[" .. i .. "] ")
  69. if term.isColor() then term.setTextColor(colors.white) end
  70. print(proj.name)
  71. end
  72.  
  73. if term.isColor() then term.setTextColor(colors.red) end
  74. print("\n[0] Exit")
  75. if term.isColor() then term.setTextColor(colors.white) end
  76.  
  77. term.write("\nChoice: ")
  78. local choice = tonumber(read())
  79.  
  80. if choice == 0 then
  81. print("Exiting...")
  82. return
  83. elseif choice and choice > 0 and choice <= #projects then
  84. local selected = projects[choice]
  85. print("\nFetching files for " .. selected.name .. "...")
  86.  
  87. -- URL encode spaces in the path for the API call just in case
  88. local safePath = string.gsub(selected.path, " ", "%%20")
  89. local projRes = http.get(apiUrl .. safePath)
  90.  
  91. if not projRes then
  92. if term.isColor() then term.setTextColor(colors.red) end
  93. print("Failed to get project contents.")
  94. os.sleep(2)
  95. else
  96. local projDataRaw = projRes.readAll()
  97. projRes.close()
  98. local projData = textutils.unserializeJSON(projDataRaw)
  99.  
  100. if projData then
  101. local filesDownloaded = 0
  102. for _, fileItem in ipairs(projData) do
  103. if fileItem.type == "file" then
  104. print("Downloading " .. fileItem.name .. "...")
  105. local fileRes = http.get(fileItem.download_url)
  106. if fileRes then
  107. local fileContent = fileRes.readAll()
  108. fileRes.close()
  109.  
  110. local f = fs.open(fileItem.name, "w")
  111. f.write(fileContent)
  112. f.close()
  113. filesDownloaded = filesDownloaded + 1
  114. else
  115. if term.isColor() then term.setTextColor(colors.red) end
  116. print("Failed to download " .. fileItem.name)
  117. if term.isColor() then term.setTextColor(colors.white) end
  118. end
  119. end
  120. end
  121.  
  122. if term.isColor() then term.setTextColor(colors.green) end
  123. print("\nSuccessfully downloaded " .. filesDownloaded .. " files!")
  124. if term.isColor() then term.setTextColor(colors.yellow) end
  125. print("Rebooting computer in 3 seconds to apply startup.lua...")
  126. os.sleep(3)
  127. os.reboot()
  128. return
  129. else
  130. if term.isColor() then term.setTextColor(colors.red) end
  131. print("Failed to parse project data.")
  132. os.sleep(2)
  133. end
  134. end
  135. else
  136. if term.isColor() then term.setTextColor(colors.red) end
  137. print("Invalid choice!")
  138. if term.isColor() then term.setTextColor(colors.white) end
  139. os.sleep(1)
  140. end
  141. end
  142.  
Pasted 2026-05-10 02:50:55

Short link: