MoondancerPony

Untitled

Dec 29th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. --[[
  2. PotatOS OmniDisk
  3. A new system to unify the existing PotatOS Uninstall/Debug/Update disks currently in existence.
  4. Comes with a flexible, modular design, centralized licensing, possibly neater code, and a menu.
  5.  
  6. This is designed to be executed by the OmniDisk Loader (https://pastebin.com/S1RS76pv) but may run on its own, though this is NOT a supported configuration.
  7.  
  8. This is NOT usable simply by copying it onto a disk due to PotatOS signing requirements.
  9. You must use the dcopy (https://pastebin.com/TfNgRUKC) program or manually generate a hex-format ECC signature and write it to "disk/signature" (PotatOS will, however, not run it unless this signature is from the PDSK).
  10. ]]
  11.  
  12. print "Killing PotatOS VM."
  13. process.signal("shell", process.signals.KILL)
  14. local sandbox = process.info "sandbox"
  15. for _, p in pairs(process.list()) do
  16. if p.parent == sandbox then
  17. process.signal(p.ID, process.signals.KILL)
  18. end
  19. end
  20. process.signal("sandbox", process.signals.KILL)
  21. os.queueEvent "stop"
  22.  
  23. local function fetch(URL)
  24. local h = http.get(URL)
  25. local o = h.readAll()
  26. h.close()
  27. return o
  28. end
  29.  
  30. local UUID = "@UUID@" -- Populated by dcopy utility, in some setups
  31.  
  32. local args = ...
  33.  
  34. if type(args) == "table" and args.UUID then UUID = args.UUID end
  35.  
  36. local json = dofile "json"
  37. local licenses = json.decode(fetch "https://pastebin.com/raw/3cVT4009")
  38. local license = licenses[UUID]
  39.  
  40. local disk_ID
  41. local disk_loader_args = args.arguments
  42. if type(disk_loader_args) == "table" and disk_loader_args.ID then
  43. disk_ID = disk_loader_args.ID
  44. end
  45.  
  46. local features = {
  47. test = {
  48. fn = function() print "Hello, World!" end,
  49. description = "Test function."
  50. },
  51. exit = {
  52. fn = function() os.reboot() end,
  53. description = "Leave OmniDisk, return to PotatOS.",
  54. always_permitted = true
  55. },
  56. UUID = {
  57. fn = function() print("UUID:", UUID) print("Disk ID:", disk_ID or "[unavailable: update potatOS]") end,
  58. description = "Print this OmniDisk's Licensing UUID.",
  59. always_permitted = true
  60. },
  61. uninstall = {
  62. fn = function() print "Uninstalling..." _G.uninstall() end,
  63. description = "Uninstall potatOS"
  64. },
  65. REPL = {
  66. fn = function() shell.run "/rom/programs/lua.lua" end,
  67. description = "Open a Lua REPL for debugging."
  68. },
  69. shell = {
  70. fn = function()
  71. printError "WARNING!"
  72. print "Do not attempt to modify the code of this PotatOS OmniDisk. Unauthorized attempts to do so will invalidate the signature and make the disk unusable. All code beyond a limited core is stored in an online file to which you do not have write access. Probably. Contact gollark for further information."
  73. shell.run "/rom/programs/shell.lua"
  74. end,
  75. description = "Open an unsandboxed shell."
  76. },
  77. update = {
  78. fn = function() shell.run "autorun update" end,
  79. description = "Update PotatOS."
  80. },
  81. dump_license = {
  82. fn = function() print(UUID) textutils.pagedPrint(textutils.serialise(license)) end,
  83. description = "Dump license information."
  84. },
  85. primes = {
  86. fn = function()
  87. if not _G.findprime or not _G.isprime then
  88. error "findprime/isprime not available. Update potatOS."
  89. end
  90. write "Difficulty? (1-16) "
  91. local difficulty = tonumber(read())
  92. if type(difficulty) ~= "number" then error "ERR_PEBKAC\nThat's not a number." end
  93. local maxrand = math.pow(10, difficulty)
  94. local p1 = findprime(math.random(2, maxrand))
  95. local p2 = findprime(math.random(2, maxrand))
  96.  
  97. local num = p1 * p2
  98. print("Please find the prime factors of the following number:", num)
  99. write "Factor 1: "
  100. local f1 = tonumber(read())
  101. write "Factor 2: "
  102. local f2 = tonumber(read())
  103. if (f1 == p1 and f2 == p2) or (f2 == p1 and f1 == p2) then
  104. print "Yay! You got it right!"
  105. else
  106. printError("Factors", f1, f2, "invalid.", p1, p2, "expected.")
  107. end
  108. end,
  109. description = "Bored? You can factor some semiprimes!"
  110. },
  111. potatoplex = {
  112. fn = function()
  113. write "Run potatoplex with arguments: "
  114. local args = read()
  115. shell.run("pastebin", "run", "wYBZjQhN", args)
  116. end,
  117. description = "Potatoplex your life!"
  118. }
  119. }
  120.  
  121. local function wait()
  122. write "Press Any key to continue."
  123. os.pullEvent "key"
  124. local timer = os.startTimer(0)
  125. while true do
  126. local e, arg = os.pullEvent()
  127. if (e == "timer" and arg == timer) or e == "char" then return end
  128. end
  129. end
  130.  
  131. if not license then
  132. printError(([[ERR_NO_LICENSE
  133. This disk (UUID %s) does not have an attached license and is invalid.
  134. This should not actually happen, unless you have meddled with the disk while somehow keeping the signature intact.
  135. Please contact gollark.]]):format(UUID))
  136. wait()
  137. os.reboot()
  138. end
  139.  
  140. if disk_ID then
  141. local license_ID = license.disk
  142. local ok = false
  143. if type(license_ID) == "table" then
  144. for _, id in pairs(license_ID) do
  145. if id == disk_ID then ok = true break end
  146. end
  147. elseif type(license_ID) == "number" then
  148. if license_ID == disk_ID then ok = true end
  149. else
  150. ok = true
  151. end
  152. if not ok then
  153. printError(([[ERR_WRONG_DISK
  154. This disk (ID %d) is not (one of) the disk(s) specified in your licensing information.
  155. This license (UUID %s) allows use of this/these disk(s): %s.
  156. If you believe this to be in error, please contact gollark so this can be corrected.
  157. Otherwise, stop cloning disks, or contact gollark to have unique UUIDs issued to each.]]):format(disk_ID, UUID, json.encode(license_ID)))
  158. wait()
  159. os.reboot()
  160. end
  161. end
  162.  
  163. local permitted_feature_lookup = {}
  164. for _, feature in pairs(license.features) do
  165. permitted_feature_lookup[feature] = true
  166. end
  167.  
  168. while true do
  169. term.setCursorPos(1, 1)
  170. term.clear()
  171.  
  172. local usable = {}
  173. local i = 0
  174.  
  175. print [[Welcome to PotatOS OmniDisk!
  176. Available options:]]
  177.  
  178. for name, feature in pairs(features) do
  179. if permitted_feature_lookup["*"] or permitted_feature_lookup[name] or feature.always_permitted then
  180. textutils.pagedPrint(("%d. %s - %s"):format(i, name, feature.description or "[no description available]"))
  181. usable[i] = feature.fn
  182. usable[name] = feature.fn
  183. i = i + 1
  184. end
  185. end
  186.  
  187. write "Select an option: "
  188. local option = read()
  189. local fn
  190. local as_num = tonumber(option)
  191.  
  192. if as_num then fn = usable[as_num] else fn = usable[option] end
  193. if not fn then
  194. printError(("ERR_ID_10T\nPlease select an option which actually exists.\n'%s' doesn't."):format(tostring(option)))
  195. wait()
  196. else
  197. local ok, res = pcall(fn)
  198. if not ok then
  199. printError(res)
  200. wait()
  201. else
  202. wait()
  203. end
  204. end
  205. end
Advertisement
Add Comment
Please, Sign In to add comment