Sir_Mr_Bman

GitHub Installer for CC

Apr 25th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. local function clear()
  2.  
  3.     term.setBackgroundColor(colors.black)
  4.     term.clear()
  5.     term.setCursorPos(1, 1)
  6.     term.setTextColor(colors.yellow)
  7.  
  8. end
  9.  
  10. -- GitGET Function
  11. --
  12. -- Written for Sir_Mr_Bman's GitHub
  13. --
  14.  
  15. local function gitGet(file, save)
  16.  
  17.     if fs.exists("/dwnlds") then
  18.         fs.delete("/dwnlds")
  19.     end
  20.  
  21.     fs.makeDir("/dwnlds")
  22.     term.setTextColor(colors.purple)
  23.     print("[GitGET] Getting file: "..file)
  24.     local response = http.get(
  25.                 "https://raw.githubusercontent.com/Sir-Mr-Bman/IndustrialSecurity/master/src/"..textutils.urlEncode(file)..".lua"  
  26.     )
  27.     if response then
  28.         print("[GitGET] Server responded. Downloading...")
  29.         local save = response.readAll()
  30.         response.close()
  31.         local h = fs.open("/dwnlds/"..save, "w")
  32.         h.write(save)
  33.         h.close()
  34.         print("[GitGET] File downloaded.")
  35.     else
  36.         print("[GitGET] Server did not respond. Is it offline?")
  37.         print("[GitGET] Check your internet connection, and firewall settings.")
  38.     end
  39.  
  40. end
  41.  
  42. -- Extract Function
  43. --
  44. -- Written to extract all files to their directories.
  45. --
  46.  
  47. local function extract(from, to)
  48.     term.setTextColor(colors.orange)
  49.     if fs.exists(to) then
  50.         fs.delete(to)
  51.     end
  52.  
  53.     if not fs.exists(from) then
  54.             print("[Extract] The file you are trying to extract does not exist.")
  55.     end
  56.  
  57.     print("[Extract] Extracting file: "..from)
  58.     fs.copy("/dwnlds/"..from, to)
  59.     sleep(1)
  60.     print("[Extract] Deleting old copy.")
  61.     fs.delete("/dwnlds/"..from)
  62.  
  63.  
  64. end
  65.  
  66. --[[ START MAIN CODE. ]]
  67.  
  68. --[[ Tests if term is advanced. ]]
  69. if not term.isColor() then
  70.  
  71.     print("Sorry, but this program requires an advanced computer.")
  72.     return
  73.  
  74. end
  75.  
  76. --[[ Tests if HTTP API is enabled.]]
  77. if not http then
  78.     print("Sorry, but this program requires the HTTP API to be enabled.")
  79.     return
  80. end
  81.  
  82. --[[ Clears screen ]]
  83. clear()
  84.  
  85. --[[ Load files into GitGet]]
  86. print("Getting file [1 / 9]")
  87. gitGet("admin", "admin")
  88. term.setTextColor(colors.yellow)
  89. print("Getting file [2 / 9]")
  90. gitGet("dev", "dev")
  91. term.setTextColor(colors.yellow)
  92. print("Getting file [3 / 9]")
  93. gitGet("door", "door") 
  94. term.setTextColor(colors.yellow)
  95. print("Getting file [4 / 9]")
  96. gitGet("rs", "rs")
  97. term.setTextColor(colors.yellow)
  98. print("Getting file [5 / 9]")
  99. gitGet("side", "side")
  100. term.setTextColor(colors.yellow)
  101. print("Getting file [6 / 9]")
  102. gitGet("pass", "pass")
  103. term.setTextColor(colors.yellow)
  104. print("Getting file [7 / 9]")
  105. gitGet("startup", "startup")   
  106. term.setTextColor(colors.yellow)
  107. print("Getting file [8 / 9]")
  108. gitGet("change", "change")
  109. term.setTextColor(colors.yellow)
  110. print("Getting file [9 / 9]")
  111. gitGet("opt", "opt")
  112. term.setTextColor(colors.yellow)
  113. print("Got all files.")
  114. sleep(3)
  115.  
  116. --[[ Extract files with Extract ]]
  117. print("Extracting files into directories.")
  118. print("Extracting file [1 / 9]")
  119. extract("admin", "/.bman/pass/admin")
  120. term.setTextColor(colors.yellow)
  121. print("Extracting file [2 / 9]")
  122. extract("dev", "/.bman/pass/dev")
  123. term.setTextColor(colors.yellow)
  124. print("Extracting file [3 / 9]")
  125. extract("door", "/.bman/pass/door")
  126. term.setTextColor(colors.yellow)
  127. print("Extracting file [4 / 9]")
  128. extract("rs", "/.bman/pass/rs")
  129. term.setTextColor(colors.yellow)
  130. print("Extracting file [5 / 9]")
  131. extract("side", "side")
  132. term.setTextColor(colors.yellow)
  133. print("Extracting file [6 / 9]")
  134. extract("pass", "/.bman/pass/pass")
  135. term.setTextColor(colors.yellow)
  136. print("Extracting file [7 / 9]")
  137. extract("startup", "/startup")
  138. term.setTextColor(colors.yellow)
  139. print("Extracting file [8 / 9]")
  140. extract("change", "/.bman/pass/change")
  141. term.setTextColor(colors.yellow)
  142. print("Extracting file [9 / 9]")
  143. extract("opt", "/.bman/pass/opt")
  144. term.setTextColor(colors.yellow)
  145. print("Done.")
  146. sleep(3)
  147. print("Your default password is: password")
  148. print("You may want to write this down.")
  149. sleep(5)
  150. print("Restarting...")
  151. sleep(2)
  152. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment