Advertisement
vittoema96

CyberOs startup (+ README)

Nov 29th, 2019 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.17 KB | None | 0 0
  1. --------------------------------------
  2. --        WHAT IS THIS?             --
  3. --------------------------------------
  4. -- This is a Lua script for the Minecraft
  5. -- mod Computercraft (or CC: Tweaked).
  6. -- It installs an OS suitable for all devices
  7. -- (basic and advanced normal and pocket computers,
  8. --  turtles and  monitors) that I'm developing.
  9. --____________________________________
  10. -- WARNING
  11. -- The OS is not finished and I
  12. -- do not assure that it will work
  13. -- nor do i assure that any future
  14. -- version will work.
  15. -- If the current install is working
  16. -- make a backup before downloading an
  17. -- update.
  18. --------------------------------------
  19. --        HOW TO INSTALL            --
  20. --------------------------------------
  21. -- First, be sure that
  22. -- YOU DO NOT HAVE A STARTUP FILE
  23. -- on this device.
  24. -- This program sets itself as the startup file,
  25. -- (but only if no other startup file is present,
  26. -- so no file is overwritten by mistake)
  27. -- If you do have one, run:
  28. -- delete startup.lua
  29. -- to delete it.
  30. -- Then simply run:
  31. --
  32. --    pastebin run qJSSf0qg
  33. --
  34. -- Now you are set, this will automatically
  35. -- run the installer.
  36. --____________________________________
  37. -- WARNING
  38. -- None of the other "CyberOs"
  39. -- files in my pastebin account are  
  40. -- meant to be downloaded by other    
  41. -- means that of this installer      
  42. -- This program auto-manages the      
  43. -- proper installation process and run
  44. -- conditions of CyberOs              
  45.  
  46.  
  47. --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--
  48. -- FOR THE DEVELOPER ONLY (ME) --
  49. --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--
  50. -- TODO:
  51. --  Complete the themes icons/images
  52. --  Make the installer more user friendly
  53. --  Explain how to update a current installation
  54. --  Implement all other CyberOSs except Next
  55.  
  56.  
  57. -- Folder where files are installed
  58. INSTALL_FOLDER = "CyberOS"
  59. local x, y = term.getSize()
  60.  
  61.  
  62. local osName = "CyberOs"
  63. local osId = "AZAXFw5b"
  64.  
  65. local startupId = "qJSSf0qg"
  66.  
  67.  
  68. local osTierName, osTierId
  69. local osDeviceName, osDeviceId
  70.  
  71. if term.isColor() then
  72.     osTierName = "CyberOsColor"
  73.     osTierId = "ATuWkjAJ"
  74. else
  75.     osTierName = "CyberOsLite"
  76.     osTierId = "ByAJwwMp"
  77. end
  78.  
  79. -- MONITOR
  80. if monitor then
  81.     osDeviceName = "CyberOsMonitor"
  82.     osDeviceId = nil
  83. -- POCKET COMPUTER
  84. elseif pocket then
  85.     assert(x==39 and y==13, "Something went wrong, size X, Y: '"..x..", "..y.."' is not the 26, 20 expected from a pocket computer")
  86.     osDeviceName = "CyberOsPocket"
  87.     osDeviceId = "BxMFPgc9"
  88. -- TURTLE
  89. elseif turtle then
  90.     assert(x==39 and y==13, "Something went wrong, size X, Y: '"..x..", "..y.."' is not the 39, 13 expected from a turtle")
  91.     osDeviceName = "CyberOsTurtle"
  92.     osDeviceId = nil
  93. -- COMPUTER
  94. else
  95.     assert(x==51 and y==19, "Something went wrong, size X, Y: '"..x..", "..y.."' is not the 51, 19 expected from a computer")
  96.     osDeviceName = "CyberOsHome"
  97.     osDeviceId = "rd1GDixz"
  98. end
  99.  
  100. -------------------------------------------------------
  101. -- THIS BIT RUNS ONLY IF INSTALL_FOLDER DOES NOT EXIST
  102. -- aka CyberOs was never installed.
  103. -- Creates INSTALL_FOLDER, saves the program as startup
  104. -- and creates an uninstaller.
  105. -------------------------------------------------------
  106. if not fs.exists(INSTALL_FOLDER) then
  107.     if not fs.exists("startup.lua") then
  108.         fs.makeDir(INSTALL_FOLDER)
  109.         shell.run("pastebin", "get", startupId, "startup.lua")
  110.  
  111.         -- Create an uninstaller
  112.         if fs.exists("uninstallCyberOs")==false then
  113.             local f = fs.open("uninstallCyberOs.lua", "w")
  114.             f.writeLine("fs.delete(\""..INSTALL_FOLDER.."\")")
  115.             f.writeLine("fs.delete(\"startup.lua\")")
  116.             f.writeLine("fs.delete(\"uninstallCyberOs.lua\")")
  117.             f.writeLine("os.reboot()")
  118.             f.close()
  119.         end
  120.  
  121.     else
  122.         error("To install this OS, no startup.lua file must be present. Delete it with: 'delete startup.lua' and try again")
  123.     end
  124. end
  125.  
  126. --- Local funtion of the installer,
  127. -- it downloads pastebin apiId
  128. -- to INSTALL_FOLDER/apiName.lua
  129. -- and loads it as an API.
  130. local initApi = function (apiId, apiName)
  131.     local apiPath = INSTALL_FOLDER .. "/" .. apiName .. ".lua"
  132.     if not fs.exists(apiPath) then
  133.         shell.run("pastebin", "get", apiId, apiPath)
  134.     end
  135.     os.loadAPI(apiPath)
  136. end
  137.        
  138.  
  139. ----------------------------------
  140. -- Checks for API files, if not
  141. -- present it downloads them.
  142. -- Then proceed to load those APIs
  143. -----------------------------------
  144.  
  145. -- Load or install CyberOs, common class to every device
  146. initApi(osId, osName)
  147.  
  148. -- Load or install  CyberOsTier (Lite or Color aka Baasic or Advanced)
  149. initApi(osTierId, osTierName)
  150.  
  151.  
  152. -- Load or install  CyberOsDevice (Home, Monitor, Pocket or Turtle)
  153. if osDeviceId == nil then  
  154.     CyberOs.basicWarning("No specific version of the API was found for this Device. "..deviceType.." may be under development.")
  155. else
  156.     initApi(osDeviceId, osDeviceName)
  157. end
  158.    
  159. ----------------
  160. -- DISCLAIMER --
  161. ----------------
  162.  
  163. CyberOs.basicWarning("This project is in it's early development stage. Please understand that most functionalities are yet to be implemented, that this Os is prone to crashing and that the Lua files on Pastebin can change at any time. Thank you for downloading this. --The Developer.")
  164.  
  165.  
  166. -- The class defining the tier (basic or advanced)
  167. local tierClass = _G[osTierName].class
  168. -- The class defining the device (computer, turtle, etc)
  169. local deviceClass = _G[osDeviceName].class
  170.  
  171. -- The instance representing the OS tweaked for this specific system
  172. local instance = CyberOs.createInstance(tierClass, deviceClass, shell)
  173.  
  174.  
  175. -- Checks for the settings file, if not
  176. -- present creates it
  177. if not fs.exists(INSTALL_FOLDER .. "/.settings") then
  178.     local settings = {}
  179.     settings["bgcolor"] = 32768
  180.     local f = fs.open(INSTALL_FOLDER .. "/.settings", "w")
  181.     f.writeLine(textutils.serialize(settings))
  182.     f.close()
  183.  
  184.     settings["theme"] = instance:themeSelection()
  185.     f = fs.open(INSTALL_FOLDER .. "/.settings", "w")
  186.     f.writeLine(textutils.serialize(settings))
  187.     f.close()
  188. end
  189.  
  190. instance:startupAnimation()
  191.  
  192. -- Checks for the .registeredTurtles file,
  193. -- if not present creates it
  194. -- TODO May be better to do this only when needed
  195. if fs.exists(INSTALL_FOLDER .. "/.registeredTurtles")==false then
  196.     local f = fs.open(INSTALL_FOLDER .. "/.registeredTurtles", "w")
  197.     f.close()
  198. end
  199.  
  200. instance:setBackground()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement