Advertisement
Tatantyler

MuSeOS Installer

Sep 14th, 2012
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.06 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3. print("MuSeOS Installer v2")
  4. io.write("Delete all files on hard drive? (Y/N)> ")
  5. local yn = io.read()
  6. yn = string.upper(yn)
  7. if yn == "Y" then
  8.     print("Clearing hard drive...")
  9.     for _,v in ipairs(fs.list("")) do
  10.         if v ~= "disk" and not fs.isReadOnly(v) then
  11.             print("Deleting: "..v)
  12.             fs.delete(v)
  13.         end
  14.         os.sleep(0.5)
  15.     end
  16. else
  17.     print("Will not clear hard drive.")
  18. end
  19.  
  20. term.clear()
  21. term.setCursorPos(1,1)
  22.  
  23. print("Installing MuSeOS...")
  24. os.sleep(0.5)
  25.  
  26. print("Placing OS Folders...")
  27.  
  28. fs.makeDir("os")
  29. fs.makeDir("os/logs")
  30. fs.makeDir("os/users")
  31. fs.makeDir("os/userSettings")
  32. fs.makeDir("apis/")
  33. fs.makeDir("modules/")
  34. fs.makeDir("bin/")
  35. os.sleep(0.5)
  36.  
  37. print("Placing logfiles...")
  38.  
  39. local fsLog = fs.open("os/logs/fileLog", "w")
  40. local osLog = fs.open("os/logs/OSLog", "w")
  41. local httpLog = fs.open("os/logs/HTTPLog", "w")
  42. local rsLog = fs.open("os/logs/RSLog", "w")
  43.  
  44. fsLog.writeLine("[installer] Inital setup.")
  45. osLog.writeLine("[installer] Inital setup.")
  46. httpLog.writeLine("[installer] Inital setup.")
  47. rsLog.writeLine("[installer] Inital setup.")
  48.  
  49. fsLog.close()
  50. osLog.close()
  51. httpLog.close()
  52. rsLog.close()
  53.  
  54. print("Placing protected folders list...")
  55.  
  56. local protectedFolders = fs.open("os/protected", "w")
  57. protectedFolders.close()
  58.  
  59. print("Retrieving MuSeOS...")
  60. os.sleep(0.5)
  61.  
  62. if http then
  63.     print("HTTP API enabled, retrieving from pastebin...")
  64.     shell.run("pastebin", "get", "fquZgJ5p", "MuSeOS")
  65.     os.sleep(0.5)
  66. else
  67.     print("HTTP API not enabled, copying from disk...")
  68.     if not fs.exists("disk/MuSeOS", "r") then
  69.         error("Can't access MuSeOS!")
  70.     end
  71.     local museOS = fs.open("disk/MuSeOS", "r")
  72.     local OSFile = fs.open("MuSeOS", "w")
  73.     OSFile.write(museOS.readAll())
  74.     OSFile.close()
  75.     os.sleep(0.5)
  76. end
  77.  
  78. local startup = fs.open("startup", "w")
  79. startup.writeLine("shell.run('MuSeOS')")
  80. startup.close()
  81.  
  82. print("Installing programs...")
  83. if http then
  84.     print("Downloading installer from pastebin...")
  85.     shell.run("pastebin", "get", "G33dymxf", "programInstaller")
  86. else
  87.     print("Copying installer from disk...")
  88.     if not fs.exists("disk/programInstaller") then
  89.         error("Can't access program installer!")
  90.     end
  91.     local disk_installer = fs.open("disk/programInstalller", "r")
  92.     local installerFile = fs.open("programInstaller", "w")
  93.     installerFile.write(disk_installer.readAll())
  94.     installerFile.close()
  95.     os.sleep(0.5)
  96. end
  97.  
  98. print("Retrieving man pages...")
  99. shell.run("pastebin", "get", "wfeGgwQH", "bin/man")
  100. os.sleep(2.5)
  101. shell.run("programInstaller")
  102. os.sleep(1) -- give it time to run
  103. fs.delete("programInstaller")
  104.  
  105. if turtle then
  106.     print("Making turtle settings file...")
  107.     local settingsFile = fs.open("os/turtle", "w")
  108.     settingsFile.writeLine("true")
  109.     settingsFile.writeLine("true")
  110.     settingsFile.writeLine("true")
  111.     settingsFile.writeLine("true")
  112.     settingsFile.close()
  113. end
  114.  
  115. local function printRootPWDialog(startX, startY)
  116.     local function readAdv(maxChars, startX, startY, replaceChar, returnToStart, backgroundChar)
  117.         term.setCursorBlink(true)
  118.         local function clearArea(clearLine, clearX, clearArea, replaceChar)
  119.             local formerX,formerY = term.getCursorPos()
  120.             for i=0, clearArea do
  121.                 term.setCursorPos(clearX+i, clearLine)
  122.                 if replaceChar ~= nil then
  123.                     io.write(replaceChar)
  124.                 else
  125.                     io.write(" ")
  126.                 end
  127.             end
  128.             term.setCursorPos(formerX,formerY)
  129.         end
  130.        
  131.         local x,y = term.getCursorPos()
  132.        
  133.         term.setCursorPos(startX, startY)
  134.         clearArea(startY, startX, maxChars, backgroundChar)
  135.        
  136.         local input = ""
  137.         while true do
  138.             local event, key = os.pullEvent()
  139.             if event == "key" then
  140.                 if key == 28 or key == 156 then
  141.                     if returnToStart then
  142.                         term.setCursorPos(x,y)
  143.                     end
  144.                     return input
  145.                 elseif key == 14 then
  146.                     input = string.sub(input, 1, #input-1)
  147.                     term.setCursorPos(startX, startY)
  148.                     clearArea(startY, startX, maxChars, backgroundChar)
  149.                     if replaceChar == nil then
  150.                         io.write(input)
  151.                     else
  152.                         for i=1, #input do
  153.                             io.write(replaceChar)
  154.                         end
  155.                     end
  156.                 end
  157.             elseif event == "char" then
  158.                 if maxChars ~= nil then
  159.                     if #input <= maxChars then
  160.                         input = input..key
  161.                         term.setCursorPos(startX, startY)
  162.                         clearArea(startY, startX, maxChars, backgroundChar)
  163.                         if replaceChar == nil then
  164.                             io.write(input)
  165.                         else
  166.                             for i=1, #input do
  167.                                 io.write(replaceChar)
  168.                             end
  169.                         end
  170.                     end
  171.                 else
  172.                     input = input..key
  173.                     term.setCursorPos(startX, startY)
  174.                     clearArea(startY, startX, maxChars, backgroundChar)
  175.                     if replaceChar == nil then
  176.                         io.write(input)
  177.                     else
  178.                         for i=1, #input do
  179.                             io.write(replaceChar)
  180.                         end
  181.                     end
  182.                 end
  183.             end
  184.         end
  185.     end
  186.     term.setCursorPos(startX, startY)
  187.     print("===========================")
  188.     term.setCursorPos(startX, startY+1)
  189.     print("|Type in a root password: |")
  190.     term.setCursorPos(startX, startY+2)
  191.     print("===========================")
  192.     term.setCursorPos(startX, startY+3)
  193.     print("|                         |")
  194.     term.setCursorPos(startX, startY+4)
  195.     print("===========================")
  196.     return readAdv(24, startX+1, startY+3, nil, false, nil)
  197. end
  198.  
  199. term.clear()
  200. term.setCursorPos(1,1)
  201.  
  202. local rootPass = printRootPWDialog(12,4)
  203. term.setCursorBlink(false)
  204. local rootUser = fs.open("os/users/root", "w")
  205. fs.makeDir("os/userSettings/root/")
  206. local protectedList = fs.open("os/protected", "a")
  207. protectedList.writeLine("root")
  208. protectedList.close()
  209. rootUser.write(rootPass)
  210. rootUser.close()
  211. os.sleep(0.5)
  212.  
  213. term.clear()
  214. term.setCursorPos(1,1)
  215.  
  216.  
  217. print(" ")
  218. print(" ")
  219. print("Inital username: root")
  220. print("Inital password: "..rootPass)
  221. print("KEEP YOUR ROOT PASSWORD SECURE.")
  222. print("ANYONE WITH ACCESS TO YOUR ROOT ACCOUNT CAN SEVERELY DAMAGE YOUR OS AND COMPUTER.")
  223. print(" ")
  224. os.sleep(1)
  225. print("This computer will reboot in 5 seconds.")
  226. if fs.exists("disk") and fs.isDir("disk") then
  227.     print("We'll eject the disk for you.")
  228.     disk.eject("right")
  229.     disk.eject("left")
  230.     disk.eject("top")
  231.     disk.eject("bottom")
  232.     disk.eject("front")
  233.     disk.eject("back")
  234. end
  235. os.sleep(5)
  236. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement